4 * IPP routines for the CUPS scheduler.
6 * Copyright 2007-2013 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
9 * This file contains Kerberos support code, copyright 2006 by
12 * These coded instructions, statements, and computer programs are the
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/".
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_subscriptions() - Add any subscriptions for a job.
27 * add_job_uuid() - Add job-uuid attribute to a job.
28 * add_printer() - Add a printer to the system.
29 * add_printer_state_reasons() - Add the "printer-state-reasons" attribute
30 * based upon the printer state...
31 * add_queued_job_count() - Add the "queued-job-count" attribute for the
32 * specified printer or class.
33 * apply_printer_defaults() - Apply printer default options to a job.
34 * authenticate_job() - Set job authentication info.
35 * cancel_all_jobs() - Cancel all or selected print jobs.
36 * cancel_job() - Cancel a print job.
37 * cancel_subscription() - Cancel a subscription.
38 * check_rss_recipient() - Check that we do not have a duplicate RSS
40 * check_quotas() - Check quotas for a printer and user.
41 * close_job() - Close a multi-file job.
42 * copy_attrs() - Copy attributes from one request to another.
43 * copy_banner() - Copy a banner file to the requests directory
44 * for the specified job.
45 * copy_file() - Copy a PPD file or interface script...
46 * copy_model() - Copy a PPD model file, substituting default
48 * copy_job_attrs() - Copy job attributes.
49 * copy_printer_attrs() - Copy printer attributes.
50 * copy_subscription_attrs() - Copy subscription attributes.
51 * create_job() - Print a file to a printer or class.
52 * create_requested_array() - Create an array for the requested-attributes.
53 * create_subscription() - Create a notification subscription.
54 * delete_printer() - Remove a printer or class from the system.
55 * get_default() - Get the default destination.
56 * get_devices() - Get the list of available devices on the
58 * get_document() - Get a copy of a job file.
59 * get_job_attrs() - Get job attributes.
60 * get_jobs() - Get a list of jobs for the specified printer.
61 * get_notifications() - Get events for a subscription.
62 * get_ppd() - Get a named PPD from the local system.
63 * get_ppds() - Get the list of PPD files on the local
65 * get_printer_attrs() - Get printer attributes.
66 * get_printer_supported() - Get printer supported values.
67 * get_printers() - Get a list of printers or classes.
68 * get_subscription_attrs() - Get subscription attributes.
69 * get_subscriptions() - Get subscriptions.
70 * get_username() - Get the username associated with a request.
71 * hold_job() - Hold a print job.
72 * hold_new_jobs() - Hold pending/new jobs on a printer or class.
73 * move_job() - Move a job to a new destination.
74 * ppd_parse_line() - Parse a PPD default line.
75 * print_job() - Print a file to a printer or class.
76 * read_job_ticket() - Read a job ticket embedded in a print file.
77 * reject_jobs() - Reject print jobs to a printer.
78 * release_held_new_jobs() - Release pending/new jobs on a printer or
80 * release_job() - Release a held print job.
81 * renew_subscription() - Renew an existing subscription...
82 * restart_job() - Restart an old print job.
83 * save_auth_info() - Save authentication information for a job.
84 * send_document() - Send a file to a printer or class.
85 * send_http_error() - Send a HTTP error back to the IPP client.
86 * send_ipp_status() - Send a status back to the IPP client.
87 * set_default() - Set the default destination...
88 * set_job_attrs() - Set job attributes.
89 * set_printer_attrs() - Set printer attributes.
90 * set_printer_defaults() - Set printer default options from a request.
91 * start_printer() - Start a printer.
92 * stop_printer() - Stop a printer.
93 * url_encode_attr() - URL-encode a string attribute.
94 * url_encode_string() - URL-encode a string.
95 * user_allowed() - See if a user is allowed to print to a queue.
96 * validate_job() - Validate printer options and destination.
97 * validate_name() - Make sure the printer name only contains
99 * validate_user() - Validate the user for the request.
103 * Include necessary headers...
107 #include <cups/ppd-private.h>
110 /*# include <ApplicationServices/ApplicationServices.h>
111 extern CFUUIDRef ColorSyncCreateUUIDFromUInt32(unsigned id);
112 # include <CoreFoundation/CoreFoundation.h>*/
113 # ifdef HAVE_MEMBERSHIP_H
114 # include <membership.h>
115 # endif /* HAVE_MEMBERSHIP_H */
116 # ifdef HAVE_MEMBERSHIPPRIV_H
117 # include <membershipPriv.h>
119 extern int mbr_user_name_to_uuid(const char* name
, uuid_t uu
);
120 extern int mbr_group_name_to_uuid(const char* name
, uuid_t uu
);
121 extern int mbr_check_membership_by_id(uuid_t user
, gid_t group
, int* ismember
);
122 # endif /* HAVE_MEMBERSHIPPRIV_H */
123 #endif /* __APPLE__ */
130 static void accept_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
131 static void add_class(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
132 static int add_file(cupsd_client_t
*con
, cupsd_job_t
*job
,
133 mime_type_t
*filetype
, int compression
);
134 static cupsd_job_t
*add_job(cupsd_client_t
*con
, cupsd_printer_t
*printer
,
135 mime_type_t
*filetype
);
136 static void add_job_subscriptions(cupsd_client_t
*con
, cupsd_job_t
*job
);
137 static void add_job_uuid(cupsd_job_t
*job
);
138 static void add_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
139 static void add_printer_state_reasons(cupsd_client_t
*con
,
141 static void add_queued_job_count(cupsd_client_t
*con
, cupsd_printer_t
*p
);
142 static void apply_printer_defaults(cupsd_printer_t
*printer
,
144 static void authenticate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
145 static void cancel_all_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
146 static void cancel_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
147 static void cancel_subscription(cupsd_client_t
*con
, int id
);
148 static int check_rss_recipient(const char *recipient
);
149 static int check_quotas(cupsd_client_t
*con
, cupsd_printer_t
*p
);
150 static void close_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
151 static void copy_attrs(ipp_t
*to
, ipp_t
*from
, cups_array_t
*ra
,
152 ipp_tag_t group
, int quickcopy
,
153 cups_array_t
*exclude
);
154 static int copy_banner(cupsd_client_t
*con
, cupsd_job_t
*job
,
156 static int copy_file(const char *from
, const char *to
);
157 static int copy_model(cupsd_client_t
*con
, const char *from
,
159 static void copy_job_attrs(cupsd_client_t
*con
,
161 cups_array_t
*ra
, cups_array_t
*exclude
);
162 static void copy_printer_attrs(cupsd_client_t
*con
,
163 cupsd_printer_t
*printer
,
165 static void copy_subscription_attrs(cupsd_client_t
*con
,
166 cupsd_subscription_t
*sub
,
168 cups_array_t
*exclude
);
169 static void create_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
170 static cups_array_t
*create_requested_array(ipp_t
*request
);
171 static void create_subscription(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
172 static void delete_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
173 static void get_default(cupsd_client_t
*con
);
174 static void get_devices(cupsd_client_t
*con
);
175 static void get_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
176 static void get_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
177 static void get_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
178 static void get_notifications(cupsd_client_t
*con
);
179 static void get_ppd(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
180 static void get_ppds(cupsd_client_t
*con
);
181 static void get_printers(cupsd_client_t
*con
, int type
);
182 static void get_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
183 static void get_printer_supported(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
184 static void get_subscription_attrs(cupsd_client_t
*con
, int sub_id
);
185 static void get_subscriptions(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
186 static const char *get_username(cupsd_client_t
*con
);
187 static void hold_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
188 static void hold_new_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
189 static void move_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
190 static int ppd_parse_line(const char *line
, char *option
, int olen
,
191 char *choice
, int clen
);
192 static void print_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
193 static void read_job_ticket(cupsd_client_t
*con
);
194 static void reject_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
195 static void release_held_new_jobs(cupsd_client_t
*con
,
196 ipp_attribute_t
*uri
);
197 static void release_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
198 static void renew_subscription(cupsd_client_t
*con
, int sub_id
);
199 static void restart_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
200 static void save_auth_info(cupsd_client_t
*con
, cupsd_job_t
*job
,
201 ipp_attribute_t
*auth_info
);
202 static void send_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
203 static void send_http_error(cupsd_client_t
*con
, http_status_t status
,
204 cupsd_printer_t
*printer
);
205 static void send_ipp_status(cupsd_client_t
*con
, ipp_status_t status
,
206 const char *message
, ...)
207 __attribute__((__format__(__printf__
, 3, 4)));
208 static void set_default(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
209 static void set_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
210 static void set_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
211 static void set_printer_defaults(cupsd_client_t
*con
,
212 cupsd_printer_t
*printer
);
213 static void start_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
214 static void stop_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
215 static void url_encode_attr(ipp_attribute_t
*attr
, char *buffer
,
217 static char *url_encode_string(const char *s
, char *buffer
, int bufsize
);
218 static int user_allowed(cupsd_printer_t
*p
, const char *username
);
219 static void validate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
220 static int validate_name(const char *name
);
221 static int validate_user(cupsd_job_t
*job
, cupsd_client_t
*con
,
222 const char *owner
, char *username
,
227 * 'cupsdProcessIPPRequest()' - Process an incoming IPP request.
230 int /* O - 1 on success, 0 on failure */
231 cupsdProcessIPPRequest(
232 cupsd_client_t
*con
) /* I - Client connection */
234 ipp_tag_t group
; /* Current group tag */
235 ipp_attribute_t
*attr
; /* Current attribute */
236 ipp_attribute_t
*charset
; /* Character set attribute */
237 ipp_attribute_t
*language
; /* Language attribute */
238 ipp_attribute_t
*uri
= NULL
; /* Printer or job URI attribute */
239 ipp_attribute_t
*username
; /* requesting-user-name attr */
240 int sub_id
; /* Subscription ID */
243 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
244 "cupsdProcessIPPRequest(%p[%d]): operation_id = %04x",
245 con
, con
->http
.fd
, con
->request
->request
.op
.operation_id
);
248 * First build an empty response message for this request...
251 con
->response
= ippNew();
253 con
->response
->request
.status
.version
[0] =
254 con
->request
->request
.op
.version
[0];
255 con
->response
->request
.status
.version
[1] =
256 con
->request
->request
.op
.version
[1];
257 con
->response
->request
.status
.request_id
=
258 con
->request
->request
.op
.request_id
;
261 * Then validate the request header and required attributes...
264 if (con
->request
->request
.any
.version
[0] != 1 &&
265 con
->request
->request
.any
.version
[0] != 2)
268 * Return an error, since we only support IPP 1.x and 2.x.
271 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
272 "%04X %s Bad request version number %d.%d",
273 IPP_VERSION_NOT_SUPPORTED
, con
->http
.hostname
,
274 con
->request
->request
.any
.version
[0],
275 con
->request
->request
.any
.version
[1]);
277 send_ipp_status(con
, IPP_VERSION_NOT_SUPPORTED
,
278 _("Bad request version number %d.%d."),
279 con
->request
->request
.any
.version
[0],
280 con
->request
->request
.any
.version
[1]);
282 else if (con
->request
->request
.any
.request_id
< 1)
285 * Return an error, since request IDs must be between 1 and 2^31-1
288 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
289 "%04X %s Bad request ID %d",
290 IPP_BAD_REQUEST
, con
->http
.hostname
,
291 con
->request
->request
.any
.request_id
);
293 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad request ID %d."),
294 con
->request
->request
.any
.request_id
);
296 else if (!con
->request
->attrs
)
298 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
299 "%04X %s No attributes in request",
300 IPP_BAD_REQUEST
, con
->http
.hostname
);
302 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No attributes in request."));
307 * Make sure that the attributes are provided in the correct order and
308 * don't repeat groups...
311 for (attr
= con
->request
->attrs
, group
= attr
->group_tag
;
314 if (attr
->group_tag
< group
&& attr
->group_tag
!= IPP_TAG_ZERO
)
317 * Out of order; return an error...
320 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
321 "%04X %s Attribute groups are out of order",
322 IPP_BAD_REQUEST
, con
->http
.hostname
);
324 send_ipp_status(con
, IPP_BAD_REQUEST
,
325 _("Attribute groups are out of order (%x < %x)."),
326 attr
->group_tag
, group
);
330 group
= attr
->group_tag
;
335 * Then make sure that the first three attributes are:
338 * attributes-natural-language
339 * printer-uri/job-uri
342 attr
= con
->request
->attrs
;
343 if (attr
&& attr
->name
&&
344 !strcmp(attr
->name
, "attributes-charset") &&
345 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_CHARSET
)
353 if (attr
&& attr
->name
&&
354 !strcmp(attr
->name
, "attributes-natural-language") &&
355 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_LANGUAGE
)
360 * Reset language for this request if different from Accept-Language.
363 if (!con
->language
||
364 strcmp(attr
->values
[0].string
.text
, con
->language
->language
))
366 cupsLangFree(con
->language
);
367 con
->language
= cupsLangGet(attr
->values
[0].string
.text
);
373 if ((attr
= ippFindAttribute(con
->request
, "printer-uri",
374 IPP_TAG_URI
)) != NULL
)
376 else if ((attr
= ippFindAttribute(con
->request
, "job-uri",
377 IPP_TAG_URI
)) != NULL
)
379 else if (con
->request
->request
.op
.operation_id
== CUPS_GET_PPD
)
380 uri
= ippFindAttribute(con
->request
, "ppd-name", IPP_TAG_NAME
);
385 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
386 "attributes-charset", NULL
,
387 charset
->values
[0].string
.text
);
389 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
390 "attributes-charset", NULL
, "utf-8");
393 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
394 "attributes-natural-language", NULL
,
395 language
->values
[0].string
.text
);
397 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
398 "attributes-natural-language", NULL
, DefaultLanguage
);
401 _cups_strcasecmp(charset
->values
[0].string
.text
, "us-ascii") &&
402 _cups_strcasecmp(charset
->values
[0].string
.text
, "utf-8"))
405 * Bad character set...
408 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unsupported character set \"%s\"",
409 charset
->values
[0].string
.text
);
410 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
411 "%04X %s Unsupported attributes-charset value \"%s\"",
412 IPP_CHARSET
, con
->http
.hostname
,
413 charset
->values
[0].string
.text
);
414 send_ipp_status(con
, IPP_BAD_REQUEST
,
415 _("Unsupported character set \"%s\"."),
416 charset
->values
[0].string
.text
);
418 else if (!charset
|| !language
||
420 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEFAULT
&&
421 con
->request
->request
.op
.operation_id
!= CUPS_GET_PRINTERS
&&
422 con
->request
->request
.op
.operation_id
!= CUPS_GET_CLASSES
&&
423 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEVICES
&&
424 con
->request
->request
.op
.operation_id
!= CUPS_GET_PPDS
))
427 * Return an error, since attributes-charset,
428 * attributes-natural-language, and printer-uri/job-uri are required
429 * for all operations.
434 cupsdLogMessage(CUPSD_LOG_ERROR
,
435 "Missing attributes-charset attribute");
437 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
438 "%04X %s Missing attributes-charset attribute",
439 IPP_BAD_REQUEST
, con
->http
.hostname
);
444 cupsdLogMessage(CUPSD_LOG_ERROR
,
445 "Missing attributes-natural-language attribute");
447 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
448 "%04X %s Missing attributes-natural-language attribute",
449 IPP_BAD_REQUEST
, con
->http
.hostname
);
454 cupsdLogMessage(CUPSD_LOG_ERROR
,
455 "Missing printer-uri, job-uri, or ppd-name "
458 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
459 "%04X %s Missing printer-uri, job-uri, or ppd-name "
460 "attribute", IPP_BAD_REQUEST
, con
->http
.hostname
);
463 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Request attributes follow...");
465 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
466 cupsdLogMessage(CUPSD_LOG_DEBUG
,
467 "attr \"%s\": group_tag = %x, value_tag = %x",
468 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
471 cupsdLogMessage(CUPSD_LOG_DEBUG
, "End of attributes...");
473 send_ipp_status(con
, IPP_BAD_REQUEST
,
474 _("Missing required attributes."));
479 * OK, all the checks pass so far; make sure requesting-user-name is
480 * not "root" from a remote host...
483 if ((username
= ippFindAttribute(con
->request
, "requesting-user-name",
484 IPP_TAG_NAME
)) != NULL
)
487 * Check for root user...
490 if (!strcmp(username
->values
[0].string
.text
, "root") &&
491 _cups_strcasecmp(con
->http
.hostname
, "localhost") &&
492 strcmp(con
->username
, "root"))
495 * Remote unauthenticated user masquerading as local root...
498 _cupsStrFree(username
->values
[0].string
.text
);
499 username
->values
[0].string
.text
= _cupsStrAlloc(RemoteRoot
);
503 if ((attr
= ippFindAttribute(con
->request
, "notify-subscription-id",
504 IPP_TAG_INTEGER
)) != NULL
)
505 sub_id
= attr
->values
[0].integer
;
510 * Then try processing the operation...
514 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s",
515 ippOpString(con
->request
->request
.op
.operation_id
),
516 uri
->values
[0].string
.text
);
518 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s",
519 ippOpString(con
->request
->request
.op
.operation_id
));
521 switch (con
->request
->request
.op
.operation_id
)
527 case IPP_VALIDATE_JOB
:
528 validate_job(con
, uri
);
531 case IPP_CREATE_JOB
:
532 create_job(con
, uri
);
535 case IPP_SEND_DOCUMENT
:
536 send_document(con
, uri
);
539 case IPP_CANCEL_JOB
:
540 cancel_job(con
, uri
);
543 case IPP_GET_JOB_ATTRIBUTES
:
544 get_job_attrs(con
, uri
);
551 case IPP_GET_PRINTER_ATTRIBUTES
:
552 get_printer_attrs(con
, uri
);
555 case IPP_GET_PRINTER_SUPPORTED_VALUES
:
556 get_printer_supported(con
, uri
);
563 case IPP_RELEASE_JOB
:
564 release_job(con
, uri
);
567 case IPP_RESTART_JOB
:
568 restart_job(con
, uri
);
571 case IPP_PAUSE_PRINTER
:
572 stop_printer(con
, uri
);
575 case IPP_RESUME_PRINTER
:
576 start_printer(con
, uri
);
579 case IPP_PURGE_JOBS
:
580 case IPP_CANCEL_JOBS
:
581 case IPP_CANCEL_MY_JOBS
:
582 cancel_all_jobs(con
, uri
);
585 case IPP_SET_JOB_ATTRIBUTES
:
586 set_job_attrs(con
, uri
);
589 case IPP_SET_PRINTER_ATTRIBUTES
:
590 set_printer_attrs(con
, uri
);
593 case IPP_HOLD_NEW_JOBS
:
594 hold_new_jobs(con
, uri
);
597 case IPP_RELEASE_HELD_NEW_JOBS
:
598 release_held_new_jobs(con
, uri
);
605 case CUPS_GET_DEFAULT
:
609 case CUPS_GET_PRINTERS
:
610 get_printers(con
, 0);
613 case CUPS_GET_CLASSES
:
614 get_printers(con
, CUPS_PRINTER_CLASS
);
617 case CUPS_ADD_PRINTER
:
618 add_printer(con
, uri
);
621 case CUPS_DELETE_PRINTER
:
622 delete_printer(con
, uri
);
625 case CUPS_ADD_CLASS
:
629 case CUPS_DELETE_CLASS
:
630 delete_printer(con
, uri
);
633 case CUPS_ACCEPT_JOBS
:
634 case IPP_ENABLE_PRINTER
:
635 accept_jobs(con
, uri
);
638 case CUPS_REJECT_JOBS
:
639 case IPP_DISABLE_PRINTER
:
640 reject_jobs(con
, uri
);
643 case CUPS_SET_DEFAULT
:
644 set_default(con
, uri
);
647 case CUPS_GET_DEVICES
:
651 case CUPS_GET_DOCUMENT
:
652 get_document(con
, uri
);
667 case CUPS_AUTHENTICATE_JOB
:
668 authenticate_job(con
, uri
);
671 case IPP_CREATE_PRINTER_SUBSCRIPTION
:
672 case IPP_CREATE_JOB_SUBSCRIPTION
:
673 create_subscription(con
, uri
);
676 case IPP_GET_SUBSCRIPTION_ATTRIBUTES
:
677 get_subscription_attrs(con
, sub_id
);
680 case IPP_GET_SUBSCRIPTIONS
:
681 get_subscriptions(con
, uri
);
684 case IPP_RENEW_SUBSCRIPTION
:
685 renew_subscription(con
, sub_id
);
688 case IPP_CANCEL_SUBSCRIPTION
:
689 cancel_subscription(con
, sub_id
);
692 case IPP_GET_NOTIFICATIONS
:
693 get_notifications(con
);
697 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
698 "%04X %s Operation %04X (%s) not supported",
699 IPP_OPERATION_NOT_SUPPORTED
, con
->http
.hostname
,
700 con
->request
->request
.op
.operation_id
,
701 ippOpString(con
->request
->request
.op
.operation_id
));
703 send_ipp_status(con
, IPP_OPERATION_NOT_SUPPORTED
,
704 _("%s not supported."),
706 con
->request
->request
.op
.operation_id
));
716 * Sending data from the scheduler...
719 cupsdLogMessage(con
->response
->request
.status
.status_code
720 >= IPP_BAD_REQUEST
&&
721 con
->response
->request
.status
.status_code
722 != IPP_NOT_FOUND
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
723 "[Client %d] Returning IPP %s for %s (%s) from %s",
725 ippErrorString(con
->response
->request
.status
.status_code
),
726 ippOpString(con
->request
->request
.op
.operation_id
),
727 uri
? uri
->values
[0].string
.text
: "no URI",
730 if (cupsdSendHeader(con
, HTTP_OK
, "application/ipp", CUPSD_AUTH_NONE
))
732 #ifdef CUPSD_USE_CHUNKING
734 * Because older versions of CUPS (1.1.17 and older) and some IPP
735 * clients do not implement chunking properly, we cannot use
736 * chunking by default. This may become the default in future
737 * CUPS releases, or we might add a configuration directive for
741 if (con
->http
.version
== HTTP_1_1
)
743 cupsdLogMessage(CUPSD_LOG_DEBUG
,
744 "[Client %d] Transfer-Encoding: chunked",
747 if (httpPrintf(HTTP(con
), "Transfer-Encoding: chunked\r\n\r\n") < 0)
750 if (cupsdFlushHeader(con
) < 0)
753 con
->http
.data_encoding
= HTTP_ENCODE_CHUNKED
;
756 #endif /* CUPSD_USE_CHUNKING */
758 size_t length
; /* Length of response */
761 length
= ippLength(con
->response
);
763 if (con
->file
>= 0 && !con
->pipe_pid
)
765 struct stat fileinfo
; /* File information */
767 if (!fstat(con
->file
, &fileinfo
))
768 length
+= fileinfo
.st_size
;
771 cupsdLogMessage(CUPSD_LOG_DEBUG
,
772 "[Client %d] Content-Length: " CUPS_LLFMT
,
773 con
->http
.fd
, CUPS_LLCAST length
);
774 if (httpPrintf(HTTP(con
), "Content-Length: " CUPS_LLFMT
"\r\n\r\n",
775 CUPS_LLCAST length
) < 0)
778 if (cupsdFlushHeader(con
) < 0)
781 con
->http
.data_encoding
= HTTP_ENCODE_LENGTH
;
782 con
->http
.data_remaining
= length
;
784 if (con
->http
.data_remaining
<= INT_MAX
)
785 con
->http
._data_remaining
= con
->http
.data_remaining
;
787 con
->http
._data_remaining
= INT_MAX
;
790 cupsdAddSelect(con
->http
.fd
, (cupsd_selfunc_t
)cupsdReadClient
,
791 (cupsd_selfunc_t
)cupsdWriteClient
, con
);
794 * Tell the caller the response header was sent successfully...
802 * Tell the caller the response header could not be sent...
811 * Sending data from a subprocess like cups-deviced; tell the caller
812 * everything is A-OK so far...
821 * 'cupsdTimeoutJob()' - Timeout a job waiting on job files.
824 int /* O - 0 on success, -1 on error */
825 cupsdTimeoutJob(cupsd_job_t
*job
) /* I - Job to timeout */
827 cupsd_printer_t
*printer
; /* Destination printer or class */
828 ipp_attribute_t
*attr
; /* job-sheets attribute */
829 int kbytes
; /* Kilobytes in banner */
832 job
->pending_timeout
= 0;
835 * See if we need to add the ending sheet...
838 if (!cupsdLoadJob(job
))
841 printer
= cupsdFindDest(job
->dest
);
842 attr
= ippFindAttribute(job
->attrs
, "job-sheets", IPP_TAG_NAME
);
844 if (printer
&& !(printer
->type
& CUPS_PRINTER_REMOTE
) &&
845 attr
&& attr
->num_values
> 1)
851 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding end banner page \"%s\".",
852 attr
->values
[1].string
.text
);
854 if ((kbytes
= copy_banner(NULL
, job
, attr
->values
[1].string
.text
)) < 0)
857 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
865 * 'accept_jobs()' - Accept print jobs to a printer.
869 accept_jobs(cupsd_client_t
*con
, /* I - Client connection */
870 ipp_attribute_t
*uri
) /* I - Printer or class URI */
872 http_status_t status
; /* Policy status */
873 cups_ptype_t dtype
; /* Destination type (printer/class) */
874 cupsd_printer_t
*printer
; /* Printer data */
877 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "accept_jobs(%p[%d], %s)", con
,
878 con
->http
.fd
, uri
->values
[0].string
.text
);
881 * Is the destination valid?
884 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
890 send_ipp_status(con
, IPP_NOT_FOUND
,
891 _("The printer or class does not exist."));
899 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
901 send_http_error(con
, status
, printer
);
906 * Accept jobs sent to the printer...
909 printer
->accepting
= 1;
910 printer
->state_message
[0] = '\0';
912 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
913 "Now accepting jobs.");
915 if (dtype
& CUPS_PRINTER_CLASS
)
917 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
919 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" now accepting jobs (\"%s\").",
920 printer
->name
, get_username(con
));
924 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
926 cupsdLogMessage(CUPSD_LOG_INFO
,
927 "Printer \"%s\" now accepting jobs (\"%s\").",
928 printer
->name
, get_username(con
));
932 * Everything was ok, so return OK status...
935 con
->response
->request
.status
.status_code
= IPP_OK
;
940 * 'add_class()' - Add a class to the system.
944 add_class(cupsd_client_t
*con
, /* I - Client connection */
945 ipp_attribute_t
*uri
) /* I - URI of class */
947 http_status_t status
; /* Policy status */
948 int i
; /* Looping var */
949 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
950 username
[HTTP_MAX_URI
], /* Username portion of URI */
951 host
[HTTP_MAX_URI
], /* Host portion of URI */
952 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
953 int port
; /* Port portion of URI */
954 cupsd_printer_t
*pclass
, /* Class */
955 *member
; /* Member printer/class */
956 cups_ptype_t dtype
; /* Destination type */
957 ipp_attribute_t
*attr
; /* Printer attribute */
958 int modify
; /* Non-zero if we just modified */
959 int need_restart_job
; /* Need to restart job? */
962 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_class(%p[%d], %s)", con
,
963 con
->http
.fd
, uri
->values
[0].string
.text
);
966 * Do we have a valid URI?
969 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
970 sizeof(scheme
), username
, sizeof(username
), host
,
971 sizeof(host
), &port
, resource
, sizeof(resource
));
974 if (strncmp(resource
, "/classes/", 9) || strlen(resource
) == 9)
977 * No, return an error...
980 send_ipp_status(con
, IPP_BAD_REQUEST
,
981 _("The printer-uri must be of the form "
982 "\"ipp://HOSTNAME/classes/CLASSNAME\"."));
987 * Do we have a valid printer name?
990 if (!validate_name(resource
+ 9))
993 * No, return an error...
996 send_ipp_status(con
, IPP_BAD_REQUEST
,
997 _("The printer-uri \"%s\" contains invalid characters."),
998 uri
->values
[0].string
.text
);
1003 * See if the class already exists; if not, create a new class...
1006 if ((pclass
= cupsdFindClass(resource
+ 9)) == NULL
)
1009 * Class doesn't exist; see if we have a printer of the same name...
1012 if ((pclass
= cupsdFindPrinter(resource
+ 9)) != NULL
)
1015 * Yes, return an error...
1018 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
1019 _("A printer named \"%s\" already exists."),
1025 * No, check the default policy and then add the class...
1028 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1030 send_http_error(con
, status
, NULL
);
1034 pclass
= cupsdAddClass(resource
+ 9);
1037 else if ((status
= cupsdCheckPolicy(pclass
->op_policy_ptr
, con
,
1040 send_http_error(con
, status
, pclass
);
1047 * Look for attributes and copy them over as needed...
1050 need_restart_job
= 0;
1052 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
1053 IPP_TAG_TEXT
)) != NULL
)
1054 cupsdSetString(&pclass
->location
, attr
->values
[0].string
.text
);
1056 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
1057 IPP_TAG_TEXT
)) != NULL
)
1058 cupsdSetString(&pclass
->info
, attr
->values
[0].string
.text
);
1060 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
1061 IPP_TAG_BOOLEAN
)) != NULL
&&
1062 attr
->values
[0].boolean
!= pclass
->accepting
)
1064 cupsdLogMessage(CUPSD_LOG_INFO
,
1065 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
1066 pclass
->name
, attr
->values
[0].boolean
, pclass
->accepting
);
1068 pclass
->accepting
= attr
->values
[0].boolean
;
1070 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s accepting jobs.",
1071 pclass
->accepting
? "Now" : "No longer");
1074 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
1075 IPP_TAG_BOOLEAN
)) != NULL
)
1077 if (pclass
->shared
&& !attr
->values
[0].boolean
)
1078 cupsdDeregisterPrinter(pclass
, 1);
1080 cupsdLogMessage(CUPSD_LOG_INFO
,
1081 "Setting %s printer-is-shared to %d (was %d.)",
1082 pclass
->name
, attr
->values
[0].boolean
, pclass
->shared
);
1084 pclass
->shared
= attr
->values
[0].boolean
;
1087 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
1088 IPP_TAG_ENUM
)) != NULL
)
1090 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
1091 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
1093 send_ipp_status(con
, IPP_BAD_REQUEST
,
1094 _("Attempt to set %s printer-state to bad value %d."),
1095 pclass
->name
, attr
->values
[0].integer
);
1099 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
1100 pclass
->name
, attr
->values
[0].integer
, pclass
->state
);
1102 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
1103 cupsdStopPrinter(pclass
, 0);
1106 cupsdSetPrinterState(pclass
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
1107 need_restart_job
= 1;
1110 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
1111 IPP_TAG_TEXT
)) != NULL
)
1113 strlcpy(pclass
->state_message
, attr
->values
[0].string
.text
,
1114 sizeof(pclass
->state_message
));
1116 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s",
1117 pclass
->state_message
);
1119 if ((attr
= ippFindAttribute(con
->request
, "member-uris",
1120 IPP_TAG_URI
)) != NULL
)
1123 * Clear the printer array as needed...
1126 need_restart_job
= 1;
1128 if (pclass
->num_printers
> 0)
1130 free(pclass
->printers
);
1131 pclass
->num_printers
= 0;
1135 * Add each printer or class that is listed...
1138 for (i
= 0; i
< attr
->num_values
; i
++)
1141 * Search for the printer or class URI...
1144 if (!cupsdValidateDest(attr
->values
[i
].string
.text
, &dtype
, &member
))
1150 send_ipp_status(con
, IPP_NOT_FOUND
,
1151 _("The printer or class does not exist."));
1154 else if (dtype
& CUPS_PRINTER_CLASS
)
1156 send_ipp_status(con
, IPP_BAD_REQUEST
,
1157 _("Nested classes are not allowed."));
1162 * Add it to the class...
1165 cupsdAddPrinterToClass(pclass
, member
);
1169 set_printer_defaults(con
, pclass
);
1171 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
1172 IPP_TAG_KEYWORD
)) != NULL
)
1173 cupsdSetAuthInfoRequired(pclass
, NULL
, attr
);
1176 * Update the printer class attributes and return...
1179 cupsdSetPrinterAttrs(pclass
);
1180 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
1182 if (need_restart_job
&& pclass
->job
)
1185 * Reset the current job to a "pending" status...
1188 cupsdSetJobState(pclass
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
1189 "Job restarted because the class was modified.");
1192 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1196 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
1197 pclass
, NULL
, "Class \"%s\" modified by \"%s\".",
1198 pclass
->name
, get_username(con
));
1200 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" modified by \"%s\".",
1201 pclass
->name
, get_username(con
));
1205 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
1206 pclass
, NULL
, "New class \"%s\" added by \"%s\".",
1207 pclass
->name
, get_username(con
));
1209 cupsdLogMessage(CUPSD_LOG_INFO
, "New class \"%s\" added by \"%s\".",
1210 pclass
->name
, get_username(con
));
1213 con
->response
->request
.status
.status_code
= IPP_OK
;
1218 * 'add_file()' - Add a file to a job.
1221 static int /* O - 0 on success, -1 on error */
1222 add_file(cupsd_client_t
*con
, /* I - Connection to client */
1223 cupsd_job_t
*job
, /* I - Job to add to */
1224 mime_type_t
*filetype
, /* I - Type of file */
1225 int compression
) /* I - Compression */
1227 mime_type_t
**filetypes
; /* New filetypes array... */
1228 int *compressions
; /* New compressions array... */
1231 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1232 "add_file(con=%p[%d], job=%d, filetype=%s/%s, "
1233 "compression=%d)", con
, con
? con
->http
.fd
: -1, job
->id
,
1234 filetype
->super
, filetype
->type
, compression
);
1237 * Add the file to the job...
1240 if (job
->num_files
== 0)
1242 compressions
= (int *)malloc(sizeof(int));
1243 filetypes
= (mime_type_t
**)malloc(sizeof(mime_type_t
*));
1247 compressions
= (int *)realloc(job
->compressions
,
1248 (job
->num_files
+ 1) * sizeof(int));
1249 filetypes
= (mime_type_t
**)realloc(job
->filetypes
,
1250 (job
->num_files
+ 1) *
1251 sizeof(mime_type_t
*));
1255 job
->compressions
= compressions
;
1258 job
->filetypes
= filetypes
;
1260 if (!compressions
|| !filetypes
)
1262 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1263 "Job aborted because the scheduler ran out of memory.");
1266 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1267 _("Unable to allocate memory for file types."));
1272 job
->compressions
[job
->num_files
] = compression
;
1273 job
->filetypes
[job
->num_files
] = filetype
;
1278 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1285 * 'add_job()' - Add a job to a print queue.
1288 static cupsd_job_t
* /* O - Job object */
1289 add_job(cupsd_client_t
*con
, /* I - Client connection */
1290 cupsd_printer_t
*printer
, /* I - Destination printer */
1291 mime_type_t
*filetype
) /* I - First print file type, if any */
1293 http_status_t status
; /* Policy status */
1294 ipp_attribute_t
*attr
, /* Current attribute */
1295 *auth_info
; /* auth-info attribute */
1296 const char *mandatory
; /* Current mandatory job attribute */
1297 const char *val
; /* Default option value */
1298 int priority
; /* Job priority */
1299 cupsd_job_t
*job
; /* Current job */
1300 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
1301 int kbytes
; /* Size of print file */
1302 int i
; /* Looping var */
1303 int lowerpagerange
; /* Page range bound */
1304 int exact
; /* Did we have an exact match? */
1305 ipp_attribute_t
*media_col
, /* media-col attribute */
1306 *media_margin
; /* media-*-margin attribute */
1307 ipp_t
*unsup_col
; /* media-col in unsupported response */
1308 static const char * const readonly
[] =/* List of read-only attributes */
1311 "job-k-octets-completed",
1312 "job-impressions-completed",
1313 "job-media-sheets-completed",
1315 "job-state-message",
1316 "job-state-reasons",
1317 "time-at-completed",
1319 "time-at-processing"
1323 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job(%p[%d], %p(%s), %p(%s/%s))",
1324 con
, con
->http
.fd
, printer
, printer
->name
,
1325 filetype
, filetype
? filetype
->super
: "none",
1326 filetype
? filetype
->type
: "none");
1329 * Check remote printing to non-shared printer...
1332 if (!printer
->shared
&&
1333 _cups_strcasecmp(con
->http
.hostname
, "localhost") &&
1334 _cups_strcasecmp(con
->http
.hostname
, ServerName
))
1336 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
1337 _("The printer or class is not shared."));
1345 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
1347 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
1349 send_http_error(con
, status
, printer
);
1352 else if (printer
->num_auth_info_required
== 1 &&
1353 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
1356 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
1360 else if (auth_info
&& !con
->http
.tls
&&
1361 !httpAddrLocalhost(con
->http
.hostaddr
))
1364 * Require encryption of auth-info over non-local connections...
1367 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
1370 #endif /* HAVE_SSL */
1373 * See if the printer is accepting jobs...
1376 if (!printer
->accepting
)
1378 send_ipp_status(con
, IPP_NOT_ACCEPTING
,
1379 _("Destination \"%s\" is not accepting jobs."),
1385 * Validate job template attributes; for now just document-format,
1386 * copies, job-sheets, number-up, page-ranges, mandatory attributes, and
1390 for (i
= 0; i
< (int)(sizeof(readonly
) / sizeof(readonly
[0])); i
++)
1392 if ((attr
= ippFindAttribute(con
->request
, readonly
[i
],
1393 IPP_TAG_ZERO
)) != NULL
)
1395 ippDeleteAttribute(con
->request
, attr
);
1397 if (StrictConformance
)
1399 send_ipp_status(con
, IPP_BAD_REQUEST
,
1400 _("The '%s' Job Description attribute cannot be "
1401 "supplied in a job creation request."), readonly
[i
]);
1405 cupsdLogMessage(CUPSD_LOG_INFO
,
1406 "Unexpected '%s' Job Description attribute in a job "
1407 "creation request.", readonly
[i
]);
1413 for (mandatory
= (char *)cupsArrayFirst(printer
->pc
->mandatory
);
1415 mandatory
= (char *)cupsArrayNext(printer
->pc
->mandatory
))
1417 if (!ippFindAttribute(con
->request
, mandatory
, IPP_TAG_ZERO
))
1420 * Missing a required attribute...
1423 send_ipp_status(con
, IPP_CONFLICT
,
1424 _("The \"%s\" attribute is required for print jobs."),
1431 if (filetype
&& printer
->filetypes
&&
1432 !cupsArrayFind(printer
->filetypes
, filetype
))
1434 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
1435 /* MIME media type string */
1438 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
1441 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
1442 _("Unsupported format \"%s\"."), mimetype
);
1444 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
1445 "document-format", NULL
, mimetype
);
1450 if ((attr
= ippFindAttribute(con
->request
, "copies",
1451 IPP_TAG_INTEGER
)) != NULL
)
1453 if (attr
->values
[0].integer
< 1 || attr
->values
[0].integer
> MaxCopies
)
1455 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad copies value %d."),
1456 attr
->values
[0].integer
);
1457 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1458 "copies", attr
->values
[0].integer
);
1463 if ((attr
= ippFindAttribute(con
->request
, "job-sheets",
1464 IPP_TAG_ZERO
)) != NULL
)
1466 if (attr
->value_tag
!= IPP_TAG_KEYWORD
&&
1467 attr
->value_tag
!= IPP_TAG_NAME
)
1469 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value type."));
1473 if (attr
->num_values
> 2)
1475 send_ipp_status(con
, IPP_BAD_REQUEST
,
1476 _("Too many job-sheets values (%d > 2)."),
1481 for (i
= 0; i
< attr
->num_values
; i
++)
1482 if (strcmp(attr
->values
[i
].string
.text
, "none") &&
1483 !cupsdFindBanner(attr
->values
[i
].string
.text
))
1485 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value \"%s\"."),
1486 attr
->values
[i
].string
.text
);
1491 if ((attr
= ippFindAttribute(con
->request
, "number-up",
1492 IPP_TAG_INTEGER
)) != NULL
)
1494 if (attr
->values
[0].integer
!= 1 &&
1495 attr
->values
[0].integer
!= 2 &&
1496 attr
->values
[0].integer
!= 4 &&
1497 attr
->values
[0].integer
!= 6 &&
1498 attr
->values
[0].integer
!= 9 &&
1499 attr
->values
[0].integer
!= 16)
1501 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad number-up value %d."),
1502 attr
->values
[0].integer
);
1503 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1504 "number-up", attr
->values
[0].integer
);
1509 if ((attr
= ippFindAttribute(con
->request
, "page-ranges",
1510 IPP_TAG_RANGE
)) != NULL
)
1512 for (i
= 0, lowerpagerange
= 1; i
< attr
->num_values
; i
++)
1514 if (attr
->values
[i
].range
.lower
< lowerpagerange
||
1515 attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
1517 send_ipp_status(con
, IPP_BAD_REQUEST
,
1518 _("Bad page-ranges values %d-%d."),
1519 attr
->values
[i
].range
.lower
,
1520 attr
->values
[i
].range
.upper
);
1524 lowerpagerange
= attr
->values
[i
].range
.upper
+ 1;
1529 * Do media selection as needed...
1532 if (!ippFindAttribute(con
->request
, "PageRegion", IPP_TAG_ZERO
) &&
1533 !ippFindAttribute(con
->request
, "PageSize", IPP_TAG_ZERO
) &&
1534 _ppdCacheGetPageSize(printer
->pc
, con
->request
, NULL
, &exact
))
1537 (media_col
= ippFindAttribute(con
->request
, "media-col",
1538 IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
1540 send_ipp_status(con
, IPP_OK_SUBST
, _("Unsupported margins."));
1542 unsup_col
= ippNew();
1543 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1544 "media-bottom-margin",
1545 IPP_TAG_INTEGER
)) != NULL
)
1546 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1547 "media-bottom-margin", media_margin
->values
[0].integer
);
1549 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1550 "media-left-margin",
1551 IPP_TAG_INTEGER
)) != NULL
)
1552 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1553 "media-left-margin", media_margin
->values
[0].integer
);
1555 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1556 "media-right-margin",
1557 IPP_TAG_INTEGER
)) != NULL
)
1558 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1559 "media-right-margin", media_margin
->values
[0].integer
);
1561 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1563 IPP_TAG_INTEGER
)) != NULL
)
1564 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1565 "media-top-margin", media_margin
->values
[0].integer
);
1567 ippAddCollection(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, "media-col",
1569 ippDelete(unsup_col
);
1574 * Make sure we aren't over our limit...
1577 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1580 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1582 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Too many active jobs."));
1586 if ((i
= check_quotas(con
, printer
)) < 0)
1588 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
1593 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
1598 * Create the job and set things up...
1601 if ((attr
= ippFindAttribute(con
->request
, "job-priority",
1602 IPP_TAG_INTEGER
)) != NULL
)
1603 priority
= attr
->values
[0].integer
;
1606 if ((val
= cupsGetOption("job-priority", printer
->num_options
,
1607 printer
->options
)) != NULL
)
1608 priority
= atoi(val
);
1612 ippAddInteger(con
->request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-priority",
1616 if ((attr
= ippFindAttribute(con
->request
, "job-name", IPP_TAG_ZERO
)) == NULL
)
1617 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
,
1619 else if ((attr
->value_tag
!= IPP_TAG_NAME
&&
1620 attr
->value_tag
!= IPP_TAG_NAMELANG
) ||
1621 attr
->num_values
!= 1)
1623 send_ipp_status(con
, IPP_ATTRIBUTES
,
1624 _("Bad job-name value: Wrong type or count."));
1625 if ((attr
= ippCopyAttribute(con
->response
, attr
, 0)) != NULL
)
1626 attr
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
1629 else if (!ippValidateAttribute(attr
))
1631 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad job-name value: %s"),
1632 cupsLastErrorString());
1633 if ((attr
= ippCopyAttribute(con
->response
, attr
, 0)) != NULL
)
1634 attr
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
1638 if ((job
= cupsdAddJob(priority
, printer
->name
)) == NULL
)
1640 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1641 _("Unable to add job for destination \"%s\"."),
1646 job
->dtype
= printer
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
1647 job
->attrs
= con
->request
;
1649 con
->request
= ippNewRequest(job
->attrs
->request
.op
.operation_id
);
1651 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1654 apply_printer_defaults(printer
, job
);
1656 attr
= ippFindAttribute(job
->attrs
, "requesting-user-name", IPP_TAG_NAME
);
1658 if (con
->username
[0])
1660 cupsdSetString(&job
->username
, con
->username
);
1663 cupsdSetString(&attr
->values
[0].string
.text
, con
->username
);
1667 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1668 "add_job: requesting-user-name=\"%s\"",
1669 attr
->values
[0].string
.text
);
1671 cupsdSetString(&job
->username
, attr
->values
[0].string
.text
);
1674 cupsdSetString(&job
->username
, "anonymous");
1677 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1678 "job-originating-user-name", NULL
, job
->username
);
1681 attr
->group_tag
= IPP_TAG_JOB
;
1682 _cupsStrFree(attr
->name
);
1683 attr
->name
= _cupsStrAlloc("job-originating-user-name");
1686 if (con
->username
[0] || auth_info
)
1688 save_auth_info(con
, job
, auth_info
);
1691 * Remove the auth-info attribute from the attribute data...
1695 ippDeleteAttribute(job
->attrs
, auth_info
);
1698 if ((attr
= ippFindAttribute(job
->attrs
, "job-originating-host-name",
1699 IPP_TAG_ZERO
)) != NULL
)
1702 * Request contains a job-originating-host-name attribute; validate it...
1705 if (attr
->value_tag
!= IPP_TAG_NAME
||
1706 attr
->num_values
!= 1 ||
1707 strcmp(con
->http
.hostname
, "localhost"))
1710 * Can't override the value if we aren't connected via localhost.
1711 * Also, we can only have 1 value and it must be a name value.
1714 switch (attr
->value_tag
)
1716 case IPP_TAG_STRING
:
1717 case IPP_TAG_TEXTLANG
:
1718 case IPP_TAG_NAMELANG
:
1721 case IPP_TAG_KEYWORD
:
1723 case IPP_TAG_URISCHEME
:
1724 case IPP_TAG_CHARSET
:
1725 case IPP_TAG_LANGUAGE
:
1726 case IPP_TAG_MIMETYPE
:
1728 * Free old strings...
1731 for (i
= 0; i
< attr
->num_values
; i
++)
1733 _cupsStrFree(attr
->values
[i
].string
.text
);
1734 attr
->values
[i
].string
.text
= NULL
;
1735 if (attr
->values
[i
].string
.language
)
1737 _cupsStrFree(attr
->values
[i
].string
.language
);
1738 attr
->values
[i
].string
.language
= NULL
;
1747 * Use the default connection hostname instead...
1750 attr
->value_tag
= IPP_TAG_NAME
;
1751 attr
->num_values
= 1;
1752 attr
->values
[0].string
.text
= _cupsStrAlloc(con
->http
.hostname
);
1755 attr
->group_tag
= IPP_TAG_JOB
;
1760 * No job-originating-host-name attribute, so use the hostname from
1764 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1765 "job-originating-host-name", NULL
, con
->http
.hostname
);
1768 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation",
1770 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1771 "time-at-processing", 0);
1772 attr
->value_tag
= IPP_TAG_NOVALUE
;
1773 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1774 "time-at-completed", 0);
1775 attr
->value_tag
= IPP_TAG_NOVALUE
;
1778 * Add remaining job attributes...
1781 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1782 job
->state
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_ENUM
,
1783 "job-state", IPP_JOB_STOPPED
);
1784 job
->state_value
= (ipp_jstate_t
)job
->state
->values
[0].integer
;
1785 job
->reasons
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1786 "job-state-reasons", NULL
, "job-incoming");
1787 job
->sheets
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1788 "job-media-sheets-completed", 0);
1789 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-printer-uri", NULL
,
1792 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
1793 IPP_TAG_INTEGER
)) != NULL
)
1794 attr
->values
[0].integer
= 0;
1796 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-k-octets", 0);
1798 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
1799 IPP_TAG_KEYWORD
)) == NULL
)
1800 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
1803 if ((val
= cupsGetOption("job-hold-until", printer
->num_options
,
1804 printer
->options
)) == NULL
)
1807 attr
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1808 "job-hold-until", NULL
, val
);
1810 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
1813 * Hold job until specified time...
1816 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
1818 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1819 job
->state_value
= IPP_JOB_HELD
;
1821 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-hold-until-specified");
1823 else if (job
->attrs
->request
.op
.operation_id
== IPP_CREATE_JOB
)
1825 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
1826 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1827 job
->state_value
= IPP_JOB_HELD
;
1831 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1832 job
->state_value
= IPP_JOB_PENDING
;
1834 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
1837 if (!(printer
->type
& CUPS_PRINTER_REMOTE
) || Classification
)
1840 * Add job sheets options...
1843 if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1844 IPP_TAG_ZERO
)) == NULL
)
1846 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1847 "Adding default job-sheets values \"%s,%s\"...",
1848 printer
->job_sheets
[0], printer
->job_sheets
[1]);
1850 attr
= ippAddStrings(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-sheets",
1852 attr
->values
[0].string
.text
= _cupsStrRetain(printer
->job_sheets
[0]);
1853 attr
->values
[1].string
.text
= _cupsStrRetain(printer
->job_sheets
[1]);
1856 job
->job_sheets
= attr
;
1859 * Enforce classification level if set...
1864 cupsdLogMessage(CUPSD_LOG_INFO
,
1865 "Classification=\"%s\", ClassifyOverride=%d",
1866 Classification
? Classification
: "(null)",
1869 if (ClassifyOverride
)
1871 if (!strcmp(attr
->values
[0].string
.text
, "none") &&
1872 (attr
->num_values
== 1 ||
1873 !strcmp(attr
->values
[1].string
.text
, "none")))
1876 * Force the leading banner to have the classification on it...
1879 cupsdSetString(&attr
->values
[0].string
.text
, Classification
);
1881 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1882 "job-sheets=\"%s,none\", "
1883 "job-originating-user-name=\"%s\"",
1884 Classification
, job
->username
);
1886 else if (attr
->num_values
== 2 &&
1887 strcmp(attr
->values
[0].string
.text
,
1888 attr
->values
[1].string
.text
) &&
1889 strcmp(attr
->values
[0].string
.text
, "none") &&
1890 strcmp(attr
->values
[1].string
.text
, "none"))
1893 * Can't put two different security markings on the same document!
1896 cupsdSetString(&attr
->values
[1].string
.text
, attr
->values
[0].string
.text
);
1898 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1899 "job-sheets=\"%s,%s\", "
1900 "job-originating-user-name=\"%s\"",
1901 attr
->values
[0].string
.text
,
1902 attr
->values
[1].string
.text
, job
->username
);
1904 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1905 strcmp(attr
->values
[0].string
.text
, "none") &&
1906 (attr
->num_values
== 1 ||
1907 (strcmp(attr
->values
[1].string
.text
, Classification
) &&
1908 strcmp(attr
->values
[1].string
.text
, "none"))))
1910 if (attr
->num_values
== 1)
1911 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1912 "CLASSIFICATION OVERRIDDEN "
1913 "job-sheets=\"%s\", "
1914 "job-originating-user-name=\"%s\"",
1915 attr
->values
[0].string
.text
, job
->username
);
1917 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1918 "CLASSIFICATION OVERRIDDEN "
1919 "job-sheets=\"%s,%s\",fffff "
1920 "job-originating-user-name=\"%s\"",
1921 attr
->values
[0].string
.text
,
1922 attr
->values
[1].string
.text
, job
->username
);
1925 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1926 (attr
->num_values
== 1 ||
1927 strcmp(attr
->values
[1].string
.text
, Classification
)))
1930 * Force the banner to have the classification on it...
1933 if (attr
->num_values
> 1 &&
1934 !strcmp(attr
->values
[0].string
.text
, attr
->values
[1].string
.text
))
1936 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1937 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1941 if (attr
->num_values
== 1 ||
1942 strcmp(attr
->values
[0].string
.text
, "none"))
1943 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1945 if (attr
->num_values
> 1 &&
1946 strcmp(attr
->values
[1].string
.text
, "none"))
1947 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1950 if (attr
->num_values
> 1)
1951 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1952 "CLASSIFICATION FORCED "
1953 "job-sheets=\"%s,%s\", "
1954 "job-originating-user-name=\"%s\"",
1955 attr
->values
[0].string
.text
,
1956 attr
->values
[1].string
.text
, job
->username
);
1958 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1959 "CLASSIFICATION FORCED "
1960 "job-sheets=\"%s\", "
1961 "job-originating-user-name=\"%s\"",
1962 Classification
, job
->username
);
1967 * See if we need to add the starting sheet...
1970 if (!(printer
->type
& CUPS_PRINTER_REMOTE
))
1972 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding start banner page \"%s\".",
1973 attr
->values
[0].string
.text
);
1975 if ((kbytes
= copy_banner(con
, job
, attr
->values
[0].string
.text
)) < 0)
1977 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1978 "Aborting job because the start banner could not be "
1983 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
1986 else if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1987 IPP_TAG_ZERO
)) != NULL
)
1988 job
->job_sheets
= attr
;
1991 * Fill in the response info...
1994 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
1995 con
->clientname
, con
->clientport
, "/jobs/%d", job
->id
);
1996 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
1999 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
2001 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
2003 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons",
2004 NULL
, job
->reasons
->values
[0].string
.text
);
2006 con
->response
->request
.status
.status_code
= IPP_OK
;
2009 * Add any job subscriptions...
2012 add_job_subscriptions(con
, job
);
2015 * Set all but the first two attributes to the job attributes group...
2018 for (attr
= job
->attrs
->attrs
->next
->next
; attr
; attr
= attr
->next
)
2019 attr
->group_tag
= IPP_TAG_JOB
;
2022 * Fire the "job created" event...
2025 cupsdAddEvent(CUPSD_EVENT_JOB_CREATED
, printer
, job
, "Job created.");
2028 * Return the new job...
2036 * 'add_job_subscriptions()' - Add any subscriptions for a job.
2040 add_job_subscriptions(
2041 cupsd_client_t
*con
, /* I - Client connection */
2042 cupsd_job_t
*job
) /* I - Newly created job */
2044 int i
; /* Looping var */
2045 ipp_attribute_t
*prev
, /* Previous attribute */
2046 *next
, /* Next attribute */
2047 *attr
; /* Current attribute */
2048 cupsd_subscription_t
*sub
; /* Subscription object */
2049 const char *recipient
, /* notify-recipient-uri */
2050 *pullmethod
; /* notify-pull-method */
2051 ipp_attribute_t
*user_data
; /* notify-user-data */
2052 int interval
; /* notify-time-interval */
2053 unsigned mask
; /* notify-events */
2057 * Find the first subscription group attribute; return if we have
2061 for (attr
= job
->attrs
->attrs
; attr
; attr
= attr
->next
)
2062 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
2069 * Process the subscription attributes in the request...
2078 mask
= CUPSD_EVENT_NONE
;
2080 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
2082 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
2083 attr
->value_tag
== IPP_TAG_URI
)
2086 * Validate the recipient scheme against the ServerBin/notifier
2090 char notifier
[1024], /* Notifier filename */
2091 scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
2092 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
2093 host
[HTTP_MAX_URI
], /* Host portion of URI */
2094 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2095 int port
; /* Port portion of URI */
2098 recipient
= attr
->values
[0].string
.text
;
2100 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
2101 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
2102 host
, sizeof(host
), &port
,
2103 resource
, sizeof(resource
)) < HTTP_URI_OK
)
2105 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2106 _("Bad notify-recipient-uri \"%s\"."), recipient
);
2107 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2108 "notify-status-code", IPP_URI_SCHEME
);
2112 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
2114 if (access(notifier
, X_OK
))
2116 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2117 _("notify-recipient-uri URI \"%s\" uses unknown "
2118 "scheme."), recipient
);
2119 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2120 "notify-status-code", IPP_URI_SCHEME
);
2124 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
2126 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2127 _("notify-recipient-uri URI \"%s\" is already used."),
2129 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2130 "notify-status-code", IPP_ATTRIBUTES
);
2134 else if (!strcmp(attr
->name
, "notify-pull-method") &&
2135 attr
->value_tag
== IPP_TAG_KEYWORD
)
2137 pullmethod
= attr
->values
[0].string
.text
;
2139 if (strcmp(pullmethod
, "ippget"))
2141 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2142 _("Bad notify-pull-method \"%s\"."), pullmethod
);
2143 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2144 "notify-status-code", IPP_ATTRIBUTES
);
2148 else if (!strcmp(attr
->name
, "notify-charset") &&
2149 attr
->value_tag
== IPP_TAG_CHARSET
&&
2150 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
2151 strcmp(attr
->values
[0].string
.text
, "utf-8"))
2153 send_ipp_status(con
, IPP_CHARSET
,
2154 _("Character set \"%s\" not supported."),
2155 attr
->values
[0].string
.text
);
2158 else if (!strcmp(attr
->name
, "notify-natural-language") &&
2159 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
2160 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
2162 send_ipp_status(con
, IPP_CHARSET
,
2163 _("Language \"%s\" not supported."),
2164 attr
->values
[0].string
.text
);
2167 else if (!strcmp(attr
->name
, "notify-user-data") &&
2168 attr
->value_tag
== IPP_TAG_STRING
)
2170 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
2172 send_ipp_status(con
, IPP_REQUEST_VALUE
,
2173 _("The notify-user-data value is too large "
2174 "(%d > 63 octets)."),
2175 attr
->values
[0].unknown
.length
);
2181 else if (!strcmp(attr
->name
, "notify-events") &&
2182 attr
->value_tag
== IPP_TAG_KEYWORD
)
2184 for (i
= 0; i
< attr
->num_values
; i
++)
2185 mask
|= cupsdEventValue(attr
->values
[i
].string
.text
);
2187 else if (!strcmp(attr
->name
, "notify-lease-duration"))
2189 send_ipp_status(con
, IPP_BAD_REQUEST
,
2190 _("The notify-lease-duration attribute cannot be "
2191 "used with job subscriptions."));
2194 else if (!strcmp(attr
->name
, "notify-time-interval") &&
2195 attr
->value_tag
== IPP_TAG_INTEGER
)
2196 interval
= attr
->values
[0].integer
;
2201 if (!recipient
&& !pullmethod
)
2204 if (mask
== CUPSD_EVENT_NONE
)
2205 mask
= CUPSD_EVENT_JOB_COMPLETED
;
2207 if ((sub
= cupsdAddSubscription(mask
, cupsdFindDest(job
->dest
), job
,
2208 recipient
, 0)) != NULL
)
2210 sub
->interval
= interval
;
2212 cupsdSetString(&sub
->owner
, job
->username
);
2216 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
2217 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
2218 sub
->user_data_len
);
2221 ippAddSeparator(con
->response
);
2222 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
2223 "notify-subscription-id", sub
->id
);
2225 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
2233 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
2236 * Remove all of the subscription attributes from the job request...
2238 * TODO: Optimize this since subscription groups have to come at the
2239 * end of the request...
2242 for (attr
= job
->attrs
->attrs
, prev
= NULL
; attr
; attr
= next
)
2246 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
||
2247 attr
->group_tag
== IPP_TAG_ZERO
)
2250 * Free and remove this attribute...
2253 ippDeleteAttribute(NULL
, attr
);
2258 job
->attrs
->attrs
= next
;
2264 job
->attrs
->last
= prev
;
2265 job
->attrs
->current
= prev
;
2270 * 'add_job_uuid()' - Add job-uuid attribute to a job.
2272 * See RFC 4122 for the definition of UUIDs and the format.
2276 add_job_uuid(cupsd_job_t
*job
) /* I - Job */
2278 char uuid
[64]; /* job-uuid string */
2282 * Add a job-uuid attribute if none exists...
2285 if (!ippFindAttribute(job
->attrs
, "job-uuid", IPP_TAG_URI
))
2286 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uuid", NULL
,
2287 _httpAssembleUUID(ServerName
, RemotePort
, job
->dest
, job
->id
,
2288 uuid
, sizeof(uuid
)));
2293 * 'add_printer()' - Add a printer to the system.
2297 add_printer(cupsd_client_t
*con
, /* I - Client connection */
2298 ipp_attribute_t
*uri
) /* I - URI of printer */
2300 http_status_t status
; /* Policy status */
2301 int i
; /* Looping var */
2302 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
2303 username
[HTTP_MAX_URI
], /* Username portion of URI */
2304 host
[HTTP_MAX_URI
], /* Host portion of URI */
2305 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2306 int port
; /* Port portion of URI */
2307 cupsd_printer_t
*printer
; /* Printer/class */
2308 ipp_attribute_t
*attr
; /* Printer attribute */
2309 cups_file_t
*fp
; /* Script/PPD file */
2310 char line
[1024]; /* Line from file... */
2311 char srcfile
[1024], /* Source Script/PPD file */
2312 dstfile
[1024]; /* Destination Script/PPD file */
2313 int modify
; /* Non-zero if we are modifying */
2314 int changed_driver
, /* Changed the PPD/interface script? */
2315 need_restart_job
, /* Need to restart job? */
2316 set_device_uri
, /* Did we set the device URI? */
2317 set_port_monitor
; /* Did we set the port monitor? */
2320 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer(%p[%d], %s)", con
,
2321 con
->http
.fd
, uri
->values
[0].string
.text
);
2324 * Do we have a valid URI?
2327 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
2328 sizeof(scheme
), username
, sizeof(username
), host
,
2329 sizeof(host
), &port
, resource
, sizeof(resource
));
2331 if (strncmp(resource
, "/printers/", 10) || strlen(resource
) == 10)
2334 * No, return an error...
2337 send_ipp_status(con
, IPP_BAD_REQUEST
,
2338 _("The printer-uri must be of the form "
2339 "\"ipp://HOSTNAME/printers/PRINTERNAME\"."));
2344 * Do we have a valid printer name?
2347 if (!validate_name(resource
+ 10))
2350 * No, return an error...
2353 send_ipp_status(con
, IPP_BAD_REQUEST
,
2354 _("The printer-uri \"%s\" contains invalid characters."),
2355 uri
->values
[0].string
.text
);
2360 * See if the printer already exists; if not, create a new printer...
2363 if ((printer
= cupsdFindPrinter(resource
+ 10)) == NULL
)
2366 * Printer doesn't exist; see if we have a class of the same name...
2369 if ((printer
= cupsdFindClass(resource
+ 10)) != NULL
)
2372 * Yes, return an error...
2375 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2376 _("A class named \"%s\" already exists."),
2382 * No, check the default policy then add the printer...
2385 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2387 send_http_error(con
, status
, NULL
);
2391 printer
= cupsdAddPrinter(resource
+ 10);
2394 else if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
2397 send_http_error(con
, status
, printer
);
2404 * Look for attributes and copy them over as needed...
2408 need_restart_job
= 0;
2410 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
2411 IPP_TAG_TEXT
)) != NULL
)
2412 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
2414 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
2415 IPP_TAG_TEXT
)) != NULL
)
2416 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
2420 if ((attr
= ippFindAttribute(con
->request
, "device-uri",
2421 IPP_TAG_URI
)) != NULL
)
2424 * Do we have a valid device URI?
2427 http_uri_status_t uri_status
; /* URI separation status */
2428 char old_device_uri
[1024];
2429 /* Old device URI */
2430 static const char * const uri_status_strings
[] =
2433 "Bad arguments to function.",
2434 "Bad resource path.",
2436 "Bad hostname/address.",
2437 "Bad username/password.",
2441 "Missing URI scheme.",
2442 "Unknown URI scheme",
2443 "Missing resource path."
2447 need_restart_job
= 1;
2449 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
,
2450 attr
->values
[0].string
.text
,
2451 scheme
, sizeof(scheme
),
2452 username
, sizeof(username
),
2453 host
, sizeof(host
), &port
,
2454 resource
, sizeof(resource
));
2456 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2457 "%s device-uri: %s", printer
->name
,
2458 uri_status_strings
[uri_status
- HTTP_URI_STATUS_OVERFLOW
]);
2460 if (uri_status
< HTTP_URI_OK
)
2462 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri \"%s\"."),
2463 attr
->values
[0].string
.text
);
2467 if (!strcmp(scheme
, "file"))
2470 * See if the administrator has enabled file devices...
2473 if (!FileDevice
&& strcmp(resource
, "/dev/null"))
2476 * File devices are disabled and the URL is not file:/dev/null...
2479 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2480 _("File device URIs have been disabled. "
2481 "To enable, see the FileDevice directive in "
2482 "\"%s/cups-files.conf\"."),
2490 * See if the backend exists and is executable...
2493 snprintf(srcfile
, sizeof(srcfile
), "%s/backend/%s", ServerBin
, scheme
);
2494 if (access(srcfile
, X_OK
))
2497 * Could not find device in list!
2500 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2501 _("Bad device-uri scheme \"%s\"."), scheme
);
2506 if (printer
->sanitized_device_uri
)
2507 strlcpy(old_device_uri
, printer
->sanitized_device_uri
,
2508 sizeof(old_device_uri
));
2510 old_device_uri
[0] = '\0';
2512 cupsdSetDeviceURI(printer
, attr
->values
[0].string
.text
);
2514 cupsdLogMessage(CUPSD_LOG_INFO
,
2515 "Setting %s device-uri to \"%s\" (was \"%s\".)",
2516 printer
->name
, printer
->sanitized_device_uri
,
2522 set_port_monitor
= 0;
2524 if ((attr
= ippFindAttribute(con
->request
, "port-monitor",
2525 IPP_TAG_NAME
)) != NULL
)
2527 ipp_attribute_t
*supported
; /* port-monitor-supported attribute */
2530 need_restart_job
= 1;
2532 supported
= ippFindAttribute(printer
->ppd_attrs
, "port-monitor-supported",
2536 for (i
= 0; i
< supported
->num_values
; i
++)
2537 if (!strcmp(supported
->values
[i
].string
.text
,
2538 attr
->values
[0].string
.text
))
2542 if (!supported
|| i
>= supported
->num_values
)
2544 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad port-monitor \"%s\"."),
2545 attr
->values
[0].string
.text
);
2549 cupsdLogMessage(CUPSD_LOG_INFO
,
2550 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2551 printer
->name
, attr
->values
[0].string
.text
,
2552 printer
->port_monitor
? printer
->port_monitor
: "none");
2554 if (strcmp(attr
->values
[0].string
.text
, "none"))
2555 cupsdSetString(&printer
->port_monitor
, attr
->values
[0].string
.text
);
2557 cupsdClearString(&printer
->port_monitor
);
2559 set_port_monitor
= 1;
2562 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
2563 IPP_TAG_BOOLEAN
)) != NULL
&&
2564 attr
->values
[0].boolean
!= printer
->accepting
)
2566 cupsdLogMessage(CUPSD_LOG_INFO
,
2567 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
2568 printer
->name
, attr
->values
[0].boolean
, printer
->accepting
);
2570 printer
->accepting
= attr
->values
[0].boolean
;
2572 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2573 "%s accepting jobs.",
2574 printer
->accepting
? "Now" : "No longer");
2577 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
2578 IPP_TAG_BOOLEAN
)) != NULL
)
2580 if (attr
->values
[0].boolean
&&
2581 printer
->num_auth_info_required
== 1 &&
2582 !strcmp(printer
->auth_info_required
[0], "negotiate"))
2584 send_ipp_status(con
, IPP_BAD_REQUEST
,
2585 _("Cannot share a remote Kerberized printer."));
2589 if (printer
->shared
&& !attr
->values
[0].boolean
)
2590 cupsdDeregisterPrinter(printer
, 1);
2592 cupsdLogMessage(CUPSD_LOG_INFO
,
2593 "Setting %s printer-is-shared to %d (was %d.)",
2594 printer
->name
, attr
->values
[0].boolean
, printer
->shared
);
2596 printer
->shared
= attr
->values
[0].boolean
;
2599 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
2600 IPP_TAG_ENUM
)) != NULL
)
2602 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
2603 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
2605 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad printer-state value %d."),
2606 attr
->values
[0].integer
);
2610 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
2611 printer
->name
, attr
->values
[0].integer
, printer
->state
);
2613 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
2614 cupsdStopPrinter(printer
, 0);
2617 need_restart_job
= 1;
2618 cupsdSetPrinterState(printer
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
2622 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
2623 IPP_TAG_TEXT
)) != NULL
)
2625 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
2626 sizeof(printer
->state_message
));
2628 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
, "%s",
2629 printer
->state_message
);
2632 if ((attr
= ippFindAttribute(con
->request
, "printer-state-reasons",
2633 IPP_TAG_KEYWORD
)) != NULL
)
2635 if (attr
->num_values
>
2636 (int)(sizeof(printer
->reasons
) / sizeof(printer
->reasons
[0])))
2638 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2639 _("Too many printer-state-reasons values (%d > %d)."),
2641 (int)(sizeof(printer
->reasons
) /
2642 sizeof(printer
->reasons
[0])));
2646 for (i
= 0; i
< printer
->num_reasons
; i
++)
2647 _cupsStrFree(printer
->reasons
[i
]);
2649 printer
->num_reasons
= 0;
2650 for (i
= 0; i
< attr
->num_values
; i
++)
2652 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
2655 printer
->reasons
[printer
->num_reasons
] =
2656 _cupsStrRetain(attr
->values
[i
].string
.text
);
2657 printer
->num_reasons
++;
2659 if (!strcmp(attr
->values
[i
].string
.text
, "paused") &&
2660 printer
->state
!= IPP_PRINTER_STOPPED
)
2662 cupsdLogMessage(CUPSD_LOG_INFO
,
2663 "Setting %s printer-state to %d (was %d.)",
2664 printer
->name
, IPP_PRINTER_STOPPED
, printer
->state
);
2665 cupsdStopPrinter(printer
, 0);
2669 if (PrintcapFormat
== PRINTCAP_PLIST
)
2670 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2672 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2673 "Printer \"%s\" state changed.", printer
->name
);
2676 set_printer_defaults(con
, printer
);
2678 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
2679 IPP_TAG_KEYWORD
)) != NULL
)
2680 cupsdSetAuthInfoRequired(printer
, NULL
, attr
);
2683 * See if we have all required attributes...
2686 if (!printer
->device_uri
)
2687 cupsdSetString(&printer
->device_uri
, "file:///dev/null");
2690 * See if we have an interface script or PPD file attached to the request...
2695 need_restart_job
= 1;
2698 strlcpy(srcfile
, con
->filename
, sizeof(srcfile
));
2700 if ((fp
= cupsFileOpen(srcfile
, "rb")))
2703 * Yes; get the first line from it...
2707 cupsFileGets(fp
, line
, sizeof(line
));
2711 * Then see what kind of file it is...
2714 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2717 if (!strncmp(line
, "*PPD-Adobe", 10))
2720 * The new file is a PPD file, so remove any old interface script
2721 * that might be lying around...
2729 * This must be an interface script, so move the file over to the
2730 * interfaces directory and make it executable...
2733 if (copy_file(srcfile
, dstfile
))
2735 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2736 _("Unable to copy interface script - %s"),
2741 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2742 "Copied interface script successfully");
2743 chmod(dstfile
, 0755);
2746 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2749 if (!strncmp(line
, "*PPD-Adobe", 10))
2752 * The new file is a PPD file, so move the file over to the
2753 * ppd directory and make it readable by all...
2756 if (copy_file(srcfile
, dstfile
))
2758 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2759 _("Unable to copy PPD file - %s"),
2764 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2765 "Copied PPD file successfully");
2766 chmod(dstfile
, 0644);
2771 * This must be an interface script, so remove any old PPD file that
2772 * may be lying around...
2779 else if ((attr
= ippFindAttribute(con
->request
, "ppd-name",
2780 IPP_TAG_NAME
)) != NULL
)
2782 need_restart_job
= 1;
2785 if (!strcmp(attr
->values
[0].string
.text
, "raw"))
2788 * Raw driver, remove any existing PPD or interface script files.
2791 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2795 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2805 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2809 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2812 if (copy_model(con
, attr
->values
[0].string
.text
, dstfile
))
2814 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file."));
2818 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2819 "Copied PPD file successfully");
2820 chmod(dstfile
, 0644);
2827 * If we changed the PPD/interface script, then remove the printer's cache
2828 * file and clear the printer-state-reasons...
2831 char cache_name
[1024]; /* Cache filename for printer attrs */
2833 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.data", CacheDir
,
2837 cupsdSetPrinterReasons(printer
, "none");
2840 * (Re)register color profiles...
2843 cupsdRegisterColor(printer
);
2847 * If we set the device URI but not the port monitor, check which port
2848 * monitor to use by default...
2851 if (set_device_uri
&& !set_port_monitor
)
2853 ppd_file_t
*ppd
; /* PPD file */
2854 ppd_attr_t
*ppdattr
; /* cupsPortMonitor attribute */
2857 httpSeparateURI(HTTP_URI_CODING_ALL
, printer
->device_uri
, scheme
,
2858 sizeof(scheme
), username
, sizeof(username
), host
,
2859 sizeof(host
), &port
, resource
, sizeof(resource
));
2861 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
,
2863 if ((ppd
= _ppdOpenFile(srcfile
, _PPD_LOCALIZATION_NONE
)) != NULL
)
2865 for (ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2867 ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
2868 if (!strcmp(scheme
, ppdattr
->spec
))
2870 cupsdLogMessage(CUPSD_LOG_INFO
,
2871 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2872 printer
->name
, ppdattr
->value
,
2873 printer
->port_monitor
? printer
->port_monitor
2876 if (strcmp(ppdattr
->value
, "none"))
2877 cupsdSetString(&printer
->port_monitor
, ppdattr
->value
);
2879 cupsdClearString(&printer
->port_monitor
);
2889 * Update the printer attributes and return...
2892 cupsdSetPrinterAttrs(printer
);
2893 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2895 if (need_restart_job
&& printer
->job
)
2898 * Restart the current job...
2901 cupsdSetJobState(printer
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
2902 "Job restarted because the printer was modified.");
2905 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2909 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
2910 printer
, NULL
, "Printer \"%s\" modified by \"%s\".",
2911 printer
->name
, get_username(con
));
2913 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" modified by \"%s\".",
2914 printer
->name
, get_username(con
));
2918 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
2919 printer
, NULL
, "New printer \"%s\" added by \"%s\".",
2920 printer
->name
, get_username(con
));
2922 cupsdLogMessage(CUPSD_LOG_INFO
, "New printer \"%s\" added by \"%s\".",
2923 printer
->name
, get_username(con
));
2926 con
->response
->request
.status
.status_code
= IPP_OK
;
2931 * 'add_printer_state_reasons()' - Add the "printer-state-reasons" attribute
2932 * based upon the printer state...
2936 add_printer_state_reasons(
2937 cupsd_client_t
*con
, /* I - Client connection */
2938 cupsd_printer_t
*p
) /* I - Printer info */
2940 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2941 "add_printer_state_reasons(%p[%d], %p[%s])",
2942 con
, con
->http
.fd
, p
, p
->name
);
2944 if (p
->num_reasons
== 0)
2945 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2946 "printer-state-reasons", NULL
, "none");
2948 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2949 "printer-state-reasons", p
->num_reasons
, NULL
,
2950 (const char * const *)p
->reasons
);
2955 * 'add_queued_job_count()' - Add the "queued-job-count" attribute for
2956 * the specified printer or class.
2960 add_queued_job_count(
2961 cupsd_client_t
*con
, /* I - Client connection */
2962 cupsd_printer_t
*p
) /* I - Printer or class */
2964 int count
; /* Number of jobs on destination */
2967 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_queued_job_count(%p[%d], %p[%s])",
2968 con
, con
->http
.fd
, p
, p
->name
);
2970 count
= cupsdGetPrinterJobCount(p
->name
);
2972 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2973 "queued-job-count", count
);
2978 * 'apply_printer_defaults()' - Apply printer default options to a job.
2982 apply_printer_defaults(
2983 cupsd_printer_t
*printer
, /* I - Printer */
2984 cupsd_job_t
*job
) /* I - Job */
2986 int i
, /* Looping var */
2987 num_options
; /* Number of default options */
2988 cups_option_t
*options
, /* Default options */
2989 *option
; /* Current option */
2993 * Collect all of the default options and add the missing ones to the
2997 for (i
= printer
->num_options
, num_options
= 0, options
= NULL
,
2998 option
= printer
->options
;
3001 if (!ippFindAttribute(job
->attrs
, option
->name
, IPP_TAG_ZERO
))
3003 num_options
= cupsAddOption(option
->name
, option
->value
, num_options
,
3008 * Encode these options as attributes in the job object...
3011 cupsEncodeOptions2(job
->attrs
, num_options
, options
, IPP_TAG_JOB
);
3012 cupsFreeOptions(num_options
, options
);
3017 * 'authenticate_job()' - Set job authentication info.
3021 authenticate_job(cupsd_client_t
*con
, /* I - Client connection */
3022 ipp_attribute_t
*uri
) /* I - Job URI */
3024 ipp_attribute_t
*attr
, /* job-id attribute */
3025 *auth_info
; /* auth-info attribute */
3026 int jobid
; /* Job ID */
3027 cupsd_job_t
*job
; /* Current job */
3028 char scheme
[HTTP_MAX_URI
],
3029 /* Method portion of URI */
3030 username
[HTTP_MAX_URI
],
3031 /* Username portion of URI */
3033 /* Host portion of URI */
3034 resource
[HTTP_MAX_URI
];
3035 /* Resource portion of URI */
3036 int port
; /* Port portion of URI */
3039 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "authenticate_job(%p[%d], %s)",
3040 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
3043 * Start with "everything is OK" status...
3046 con
->response
->request
.status
.status_code
= IPP_OK
;
3049 * See if we have a job URI or a printer URI...
3052 if (!strcmp(uri
->name
, "printer-uri"))
3055 * Got a printer URI; see if we also have a job-id attribute...
3058 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3059 IPP_TAG_INTEGER
)) == NULL
)
3061 send_ipp_status(con
, IPP_BAD_REQUEST
,
3062 _("Got a printer-uri attribute but no job-id."));
3066 jobid
= attr
->values
[0].integer
;
3071 * Got a job URI; parse it to get the job ID...
3074 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
3075 sizeof(scheme
), username
, sizeof(username
), host
,
3076 sizeof(host
), &port
, resource
, sizeof(resource
));
3078 if (strncmp(resource
, "/jobs/", 6))
3084 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
3085 uri
->values
[0].string
.text
);
3089 jobid
= atoi(resource
+ 6);
3093 * See if the job exists...
3096 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3099 * Nope - return a "not found" error...
3102 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
3107 * See if the job has been completed...
3110 if (job
->state_value
!= IPP_JOB_HELD
)
3113 * Return a "not-possible" error...
3116 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3117 _("Job #%d is not held for authentication."),
3123 * See if we have already authenticated...
3126 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
3128 if (!con
->username
[0] && !auth_info
)
3130 cupsd_printer_t
*printer
; /* Job destination */
3133 * No auth data. If we need to authenticate via Kerberos, send a
3134 * HTTP auth challenge, otherwise just return an IPP error...
3137 printer
= cupsdFindDest(job
->dest
);
3139 if (printer
&& printer
->num_auth_info_required
> 0 &&
3140 !strcmp(printer
->auth_info_required
[0], "negotiate"))
3141 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
3143 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
3144 _("No authentication information provided."));
3149 * See if the job is owned by the requesting user...
3152 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3154 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3155 cupsdFindDest(job
->dest
));
3160 * Save the authentication information for this job...
3163 save_auth_info(con
, job
, auth_info
);
3166 * Reset the job-hold-until value to "no-hold"...
3169 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
3170 IPP_TAG_KEYWORD
)) == NULL
)
3171 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
3175 attr
->value_tag
= IPP_TAG_KEYWORD
;
3176 cupsdSetString(&(attr
->values
[0].string
.text
), "no-hold");
3180 * Release the job and return...
3183 cupsdReleaseJob(job
);
3185 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, NULL
, job
, "Job authenticated by user");
3187 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Authenticated by \"%s\".", con
->username
);
3194 * 'cancel_all_jobs()' - Cancel all or selected print jobs.
3198 cancel_all_jobs(cupsd_client_t
*con
, /* I - Client connection */
3199 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3201 int i
; /* Looping var */
3202 http_status_t status
; /* Policy status */
3203 cups_ptype_t dtype
; /* Destination type */
3204 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3205 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
3206 hostname
[HTTP_MAX_URI
], /* Host portion of URI */
3207 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3208 int port
; /* Port portion of URI */
3209 ipp_attribute_t
*attr
; /* Attribute in request */
3210 const char *username
= NULL
; /* Username */
3211 cupsd_jobaction_t purge
= CUPSD_JOB_DEFAULT
;
3213 cupsd_printer_t
*printer
; /* Printer */
3214 ipp_attribute_t
*job_ids
; /* job-ids attribute */
3215 cupsd_job_t
*job
; /* Job */
3218 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_all_jobs(%p[%d], %s)", con
,
3219 con
->http
.fd
, uri
->values
[0].string
.text
);
3222 * Get the jobs to cancel/purge...
3225 switch (con
->request
->request
.op
.operation_id
)
3227 case IPP_PURGE_JOBS
:
3229 * Get the username (if any) for the jobs we want to cancel (only if
3230 * "my-jobs" is specified...
3233 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
3234 IPP_TAG_BOOLEAN
)) != NULL
&&
3235 attr
->values
[0].boolean
)
3237 if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3238 IPP_TAG_NAME
)) != NULL
)
3239 username
= attr
->values
[0].string
.text
;
3242 send_ipp_status(con
, IPP_BAD_REQUEST
,
3243 _("Missing requesting-user-name attribute."));
3249 * Look for the "purge-jobs" attribute...
3252 if ((attr
= ippFindAttribute(con
->request
, "purge-jobs",
3253 IPP_TAG_BOOLEAN
)) != NULL
)
3254 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
3256 purge
= CUPSD_JOB_PURGE
;
3259 case IPP_CANCEL_MY_JOBS
:
3260 if (con
->username
[0])
3261 username
= con
->username
;
3262 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3263 IPP_TAG_NAME
)) != NULL
)
3264 username
= attr
->values
[0].string
.text
;
3267 send_ipp_status(con
, IPP_BAD_REQUEST
,
3268 _("Missing requesting-user-name attribute."));
3276 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
3279 * See if we have a printer URI...
3282 if (strcmp(uri
->name
, "printer-uri"))
3284 send_ipp_status(con
, IPP_BAD_REQUEST
,
3285 _("The printer-uri attribute is required."));
3290 * And if the destination is valid...
3293 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3299 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
,
3300 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
3301 hostname
, sizeof(hostname
), &port
,
3302 resource
, sizeof(resource
));
3304 if ((!strncmp(resource
, "/printers/", 10) && resource
[10]) ||
3305 (!strncmp(resource
, "/classes/", 9) && resource
[9]))
3307 send_ipp_status(con
, IPP_NOT_FOUND
,
3308 _("The printer or class does not exist."));
3316 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
3318 send_http_error(con
, status
, NULL
);
3324 for (i
= 0; i
< job_ids
->num_values
; i
++)
3326 if ((job
= cupsdFindJob(job_ids
->values
[i
].integer
)) == NULL
)
3329 if (con
->request
->request
.op
.operation_id
== IPP_CANCEL_MY_JOBS
&&
3330 _cups_strcasecmp(job
->username
, username
))
3334 if (i
< job_ids
->num_values
)
3336 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3337 job_ids
->values
[i
].integer
);
3341 for (i
= 0; i
< job_ids
->num_values
; i
++)
3343 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
3345 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3346 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
3347 "Job canceled by user.");
3350 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
3351 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3357 * Cancel all jobs on all printers...
3360 cupsdCancelJobs(NULL
, username
, purge
);
3362 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs were %s by \"%s\".",
3363 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3373 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
3376 send_http_error(con
, status
, printer
);
3382 for (i
= 0; i
< job_ids
->num_values
; i
++)
3384 if ((job
= cupsdFindJob(job_ids
->values
[i
].integer
)) == NULL
||
3385 _cups_strcasecmp(job
->dest
, printer
->name
))
3388 if (con
->request
->request
.op
.operation_id
== IPP_CANCEL_MY_JOBS
&&
3389 _cups_strcasecmp(job
->username
, username
))
3393 if (i
< job_ids
->num_values
)
3395 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3396 job_ids
->values
[i
].integer
);
3400 for (i
= 0; i
< job_ids
->num_values
; i
++)
3402 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
3404 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3405 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
3406 "Job canceled by user.");
3409 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
3410 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3416 * Cancel all of the jobs on the named printer...
3419 cupsdCancelJobs(printer
->name
, username
, purge
);
3421 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs on \"%s\" were %s by \"%s\".",
3423 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3428 con
->response
->request
.status
.status_code
= IPP_OK
;
3433 * 'cancel_job()' - Cancel a print job.
3437 cancel_job(cupsd_client_t
*con
, /* I - Client connection */
3438 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3440 ipp_attribute_t
*attr
; /* Current attribute */
3441 int jobid
; /* Job ID */
3442 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3443 username
[HTTP_MAX_URI
], /* Username portion of URI */
3444 host
[HTTP_MAX_URI
], /* Host portion of URI */
3445 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3446 int port
; /* Port portion of URI */
3447 cupsd_job_t
*job
; /* Job information */
3448 cups_ptype_t dtype
; /* Destination type (printer/class) */
3449 cupsd_printer_t
*printer
; /* Printer data */
3450 cupsd_jobaction_t purge
; /* Purge the job? */
3453 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_job(%p[%d], %s)", con
,
3454 con
->http
.fd
, uri
->values
[0].string
.text
);
3457 * See if we have a job URI or a printer URI...
3460 if (!strcmp(uri
->name
, "printer-uri"))
3463 * Got a printer URI; see if we also have a job-id attribute...
3466 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3467 IPP_TAG_INTEGER
)) == NULL
)
3469 send_ipp_status(con
, IPP_BAD_REQUEST
,
3470 _("Got a printer-uri attribute but no job-id."));
3474 if ((jobid
= attr
->values
[0].integer
) == 0)
3477 * Find the current job on the specified printer...
3480 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3486 send_ipp_status(con
, IPP_NOT_FOUND
,
3487 _("The printer or class does not exist."));
3492 * See if there are any pending jobs...
3495 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3497 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3498 if (job
->state_value
<= IPP_JOB_PROCESSING
&&
3499 !_cups_strcasecmp(job
->dest
, printer
->name
))
3507 * No, try stopped jobs...
3510 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3512 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3513 if (job
->state_value
== IPP_JOB_STOPPED
&&
3514 !_cups_strcasecmp(job
->dest
, printer
->name
))
3521 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("No active jobs on %s."),
3531 * Got a job URI; parse it to get the job ID...
3534 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
3535 sizeof(scheme
), username
, sizeof(username
), host
,
3536 sizeof(host
), &port
, resource
, sizeof(resource
));
3538 if (strncmp(resource
, "/jobs/", 6))
3544 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
3545 uri
->values
[0].string
.text
);
3549 jobid
= atoi(resource
+ 6);
3553 * Look for the "purge-job" attribute...
3556 if ((attr
= ippFindAttribute(con
->request
, "purge-job",
3557 IPP_TAG_BOOLEAN
)) != NULL
)
3558 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
3560 purge
= CUPSD_JOB_DEFAULT
;
3563 * See if the job exists...
3566 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3569 * Nope - return a "not found" error...
3572 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
3577 * See if the job is owned by the requesting user...
3580 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3582 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3583 cupsdFindDest(job
->dest
));
3588 * See if the job is already completed, canceled, or aborted; if so,
3589 * we can't cancel...
3592 if (job
->state_value
>= IPP_JOB_CANCELED
&& purge
!= CUPSD_JOB_PURGE
)
3594 switch (job
->state_value
)
3596 case IPP_JOB_CANCELED
:
3597 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3598 _("Job #%d is already canceled - can\'t cancel."),
3602 case IPP_JOB_ABORTED
:
3603 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3604 _("Job #%d is already aborted - can\'t cancel."),
3609 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3610 _("Job #%d is already completed - can\'t cancel."),
3619 * Cancel the job and return...
3622 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3623 purge
== CUPSD_JOB_PURGE
? "Job purged by \"%s\"" :
3624 "Job canceled by \"%s\"",
3628 if (purge
== CUPSD_JOB_PURGE
)
3629 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Purged by \"%s\".", jobid
,
3632 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Canceled by \"%s\".", jobid
,
3635 con
->response
->request
.status
.status_code
= IPP_OK
;
3640 * 'cancel_subscription()' - Cancel a subscription.
3644 cancel_subscription(
3645 cupsd_client_t
*con
, /* I - Client connection */
3646 int sub_id
) /* I - Subscription ID */
3648 http_status_t status
; /* Policy status */
3649 cupsd_subscription_t
*sub
; /* Subscription */
3652 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3653 "cancel_subscription(con=%p[%d], sub_id=%d)",
3654 con
, con
->http
.fd
, sub_id
);
3657 * Is the subscription ID valid?
3660 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
3663 * Bad subscription ID...
3666 send_ipp_status(con
, IPP_NOT_FOUND
,
3667 _("Subscription #%d does not exist."), sub_id
);
3675 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
3677 con
, sub
->owner
)) != HTTP_OK
)
3679 send_http_error(con
, status
, sub
->dest
);
3684 * Cancel the subscription...
3687 cupsdDeleteSubscription(sub
, 1);
3689 con
->response
->request
.status
.status_code
= IPP_OK
;
3694 * 'check_rss_recipient()' - Check that we do not have a duplicate RSS feed URI.
3697 static int /* O - 1 if OK, 0 if not */
3698 check_rss_recipient(
3699 const char *recipient
) /* I - Recipient URI */
3701 cupsd_subscription_t
*sub
; /* Current subscription */
3704 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
);
3706 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
3710 * Compare the URIs up to the first ?...
3713 const char *r1
, *r2
;
3715 for (r1
= recipient
, r2
= sub
->recipient
;
3716 *r1
== *r2
&& *r1
&& *r1
!= '?' && *r2
&& *r2
!= '?';
3728 * 'check_quotas()' - Check quotas for a printer and user.
3731 static int /* O - 1 if OK, 0 if forbidden,
3732 -1 if limit reached */
3733 check_quotas(cupsd_client_t
*con
, /* I - Client connection */
3734 cupsd_printer_t
*p
) /* I - Printer or class */
3736 char username
[33], /* Username */
3737 *name
; /* Current user name */
3738 cupsd_quota_t
*q
; /* Quota data */
3739 #ifdef HAVE_MBR_UID_TO_UUID
3741 * Use Apple membership APIs which require that all names represent
3742 * valid user account or group records accessible by the server.
3745 uuid_t usr_uuid
; /* UUID for job requesting user */
3746 uuid_t usr2_uuid
; /* UUID for ACL user name entry */
3747 uuid_t grp_uuid
; /* UUID for ACL group name entry */
3748 int mbr_err
; /* Error from membership function */
3749 int is_member
; /* Is this user a member? */
3752 * Use standard POSIX APIs for checking users and groups...
3755 struct passwd
*pw
; /* User password data */
3756 #endif /* HAVE_MBR_UID_TO_UUID */
3759 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "check_quotas(%p[%d], %p[%s])",
3760 con
, con
->http
.fd
, p
, p
->name
);
3763 * Figure out who is printing...
3766 strlcpy(username
, get_username(con
), sizeof(username
));
3768 if ((name
= strchr(username
, '@')) != NULL
)
3769 *name
= '\0'; /* Strip @REALM */
3772 * Check global active job limits for printers and users...
3775 if (MaxJobsPerPrinter
)
3778 * Check if there are too many pending jobs on this printer...
3781 if (cupsdGetPrinterJobCount(p
->name
) >= MaxJobsPerPrinter
)
3783 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for printer \"%s\"...",
3792 * Check if there are too many pending jobs for this user...
3795 if (cupsdGetUserJobCount(username
) >= MaxJobsPerUser
)
3797 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for user \"%s\"...",
3804 * Check against users...
3807 if (cupsArrayCount(p
->users
) == 0 && p
->k_limit
== 0 && p
->page_limit
== 0)
3810 if (cupsArrayCount(p
->users
))
3812 #ifdef HAVE_MBR_UID_TO_UUID
3814 * Get UUID for job requesting user...
3817 if (mbr_user_name_to_uuid((char *)username
, usr_uuid
))
3823 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3824 "check_quotas: UUID lookup failed for user \"%s\"",
3826 cupsdLogMessage(CUPSD_LOG_INFO
,
3827 "Denying user \"%s\" access to printer \"%s\" "
3828 "(unknown user)...",
3834 * Get UID and GID of requesting user...
3837 pw
= getpwnam(username
);
3839 #endif /* HAVE_MBR_UID_TO_UUID */
3841 for (name
= (char *)cupsArrayFirst(p
->users
);
3843 name
= (char *)cupsArrayNext(p
->users
))
3847 * Check group membership...
3850 #ifdef HAVE_MBR_UID_TO_UUID
3853 if (uuid_parse(name
+ 2, grp_uuid
))
3854 uuid_clear(grp_uuid
);
3856 else if ((mbr_err
= mbr_group_name_to_uuid(name
+ 1, grp_uuid
)) != 0)
3859 * Invalid ACL entries are ignored for matching; just record a
3860 * warning in the log...
3863 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3864 "check_quotas: UUID lookup failed for ACL entry "
3865 "\"%s\" (err=%d)", name
, mbr_err
);
3866 cupsdLogMessage(CUPSD_LOG_WARN
,
3867 "Access control entry \"%s\" not a valid group name; "
3868 "entry ignored", name
);
3871 if ((mbr_err
= mbr_check_membership(usr_uuid
, grp_uuid
,
3875 * At this point, there should be no errors, but check anyways...
3878 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3879 "check_quotas: group \"%s\" membership check "
3880 "failed (err=%d)", name
+ 1, mbr_err
);
3885 * Stop if we found a match...
3892 if (cupsdCheckGroup(username
, pw
, name
+ 1))
3894 #endif /* HAVE_MBR_UID_TO_UUID */
3896 #ifdef HAVE_MBR_UID_TO_UUID
3901 if (uuid_parse(name
+ 1, usr2_uuid
))
3902 uuid_clear(usr2_uuid
);
3904 else if ((mbr_err
= mbr_user_name_to_uuid(name
, usr2_uuid
)) != 0)
3907 * Invalid ACL entries are ignored for matching; just record a
3908 * warning in the log...
3911 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3912 "check_quotas: UUID lookup failed for ACL entry "
3913 "\"%s\" (err=%d)", name
, mbr_err
);
3914 cupsdLogMessage(CUPSD_LOG_WARN
,
3915 "Access control entry \"%s\" not a valid user name; "
3916 "entry ignored", name
);
3919 if (!uuid_compare(usr_uuid
, usr2_uuid
))
3923 else if (!_cups_strcasecmp(username
, name
))
3925 #endif /* HAVE_MBR_UID_TO_UUID */
3927 if ((name
!= NULL
) == p
->deny_users
)
3929 cupsdLogMessage(CUPSD_LOG_INFO
,
3930 "Denying user \"%s\" access to printer \"%s\"...",
3940 if (p
->k_limit
|| p
->page_limit
)
3942 if ((q
= cupsdUpdateQuota(p
, username
, 0, 0)) == NULL
)
3944 cupsdLogMessage(CUPSD_LOG_ERROR
,
3945 "Unable to allocate quota data for user \"%s\"",
3950 if ((q
->k_count
>= p
->k_limit
&& p
->k_limit
) ||
3951 (q
->page_count
>= p
->page_limit
&& p
->page_limit
))
3953 cupsdLogMessage(CUPSD_LOG_INFO
, "User \"%s\" is over the quota limit...",
3960 * If we have gotten this far, we're done!
3968 * 'close_job()' - Close a multi-file job.
3972 close_job(cupsd_client_t
*con
, /* I - Client connection */
3973 ipp_attribute_t
*uri
) /* I - Printer URI */
3975 cupsd_job_t
*job
; /* Job */
3976 ipp_attribute_t
*attr
; /* Attribute */
3977 char job_uri
[HTTP_MAX_URI
],
3979 username
[256]; /* User name */
3982 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "close_job(%p[%d], %s)", con
,
3983 con
->http
.fd
, uri
->values
[0].string
.text
);
3986 * See if we have a job URI or a printer URI...
3989 if (strcmp(uri
->name
, "printer-uri"))
3992 * job-uri is not supported by Close-Job!
3995 send_ipp_status(con
, IPP_BAD_REQUEST
,
3996 _("Close-Job doesn't support the job-uri attribute."));
4001 * Got a printer URI; see if we also have a job-id attribute...
4004 if ((attr
= ippFindAttribute(con
->request
, "job-id",
4005 IPP_TAG_INTEGER
)) == NULL
)
4007 send_ipp_status(con
, IPP_BAD_REQUEST
,
4008 _("Got a printer-uri attribute but no job-id."));
4012 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
4015 * Nope - return a "not found" error...
4018 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
4019 attr
->values
[0].integer
);
4024 * See if the job is owned by the requesting user...
4027 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
4029 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
4030 cupsdFindDest(job
->dest
));
4035 * Add any ending sheet...
4038 if (cupsdTimeoutJob(job
))
4041 if (job
->state_value
== IPP_JOB_STOPPED
)
4043 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
4044 job
->state_value
= IPP_JOB_PENDING
;
4046 else if (job
->state_value
== IPP_JOB_HELD
)
4048 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
4049 IPP_TAG_KEYWORD
)) == NULL
)
4050 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
4052 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
4054 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
4055 job
->state_value
= IPP_JOB_PENDING
;
4060 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
4063 * Fill in the response info...
4066 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
4067 con
->clientname
, con
->clientport
, "/jobs/%d", job
->id
);
4068 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
4071 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
4073 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
4076 con
->response
->request
.status
.status_code
= IPP_OK
;
4079 * Start the job if necessary...
4087 * 'copy_attrs()' - Copy attributes from one request to another.
4091 copy_attrs(ipp_t
*to
, /* I - Destination request */
4092 ipp_t
*from
, /* I - Source request */
4093 cups_array_t
*ra
, /* I - Requested attributes */
4094 ipp_tag_t group
, /* I - Group to copy */
4095 int quickcopy
, /* I - Do a quick copy? */
4096 cups_array_t
*exclude
) /* I - Attributes to exclude? */
4098 ipp_attribute_t
*fromattr
; /* Source attribute */
4101 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4102 "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)",
4103 to
, from
, ra
, group
, quickcopy
);
4108 for (fromattr
= from
->attrs
; fromattr
; fromattr
= fromattr
->next
)
4111 * Filter attributes as needed...
4114 if ((group
!= IPP_TAG_ZERO
&& fromattr
->group_tag
!= group
&&
4115 fromattr
->group_tag
!= IPP_TAG_ZERO
) || !fromattr
->name
)
4118 if (!strcmp(fromattr
->name
, "document-password") ||
4119 !strcmp(fromattr
->name
, "job-authorization-uri") ||
4120 !strcmp(fromattr
->name
, "job-password") ||
4121 !strcmp(fromattr
->name
, "job-password-encryption") ||
4122 !strcmp(fromattr
->name
, "job-printer-uri"))
4126 (cupsArrayFind(exclude
, fromattr
->name
) ||
4127 cupsArrayFind(exclude
, "all")))
4130 * We need to exclude this attribute for security reasons; we require the
4131 * job-id attribute regardless of the security settings for IPP
4134 * The job-printer-uri attribute is handled by copy_job_attrs().
4136 * Subscription attribute security is handled by copy_subscription_attrs().
4139 if (strcmp(fromattr
->name
, "job-id"))
4143 if (!ra
|| cupsArrayFind(ra
, fromattr
->name
))
4146 * Don't send collection attributes by default to IPP/1.x clients
4147 * since many do not support collections. Also don't send
4148 * media-col-database unless specifically requested by the client.
4151 if (fromattr
->value_tag
== IPP_TAG_BEGIN_COLLECTION
&&
4153 (to
->request
.status
.version
[0] == 1 ||
4154 !strcmp(fromattr
->name
, "media-col-database")))
4157 ippCopyAttribute(to
, fromattr
, quickcopy
);
4164 * 'copy_banner()' - Copy a banner file to the requests directory for the
4168 static int /* O - Size of banner file in kbytes */
4169 copy_banner(cupsd_client_t
*con
, /* I - Client connection */
4170 cupsd_job_t
*job
, /* I - Job information */
4171 const char *name
) /* I - Name of banner */
4173 int i
; /* Looping var */
4174 int kbytes
; /* Size of banner file in kbytes */
4175 char filename
[1024]; /* Job filename */
4176 cupsd_banner_t
*banner
; /* Pointer to banner */
4177 cups_file_t
*in
; /* Input file */
4178 cups_file_t
*out
; /* Output file */
4179 int ch
; /* Character from file */
4180 char attrname
[255], /* Name of attribute */
4181 *s
; /* Pointer into name */
4182 ipp_attribute_t
*attr
; /* Attribute */
4185 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4186 "copy_banner(con=%p[%d], job=%p[%d], name=\"%s\")",
4187 con
, con
? con
->http
.fd
: -1, job
, job
->id
,
4188 name
? name
: "(null)");
4191 * Find the banner; return if not found or "none"...
4194 if (!name
|| !strcmp(name
, "none") ||
4195 (banner
= cupsdFindBanner(name
)) == NULL
)
4199 * Open the banner and job files...
4202 if (add_file(con
, job
, banner
->filetype
, 0))
4205 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
4207 if ((out
= cupsFileOpen(filename
, "w")) == NULL
)
4209 cupsdLogMessage(CUPSD_LOG_ERROR
,
4210 "Unable to create banner job file %s - %s",
4211 filename
, strerror(errno
));
4216 fchmod(cupsFileNumber(out
), 0640);
4217 fchown(cupsFileNumber(out
), RunUser
, Group
);
4220 * Try the localized banner file under the subdirectory...
4223 strlcpy(attrname
, job
->attrs
->attrs
->next
->values
[0].string
.text
,
4225 if (strlen(attrname
) > 2 && attrname
[2] == '-')
4228 * Convert ll-cc to ll_CC...
4232 attrname
[3] = toupper(attrname
[3] & 255);
4233 attrname
[4] = toupper(attrname
[4] & 255);
4236 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4239 if (access(filename
, 0) && strlen(attrname
) > 2)
4242 * Wasn't able to find "ll_CC" locale file; try the non-national
4243 * localization banner directory.
4248 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4252 if (access(filename
, 0))
4255 * Use the non-localized banner file.
4258 snprintf(filename
, sizeof(filename
), "%s/banners/%s", DataDir
, name
);
4261 if ((in
= cupsFileOpen(filename
, "r")) == NULL
)
4265 cupsdLogMessage(CUPSD_LOG_ERROR
,
4266 "Unable to open banner template file %s - %s",
4267 filename
, strerror(errno
));
4273 * Parse the file to the end...
4276 while ((ch
= cupsFileGetChar(in
)) != EOF
)
4280 * Get an attribute name...
4283 for (s
= attrname
; (ch
= cupsFileGetChar(in
)) != EOF
;)
4284 if (!isalpha(ch
& 255) && ch
!= '-' && ch
!= '?')
4286 else if (s
< (attrname
+ sizeof(attrname
) - 1))
4296 * Ignore { followed by stuff that is not an attribute name...
4299 cupsFilePrintf(out
, "{%s%c", attrname
, ch
);
4304 * See if it is defined...
4307 if (attrname
[0] == '?')
4312 if (!strcmp(s
, "printer-name"))
4314 cupsFilePuts(out
, job
->dest
);
4317 else if ((attr
= ippFindAttribute(job
->attrs
, s
, IPP_TAG_ZERO
)) == NULL
)
4320 * See if we have a leading question mark...
4323 if (attrname
[0] != '?')
4326 * Nope, write to file as-is; probably a PostScript procedure...
4329 cupsFilePrintf(out
, "{%s}", attrname
);
4336 * Output value(s)...
4339 for (i
= 0; i
< attr
->num_values
; i
++)
4342 cupsFilePutChar(out
, ',');
4344 switch (attr
->value_tag
)
4346 case IPP_TAG_INTEGER
:
4348 if (!strncmp(s
, "time-at-", 8))
4350 struct timeval tv
; /* Time value */
4352 tv
.tv_sec
= attr
->values
[i
].integer
;
4355 cupsFilePuts(out
, cupsdGetDateTime(&tv
, CUPSD_TIME_STANDARD
));
4358 cupsFilePrintf(out
, "%d", attr
->values
[i
].integer
);
4361 case IPP_TAG_BOOLEAN
:
4362 cupsFilePrintf(out
, "%d", attr
->values
[i
].boolean
);
4365 case IPP_TAG_NOVALUE
:
4366 cupsFilePuts(out
, "novalue");
4369 case IPP_TAG_RANGE
:
4370 cupsFilePrintf(out
, "%d-%d", attr
->values
[i
].range
.lower
,
4371 attr
->values
[i
].range
.upper
);
4374 case IPP_TAG_RESOLUTION
:
4375 cupsFilePrintf(out
, "%dx%d%s", attr
->values
[i
].resolution
.xres
,
4376 attr
->values
[i
].resolution
.yres
,
4377 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
4382 case IPP_TAG_STRING
:
4385 case IPP_TAG_KEYWORD
:
4386 case IPP_TAG_CHARSET
:
4387 case IPP_TAG_LANGUAGE
:
4388 if (!_cups_strcasecmp(banner
->filetype
->type
, "postscript"))
4391 * Need to quote strings for PS banners...
4396 for (p
= attr
->values
[i
].string
.text
; *p
; p
++)
4398 if (*p
== '(' || *p
== ')' || *p
== '\\')
4400 cupsFilePutChar(out
, '\\');
4401 cupsFilePutChar(out
, *p
);
4403 else if (*p
< 32 || *p
> 126)
4404 cupsFilePrintf(out
, "\\%03o", *p
& 255);
4406 cupsFilePutChar(out
, *p
);
4410 cupsFilePuts(out
, attr
->values
[i
].string
.text
);
4414 break; /* anti-compiler-warning-code */
4418 else if (ch
== '\\') /* Quoted char */
4420 ch
= cupsFileGetChar(in
);
4422 if (ch
!= '{') /* Only do special handling for \{ */
4423 cupsFilePutChar(out
, '\\');
4425 cupsFilePutChar(out
, ch
);
4428 cupsFilePutChar(out
, ch
);
4432 kbytes
= (cupsFileTell(out
) + 1023) / 1024;
4434 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
4435 IPP_TAG_INTEGER
)) != NULL
)
4436 attr
->values
[0].integer
+= kbytes
;
4445 * 'copy_file()' - Copy a PPD file or interface script...
4448 static int /* O - 0 = success, -1 = error */
4449 copy_file(const char *from
, /* I - Source file */
4450 const char *to
) /* I - Destination file */
4452 cups_file_t
*src
, /* Source file */
4453 *dst
; /* Destination file */
4454 int bytes
; /* Bytes to read/write */
4455 char buffer
[2048]; /* Copy buffer */
4458 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_file(\"%s\", \"%s\")", from
, to
);
4461 * Open the source and destination file for a copy...
4464 if ((src
= cupsFileOpen(from
, "rb")) == NULL
)
4467 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
4474 * Copy the source file to the destination...
4477 while ((bytes
= cupsFileRead(src
, buffer
, sizeof(buffer
))) > 0)
4478 if (cupsFileWrite(dst
, buffer
, bytes
) < bytes
)
4486 * Close both files and return...
4491 return (cupsFileClose(dst
));
4496 * 'copy_model()' - Copy a PPD model file, substituting default values
4500 static int /* O - 0 = success, -1 = error */
4501 copy_model(cupsd_client_t
*con
, /* I - Client connection */
4502 const char *from
, /* I - Source file */
4503 const char *to
) /* I - Destination file */
4505 fd_set input
; /* select() input set */
4506 struct timeval timeout
; /* select() timeout */
4507 int maxfd
; /* Max file descriptor for select() */
4508 char tempfile
[1024]; /* Temporary PPD file */
4509 int tempfd
; /* Temporary PPD file descriptor */
4510 int temppid
; /* Process ID of cups-driverd */
4511 int temppipe
[2]; /* Temporary pipes */
4512 char *argv
[4], /* Command-line arguments */
4513 *envp
[MAX_ENV
]; /* Environment */
4514 cups_file_t
*src
, /* Source file */
4515 *dst
; /* Destination file */
4516 ppd_file_t
*ppd
; /* PPD file */
4517 int bytes
, /* Bytes from pipe */
4518 total
; /* Total bytes from pipe */
4519 char buffer
[2048]; /* Copy buffer */
4520 int i
; /* Looping var */
4521 char option
[PPD_MAX_NAME
], /* Option name */
4522 choice
[PPD_MAX_NAME
]; /* Choice name */
4523 ppd_size_t
*size
; /* Default size */
4524 int num_defaults
; /* Number of default options */
4525 cups_option_t
*defaults
; /* Default options */
4526 char cups_protocol
[PPD_MAX_LINE
];
4527 /* cupsProtocol attribute */
4530 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4531 "copy_model(con=%p, from=\"%s\", to=\"%s\")",
4535 * Run cups-driverd to get the PPD file...
4538 argv
[0] = "cups-driverd";
4540 argv
[2] = (char *)from
;
4543 cupsdLoadEnv(envp
, (int)(sizeof(envp
) / sizeof(envp
[0])));
4545 snprintf(buffer
, sizeof(buffer
), "%s/daemon/cups-driverd", ServerBin
);
4546 snprintf(tempfile
, sizeof(tempfile
), "%s/%d.ppd", TempDir
, con
->http
.fd
);
4547 tempfd
= open(tempfile
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
4548 if (tempfd
< 0 || cupsdOpenPipe(temppipe
))
4551 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4552 "copy_model: Running \"cups-driverd cat %s\"...", from
);
4554 if (!cupsdStartProcess(buffer
, argv
, envp
, -1, temppipe
[1], CGIPipes
[1],
4555 -1, -1, 0, DefaultProfile
, NULL
, &temppid
))
4566 * Wait up to 30 seconds for the PPD file to be copied...
4571 if (temppipe
[0] > CGIPipes
[0])
4572 maxfd
= temppipe
[0] + 1;
4574 maxfd
= CGIPipes
[0] + 1;
4579 * See if we have data ready...
4583 FD_SET(temppipe
[0], &input
);
4584 FD_SET(CGIPipes
[0], &input
);
4586 timeout
.tv_sec
= 30;
4587 timeout
.tv_usec
= 0;
4589 if ((i
= select(maxfd
, &input
, NULL
, NULL
, &timeout
)) < 0)
4599 * We have timed out...
4605 if (FD_ISSET(temppipe
[0], &input
))
4608 * Read the PPD file from the pipe, and write it to the PPD file.
4611 if ((bytes
= read(temppipe
[0], buffer
, sizeof(buffer
))) > 0)
4613 if (write(tempfd
, buffer
, bytes
) < bytes
)
4622 if (FD_ISSET(CGIPipes
[0], &input
))
4632 * No data from cups-deviced...
4635 cupsdLogMessage(CUPSD_LOG_ERROR
, "copy_model: empty PPD file");
4641 * Open the source file for a copy...
4644 if ((src
= cupsFileOpen(tempfile
, "rb")) == NULL
)
4651 * Read the source file and see what page sizes are supported...
4654 if ((ppd
= _ppdOpen(src
, _PPD_LOCALIZATION_NONE
)) == NULL
)
4662 * Open the destination (if possible) and set the default options...
4667 cups_protocol
[0] = '\0';
4669 if ((dst
= cupsFileOpen(to
, "rb")) != NULL
)
4672 * Read all of the default lines from the old PPD...
4675 while (cupsFileGets(dst
, buffer
, sizeof(buffer
)))
4676 if (!strncmp(buffer
, "*Default", 8))
4679 * Add the default option...
4682 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
4683 choice
, sizeof(choice
)))
4685 ppd_option_t
*ppdo
; /* PPD option */
4689 * Only add the default if the default hasn't already been
4690 * set and the choice exists in the new PPD...
4693 if (!cupsGetOption(option
, num_defaults
, defaults
) &&
4694 (ppdo
= ppdFindOption(ppd
, option
)) != NULL
&&
4695 ppdFindChoice(ppdo
, choice
))
4696 num_defaults
= cupsAddOption(option
, choice
, num_defaults
,
4700 else if (!strncmp(buffer
, "*cupsProtocol:", 14))
4701 strlcpy(cups_protocol
, buffer
, sizeof(cups_protocol
));
4705 else if ((size
= ppdPageSize(ppd
, DefaultPaperSize
)) != NULL
)
4708 * Add the default media sizes...
4711 num_defaults
= cupsAddOption("PageSize", size
->name
,
4712 num_defaults
, &defaults
);
4713 num_defaults
= cupsAddOption("PageRegion", size
->name
,
4714 num_defaults
, &defaults
);
4715 num_defaults
= cupsAddOption("PaperDimension", size
->name
,
4716 num_defaults
, &defaults
);
4717 num_defaults
= cupsAddOption("ImageableArea", size
->name
,
4718 num_defaults
, &defaults
);
4724 * Open the destination file for a copy...
4727 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
4729 cupsFreeOptions(num_defaults
, defaults
);
4736 * Copy the source file to the destination...
4739 cupsFileRewind(src
);
4741 while (cupsFileGets(src
, buffer
, sizeof(buffer
)))
4743 if (!strncmp(buffer
, "*Default", 8))
4746 * Check for an previous default option choice...
4749 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
4750 choice
, sizeof(choice
)))
4752 const char *val
; /* Default option value */
4755 if ((val
= cupsGetOption(option
, num_defaults
, defaults
)) != NULL
)
4758 * Substitute the previous choice...
4761 snprintf(buffer
, sizeof(buffer
), "*Default%s: %s", option
, val
);
4766 cupsFilePrintf(dst
, "%s\n", buffer
);
4769 if (cups_protocol
[0])
4770 cupsFilePrintf(dst
, "%s\n", cups_protocol
);
4772 cupsFreeOptions(num_defaults
, defaults
);
4775 * Close both files and return...
4782 return (cupsFileClose(dst
));
4787 * 'copy_job_attrs()' - Copy job attributes.
4791 copy_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
4792 cupsd_job_t
*job
, /* I - Job */
4793 cups_array_t
*ra
, /* I - Requested attributes array */
4794 cups_array_t
*exclude
) /* I - Private attributes array */
4796 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
4800 * Send the requested attributes for each job...
4803 if (!cupsArrayFind(exclude
, "all"))
4805 if ((!exclude
|| !cupsArrayFind(exclude
, "number-of-documents")) &&
4806 (!ra
|| cupsArrayFind(ra
, "number-of-documents")))
4807 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4808 "number-of-documents", job
->num_files
);
4810 if ((!exclude
|| !cupsArrayFind(exclude
, "job-media-progress")) &&
4811 (!ra
|| cupsArrayFind(ra
, "job-media-progress")))
4812 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4813 "job-media-progress", job
->progress
);
4815 if ((!exclude
|| !cupsArrayFind(exclude
, "job-more-info")) &&
4816 (!ra
|| cupsArrayFind(ra
, "job-more-info")))
4818 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "http",
4819 NULL
, con
->clientname
, con
->clientport
, "/jobs/%d",
4821 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4822 "job-more-info", NULL
, job_uri
);
4825 if (job
->state_value
> IPP_JOB_PROCESSING
&&
4826 (!exclude
|| !cupsArrayFind(exclude
, "job-preserved")) &&
4827 (!ra
|| cupsArrayFind(ra
, "job-preserved")))
4828 ippAddBoolean(con
->response
, IPP_TAG_JOB
, "job-preserved",
4829 job
->num_files
> 0);
4831 if ((!exclude
|| !cupsArrayFind(exclude
, "job-printer-up-time")) &&
4832 (!ra
|| cupsArrayFind(ra
, "job-printer-up-time")))
4833 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4834 "job-printer-up-time", time(NULL
));
4837 if (!ra
|| cupsArrayFind(ra
, "job-printer-uri"))
4839 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
4840 con
->clientname
, con
->clientport
,
4841 (job
->dtype
& CUPS_PRINTER_CLASS
) ? "/classes/%s" :
4844 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4845 "job-printer-uri", NULL
, job_uri
);
4848 if (!ra
|| cupsArrayFind(ra
, "job-uri"))
4850 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
4851 con
->clientname
, con
->clientport
, "/jobs/%d",
4853 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4854 "job-uri", NULL
, job_uri
);
4857 copy_attrs(con
->response
, job
->attrs
, ra
, IPP_TAG_JOB
, 0, exclude
);
4862 * 'copy_printer_attrs()' - Copy printer attributes.
4867 cupsd_client_t
*con
, /* I - Client connection */
4868 cupsd_printer_t
*printer
, /* I - Printer */
4869 cups_array_t
*ra
) /* I - Requested attributes array */
4871 char printer_uri
[HTTP_MAX_URI
];
4873 char printer_icons
[HTTP_MAX_URI
];
4875 time_t curtime
; /* Current time */
4876 int i
; /* Looping var */
4880 * Copy the printer attributes to the response using requested-attributes
4881 * and document-format attributes that may be provided by the client.
4884 curtime
= time(NULL
);
4886 if (!ra
|| cupsArrayFind(ra
, "marker-change-time"))
4887 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4888 "marker-change-time", printer
->marker_time
);
4890 if (printer
->num_printers
> 0 &&
4891 (!ra
|| cupsArrayFind(ra
, "member-uris")))
4893 ipp_attribute_t
*member_uris
; /* member-uris attribute */
4894 cupsd_printer_t
*p2
; /* Printer in class */
4895 ipp_attribute_t
*p2_uri
; /* printer-uri-supported for class printer */
4898 if ((member_uris
= ippAddStrings(con
->response
, IPP_TAG_PRINTER
,
4899 IPP_TAG_URI
, "member-uris",
4900 printer
->num_printers
, NULL
,
4903 for (i
= 0; i
< printer
->num_printers
; i
++)
4905 p2
= printer
->printers
[i
];
4907 if ((p2_uri
= ippFindAttribute(p2
->attrs
, "printer-uri-supported",
4908 IPP_TAG_URI
)) != NULL
)
4909 member_uris
->values
[i
].string
.text
=
4910 _cupsStrRetain(p2_uri
->values
[0].string
.text
);
4913 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
,
4914 sizeof(printer_uri
), "ipp", NULL
, con
->clientname
,
4916 (p2
->type
& CUPS_PRINTER_CLASS
) ?
4917 "/classes/%s" : "/printers/%s", p2
->name
);
4918 member_uris
->values
[i
].string
.text
= _cupsStrAlloc(printer_uri
);
4924 if (printer
->alert
&& (!ra
|| cupsArrayFind(ra
, "printer-alert")))
4925 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_STRING
,
4926 "printer-alert", NULL
, printer
->alert
);
4928 if (printer
->alert_description
&&
4929 (!ra
|| cupsArrayFind(ra
, "printer-alert-description")))
4930 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4931 "printer-alert-description", NULL
,
4932 printer
->alert_description
);
4934 if (!ra
|| cupsArrayFind(ra
, "printer-current-time"))
4935 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-current-time",
4936 ippTimeToDate(curtime
));
4938 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
4939 if (!ra
|| cupsArrayFind(ra
, "printer-dns-sd-name"))
4941 if (printer
->reg_name
)
4942 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4943 "printer-dns-sd-name", NULL
, printer
->reg_name
);
4945 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
4946 "printer-dns-sd-name", 0);
4948 #endif /* HAVE_DNSSD || HAVE_AVAHI */
4950 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy"))
4951 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4952 "printer-error-policy", NULL
, printer
->error_policy
);
4954 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy-supported"))
4956 static const char * const errors
[] =/* printer-error-policy-supported values */
4959 "retry-current-job",
4964 if (printer
->type
& CUPS_PRINTER_CLASS
)
4965 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
4966 "printer-error-policy-supported", NULL
, "retry-current-job");
4968 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
4969 "printer-error-policy-supported",
4970 sizeof(errors
) / sizeof(errors
[0]), NULL
, errors
);
4973 if (!ra
|| cupsArrayFind(ra
, "printer-icons"))
4975 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_icons
, sizeof(printer_icons
),
4976 "http", NULL
, con
->clientname
, con
->clientport
,
4977 "/icons/%s.png", printer
->name
);
4978 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-icons",
4979 NULL
, printer_icons
);
4980 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-icons=\"%s\"", printer_icons
);
4983 if (!ra
|| cupsArrayFind(ra
, "printer-is-accepting-jobs"))
4984 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
4985 printer
->accepting
);
4987 if (!ra
|| cupsArrayFind(ra
, "printer-is-shared"))
4988 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-shared",
4991 if (!ra
|| cupsArrayFind(ra
, "printer-more-info"))
4993 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
4994 "http", NULL
, con
->clientname
, con
->clientport
,
4995 (printer
->type
& CUPS_PRINTER_CLASS
) ?
4996 "/classes/%s" : "/printers/%s", printer
->name
);
4997 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
4998 "printer-more-info", NULL
, printer_uri
);
5001 if (!ra
|| cupsArrayFind(ra
, "printer-op-policy"))
5002 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5003 "printer-op-policy", NULL
, printer
->op_policy
);
5005 if (!ra
|| cupsArrayFind(ra
, "printer-state"))
5006 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
5009 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-time"))
5010 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5011 "printer-state-change-time", printer
->state_time
);
5013 if (!ra
|| cupsArrayFind(ra
, "printer-state-message"))
5014 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5015 "printer-state-message", NULL
, printer
->state_message
);
5017 if (!ra
|| cupsArrayFind(ra
, "printer-state-reasons"))
5018 add_printer_state_reasons(con
, printer
);
5020 if (!ra
|| cupsArrayFind(ra
, "printer-type"))
5022 int type
; /* printer-type value */
5025 * Add the CUPS-specific printer-type attribute...
5028 type
= printer
->type
;
5030 if (printer
== DefaultPrinter
)
5031 type
|= CUPS_PRINTER_DEFAULT
;
5033 if (!printer
->accepting
)
5034 type
|= CUPS_PRINTER_REJECTING
;
5036 if (!printer
->shared
)
5037 type
|= CUPS_PRINTER_NOT_SHARED
;
5039 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-type",
5043 if (!ra
|| cupsArrayFind(ra
, "printer-up-time"))
5044 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5045 "printer-up-time", curtime
);
5047 if (!ra
|| cupsArrayFind(ra
, "printer-uri-supported"))
5049 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5050 "ipp", NULL
, con
->clientname
, con
->clientport
,
5051 (printer
->type
& CUPS_PRINTER_CLASS
) ?
5052 "/classes/%s" : "/printers/%s", printer
->name
);
5053 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5054 "printer-uri-supported", NULL
, printer_uri
);
5055 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-uri-supported=\"%s\"",
5059 if (!ra
|| cupsArrayFind(ra
, "queued-job-count"))
5060 add_queued_job_count(con
, printer
);
5062 copy_attrs(con
->response
, printer
->attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
5063 if (printer
->ppd_attrs
)
5064 copy_attrs(con
->response
, printer
->ppd_attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
5065 copy_attrs(con
->response
, CommonData
, ra
, IPP_TAG_ZERO
, IPP_TAG_COPY
, NULL
);
5070 * 'copy_subscription_attrs()' - Copy subscription attributes.
5074 copy_subscription_attrs(
5075 cupsd_client_t
*con
, /* I - Client connection */
5076 cupsd_subscription_t
*sub
, /* I - Subscription */
5077 cups_array_t
*ra
, /* I - Requested attributes array */
5078 cups_array_t
*exclude
) /* I - Private attributes array */
5080 ipp_attribute_t
*attr
; /* Current attribute */
5081 char printer_uri
[HTTP_MAX_URI
];
5083 int count
; /* Number of events */
5084 unsigned mask
; /* Current event mask */
5085 const char *name
; /* Current event name */
5088 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5089 "copy_subscription_attrs(con=%p, sub=%p, ra=%p, exclude=%p)",
5090 con
, sub
, ra
, exclude
);
5093 * Copy the subscription attributes to the response using the
5094 * requested-attributes attribute that may be provided by the client.
5097 if (!exclude
|| !cupsArrayFind(exclude
, "all"))
5099 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-events")) &&
5100 (!ra
|| cupsArrayFind(ra
, "notify-events")))
5102 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_subscription_attrs: notify-events");
5104 if ((name
= cupsdEventName((cupsd_eventmask_t
)sub
->mask
)) != NULL
)
5107 * Simple event list...
5110 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
,
5111 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5112 "notify-events", NULL
, name
);
5117 * Complex event list...
5120 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5121 if (sub
->mask
& mask
)
5124 attr
= ippAddStrings(con
->response
, IPP_TAG_SUBSCRIPTION
,
5125 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5126 "notify-events", count
, NULL
, NULL
);
5128 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5129 if (sub
->mask
& mask
)
5131 attr
->values
[count
].string
.text
=
5132 (char *)cupsdEventName((cupsd_eventmask_t
)mask
);
5139 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-lease-duration")) &&
5140 (!sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-lease-duration"))))
5141 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5142 "notify-lease-duration", sub
->lease
);
5144 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-recipient-uri")) &&
5145 (sub
->recipient
&& (!ra
|| cupsArrayFind(ra
, "notify-recipient-uri"))))
5146 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5147 "notify-recipient-uri", NULL
, sub
->recipient
);
5148 else if ((!exclude
|| !cupsArrayFind(exclude
, "notify-pull-method")) &&
5149 (!ra
|| cupsArrayFind(ra
, "notify-pull-method")))
5150 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_KEYWORD
,
5151 "notify-pull-method", NULL
, "ippget");
5153 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-subscriber-user-name")) &&
5154 (!ra
|| cupsArrayFind(ra
, "notify-subscriber-user-name")))
5155 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_NAME
,
5156 "notify-subscriber-user-name", NULL
, sub
->owner
);
5158 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-time-interval")) &&
5159 (!ra
|| cupsArrayFind(ra
, "notify-time-interval")))
5160 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5161 "notify-time-interval", sub
->interval
);
5163 if (sub
->user_data_len
> 0 &&
5164 (!exclude
|| !cupsArrayFind(exclude
, "notify-user-data")) &&
5165 (!ra
|| cupsArrayFind(ra
, "notify-user-data")))
5166 ippAddOctetString(con
->response
, IPP_TAG_SUBSCRIPTION
, "notify-user-data",
5167 sub
->user_data
, sub
->user_data_len
);
5170 if (sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-job-id")))
5171 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5172 "notify-job-id", sub
->job
->id
);
5174 if (sub
->dest
&& (!ra
|| cupsArrayFind(ra
, "notify-printer-uri")))
5176 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5177 "ipp", NULL
, con
->clientname
, con
->clientport
,
5178 "/printers/%s", sub
->dest
->name
);
5179 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5180 "notify-printer-uri", NULL
, printer_uri
);
5183 if (!ra
|| cupsArrayFind(ra
, "notify-subscription-id"))
5184 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5185 "notify-subscription-id", sub
->id
);
5190 * 'create_job()' - Print a file to a printer or class.
5194 create_job(cupsd_client_t
*con
, /* I - Client connection */
5195 ipp_attribute_t
*uri
) /* I - Printer URI */
5197 int i
; /* Looping var */
5198 cupsd_printer_t
*printer
; /* Printer */
5199 cupsd_job_t
*job
; /* New job */
5200 static const char * const forbidden_attrs
[] =
5201 { /* List of forbidden attributes */
5205 "document-natural-language"
5209 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "create_job(%p[%d], %s)", con
,
5210 con
->http
.fd
, uri
->values
[0].string
.text
);
5213 * Is the destination valid?
5216 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
5222 send_ipp_status(con
, IPP_NOT_FOUND
,
5223 _("The printer or class does not exist."));
5228 * Check for invalid Create-Job attributes and log a warning or error depending
5229 * on whether cupsd is running in "strict conformance" mode...
5233 i
< (int)(sizeof(forbidden_attrs
) / sizeof(forbidden_attrs
[0]));
5235 if (ippFindAttribute(con
->request
, forbidden_attrs
[i
], IPP_TAG_ZERO
))
5237 if (StrictConformance
)
5239 send_ipp_status(con
, IPP_BAD_REQUEST
,
5240 _("The '%s' operation attribute cannot be supplied in a "
5241 "Create-Job request."), forbidden_attrs
[i
]);
5245 cupsdLogMessage(CUPSD_LOG_WARN
,
5246 "Unexpected '%s' operation attribute in a Create-Job "
5247 "request.", forbidden_attrs
[i
]);
5251 * Create the job object...
5254 if ((job
= add_job(con
, printer
, NULL
)) == NULL
)
5257 job
->pending_timeout
= 1;
5260 * Save and log the job...
5263 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
5264 job
->dest
, job
->username
);
5269 * 'create_requested_array()' - Create an array for the requested-attributes.
5272 static cups_array_t
* /* O - Array of attributes or NULL */
5273 create_requested_array(ipp_t
*request
) /* I - IPP request */
5275 cups_array_t
*ra
; /* Requested attributes array */
5279 * Create the array for standard attributes...
5282 ra
= ippCreateRequestedArray(request
);
5285 * Add CUPS defaults as needed...
5288 if (cupsArrayFind(ra
, "printer-defaults"))
5291 * Include user-set defaults...
5294 char *name
; /* Option name */
5296 cupsArrayRemove(ra
, "printer-defaults");
5298 for (name
= (char *)cupsArrayFirst(CommonDefaults
);
5300 name
= (char *)cupsArrayNext(CommonDefaults
))
5301 if (!cupsArrayFind(ra
, name
))
5302 cupsArrayAdd(ra
, name
);
5310 * 'create_subscription()' - Create a notification subscription.
5314 create_subscription(
5315 cupsd_client_t
*con
, /* I - Client connection */
5316 ipp_attribute_t
*uri
) /* I - Printer URI */
5318 http_status_t status
; /* Policy status */
5319 int i
; /* Looping var */
5320 ipp_attribute_t
*attr
; /* Current attribute */
5321 cups_ptype_t dtype
; /* Destination type (printer/class) */
5322 char scheme
[HTTP_MAX_URI
],
5323 /* Scheme portion of URI */
5324 userpass
[HTTP_MAX_URI
],
5325 /* Username portion of URI */
5327 /* Host portion of URI */
5328 resource
[HTTP_MAX_URI
];
5329 /* Resource portion of URI */
5330 int port
; /* Port portion of URI */
5331 cupsd_printer_t
*printer
; /* Printer/class */
5332 cupsd_job_t
*job
; /* Job */
5333 int jobid
; /* Job ID */
5334 cupsd_subscription_t
*sub
; /* Subscription object */
5335 const char *username
, /* requesting-user-name or
5336 authenticated username */
5337 *recipient
, /* notify-recipient-uri */
5338 *pullmethod
; /* notify-pull-method */
5339 ipp_attribute_t
*user_data
; /* notify-user-data */
5340 int interval
, /* notify-time-interval */
5341 lease
; /* notify-lease-duration */
5342 unsigned mask
; /* notify-events */
5343 ipp_attribute_t
*notify_events
,/* notify-events(-default) */
5344 *notify_lease
; /* notify-lease-duration(-default) */
5348 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
5350 if (attr
->group_tag
!= IPP_TAG_ZERO
)
5351 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "g%04x v%04x %s", attr
->group_tag
,
5352 attr
->value_tag
, attr
->name
);
5354 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "----SEP----");
5359 * Is the destination valid?
5362 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5363 "cupsdCreateSubscription(con=%p(%d), uri=\"%s\")",
5364 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
5366 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
5367 sizeof(scheme
), userpass
, sizeof(userpass
), host
,
5368 sizeof(host
), &port
, resource
, sizeof(resource
));
5370 if (!strcmp(resource
, "/"))
5372 dtype
= (cups_ptype_t
)0;
5375 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
5377 dtype
= (cups_ptype_t
)0;
5380 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
5382 dtype
= CUPS_PRINTER_CLASS
;
5385 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
5391 send_ipp_status(con
, IPP_NOT_FOUND
,
5392 _("The printer or class does not exist."));
5402 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
5405 send_http_error(con
, status
, printer
);
5409 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5411 send_http_error(con
, status
, NULL
);
5416 * Get the user that is requesting the subscription...
5419 username
= get_username(con
);
5422 * Find the first subscription group attribute; return if we have
5426 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
5427 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
5432 send_ipp_status(con
, IPP_BAD_REQUEST
,
5433 _("No subscription attributes in request."));
5438 * Process the subscription attributes in the request...
5441 con
->response
->request
.status
.status_code
= IPP_BAD_REQUEST
;
5449 lease
= DefaultLeaseDuration
;
5451 mask
= CUPSD_EVENT_NONE
;
5455 notify_events
= ippFindAttribute(printer
->attrs
, "notify-events-default",
5457 notify_lease
= ippFindAttribute(printer
->attrs
,
5458 "notify-lease-duration-default",
5462 lease
= notify_lease
->values
[0].integer
;
5466 notify_events
= NULL
;
5467 notify_lease
= NULL
;
5470 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
5472 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
5473 attr
->value_tag
== IPP_TAG_URI
)
5476 * Validate the recipient scheme against the ServerBin/notifier
5480 char notifier
[1024]; /* Notifier filename */
5483 recipient
= attr
->values
[0].string
.text
;
5485 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
5486 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
5487 host
, sizeof(host
), &port
,
5488 resource
, sizeof(resource
)) < HTTP_URI_OK
)
5490 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5491 _("Bad notify-recipient-uri \"%s\"."), recipient
);
5492 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5493 "notify-status-code", IPP_URI_SCHEME
);
5497 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
5499 if (access(notifier
, X_OK
))
5501 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5502 _("notify-recipient-uri URI \"%s\" uses unknown "
5503 "scheme."), recipient
);
5504 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5505 "notify-status-code", IPP_URI_SCHEME
);
5509 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
5511 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5512 _("notify-recipient-uri URI \"%s\" is already used."),
5514 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5515 "notify-status-code", IPP_ATTRIBUTES
);
5519 else if (!strcmp(attr
->name
, "notify-pull-method") &&
5520 attr
->value_tag
== IPP_TAG_KEYWORD
)
5522 pullmethod
= attr
->values
[0].string
.text
;
5524 if (strcmp(pullmethod
, "ippget"))
5526 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5527 _("Bad notify-pull-method \"%s\"."), pullmethod
);
5528 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5529 "notify-status-code", IPP_ATTRIBUTES
);
5533 else if (!strcmp(attr
->name
, "notify-charset") &&
5534 attr
->value_tag
== IPP_TAG_CHARSET
&&
5535 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
5536 strcmp(attr
->values
[0].string
.text
, "utf-8"))
5538 send_ipp_status(con
, IPP_CHARSET
,
5539 _("Character set \"%s\" not supported."),
5540 attr
->values
[0].string
.text
);
5543 else if (!strcmp(attr
->name
, "notify-natural-language") &&
5544 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
5545 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
5547 send_ipp_status(con
, IPP_CHARSET
,
5548 _("Language \"%s\" not supported."),
5549 attr
->values
[0].string
.text
);
5552 else if (!strcmp(attr
->name
, "notify-user-data") &&
5553 attr
->value_tag
== IPP_TAG_STRING
)
5555 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
5557 send_ipp_status(con
, IPP_REQUEST_VALUE
,
5558 _("The notify-user-data value is too large "
5559 "(%d > 63 octets)."),
5560 attr
->values
[0].unknown
.length
);
5566 else if (!strcmp(attr
->name
, "notify-events") &&
5567 attr
->value_tag
== IPP_TAG_KEYWORD
)
5568 notify_events
= attr
;
5569 else if (!strcmp(attr
->name
, "notify-lease-duration") &&
5570 attr
->value_tag
== IPP_TAG_INTEGER
)
5571 lease
= attr
->values
[0].integer
;
5572 else if (!strcmp(attr
->name
, "notify-time-interval") &&
5573 attr
->value_tag
== IPP_TAG_INTEGER
)
5574 interval
= attr
->values
[0].integer
;
5575 else if (!strcmp(attr
->name
, "notify-job-id") &&
5576 attr
->value_tag
== IPP_TAG_INTEGER
)
5577 jobid
= attr
->values
[0].integer
;
5584 for (i
= 0; i
< notify_events
->num_values
; i
++)
5585 mask
|= cupsdEventValue(notify_events
->values
[i
].string
.text
);
5589 cupsdLogMessage(CUPSD_LOG_DEBUG
, "recipient=\"%s\"", recipient
);
5591 cupsdLogMessage(CUPSD_LOG_DEBUG
, "pullmethod=\"%s\"", pullmethod
);
5592 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-lease-duration=%d", lease
);
5593 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-time-interval=%d", interval
);
5595 if (!recipient
&& !pullmethod
)
5598 if (mask
== CUPSD_EVENT_NONE
)
5601 mask
= CUPSD_EVENT_JOB_COMPLETED
;
5603 mask
= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
5606 send_ipp_status(con
, IPP_BAD_REQUEST
,
5607 _("notify-events not specified."));
5612 if (MaxLeaseDuration
&& (lease
== 0 || lease
> MaxLeaseDuration
))
5614 cupsdLogMessage(CUPSD_LOG_INFO
,
5615 "create_subscription: Limiting notify-lease-duration to "
5618 lease
= MaxLeaseDuration
;
5623 if ((job
= cupsdFindJob(jobid
)) == NULL
)
5625 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
5633 if ((sub
= cupsdAddSubscription(mask
, printer
, job
, recipient
, 0)) == NULL
)
5635 send_ipp_status(con
, IPP_TOO_MANY_SUBSCRIPTIONS
,
5636 _("There are too many subscriptions."));
5641 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription #%d for job %d.",
5644 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5645 "Added subscription #%d for printer \"%s\".",
5646 sub
->id
, printer
->name
);
5648 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription #%d for server.",
5651 sub
->interval
= interval
;
5653 sub
->expire
= lease
? time(NULL
) + lease
: 0;
5655 cupsdSetString(&sub
->owner
, username
);
5659 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
5660 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
5661 sub
->user_data_len
);
5664 ippAddSeparator(con
->response
);
5665 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5666 "notify-subscription-id", sub
->id
);
5668 con
->response
->request
.status
.status_code
= IPP_OK
;
5674 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
5679 * 'delete_printer()' - Remove a printer or class from the system.
5683 delete_printer(cupsd_client_t
*con
, /* I - Client connection */
5684 ipp_attribute_t
*uri
) /* I - URI of printer or class */
5686 http_status_t status
; /* Policy status */
5687 cups_ptype_t dtype
; /* Destination type (printer/class) */
5688 cupsd_printer_t
*printer
; /* Printer/class */
5689 char filename
[1024]; /* Script/PPD filename */
5692 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "delete_printer(%p[%d], %s)", con
,
5693 con
->http
.fd
, uri
->values
[0].string
.text
);
5696 * Do we have a valid URI?
5699 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
5705 send_ipp_status(con
, IPP_NOT_FOUND
,
5706 _("The printer or class does not exist."));
5714 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5716 send_http_error(con
, status
, NULL
);
5721 * Remove old jobs...
5724 cupsdCancelJobs(printer
->name
, NULL
, 1);
5727 * Remove old subscriptions and send a "deleted printer" event...
5730 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED
, printer
, NULL
,
5731 "%s \"%s\" deleted by \"%s\".",
5732 (dtype
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
5733 printer
->name
, get_username(con
));
5735 cupsdExpireSubscriptions(printer
, NULL
);
5738 * Remove any old PPD or script files...
5741 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
,
5745 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
5749 snprintf(filename
, sizeof(filename
), "%s/%s.png", CacheDir
, printer
->name
);
5752 snprintf(filename
, sizeof(filename
), "%s/%s.data", CacheDir
, printer
->name
);
5756 * Unregister color profiles...
5759 cupsdUnregisterColor(printer
);
5761 if (dtype
& CUPS_PRINTER_CLASS
)
5763 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" deleted by \"%s\".",
5764 printer
->name
, get_username(con
));
5766 cupsdDeletePrinter(printer
, 0);
5767 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
5771 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" deleted by \"%s\".",
5772 printer
->name
, get_username(con
));
5774 if (cupsdDeletePrinter(printer
, 0))
5775 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
5777 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
5780 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
5783 * Return with no errors...
5786 con
->response
->request
.status
.status_code
= IPP_OK
;
5791 * 'get_default()' - Get the default destination.
5795 get_default(cupsd_client_t
*con
) /* I - Client connection */
5797 http_status_t status
; /* Policy status */
5798 cups_array_t
*ra
; /* Requested attributes array */
5801 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_default(%p[%d])", con
, con
->http
.fd
);
5807 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5809 send_http_error(con
, status
, NULL
);
5815 ra
= create_requested_array(con
->request
);
5817 copy_printer_attrs(con
, DefaultPrinter
, ra
);
5819 cupsArrayDelete(ra
);
5821 con
->response
->request
.status
.status_code
= IPP_OK
;
5824 send_ipp_status(con
, IPP_NOT_FOUND
, _("No default printer."));
5829 * 'get_devices()' - Get the list of available devices on the local system.
5833 get_devices(cupsd_client_t
*con
) /* I - Client connection */
5835 http_status_t status
; /* Policy status */
5836 ipp_attribute_t
*limit
, /* limit attribute */
5837 *timeout
, /* timeout attribute */
5838 *requested
, /* requested-attributes attribute */
5839 *exclude
, /* exclude-schemes attribute */
5840 *include
; /* include-schemes attribute */
5841 char command
[1024], /* cups-deviced command */
5842 options
[2048], /* Options to pass to command */
5844 /* String for requested attributes */
5846 /* String for excluded schemes */
5848 /* String for included schemes */
5851 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_devices(%p[%d])", con
, con
->http
.fd
);
5857 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5859 send_http_error(con
, status
, NULL
);
5864 * Run cups-deviced command with the given options...
5867 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
5868 timeout
= ippFindAttribute(con
->request
, "timeout", IPP_TAG_INTEGER
);
5869 requested
= ippFindAttribute(con
->request
, "requested-attributes",
5871 exclude
= ippFindAttribute(con
->request
, "exclude-schemes", IPP_TAG_NAME
);
5872 include
= ippFindAttribute(con
->request
, "include-schemes", IPP_TAG_NAME
);
5875 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
5877 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
5880 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
5882 exclude_str
[0] = '\0';
5885 url_encode_attr(include
, include_str
, sizeof(include_str
));
5887 include_str
[0] = '\0';
5889 snprintf(command
, sizeof(command
), "%s/daemon/cups-deviced", ServerBin
);
5890 snprintf(options
, sizeof(options
),
5891 "%d+%d+%d+%d+%s%s%s%s%s",
5892 con
->request
->request
.op
.request_id
,
5893 limit
? limit
->values
[0].integer
: 0,
5894 timeout
? timeout
->values
[0].integer
: 15,
5897 exclude_str
[0] ? "%20" : "", exclude_str
,
5898 include_str
[0] ? "%20" : "", include_str
);
5900 if (cupsdSendCommand(con
, command
, options
, 1))
5903 * Command started successfully, don't send an IPP response here...
5906 ippDelete(con
->response
);
5907 con
->response
= NULL
;
5912 * Command failed, return "internal error" so the user knows something
5916 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
5917 _("cups-deviced failed to execute."));
5923 * 'get_document()' - Get a copy of a job file.
5927 get_document(cupsd_client_t
*con
, /* I - Client connection */
5928 ipp_attribute_t
*uri
) /* I - Job URI */
5930 http_status_t status
; /* Policy status */
5931 ipp_attribute_t
*attr
; /* Current attribute */
5932 int jobid
; /* Job ID */
5933 int docnum
; /* Document number */
5934 cupsd_job_t
*job
; /* Current job */
5935 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
5936 username
[HTTP_MAX_URI
], /* Username portion of URI */
5937 host
[HTTP_MAX_URI
], /* Host portion of URI */
5938 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
5939 int port
; /* Port portion of URI */
5940 char filename
[1024], /* Filename for document */
5941 format
[1024]; /* Format for document */
5944 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_document(%p[%d], %s)", con
,
5945 con
->http
.fd
, uri
->values
[0].string
.text
);
5948 * See if we have a job URI or a printer URI...
5951 if (!strcmp(uri
->name
, "printer-uri"))
5954 * Got a printer URI; see if we also have a job-id attribute...
5957 if ((attr
= ippFindAttribute(con
->request
, "job-id",
5958 IPP_TAG_INTEGER
)) == NULL
)
5960 send_ipp_status(con
, IPP_BAD_REQUEST
,
5961 _("Got a printer-uri attribute but no job-id."));
5965 jobid
= attr
->values
[0].integer
;
5970 * Got a job URI; parse it to get the job ID...
5973 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
5974 sizeof(scheme
), username
, sizeof(username
), host
,
5975 sizeof(host
), &port
, resource
, sizeof(resource
));
5977 if (strncmp(resource
, "/jobs/", 6))
5983 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
5984 uri
->values
[0].string
.text
);
5988 jobid
= atoi(resource
+ 6);
5992 * See if the job exists...
5995 if ((job
= cupsdFindJob(jobid
)) == NULL
)
5998 * Nope - return a "not found" error...
6001 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
6009 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
,
6010 job
->username
)) != HTTP_OK
)
6012 send_http_error(con
, status
, NULL
);
6017 * Get the document number...
6020 if ((attr
= ippFindAttribute(con
->request
, "document-number",
6021 IPP_TAG_INTEGER
)) == NULL
)
6023 send_ipp_status(con
, IPP_BAD_REQUEST
,
6024 _("Missing document-number attribute."));
6028 if ((docnum
= attr
->values
[0].integer
) < 1 || docnum
> job
->num_files
||
6029 attr
->num_values
> 1)
6031 send_ipp_status(con
, IPP_NOT_FOUND
,
6032 _("Document #%d does not exist in job #%d."), docnum
,
6037 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, jobid
,
6039 if ((con
->file
= open(filename
, O_RDONLY
)) == -1)
6041 cupsdLogMessage(CUPSD_LOG_ERROR
,
6042 "Unable to open document %d in job %d - %s", docnum
, jobid
,
6044 send_ipp_status(con
, IPP_NOT_FOUND
,
6045 _("Unable to open document #%d in job #%d."), docnum
,
6050 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
6054 snprintf(format
, sizeof(format
), "%s/%s", job
->filetypes
[docnum
- 1]->super
,
6055 job
->filetypes
[docnum
- 1]->type
);
6057 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format",
6059 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "document-number",
6061 if ((attr
= ippFindAttribute(job
->attrs
, "document-name",
6062 IPP_TAG_NAME
)) != NULL
)
6063 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name",
6064 NULL
, attr
->values
[0].string
.text
);
6069 * 'get_job_attrs()' - Get job attributes.
6073 get_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
6074 ipp_attribute_t
*uri
) /* I - Job URI */
6076 http_status_t status
; /* Policy status */
6077 ipp_attribute_t
*attr
; /* Current attribute */
6078 int jobid
; /* Job ID */
6079 cupsd_job_t
*job
; /* Current job */
6080 cupsd_printer_t
*printer
; /* Current printer */
6081 cupsd_policy_t
*policy
; /* Current security policy */
6082 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6083 username
[HTTP_MAX_URI
], /* Username portion of URI */
6084 host
[HTTP_MAX_URI
], /* Host portion of URI */
6085 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6086 int port
; /* Port portion of URI */
6087 cups_array_t
*ra
, /* Requested attributes array */
6088 *exclude
; /* Private attributes array */
6091 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_job_attrs(%p[%d], %s)", con
,
6092 con
->http
.fd
, uri
->values
[0].string
.text
);
6095 * See if we have a job URI or a printer URI...
6098 if (!strcmp(uri
->name
, "printer-uri"))
6101 * Got a printer URI; see if we also have a job-id attribute...
6104 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6105 IPP_TAG_INTEGER
)) == NULL
)
6107 send_ipp_status(con
, IPP_BAD_REQUEST
,
6108 _("Got a printer-uri attribute but no job-id."));
6112 jobid
= attr
->values
[0].integer
;
6117 * Got a job URI; parse it to get the job ID...
6120 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6121 sizeof(scheme
), username
, sizeof(username
), host
,
6122 sizeof(host
), &port
, resource
, sizeof(resource
));
6124 if (strncmp(resource
, "/jobs/", 6))
6130 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
6131 uri
->values
[0].string
.text
);
6135 jobid
= atoi(resource
+ 6);
6139 * See if the job exists...
6142 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6145 * Nope - return a "not found" error...
6148 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
6156 if ((printer
= job
->printer
) == NULL
)
6157 printer
= cupsdFindDest(job
->dest
);
6160 policy
= printer
->op_policy_ptr
;
6162 policy
= DefaultPolicyPtr
;
6164 if ((status
= cupsdCheckPolicy(policy
, con
, job
->username
)) != HTTP_OK
)
6166 send_http_error(con
, status
, NULL
);
6170 exclude
= cupsdGetPrivateAttrs(policy
, con
, printer
, job
->username
);
6173 * Copy attributes...
6178 ra
= create_requested_array(con
->request
);
6179 copy_job_attrs(con
, job
, ra
, exclude
);
6180 cupsArrayDelete(ra
);
6182 con
->response
->request
.status
.status_code
= IPP_OK
;
6187 * 'get_jobs()' - Get a list of jobs for the specified printer.
6191 get_jobs(cupsd_client_t
*con
, /* I - Client connection */
6192 ipp_attribute_t
*uri
) /* I - Printer URI */
6194 http_status_t status
; /* Policy status */
6195 ipp_attribute_t
*attr
; /* Current attribute */
6196 const char *dest
; /* Destination */
6197 cups_ptype_t dtype
; /* Destination type (printer/class) */
6198 cups_ptype_t dmask
; /* Destination type mask */
6199 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6200 username
[HTTP_MAX_URI
], /* Username portion of URI */
6201 host
[HTTP_MAX_URI
], /* Host portion of URI */
6202 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6203 int port
; /* Port portion of URI */
6204 int job_comparison
; /* Job comparison */
6205 ipp_jstate_t job_state
; /* job-state value */
6206 int first_job_id
; /* First job ID */
6207 int limit
; /* Maximum number of jobs to return */
6208 int count
; /* Number of jobs that match */
6209 ipp_attribute_t
*job_ids
; /* job-ids attribute */
6210 cupsd_job_t
*job
; /* Current job pointer */
6211 cupsd_printer_t
*printer
; /* Printer */
6212 cups_array_t
*list
; /* Which job list... */
6213 cups_array_t
*ra
, /* Requested attributes array */
6214 *exclude
; /* Private attributes array */
6215 cupsd_policy_t
*policy
; /* Current policy */
6218 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs(%p[%d], %s)", con
, con
->http
.fd
,
6219 uri
->values
[0].string
.text
);
6222 * Is the destination valid?
6225 if (strcmp(uri
->name
, "printer-uri"))
6227 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No printer-uri in request."));
6231 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6232 sizeof(scheme
), username
, sizeof(username
), host
,
6233 sizeof(host
), &port
, resource
, sizeof(resource
));
6235 if (!strcmp(resource
, "/") || !strcmp(resource
, "/jobs"))
6238 dtype
= (cups_ptype_t
)0;
6239 dmask
= (cups_ptype_t
)0;
6242 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6245 dtype
= (cups_ptype_t
)0;
6246 dmask
= CUPS_PRINTER_CLASS
;
6249 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6252 dtype
= CUPS_PRINTER_CLASS
;
6253 dmask
= CUPS_PRINTER_CLASS
;
6256 else if ((dest
= cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
,
6263 send_ipp_status(con
, IPP_NOT_FOUND
,
6264 _("The printer or class does not exist."));
6269 dtype
&= CUPS_PRINTER_CLASS
;
6270 dmask
= CUPS_PRINTER_CLASS
;
6278 policy
= printer
->op_policy_ptr
;
6280 policy
= DefaultPolicyPtr
;
6282 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
6284 send_http_error(con
, status
, NULL
);
6288 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
6291 * See if the "which-jobs" attribute have been specified...
6294 if ((attr
= ippFindAttribute(con
->request
, "which-jobs",
6295 IPP_TAG_KEYWORD
)) != NULL
&& job_ids
)
6297 send_ipp_status(con
, IPP_CONFLICT
,
6298 _("The %s attribute cannot be provided with job-ids."),
6302 else if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "not-completed"))
6304 job_comparison
= -1;
6305 job_state
= IPP_JOB_STOPPED
;
6308 else if (!strcmp(attr
->values
[0].string
.text
, "completed"))
6311 job_state
= IPP_JOB_CANCELED
;
6314 else if (!strcmp(attr
->values
[0].string
.text
, "aborted"))
6317 job_state
= IPP_JOB_ABORTED
;
6320 else if (!strcmp(attr
->values
[0].string
.text
, "all"))
6323 job_state
= IPP_JOB_PENDING
;
6326 else if (!strcmp(attr
->values
[0].string
.text
, "canceled"))
6329 job_state
= IPP_JOB_CANCELED
;
6332 else if (!strcmp(attr
->values
[0].string
.text
, "pending"))
6335 job_state
= IPP_JOB_PENDING
;
6338 else if (!strcmp(attr
->values
[0].string
.text
, "pending-held"))
6341 job_state
= IPP_JOB_HELD
;
6344 else if (!strcmp(attr
->values
[0].string
.text
, "processing"))
6347 job_state
= IPP_JOB_PROCESSING
;
6348 list
= PrintingJobs
;
6350 else if (!strcmp(attr
->values
[0].string
.text
, "processing-stopped"))
6353 job_state
= IPP_JOB_STOPPED
;
6358 send_ipp_status(con
, IPP_ATTRIBUTES
,
6359 _("The which-jobs value \"%s\" is not supported."),
6360 attr
->values
[0].string
.text
);
6361 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
6362 "which-jobs", NULL
, attr
->values
[0].string
.text
);
6367 * See if they want to limit the number of jobs reported...
6370 if ((attr
= ippFindAttribute(con
->request
, "limit",
6371 IPP_TAG_INTEGER
)) != NULL
)
6375 send_ipp_status(con
, IPP_CONFLICT
,
6376 _("The %s attribute cannot be provided with job-ids."),
6381 limit
= attr
->values
[0].integer
;
6386 if ((attr
= ippFindAttribute(con
->request
, "first-job-id",
6387 IPP_TAG_INTEGER
)) != NULL
)
6391 send_ipp_status(con
, IPP_CONFLICT
,
6392 _("The %s attribute cannot be provided with job-ids."),
6397 first_job_id
= attr
->values
[0].integer
;
6403 * See if we only want to see jobs for a specific user...
6406 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
6407 IPP_TAG_BOOLEAN
)) != NULL
&& job_ids
)
6409 send_ipp_status(con
, IPP_CONFLICT
,
6410 _("The %s attribute cannot be provided with job-ids."),
6414 else if (attr
&& attr
->values
[0].boolean
)
6415 strlcpy(username
, get_username(con
), sizeof(username
));
6419 ra
= create_requested_array(con
->request
);
6422 * OK, build a list of jobs for this printer...
6427 int i
; /* Looping var */
6429 for (i
= 0; i
< job_ids
->num_values
; i
++)
6431 if (!cupsdFindJob(job_ids
->values
[i
].integer
))
6435 if (i
< job_ids
->num_values
)
6437 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
6438 job_ids
->values
[i
].integer
);
6442 for (i
= 0; i
< job_ids
->num_values
; i
++)
6444 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
6450 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d",
6456 ippAddSeparator(con
->response
);
6458 exclude
= cupsdGetPrivateAttrs(job
->printer
?
6459 job
->printer
->op_policy_ptr
:
6460 policy
, con
, job
->printer
,
6463 copy_job_attrs(con
, job
, ra
, exclude
);
6468 for (count
= 0, job
= (cupsd_job_t
*)cupsArrayFirst(list
);
6469 (limit
<= 0 || count
< limit
) && job
;
6470 job
= (cupsd_job_t
*)cupsArrayNext(list
))
6473 * Filter out jobs that don't match...
6476 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
6477 "get_jobs: job->id=%d, dest=\"%s\", username=\"%s\", "
6478 "state_value=%d, attrs=%p", job
->id
, job
->dest
,
6479 job
->username
, job
->state_value
, job
->attrs
);
6481 if (!job
->dest
|| !job
->username
)
6484 if (!job
->dest
|| !job
->username
)
6487 if ((dest
&& strcmp(job
->dest
, dest
)) &&
6488 (!job
->printer
|| !dest
|| strcmp(job
->printer
->name
, dest
)))
6490 if ((job
->dtype
& dmask
) != dtype
&&
6491 (!job
->printer
|| (job
->printer
->type
& dmask
) != dtype
))
6494 if ((job_comparison
< 0 && job
->state_value
> job_state
) ||
6495 (job_comparison
== 0 && job
->state_value
!= job_state
) ||
6496 (job_comparison
> 0 && job
->state_value
< job_state
))
6499 if (job
->id
< first_job_id
)
6506 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d",
6511 if (username
[0] && _cups_strcasecmp(username
, job
->username
))
6515 ippAddSeparator(con
->response
);
6519 exclude
= cupsdGetPrivateAttrs(job
->printer
?
6520 job
->printer
->op_policy_ptr
:
6521 policy
, con
, job
->printer
,
6524 copy_job_attrs(con
, job
, ra
, exclude
);
6527 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: count=%d", count
);
6530 cupsArrayDelete(ra
);
6532 con
->response
->request
.status
.status_code
= IPP_OK
;
6537 * 'get_notifications()' - Get events for a subscription.
6541 get_notifications(cupsd_client_t
*con
) /* I - Client connection */
6543 int i
, j
; /* Looping vars */
6544 http_status_t status
; /* Policy status */
6545 cupsd_subscription_t
*sub
; /* Subscription */
6546 ipp_attribute_t
*ids
, /* notify-subscription-ids */
6547 *sequences
; /* notify-sequence-numbers */
6548 int min_seq
; /* Minimum sequence number */
6549 int interval
; /* Poll interval */
6552 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_notifications(con=%p[%d])",
6556 * Get subscription attributes...
6559 ids
= ippFindAttribute(con
->request
, "notify-subscription-ids",
6561 sequences
= ippFindAttribute(con
->request
, "notify-sequence-numbers",
6566 send_ipp_status(con
, IPP_BAD_REQUEST
,
6567 _("Missing notify-subscription-ids attribute."));
6572 * Are the subscription IDs valid?
6575 for (i
= 0, interval
= 60; i
< ids
->num_values
; i
++)
6577 if ((sub
= cupsdFindSubscription(ids
->values
[i
].integer
)) == NULL
)
6580 * Bad subscription ID...
6583 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
6584 ids
->values
[i
].integer
);
6592 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
6594 con
, sub
->owner
)) != HTTP_OK
)
6596 send_http_error(con
, status
, sub
->dest
);
6601 * Check the subscription type and update the interval accordingly.
6604 if (sub
->job
&& sub
->job
->state_value
== IPP_JOB_PROCESSING
&&
6607 else if (sub
->job
&& sub
->job
->state_value
>= IPP_JOB_STOPPED
)
6609 else if (sub
->dest
&& sub
->dest
->state
== IPP_PRINTER_PROCESSING
&&
6615 * Tell the client to poll again in N seconds...
6619 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
6620 "notify-get-interval", interval
);
6622 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
6623 "printer-up-time", time(NULL
));
6626 * Copy the subscription event attributes to the response.
6629 con
->response
->request
.status
.status_code
=
6630 interval
? IPP_OK
: IPP_OK_EVENTS_COMPLETE
;
6632 for (i
= 0; i
< ids
->num_values
; i
++)
6635 * Get the subscription and sequence number...
6638 sub
= cupsdFindSubscription(ids
->values
[i
].integer
);
6640 if (sequences
&& i
< sequences
->num_values
)
6641 min_seq
= sequences
->values
[i
].integer
;
6646 * If we don't have any new events, nothing to do here...
6649 if (min_seq
> (sub
->first_event_id
+ cupsArrayCount(sub
->events
)))
6653 * Otherwise copy all of the new events...
6656 if (sub
->first_event_id
> min_seq
)
6659 j
= min_seq
- sub
->first_event_id
;
6661 for (; j
< cupsArrayCount(sub
->events
); j
++)
6663 ippAddSeparator(con
->response
);
6665 copy_attrs(con
->response
,
6666 ((cupsd_event_t
*)cupsArrayIndex(sub
->events
, j
))->attrs
, NULL
,
6667 IPP_TAG_EVENT_NOTIFICATION
, 0, NULL
);
6674 * 'get_ppd()' - Get a named PPD from the local system.
6678 get_ppd(cupsd_client_t
*con
, /* I - Client connection */
6679 ipp_attribute_t
*uri
) /* I - Printer URI or PPD name */
6681 http_status_t status
; /* Policy status */
6682 cupsd_printer_t
*dest
; /* Destination */
6683 cups_ptype_t dtype
; /* Destination type */
6686 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppd(%p[%d], %p[%s=%s])", con
,
6687 con
->http
.fd
, uri
, uri
->name
, uri
->values
[0].string
.text
);
6689 if (!strcmp(uri
->name
, "ppd-name"))
6692 * Return a PPD file from cups-driverd...
6695 char command
[1024], /* cups-driverd command */
6696 options
[1024], /* Options to pass to command */
6697 ppd_name
[1024]; /* ppd-name */
6704 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6706 send_http_error(con
, status
, NULL
);
6711 * Run cups-driverd command with the given options...
6714 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
6715 url_encode_string(uri
->values
[0].string
.text
, ppd_name
, sizeof(ppd_name
));
6716 snprintf(options
, sizeof(options
), "get+%d+%s",
6717 con
->request
->request
.op
.request_id
, ppd_name
);
6719 if (cupsdSendCommand(con
, command
, options
, 0))
6722 * Command started successfully, don't send an IPP response here...
6725 ippDelete(con
->response
);
6726 con
->response
= NULL
;
6731 * Command failed, return "internal error" so the user knows something
6735 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
6736 _("cups-driverd failed to execute."));
6739 else if (!strcmp(uri
->name
, "printer-uri") &&
6740 cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &dest
))
6742 int i
; /* Looping var */
6743 char filename
[1024]; /* PPD filename */
6750 if ((status
= cupsdCheckPolicy(dest
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
6752 send_http_error(con
, status
, dest
);
6757 * See if we need the PPD for a class or remote printer...
6760 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
6763 if ((dtype
& CUPS_PRINTER_REMOTE
) && access(filename
, 0))
6765 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
6766 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
6767 "printer-uri", NULL
, dest
->uri
);
6770 else if (dtype
& CUPS_PRINTER_CLASS
)
6772 for (i
= 0; i
< dest
->num_printers
; i
++)
6773 if (!(dest
->printers
[i
]->type
& CUPS_PRINTER_CLASS
))
6775 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
6776 dest
->printers
[i
]->name
);
6778 if (!access(filename
, 0))
6782 if (i
< dest
->num_printers
)
6783 dest
= dest
->printers
[i
];
6786 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
6787 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
6788 "printer-uri", NULL
, dest
->printers
[0]->uri
);
6794 * Found the printer with the PPD file, now see if there is one...
6797 if ((con
->file
= open(filename
, O_RDONLY
)) < 0)
6799 send_ipp_status(con
, IPP_NOT_FOUND
,
6800 _("The PPD file \"%s\" could not be opened: %s"),
6801 uri
->values
[0].string
.text
, strerror(errno
));
6805 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
6809 con
->response
->request
.status
.status_code
= IPP_OK
;
6812 send_ipp_status(con
, IPP_NOT_FOUND
,
6813 _("The PPD file \"%s\" could not be found."),
6814 uri
->values
[0].string
.text
);
6819 * 'get_ppds()' - Get the list of PPD files on the local system.
6823 get_ppds(cupsd_client_t
*con
) /* I - Client connection */
6825 http_status_t status
; /* Policy status */
6826 ipp_attribute_t
*limit
, /* Limit attribute */
6827 *device
, /* ppd-device-id attribute */
6828 *language
, /* ppd-natural-language attribute */
6829 *make
, /* ppd-make attribute */
6830 *model
, /* ppd-make-and-model attribute */
6831 *model_number
, /* ppd-model-number attribute */
6832 *product
, /* ppd-product attribute */
6833 *psversion
, /* ppd-psverion attribute */
6834 *type
, /* ppd-type attribute */
6835 *requested
, /* requested-attributes attribute */
6836 *exclude
, /* exclude-schemes attribute */
6837 *include
; /* include-schemes attribute */
6838 char command
[1024], /* cups-driverd command */
6839 options
[4096], /* Options to pass to command */
6840 device_str
[256],/* Escaped ppd-device-id string */
6842 /* Escaped ppd-natural-language */
6843 make_str
[256], /* Escaped ppd-make string */
6844 model_str
[256], /* Escaped ppd-make-and-model string */
6845 model_number_str
[256],
6846 /* ppd-model-number string */
6848 /* Escaped ppd-product string */
6850 /* Escaped ppd-psversion string */
6851 type_str
[256], /* Escaped ppd-type string */
6853 /* String for requested attributes */
6855 /* String for excluded schemes */
6857 /* String for included schemes */
6860 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppds(%p[%d])", con
, con
->http
.fd
);
6866 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6868 send_http_error(con
, status
, NULL
);
6873 * Run cups-driverd command with the given options...
6876 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
6877 device
= ippFindAttribute(con
->request
, "ppd-device-id", IPP_TAG_TEXT
);
6878 language
= ippFindAttribute(con
->request
, "ppd-natural-language",
6880 make
= ippFindAttribute(con
->request
, "ppd-make", IPP_TAG_TEXT
);
6881 model
= ippFindAttribute(con
->request
, "ppd-make-and-model",
6883 model_number
= ippFindAttribute(con
->request
, "ppd-model-number",
6885 product
= ippFindAttribute(con
->request
, "ppd-product", IPP_TAG_TEXT
);
6886 psversion
= ippFindAttribute(con
->request
, "ppd-psversion", IPP_TAG_TEXT
);
6887 type
= ippFindAttribute(con
->request
, "ppd-type", IPP_TAG_KEYWORD
);
6888 requested
= ippFindAttribute(con
->request
, "requested-attributes",
6890 exclude
= ippFindAttribute(con
->request
, "exclude-schemes",
6892 include
= ippFindAttribute(con
->request
, "include-schemes",
6896 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
6898 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
6901 url_encode_attr(device
, device_str
, sizeof(device_str
));
6903 device_str
[0] = '\0';
6906 url_encode_attr(language
, language_str
, sizeof(language_str
));
6908 language_str
[0] = '\0';
6911 url_encode_attr(make
, make_str
, sizeof(make_str
));
6916 url_encode_attr(model
, model_str
, sizeof(model_str
));
6918 model_str
[0] = '\0';
6921 snprintf(model_number_str
, sizeof(model_number_str
), "ppd-model-number=%d",
6922 model_number
->values
[0].integer
);
6924 model_number_str
[0] = '\0';
6927 url_encode_attr(product
, product_str
, sizeof(product_str
));
6929 product_str
[0] = '\0';
6932 url_encode_attr(psversion
, psversion_str
, sizeof(psversion_str
));
6934 psversion_str
[0] = '\0';
6937 url_encode_attr(type
, type_str
, sizeof(type_str
));
6942 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
6944 exclude_str
[0] = '\0';
6947 url_encode_attr(include
, include_str
, sizeof(include_str
));
6949 include_str
[0] = '\0';
6951 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
6952 snprintf(options
, sizeof(options
),
6953 "list+%d+%d+%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
6954 con
->request
->request
.op
.request_id
,
6955 limit
? limit
->values
[0].integer
: 0,
6957 device
? "%20" : "", device_str
,
6958 language
? "%20" : "", language_str
,
6959 make
? "%20" : "", make_str
,
6960 model
? "%20" : "", model_str
,
6961 model_number
? "%20" : "", model_number_str
,
6962 product
? "%20" : "", product_str
,
6963 psversion
? "%20" : "", psversion_str
,
6964 type
? "%20" : "", type_str
,
6965 exclude_str
[0] ? "%20" : "", exclude_str
,
6966 include_str
[0] ? "%20" : "", include_str
);
6968 if (cupsdSendCommand(con
, command
, options
, 0))
6971 * Command started successfully, don't send an IPP response here...
6974 ippDelete(con
->response
);
6975 con
->response
= NULL
;
6980 * Command failed, return "internal error" so the user knows something
6984 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
6985 _("cups-driverd failed to execute."));
6991 * 'get_printer_attrs()' - Get printer attributes.
6995 get_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
6996 ipp_attribute_t
*uri
) /* I - Printer URI */
6998 http_status_t status
; /* Policy status */
6999 cups_ptype_t dtype
; /* Destination type (printer/class) */
7000 cupsd_printer_t
*printer
; /* Printer/class */
7001 cups_array_t
*ra
; /* Requested attributes array */
7004 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_attrs(%p[%d], %s)", con
,
7005 con
->http
.fd
, uri
->values
[0].string
.text
);
7008 * Is the destination valid?
7011 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7017 send_ipp_status(con
, IPP_NOT_FOUND
,
7018 _("The printer or class does not exist."));
7026 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7028 send_http_error(con
, status
, printer
);
7033 * Send the attributes...
7036 ra
= create_requested_array(con
->request
);
7038 copy_printer_attrs(con
, printer
, ra
);
7040 cupsArrayDelete(ra
);
7042 con
->response
->request
.status
.status_code
= IPP_OK
;
7047 * 'get_printer_supported()' - Get printer supported values.
7051 get_printer_supported(
7052 cupsd_client_t
*con
, /* I - Client connection */
7053 ipp_attribute_t
*uri
) /* I - Printer URI */
7055 http_status_t status
; /* Policy status */
7056 cups_ptype_t dtype
; /* Destination type (printer/class) */
7057 cupsd_printer_t
*printer
; /* Printer/class */
7060 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_supported(%p[%d], %s)", con
,
7061 con
->http
.fd
, uri
->values
[0].string
.text
);
7064 * Is the destination valid?
7067 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7073 send_ipp_status(con
, IPP_NOT_FOUND
,
7074 _("The printer or class does not exist."));
7082 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7084 send_http_error(con
, status
, printer
);
7089 * Return a list of attributes that can be set via Set-Printer-Attributes.
7092 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7094 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7095 "printer-location", 0);
7097 con
->response
->request
.status
.status_code
= IPP_OK
;
7102 * 'get_printers()' - Get a list of printers or classes.
7106 get_printers(cupsd_client_t
*con
, /* I - Client connection */
7107 int type
) /* I - 0 or CUPS_PRINTER_CLASS */
7109 http_status_t status
; /* Policy status */
7110 ipp_attribute_t
*attr
; /* Current attribute */
7111 int limit
; /* Max number of printers to return */
7112 int count
; /* Number of printers that match */
7113 cupsd_printer_t
*printer
; /* Current printer pointer */
7114 int printer_type
, /* printer-type attribute */
7115 printer_mask
; /* printer-type-mask attribute */
7116 char *location
; /* Location string */
7117 const char *username
; /* Current user */
7118 char *first_printer_name
; /* first-printer-name attribute */
7119 cups_array_t
*ra
; /* Requested attributes array */
7120 int local
; /* Local connection? */
7123 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printers(%p[%d], %x)", con
,
7124 con
->http
.fd
, type
);
7130 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7132 send_http_error(con
, status
, NULL
);
7137 * Check for printers...
7140 if (!Printers
|| !cupsArrayCount(Printers
))
7142 send_ipp_status(con
, IPP_NOT_FOUND
, _("No destinations added."));
7147 * See if they want to limit the number of printers reported...
7150 if ((attr
= ippFindAttribute(con
->request
, "limit",
7151 IPP_TAG_INTEGER
)) != NULL
)
7152 limit
= attr
->values
[0].integer
;
7156 if ((attr
= ippFindAttribute(con
->request
, "first-printer-name",
7157 IPP_TAG_NAME
)) != NULL
)
7158 first_printer_name
= attr
->values
[0].string
.text
;
7160 first_printer_name
= NULL
;
7163 * Support filtering...
7166 if ((attr
= ippFindAttribute(con
->request
, "printer-type",
7167 IPP_TAG_ENUM
)) != NULL
)
7168 printer_type
= attr
->values
[0].integer
;
7172 if ((attr
= ippFindAttribute(con
->request
, "printer-type-mask",
7173 IPP_TAG_ENUM
)) != NULL
)
7174 printer_mask
= attr
->values
[0].integer
;
7178 local
= httpAddrLocalhost(&(con
->clientaddr
));
7180 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
7181 IPP_TAG_TEXT
)) != NULL
)
7182 location
= attr
->values
[0].string
.text
;
7186 if (con
->username
[0])
7187 username
= con
->username
;
7188 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7189 IPP_TAG_NAME
)) != NULL
)
7190 username
= attr
->values
[0].string
.text
;
7194 ra
= create_requested_array(con
->request
);
7197 * OK, build a list of printers for this printer...
7200 if (first_printer_name
)
7202 if ((printer
= cupsdFindDest(first_printer_name
)) == NULL
)
7203 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7206 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7209 count
< limit
&& printer
;
7210 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
7212 if (!local
&& !printer
->shared
)
7215 if ((!type
|| (printer
->type
& CUPS_PRINTER_CLASS
) == type
) &&
7216 (printer
->type
& printer_mask
) == printer_type
&&
7218 (printer
->location
&& !_cups_strcasecmp(printer
->location
, location
))))
7221 * If a username is specified, see if it is allowed or denied
7225 if (cupsArrayCount(printer
->users
) && username
&&
7226 !user_allowed(printer
, username
))
7230 * Add the group separator as needed...
7234 ippAddSeparator(con
->response
);
7239 * Send the attributes...
7242 copy_printer_attrs(con
, printer
, ra
);
7246 cupsArrayDelete(ra
);
7248 con
->response
->request
.status
.status_code
= IPP_OK
;
7253 * 'get_subscription_attrs()' - Get subscription attributes.
7257 get_subscription_attrs(
7258 cupsd_client_t
*con
, /* I - Client connection */
7259 int sub_id
) /* I - Subscription ID */
7261 http_status_t status
; /* Policy status */
7262 cupsd_subscription_t
*sub
; /* Subscription */
7263 cupsd_policy_t
*policy
; /* Current security policy */
7264 cups_array_t
*ra
, /* Requested attributes array */
7265 *exclude
; /* Private attributes array */
7268 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7269 "get_subscription_attrs(con=%p[%d], sub_id=%d)",
7270 con
, con
->http
.fd
, sub_id
);
7273 * Is the subscription ID valid?
7276 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
7279 * Bad subscription ID...
7282 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
7292 policy
= sub
->dest
->op_policy_ptr
;
7294 policy
= DefaultPolicyPtr
;
7296 if ((status
= cupsdCheckPolicy(policy
, con
, sub
->owner
)) != HTTP_OK
)
7298 send_http_error(con
, status
, sub
->dest
);
7302 exclude
= cupsdGetPrivateAttrs(policy
, con
, sub
->dest
, sub
->owner
);
7305 * Copy the subscription attributes to the response using the
7306 * requested-attributes attribute that may be provided by the client.
7309 ra
= create_requested_array(con
->request
);
7311 copy_subscription_attrs(con
, sub
, ra
, exclude
);
7313 cupsArrayDelete(ra
);
7315 con
->response
->request
.status
.status_code
= IPP_OK
;
7320 * 'get_subscriptions()' - Get subscriptions.
7324 get_subscriptions(cupsd_client_t
*con
, /* I - Client connection */
7325 ipp_attribute_t
*uri
) /* I - Printer/job URI */
7327 http_status_t status
; /* Policy status */
7328 int count
; /* Number of subscriptions */
7329 int limit
; /* Limit */
7330 cupsd_subscription_t
*sub
; /* Subscription */
7331 cups_array_t
*ra
; /* Requested attributes array */
7332 ipp_attribute_t
*attr
; /* Attribute */
7333 cups_ptype_t dtype
; /* Destination type (printer/class) */
7334 char scheme
[HTTP_MAX_URI
],
7335 /* Scheme portion of URI */
7336 username
[HTTP_MAX_URI
],
7337 /* Username portion of URI */
7339 /* Host portion of URI */
7340 resource
[HTTP_MAX_URI
];
7341 /* Resource portion of URI */
7342 int port
; /* Port portion of URI */
7343 cupsd_job_t
*job
; /* Job pointer */
7344 cupsd_printer_t
*printer
; /* Printer */
7345 cupsd_policy_t
*policy
; /* Policy */
7346 cups_array_t
*exclude
; /* Private attributes array */
7349 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7350 "get_subscriptions(con=%p[%d], uri=%s)",
7351 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
7354 * Is the destination valid?
7357 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7358 sizeof(scheme
), username
, sizeof(username
), host
,
7359 sizeof(host
), &port
, resource
, sizeof(resource
));
7361 if (!strcmp(resource
, "/") ||
7362 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6) ||
7363 (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10) ||
7364 (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9))
7369 else if (!strncmp(resource
, "/jobs/", 6) && resource
[6])
7372 job
= cupsdFindJob(atoi(resource
+ 6));
7376 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
7377 atoi(resource
+ 6));
7381 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7387 send_ipp_status(con
, IPP_NOT_FOUND
,
7388 _("The printer or class does not exist."));
7391 else if ((attr
= ippFindAttribute(con
->request
, "notify-job-id",
7392 IPP_TAG_INTEGER
)) != NULL
)
7394 job
= cupsdFindJob(attr
->values
[0].integer
);
7398 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
7399 attr
->values
[0].integer
);
7411 policy
= printer
->op_policy_ptr
;
7413 policy
= DefaultPolicyPtr
;
7415 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
7417 send_http_error(con
, status
, printer
);
7422 * Copy the subscription attributes to the response using the
7423 * requested-attributes attribute that may be provided by the client.
7426 ra
= create_requested_array(con
->request
);
7428 if ((attr
= ippFindAttribute(con
->request
, "limit",
7429 IPP_TAG_INTEGER
)) != NULL
)
7430 limit
= attr
->values
[0].integer
;
7435 * See if we only want to see subscriptions for a specific user...
7438 if ((attr
= ippFindAttribute(con
->request
, "my-subscriptions",
7439 IPP_TAG_BOOLEAN
)) != NULL
&&
7440 attr
->values
[0].boolean
)
7441 strlcpy(username
, get_username(con
), sizeof(username
));
7445 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
), count
= 0;
7447 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
7448 if ((!printer
|| sub
->dest
== printer
) && (!job
|| sub
->job
== job
) &&
7449 (!username
[0] || !_cups_strcasecmp(username
, sub
->owner
)))
7451 ippAddSeparator(con
->response
);
7453 exclude
= cupsdGetPrivateAttrs(sub
->dest
? sub
->dest
->op_policy_ptr
:
7454 policy
, con
, sub
->dest
,
7457 copy_subscription_attrs(con
, sub
, ra
, exclude
);
7460 if (limit
&& count
>= limit
)
7464 cupsArrayDelete(ra
);
7467 con
->response
->request
.status
.status_code
= IPP_OK
;
7469 send_ipp_status(con
, IPP_NOT_FOUND
, _("No subscriptions found."));
7474 * 'get_username()' - Get the username associated with a request.
7477 static const char * /* O - Username */
7478 get_username(cupsd_client_t
*con
) /* I - Connection */
7480 ipp_attribute_t
*attr
; /* Attribute */
7483 if (con
->username
[0])
7484 return (con
->username
);
7485 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7486 IPP_TAG_NAME
)) != NULL
)
7487 return (attr
->values
[0].string
.text
);
7489 return ("anonymous");
7494 * 'hold_job()' - Hold a print job.
7498 hold_job(cupsd_client_t
*con
, /* I - Client connection */
7499 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
7501 ipp_attribute_t
*attr
; /* Current job-hold-until */
7502 const char *when
; /* New value */
7503 int jobid
; /* Job ID */
7504 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
7505 username
[HTTP_MAX_URI
], /* Username portion of URI */
7506 host
[HTTP_MAX_URI
], /* Host portion of URI */
7507 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7508 int port
; /* Port portion of URI */
7509 cupsd_job_t
*job
; /* Job information */
7512 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_job(%p[%d], %s)", con
, con
->http
.fd
,
7513 uri
->values
[0].string
.text
);
7516 * See if we have a job URI or a printer URI...
7519 if (!strcmp(uri
->name
, "printer-uri"))
7522 * Got a printer URI; see if we also have a job-id attribute...
7525 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7526 IPP_TAG_INTEGER
)) == NULL
)
7528 send_ipp_status(con
, IPP_BAD_REQUEST
,
7529 _("Got a printer-uri attribute but no job-id."));
7533 jobid
= attr
->values
[0].integer
;
7538 * Got a job URI; parse it to get the job ID...
7541 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7542 sizeof(scheme
), username
, sizeof(username
), host
,
7543 sizeof(host
), &port
, resource
, sizeof(resource
));
7545 if (strncmp(resource
, "/jobs/", 6))
7551 send_ipp_status(con
, IPP_BAD_REQUEST
,
7552 _("Bad job-uri \"%s\"."),
7553 uri
->values
[0].string
.text
);
7557 jobid
= atoi(resource
+ 6);
7561 * See if the job exists...
7564 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7567 * Nope - return a "not found" error...
7570 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
7575 * See if the job is owned by the requesting user...
7578 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7580 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
7581 cupsdFindDest(job
->dest
));
7586 * See if the job is in a state that allows holding...
7589 if (job
->state_value
> IPP_JOB_STOPPED
)
7592 * Return a "not-possible" error...
7595 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
7596 _("Job #%d is finished and cannot be altered."),
7602 * Hold the job and return...
7605 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
7606 IPP_TAG_KEYWORD
)) == NULL
)
7607 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
7611 when
= attr
->values
[0].string
.text
;
7613 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
7614 "Job job-hold-until value changed by user.");
7617 when
= "indefinite";
7619 cupsdSetJobHoldUntil(job
, when
, 1);
7620 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
, "Job held by \"%s\".",
7623 con
->response
->request
.status
.status_code
= IPP_OK
;
7628 * 'hold_new_jobs()' - Hold pending/new jobs on a printer or class.
7632 hold_new_jobs(cupsd_client_t
*con
, /* I - Connection */
7633 ipp_attribute_t
*uri
) /* I - Printer URI */
7635 http_status_t status
; /* Policy status */
7636 cups_ptype_t dtype
; /* Destination type (printer/class) */
7637 cupsd_printer_t
*printer
; /* Printer data */
7640 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_new_jobs(%p[%d], %s)", con
,
7641 con
->http
.fd
, uri
->values
[0].string
.text
);
7644 * Is the destination valid?
7647 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7653 send_ipp_status(con
, IPP_NOT_FOUND
,
7654 _("The printer or class does not exist."));
7662 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7664 send_http_error(con
, status
, printer
);
7669 * Hold pending/new jobs sent to the printer...
7672 printer
->holding_new_jobs
= 1;
7674 cupsdSetPrinterReasons(printer
, "+hold-new-jobs");
7676 if (dtype
& CUPS_PRINTER_CLASS
)
7677 cupsdLogMessage(CUPSD_LOG_INFO
,
7678 "Class \"%s\" now holding pending/new jobs (\"%s\").",
7679 printer
->name
, get_username(con
));
7681 cupsdLogMessage(CUPSD_LOG_INFO
,
7682 "Printer \"%s\" now holding pending/new jobs (\"%s\").",
7683 printer
->name
, get_username(con
));
7686 * Everything was ok, so return OK status...
7689 con
->response
->request
.status
.status_code
= IPP_OK
;
7694 * 'move_job()' - Move a job to a new destination.
7698 move_job(cupsd_client_t
*con
, /* I - Client connection */
7699 ipp_attribute_t
*uri
) /* I - Job URI */
7701 http_status_t status
; /* Policy status */
7702 ipp_attribute_t
*attr
; /* Current attribute */
7703 int jobid
; /* Job ID */
7704 cupsd_job_t
*job
; /* Current job */
7705 const char *src
; /* Source printer/class */
7706 cups_ptype_t stype
, /* Source type (printer or class) */
7707 dtype
; /* Destination type (printer/class) */
7708 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
7709 username
[HTTP_MAX_URI
], /* Username portion of URI */
7710 host
[HTTP_MAX_URI
], /* Host portion of URI */
7711 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7712 int port
; /* Port portion of URI */
7713 cupsd_printer_t
*sprinter
, /* Source printer */
7714 *dprinter
; /* Destination printer */
7717 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "move_job(%p[%d], %s)", con
, con
->http
.fd
,
7718 uri
->values
[0].string
.text
);
7721 * Get the new printer or class...
7724 if ((attr
= ippFindAttribute(con
->request
, "job-printer-uri",
7725 IPP_TAG_URI
)) == NULL
)
7728 * Need job-printer-uri...
7731 send_ipp_status(con
, IPP_BAD_REQUEST
,
7732 _("job-printer-uri attribute missing."));
7736 if (!cupsdValidateDest(attr
->values
[0].string
.text
, &dtype
, &dprinter
))
7742 send_ipp_status(con
, IPP_NOT_FOUND
,
7743 _("The printer or class does not exist."));
7748 * See if we have a job URI or a printer URI...
7751 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7752 sizeof(scheme
), username
, sizeof(username
), host
,
7753 sizeof(host
), &port
, resource
, sizeof(resource
));
7755 if (!strcmp(uri
->name
, "printer-uri"))
7758 * Got a printer URI; see if we also have a job-id attribute...
7761 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7762 IPP_TAG_INTEGER
)) == NULL
)
7768 if ((src
= cupsdValidateDest(uri
->values
[0].string
.text
, &stype
,
7769 &sprinter
)) == NULL
)
7775 send_ipp_status(con
, IPP_NOT_FOUND
,
7776 _("The printer or class does not exist."));
7785 * Otherwise, just move a single job...
7788 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
7791 * Nope - return a "not found" error...
7794 send_ipp_status(con
, IPP_NOT_FOUND
,
7795 _("Job #%d does not exist."), attr
->values
[0].integer
);
7801 * Job found, initialize source pointers...
7812 * Got a job URI; parse it to get the job ID...
7815 if (strncmp(resource
, "/jobs/", 6))
7821 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
7822 uri
->values
[0].string
.text
);
7827 * See if the job exists...
7830 jobid
= atoi(resource
+ 6);
7832 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7835 * Nope - return a "not found" error...
7838 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
7844 * Job found, initialize source pointers...
7853 * Check the policy of the destination printer...
7856 if ((status
= cupsdCheckPolicy(dprinter
->op_policy_ptr
, con
,
7857 job
? job
->username
: NULL
)) != HTTP_OK
)
7859 send_http_error(con
, status
, dprinter
);
7864 * Now move the job or jobs...
7870 * See if the job has been completed...
7873 if (job
->state_value
> IPP_JOB_STOPPED
)
7876 * Return a "not-possible" error...
7879 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
7880 _("Job #%d is finished and cannot be altered."),
7886 * See if the job is owned by the requesting user...
7889 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7891 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
7892 cupsdFindDest(job
->dest
));
7897 * Move the job to a different printer or class...
7900 cupsdMoveJob(job
, dprinter
);
7905 * Got the source printer, now look through the jobs...
7908 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
7910 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
7913 * See if the job is pointing at the source printer or has not been
7917 if (_cups_strcasecmp(job
->dest
, src
) ||
7918 job
->state_value
> IPP_JOB_STOPPED
)
7922 * See if the job can be moved by the requesting user...
7925 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7929 * Move the job to a different printer or class...
7932 cupsdMoveJob(job
, dprinter
);
7937 * Start jobs if possible...
7943 * Return with "everything is OK" status...
7946 con
->response
->request
.status
.status_code
= IPP_OK
;
7951 * 'ppd_parse_line()' - Parse a PPD default line.
7954 static int /* O - 0 on success, -1 on failure */
7955 ppd_parse_line(const char *line
, /* I - Line */
7956 char *option
, /* O - Option name */
7957 int olen
, /* I - Size of option name */
7958 char *choice
, /* O - Choice name */
7959 int clen
) /* I - Size of choice name */
7962 * Verify this is a default option line...
7965 if (strncmp(line
, "*Default", 8))
7969 * Read the option name...
7972 for (line
+= 8, olen
--;
7973 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
7984 * Skip everything else up to the colon (:)...
7987 while (*line
&& *line
!= ':')
7996 * Now grab the option choice, skipping leading whitespace...
7999 while (isspace(*line
& 255))
8003 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
8014 * Return with no errors...
8022 * 'print_job()' - Print a file to a printer or class.
8026 print_job(cupsd_client_t
*con
, /* I - Client connection */
8027 ipp_attribute_t
*uri
) /* I - Printer URI */
8029 ipp_attribute_t
*attr
; /* Current attribute */
8030 ipp_attribute_t
*format
; /* Document-format attribute */
8031 const char *default_format
; /* document-format-default value */
8032 cupsd_job_t
*job
; /* New job */
8033 char filename
[1024]; /* Job filename */
8034 mime_type_t
*filetype
; /* Type of file */
8035 char super
[MIME_MAX_SUPER
], /* Supertype of file */
8036 type
[MIME_MAX_TYPE
], /* Subtype of file */
8037 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
8038 /* Textual name of mime type */
8039 cupsd_printer_t
*printer
; /* Printer data */
8040 struct stat fileinfo
; /* File information */
8041 int kbytes
; /* Size of file */
8042 int compression
; /* Document compression */
8045 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "print_job(%p[%d], %s)", con
, con
->http
.fd
,
8046 uri
->values
[0].string
.text
);
8049 * Validate print file attributes, for now just document-format and
8050 * compression (CUPS only supports "none" and "gzip")...
8053 compression
= CUPS_FILE_NONE
;
8055 if ((attr
= ippFindAttribute(con
->request
, "compression",
8056 IPP_TAG_KEYWORD
)) != NULL
)
8058 if (strcmp(attr
->values
[0].string
.text
, "none")
8060 && strcmp(attr
->values
[0].string
.text
, "gzip")
8061 #endif /* HAVE_LIBZ */
8064 send_ipp_status(con
, IPP_ATTRIBUTES
,
8065 _("Unsupported compression \"%s\"."),
8066 attr
->values
[0].string
.text
);
8067 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
8068 "compression", NULL
, attr
->values
[0].string
.text
);
8073 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
8074 compression
= CUPS_FILE_GZIP
;
8075 #endif /* HAVE_LIBZ */
8079 * Do we have a file to print?
8084 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file in print request."));
8089 * Is the destination valid?
8092 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
8098 send_ipp_status(con
, IPP_NOT_FOUND
,
8099 _("The printer or class does not exist."));
8104 * Is it a format we support?
8107 if ((format
= ippFindAttribute(con
->request
, "document-format",
8108 IPP_TAG_MIMETYPE
)) != NULL
)
8111 * Grab format from client...
8114 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%255[^;]", super
,
8117 send_ipp_status(con
, IPP_BAD_REQUEST
,
8118 _("Bad document-format \"%s\"."),
8119 format
->values
[0].string
.text
);
8123 else if ((default_format
= cupsGetOption("document-format",
8124 printer
->num_options
,
8125 printer
->options
)) != NULL
)
8128 * Use default document format...
8131 if (sscanf(default_format
, "%15[^/]/%255[^;]", super
, type
) != 2)
8133 send_ipp_status(con
, IPP_BAD_REQUEST
,
8134 _("Bad document-format \"%s\"."),
8145 strlcpy(super
, "application", sizeof(super
));
8146 strlcpy(type
, "octet-stream", sizeof(type
));
8149 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
8152 * Auto-type the file...
8155 ipp_attribute_t
*doc_name
; /* document-name attribute */
8158 cupsdLogMessage(CUPSD_LOG_DEBUG
, "[Job ???] Auto-typing file...");
8160 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
8161 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
8162 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
8166 filetype
= mimeType(MimeDatabase
, super
, type
);
8168 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job ???] Request file type is %s/%s.",
8169 filetype
->super
, filetype
->type
);
8172 filetype
= mimeType(MimeDatabase
, super
, type
);
8176 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
8179 * Replace the document-format attribute value with the auto-typed or
8183 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
8188 _cupsStrFree(format
->values
[0].string
.text
);
8190 format
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
8193 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
8194 "document-format", NULL
, mimetype
);
8198 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
8199 _("Unsupported document-format \"%s\"."),
8200 format
? format
->values
[0].string
.text
:
8201 "application/octet-stream");
8202 cupsdLogMessage(CUPSD_LOG_INFO
,
8203 "Hint: Do you have the raw file printing rules enabled?");
8206 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
8207 "document-format", NULL
, format
->values
[0].string
.text
);
8213 * Read any embedded job ticket info from PS files...
8216 if (!_cups_strcasecmp(filetype
->super
, "application") &&
8217 (!_cups_strcasecmp(filetype
->type
, "postscript") ||
8218 !_cups_strcasecmp(filetype
->type
, "pdf")))
8219 read_job_ticket(con
);
8222 * Create the job object...
8225 if ((job
= add_job(con
, printer
, filetype
)) == NULL
)
8229 * Update quota data...
8232 if (stat(con
->filename
, &fileinfo
))
8235 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
8237 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
8239 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
8240 IPP_TAG_INTEGER
)) != NULL
)
8241 attr
->values
[0].integer
+= kbytes
;
8244 * Add the job file...
8247 if (add_file(con
, job
, filetype
, compression
))
8250 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
8252 rename(con
->filename
, filename
);
8253 cupsdClearString(&con
->filename
);
8256 * See if we need to add the ending sheet...
8259 if (cupsdTimeoutJob(job
))
8263 * Log and save the job...
8266 cupsdLogJob(job
, CUPSD_LOG_INFO
,
8267 "File of type %s/%s queued by \"%s\".",
8268 filetype
->super
, filetype
->type
, job
->username
);
8269 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "hold_until=%d", (int)job
->hold_until
);
8270 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
8271 job
->dest
, job
->username
);
8274 * Start the job if possible...
8282 * 'read_job_ticket()' - Read a job ticket embedded in a print file.
8284 * This function only gets called when printing a single PDF or PostScript
8285 * file using the Print-Job operation. It doesn't work for Create-Job +
8286 * Send-File, since the job attributes need to be set at job creation
8287 * time for banners to work. The embedded job ticket stuff is here
8288 * primarily to allow the Windows printer driver for CUPS to pass in JCL
8289 * options and IPP attributes which otherwise would be lost.
8291 * The format of a job ticket is simple:
8293 * %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
8295 * %cupsJobTicket: attr1=value1
8296 * %cupsJobTicket: attr2=value2
8298 * %cupsJobTicket: attrN=valueN
8300 * Job ticket lines must appear immediately after the first line that
8301 * specifies PostScript (%!PS-Adobe-3.0) or PDF (%PDF) format, and CUPS
8302 * stops looking for job ticket info when it finds a line that does not begin
8303 * with "%cupsJobTicket:".
8305 * The maximum length of a job ticket line, including the prefix, is
8306 * 255 characters to conform with the Adobe DSC.
8308 * Read-only attributes are rejected with a notice to the error log in
8309 * case a malicious user tries anything. Since the job ticket is read
8310 * prior to attribute validation in print_job(), job ticket attributes
8311 * will go through the same validation as IPP attributes...
8315 read_job_ticket(cupsd_client_t
*con
) /* I - Client connection */
8317 cups_file_t
*fp
; /* File to read from */
8318 char line
[256]; /* Line data */
8319 int num_options
; /* Number of options */
8320 cups_option_t
*options
; /* Options */
8321 ipp_t
*ticket
; /* New attributes */
8322 ipp_attribute_t
*attr
, /* Current attribute */
8323 *attr2
, /* Job attribute */
8324 *prev2
; /* Previous job attribute */
8328 * First open the print file...
8331 if ((fp
= cupsFileOpen(con
->filename
, "rb")) == NULL
)
8333 cupsdLogMessage(CUPSD_LOG_ERROR
,
8334 "Unable to open print file for job ticket - %s",
8340 * Skip the first line...
8343 if (cupsFileGets(fp
, line
, sizeof(line
)) == NULL
)
8345 cupsdLogMessage(CUPSD_LOG_ERROR
,
8346 "Unable to read from print file for job ticket - %s",
8352 if (strncmp(line
, "%!PS-Adobe-", 11) && strncmp(line
, "%PDF-", 5))
8355 * Not a DSC-compliant file, so no job ticket info will be available...
8363 * Read job ticket info from the file...
8369 while (cupsFileGets(fp
, line
, sizeof(line
)))
8372 * Stop at the first non-ticket line...
8375 if (strncmp(line
, "%cupsJobTicket:", 15))
8379 * Add the options to the option array...
8382 num_options
= cupsParseOptions(line
+ 15, num_options
, &options
);
8386 * Done with the file; see if we have any options...
8391 if (num_options
== 0)
8395 * OK, convert the options to an attribute list, and apply them to
8400 cupsEncodeOptions(ticket
, num_options
, options
);
8403 * See what the user wants to change.
8406 for (attr
= ticket
->attrs
; attr
; attr
= attr
->next
)
8408 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
8411 if (!strcmp(attr
->name
, "job-originating-host-name") ||
8412 !strcmp(attr
->name
, "job-originating-user-name") ||
8413 !strcmp(attr
->name
, "job-media-sheets-completed") ||
8414 !strcmp(attr
->name
, "job-k-octets") ||
8415 !strcmp(attr
->name
, "job-id") ||
8416 !strncmp(attr
->name
, "job-state", 9) ||
8417 !strncmp(attr
->name
, "time-at-", 8))
8418 continue; /* Read-only attrs */
8420 if ((attr2
= ippFindAttribute(con
->request
, attr
->name
,
8421 IPP_TAG_ZERO
)) != NULL
)
8424 * Some other value; first free the old value...
8427 if (con
->request
->attrs
== attr2
)
8429 con
->request
->attrs
= attr2
->next
;
8434 for (prev2
= con
->request
->attrs
; prev2
; prev2
= prev2
->next
)
8435 if (prev2
->next
== attr2
)
8437 prev2
->next
= attr2
->next
;
8442 if (con
->request
->last
== attr2
)
8443 con
->request
->last
= prev2
;
8445 ippDeleteAttribute(NULL
, attr2
);
8449 * Add new option by copying it...
8452 ippCopyAttribute(con
->request
, attr
, 0);
8456 * Then free the attribute list and option array...
8460 cupsFreeOptions(num_options
, options
);
8465 * 'reject_jobs()' - Reject print jobs to a printer.
8469 reject_jobs(cupsd_client_t
*con
, /* I - Client connection */
8470 ipp_attribute_t
*uri
) /* I - Printer or class URI */
8472 http_status_t status
; /* Policy status */
8473 cups_ptype_t dtype
; /* Destination type (printer/class) */
8474 cupsd_printer_t
*printer
; /* Printer data */
8475 ipp_attribute_t
*attr
; /* printer-state-message text */
8478 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "reject_jobs(%p[%d], %s)", con
,
8479 con
->http
.fd
, uri
->values
[0].string
.text
);
8482 * Is the destination valid?
8485 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8491 send_ipp_status(con
, IPP_NOT_FOUND
,
8492 _("The printer or class does not exist."));
8500 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8502 send_http_error(con
, status
, printer
);
8507 * Reject jobs sent to the printer...
8510 printer
->accepting
= 0;
8512 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
8513 IPP_TAG_TEXT
)) == NULL
)
8514 strlcpy(printer
->state_message
, "Rejecting Jobs",
8515 sizeof(printer
->state_message
));
8517 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
8518 sizeof(printer
->state_message
));
8520 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
8521 "No longer accepting jobs.");
8523 if (dtype
& CUPS_PRINTER_CLASS
)
8525 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
8527 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" rejecting jobs (\"%s\").",
8528 printer
->name
, get_username(con
));
8532 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
8534 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" rejecting jobs (\"%s\").",
8535 printer
->name
, get_username(con
));
8539 * Everything was ok, so return OK status...
8542 con
->response
->request
.status
.status_code
= IPP_OK
;
8547 * 'release_held_new_jobs()' - Release pending/new jobs on a printer or class.
8551 release_held_new_jobs(
8552 cupsd_client_t
*con
, /* I - Connection */
8553 ipp_attribute_t
*uri
) /* I - Printer URI */
8555 http_status_t status
; /* Policy status */
8556 cups_ptype_t dtype
; /* Destination type (printer/class) */
8557 cupsd_printer_t
*printer
; /* Printer data */
8560 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_held_new_jobs(%p[%d], %s)", con
,
8561 con
->http
.fd
, uri
->values
[0].string
.text
);
8564 * Is the destination valid?
8567 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8573 send_ipp_status(con
, IPP_NOT_FOUND
,
8574 _("The printer or class does not exist."));
8582 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8584 send_http_error(con
, status
, printer
);
8589 * Hold pending/new jobs sent to the printer...
8592 printer
->holding_new_jobs
= 0;
8594 cupsdSetPrinterReasons(printer
, "-hold-new-jobs");
8596 if (dtype
& CUPS_PRINTER_CLASS
)
8597 cupsdLogMessage(CUPSD_LOG_INFO
,
8598 "Class \"%s\" now printing pending/new jobs (\"%s\").",
8599 printer
->name
, get_username(con
));
8601 cupsdLogMessage(CUPSD_LOG_INFO
,
8602 "Printer \"%s\" now printing pending/new jobs (\"%s\").",
8603 printer
->name
, get_username(con
));
8606 * Everything was ok, so return OK status...
8609 con
->response
->request
.status
.status_code
= IPP_OK
;
8614 * 'release_job()' - Release a held print job.
8618 release_job(cupsd_client_t
*con
, /* I - Client connection */
8619 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
8621 ipp_attribute_t
*attr
; /* Current attribute */
8622 int jobid
; /* Job ID */
8623 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
8624 username
[HTTP_MAX_URI
], /* Username portion of URI */
8625 host
[HTTP_MAX_URI
], /* Host portion of URI */
8626 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8627 int port
; /* Port portion of URI */
8628 cupsd_job_t
*job
; /* Job information */
8631 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_job(%p[%d], %s)", con
,
8632 con
->http
.fd
, uri
->values
[0].string
.text
);
8635 * See if we have a job URI or a printer URI...
8638 if (!strcmp(uri
->name
, "printer-uri"))
8641 * Got a printer URI; see if we also have a job-id attribute...
8644 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8645 IPP_TAG_INTEGER
)) == NULL
)
8647 send_ipp_status(con
, IPP_BAD_REQUEST
,
8648 _("Got a printer-uri attribute but no job-id."));
8652 jobid
= attr
->values
[0].integer
;
8657 * Got a job URI; parse it to get the job ID...
8660 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8661 sizeof(scheme
), username
, sizeof(username
), host
,
8662 sizeof(host
), &port
, resource
, sizeof(resource
));
8664 if (strncmp(resource
, "/jobs/", 6))
8670 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
8671 uri
->values
[0].string
.text
);
8675 jobid
= atoi(resource
+ 6);
8679 * See if the job exists...
8682 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8685 * Nope - return a "not found" error...
8688 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
8693 * See if job is "held"...
8696 if (job
->state_value
!= IPP_JOB_HELD
)
8699 * Nope - return a "not possible" error...
8702 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not held."), jobid
);
8707 * See if the job is owned by the requesting user...
8710 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8712 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8713 cupsdFindDest(job
->dest
));
8718 * Reset the job-hold-until value to "no-hold"...
8721 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
8722 IPP_TAG_KEYWORD
)) == NULL
)
8723 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
8727 _cupsStrFree(attr
->values
[0].string
.text
);
8729 attr
->value_tag
= IPP_TAG_KEYWORD
;
8730 attr
->values
[0].string
.text
= _cupsStrAlloc("no-hold");
8732 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
8733 "Job job-hold-until value changed by user.");
8734 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
8738 * Release the job and return...
8741 cupsdReleaseJob(job
);
8743 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
8744 "Job released by user.");
8746 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Released by \"%s\".", username
);
8748 con
->response
->request
.status
.status_code
= IPP_OK
;
8755 * 'renew_subscription()' - Renew an existing subscription...
8760 cupsd_client_t
*con
, /* I - Client connection */
8761 int sub_id
) /* I - Subscription ID */
8763 http_status_t status
; /* Policy status */
8764 cupsd_subscription_t
*sub
; /* Subscription */
8765 ipp_attribute_t
*lease
; /* notify-lease-duration */
8768 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
8769 "renew_subscription(con=%p[%d], sub_id=%d)",
8770 con
, con
->http
.fd
, sub_id
);
8773 * Is the subscription ID valid?
8776 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
8779 * Bad subscription ID...
8782 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
8790 * Job subscriptions cannot be renewed...
8793 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8794 _("Job subscriptions cannot be renewed."));
8802 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
8804 con
, sub
->owner
)) != HTTP_OK
)
8806 send_http_error(con
, status
, sub
->dest
);
8811 * Renew the subscription...
8814 lease
= ippFindAttribute(con
->request
, "notify-lease-duration",
8817 sub
->lease
= lease
? lease
->values
[0].integer
: DefaultLeaseDuration
;
8819 if (MaxLeaseDuration
&& (sub
->lease
== 0 || sub
->lease
> MaxLeaseDuration
))
8821 cupsdLogMessage(CUPSD_LOG_INFO
,
8822 "renew_subscription: Limiting notify-lease-duration to "
8825 sub
->lease
= MaxLeaseDuration
;
8828 sub
->expire
= sub
->lease
? time(NULL
) + sub
->lease
: 0;
8830 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
8832 con
->response
->request
.status
.status_code
= IPP_OK
;
8834 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
8835 "notify-lease-duration", sub
->lease
);
8840 * 'restart_job()' - Restart an old print job.
8844 restart_job(cupsd_client_t
*con
, /* I - Client connection */
8845 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
8847 ipp_attribute_t
*attr
; /* Current attribute */
8848 int jobid
; /* Job ID */
8849 cupsd_job_t
*job
; /* Job information */
8850 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
8851 username
[HTTP_MAX_URI
], /* Username portion of URI */
8852 host
[HTTP_MAX_URI
], /* Host portion of URI */
8853 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8854 int port
; /* Port portion of URI */
8857 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "restart_job(%p[%d], %s)", con
,
8858 con
->http
.fd
, uri
->values
[0].string
.text
);
8861 * See if we have a job URI or a printer URI...
8864 if (!strcmp(uri
->name
, "printer-uri"))
8867 * Got a printer URI; see if we also have a job-id attribute...
8870 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8871 IPP_TAG_INTEGER
)) == NULL
)
8873 send_ipp_status(con
, IPP_BAD_REQUEST
,
8874 _("Got a printer-uri attribute but no job-id."));
8878 jobid
= attr
->values
[0].integer
;
8883 * Got a job URI; parse it to get the job ID...
8886 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8887 sizeof(scheme
), username
, sizeof(username
), host
,
8888 sizeof(host
), &port
, resource
, sizeof(resource
));
8890 if (strncmp(resource
, "/jobs/", 6))
8896 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
8897 uri
->values
[0].string
.text
);
8901 jobid
= atoi(resource
+ 6);
8905 * See if the job exists...
8908 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8911 * Nope - return a "not found" error...
8914 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
8919 * See if job is in any of the "completed" states...
8922 if (job
->state_value
<= IPP_JOB_PROCESSING
)
8925 * Nope - return a "not possible" error...
8928 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not complete."),
8934 * See if we have retained the job files...
8939 if (!job
->attrs
|| job
->num_files
== 0)
8942 * Nope - return a "not possible" error...
8945 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8946 _("Job #%d cannot be restarted - no files."), jobid
);
8951 * See if the job is owned by the requesting user...
8954 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8956 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8957 cupsdFindDest(job
->dest
));
8962 * See if the job-hold-until attribute is specified...
8965 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
8966 IPP_TAG_KEYWORD
)) == NULL
)
8967 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
8969 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
8972 * Return the job to a held state...
8975 cupsdLogJob(job
, CUPSD_LOG_DEBUG
,
8976 "Restarted by \"%s\" with job-hold-until=%s.",
8977 username
, attr
->values
[0].string
.text
);
8978 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
8980 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
,
8981 NULL
, job
, "Job restarted by user with job-hold-until=%s",
8982 attr
->values
[0].string
.text
);
8987 * Restart the job...
8990 cupsdRestartJob(job
);
8994 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Restarted by \"%s\".", username
);
8996 con
->response
->request
.status
.status_code
= IPP_OK
;
9001 * 'save_auth_info()' - Save authentication information for a job.
9006 cupsd_client_t
*con
, /* I - Client connection */
9007 cupsd_job_t
*job
, /* I - Job */
9008 ipp_attribute_t
*auth_info
) /* I - auth-info attribute, if any */
9010 int i
; /* Looping var */
9011 char filename
[1024]; /* Job authentication filename */
9012 cups_file_t
*fp
; /* Job authentication file */
9013 char line
[65536]; /* Line for file */
9014 cupsd_printer_t
*dest
; /* Destination printer/class */
9018 * This function saves the in-memory authentication information for
9019 * a job so that it can be used to authenticate with a remote host.
9020 * The information is stored in a file that is readable only by the
9021 * root user. The fields are Base-64 encoded, each on a separate line,
9022 * followed by random number (up to 1024) of newlines to limit the
9023 * amount of information that is exposed.
9025 * Because of the potential for exposing of authentication information,
9026 * this functionality is only enabled when running cupsd as root.
9028 * This caching only works for the Basic and BasicDigest authentication
9029 * types. Digest authentication cannot be cached this way, and in
9030 * the future Kerberos authentication may make all of this obsolete.
9032 * Authentication information is saved whenever an authenticated
9033 * Print-Job, Create-Job, or CUPS-Authenticate-Job operation is
9036 * This information is deleted after a job is completed or canceled,
9037 * so reprints may require subsequent re-authentication.
9043 if ((dest
= cupsdFindDest(job
->dest
)) == NULL
)
9047 * Create the authentication file and change permissions...
9050 snprintf(filename
, sizeof(filename
), "%s/a%05d", RequestRoot
, job
->id
);
9051 if ((fp
= cupsFileOpen(filename
, "w")) == NULL
)
9053 cupsdLogMessage(CUPSD_LOG_ERROR
,
9054 "Unable to save authentication info to \"%s\" - %s",
9055 filename
, strerror(errno
));
9059 fchown(cupsFileNumber(fp
), 0, 0);
9060 fchmod(cupsFileNumber(fp
), 0400);
9062 cupsFilePuts(fp
, "CUPSD-AUTH-V3\n");
9065 i
< (int)(sizeof(job
->auth_env
) / sizeof(job
->auth_env
[0]));
9067 cupsdClearString(job
->auth_env
+ i
);
9069 if (auth_info
&& auth_info
->num_values
== dest
->num_auth_info_required
)
9072 * Write 1 to 3 auth values...
9076 i
< auth_info
->num_values
&&
9077 i
< (int)(sizeof(job
->auth_env
) / sizeof(job
->auth_env
[0]));
9080 if (strcmp(dest
->auth_info_required
[i
], "negotiate"))
9082 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[i
].string
.text
,
9083 strlen(auth_info
->values
[i
].string
.text
));
9084 cupsFilePutConf(fp
, dest
->auth_info_required
[i
], line
);
9087 cupsFilePutConf(fp
, dest
->auth_info_required
[i
],
9088 auth_info
->values
[i
].string
.text
);
9090 if (!strcmp(dest
->auth_info_required
[i
], "username"))
9091 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_USERNAME=%s",
9092 auth_info
->values
[i
].string
.text
);
9093 else if (!strcmp(dest
->auth_info_required
[i
], "domain"))
9094 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_DOMAIN=%s",
9095 auth_info
->values
[i
].string
.text
);
9096 else if (!strcmp(dest
->auth_info_required
[i
], "password"))
9097 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_PASSWORD=%s",
9098 auth_info
->values
[i
].string
.text
);
9099 else if (!strcmp(dest
->auth_info_required
[i
], "negotiate"))
9100 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_NEGOTIATE=%s",
9101 auth_info
->values
[i
].string
.text
);
9106 else if (auth_info
&& auth_info
->num_values
== 2 &&
9107 dest
->num_auth_info_required
== 1 &&
9108 !strcmp(dest
->auth_info_required
[0], "negotiate"))
9111 * Allow fallback to username+password for Kerberized queues...
9114 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[0].string
.text
,
9115 strlen(auth_info
->values
[0].string
.text
));
9116 cupsFilePutConf(fp
, "username", line
);
9118 cupsdSetStringf(job
->auth_env
+ 0, "AUTH_USERNAME=%s",
9119 auth_info
->values
[0].string
.text
);
9121 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[1].string
.text
,
9122 strlen(auth_info
->values
[1].string
.text
));
9123 cupsFilePutConf(fp
, "password", line
);
9125 cupsdSetStringf(job
->auth_env
+ 1, "AUTH_PASSWORD=%s",
9126 auth_info
->values
[1].string
.text
);
9128 else if (con
->username
[0])
9131 * Write the authenticated username...
9134 httpEncode64_2(line
, sizeof(line
), con
->username
, strlen(con
->username
));
9135 cupsFilePutConf(fp
, "username", line
);
9137 cupsdSetStringf(job
->auth_env
+ 0, "AUTH_USERNAME=%s", con
->username
);
9140 * Write the authenticated password...
9143 httpEncode64_2(line
, sizeof(line
), con
->password
, strlen(con
->password
));
9144 cupsFilePutConf(fp
, "password", line
);
9146 cupsdSetStringf(job
->auth_env
+ 1, "AUTH_PASSWORD=%s", con
->password
);
9150 if (con
->gss_uid
> 0)
9152 cupsFilePrintf(fp
, "uid %d\n", (int)con
->gss_uid
);
9153 cupsdSetStringf(&job
->auth_uid
, "AUTH_UID=%d", (int)con
->gss_uid
);
9155 #endif /* HAVE_GSSAPI */
9158 * Write a random number of newlines to the end of the file...
9161 for (i
= (CUPS_RAND() % 1024); i
>= 0; i
--)
9162 cupsFilePutChar(fp
, '\n');
9165 * Close the file and return...
9173 * 'send_document()' - Send a file to a printer or class.
9177 send_document(cupsd_client_t
*con
, /* I - Client connection */
9178 ipp_attribute_t
*uri
) /* I - Printer URI */
9180 ipp_attribute_t
*attr
; /* Current attribute */
9181 ipp_attribute_t
*format
; /* Request's document-format attribute */
9182 ipp_attribute_t
*jformat
; /* Job's document-format attribute */
9183 const char *default_format
;/* document-format-default value */
9184 int jobid
; /* Job ID number */
9185 cupsd_job_t
*job
; /* Current job */
9186 char job_uri
[HTTP_MAX_URI
],
9188 scheme
[HTTP_MAX_URI
],
9189 /* Method portion of URI */
9190 username
[HTTP_MAX_URI
],
9191 /* Username portion of URI */
9193 /* Host portion of URI */
9194 resource
[HTTP_MAX_URI
];
9195 /* Resource portion of URI */
9196 int port
; /* Port portion of URI */
9197 mime_type_t
*filetype
; /* Type of file */
9198 char super
[MIME_MAX_SUPER
],
9199 /* Supertype of file */
9200 type
[MIME_MAX_TYPE
],
9201 /* Subtype of file */
9202 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
9203 /* Textual name of mime type */
9204 char filename
[1024]; /* Job filename */
9205 cupsd_printer_t
*printer
; /* Current printer */
9206 struct stat fileinfo
; /* File information */
9207 int kbytes
; /* Size of file */
9208 int compression
; /* Type of compression */
9209 int start_job
; /* Start the job? */
9212 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "send_document(%p[%d], %s)", con
,
9213 con
->http
.fd
, uri
->values
[0].string
.text
);
9216 * See if we have a job URI or a printer URI...
9219 if (!strcmp(uri
->name
, "printer-uri"))
9222 * Got a printer URI; see if we also have a job-id attribute...
9225 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9226 IPP_TAG_INTEGER
)) == NULL
)
9228 send_ipp_status(con
, IPP_BAD_REQUEST
,
9229 _("Got a printer-uri attribute but no job-id."));
9233 jobid
= attr
->values
[0].integer
;
9238 * Got a job URI; parse it to get the job ID...
9241 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9242 sizeof(scheme
), username
, sizeof(username
), host
,
9243 sizeof(host
), &port
, resource
, sizeof(resource
));
9245 if (strncmp(resource
, "/jobs/", 6))
9251 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9252 uri
->values
[0].string
.text
);
9256 jobid
= atoi(resource
+ 6);
9260 * See if the job exists...
9263 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9266 * Nope - return a "not found" error...
9269 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9273 printer
= cupsdFindDest(job
->dest
);
9276 * See if the job is owned by the requesting user...
9279 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9281 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9282 cupsdFindDest(job
->dest
));
9287 * OK, see if the client is sending the document compressed - CUPS
9288 * only supports "none" and "gzip".
9291 compression
= CUPS_FILE_NONE
;
9293 if ((attr
= ippFindAttribute(con
->request
, "compression",
9294 IPP_TAG_KEYWORD
)) != NULL
)
9296 if (strcmp(attr
->values
[0].string
.text
, "none")
9298 && strcmp(attr
->values
[0].string
.text
, "gzip")
9299 #endif /* HAVE_LIBZ */
9302 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Unsupported compression \"%s\"."),
9303 attr
->values
[0].string
.text
);
9304 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
9305 "compression", NULL
, attr
->values
[0].string
.text
);
9310 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
9311 compression
= CUPS_FILE_GZIP
;
9312 #endif /* HAVE_LIBZ */
9316 * Do we have a file to print?
9319 if ((attr
= ippFindAttribute(con
->request
, "last-document",
9320 IPP_TAG_BOOLEAN
)) == NULL
)
9322 send_ipp_status(con
, IPP_BAD_REQUEST
,
9323 _("Missing last-document attribute in request."));
9330 * Check for an empty request with "last-document" set to true, which is
9331 * used to close an "open" job by RFC 2911, section 3.3.2.
9334 if (job
->num_files
> 0 && attr
->values
[0].boolean
)
9337 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file in print request."));
9342 * Is it a format we support?
9345 if ((format
= ippFindAttribute(con
->request
, "document-format",
9346 IPP_TAG_MIMETYPE
)) != NULL
)
9349 * Grab format from client...
9352 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%255[^;]",
9355 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"."),
9356 format
->values
[0].string
.text
);
9360 else if ((default_format
= cupsGetOption("document-format",
9361 printer
->num_options
,
9362 printer
->options
)) != NULL
)
9365 * Use default document format...
9368 if (sscanf(default_format
, "%15[^/]/%255[^;]", super
, type
) != 2)
9370 send_ipp_status(con
, IPP_BAD_REQUEST
,
9371 _("Bad document-format-default \"%s\"."), default_format
);
9378 * No document format attribute? Auto-type it!
9381 strlcpy(super
, "application", sizeof(super
));
9382 strlcpy(type
, "octet-stream", sizeof(type
));
9385 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
9388 * Auto-type the file...
9391 ipp_attribute_t
*doc_name
; /* document-name attribute */
9394 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Auto-typing file...");
9396 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
9397 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
9398 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
9402 filetype
= mimeType(MimeDatabase
, super
, type
);
9405 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Request file type is %s/%s.",
9406 filetype
->super
, filetype
->type
);
9409 filetype
= mimeType(MimeDatabase
, super
, type
);
9414 * Replace the document-format attribute value with the auto-typed or
9418 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9421 if ((jformat
= ippFindAttribute(job
->attrs
, "document-format",
9422 IPP_TAG_MIMETYPE
)) != NULL
)
9424 _cupsStrFree(jformat
->values
[0].string
.text
);
9426 jformat
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
9429 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
9430 "document-format", NULL
, mimetype
);
9434 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9435 _("Unsupported document-format \"%s/%s\"."), super
, type
);
9436 cupsdLogMessage(CUPSD_LOG_INFO
,
9437 "Hint: Do you have the raw file printing rules enabled?");
9440 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9441 "document-format", NULL
, format
->values
[0].string
.text
);
9446 if (printer
->filetypes
&& !cupsArrayFind(printer
->filetypes
, filetype
))
9448 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9451 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9452 _("Unsupported document-format \"%s\"."), mimetype
);
9454 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9455 "document-format", NULL
, mimetype
);
9461 * Add the file to the job...
9466 if (add_file(con
, job
, filetype
, compression
))
9469 if (stat(con
->filename
, &fileinfo
))
9472 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
9474 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
9476 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
9477 IPP_TAG_INTEGER
)) != NULL
)
9478 attr
->values
[0].integer
+= kbytes
;
9480 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
9482 rename(con
->filename
, filename
);
9484 cupsdClearString(&con
->filename
);
9486 cupsdLogJob(job
, CUPSD_LOG_INFO
, "File of type %s/%s queued by \"%s\".",
9487 filetype
->super
, filetype
->type
, job
->username
);
9490 * Start the job if this is the last document...
9495 if ((attr
= ippFindAttribute(con
->request
, "last-document",
9496 IPP_TAG_BOOLEAN
)) != NULL
&&
9497 attr
->values
[0].boolean
)
9500 * See if we need to add the ending sheet...
9503 if (cupsdTimeoutJob(job
))
9506 if (job
->state_value
== IPP_JOB_STOPPED
)
9508 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9509 job
->state_value
= IPP_JOB_PENDING
;
9511 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
9513 else if (job
->state_value
== IPP_JOB_HELD
)
9515 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9516 IPP_TAG_KEYWORD
)) == NULL
)
9517 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9519 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9521 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9522 job
->state_value
= IPP_JOB_PENDING
;
9524 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
9527 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-hold-until-specified");
9531 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
9537 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9538 IPP_TAG_KEYWORD
)) == NULL
)
9539 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9541 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9543 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
9544 job
->state_value
= IPP_JOB_HELD
;
9545 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
9547 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-incoming");
9550 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
9557 * Fill in the response info...
9560 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
9561 con
->clientname
, con
->clientport
, "/jobs/%d", jobid
);
9562 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
9565 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", jobid
);
9567 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
9569 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons",
9570 NULL
, job
->reasons
->values
[0].string
.text
);
9572 con
->response
->request
.status
.status_code
= IPP_OK
;
9575 * Start the job if necessary...
9584 * 'send_http_error()' - Send a HTTP error back to the IPP client.
9589 cupsd_client_t
*con
, /* I - Client connection */
9590 http_status_t status
, /* I - HTTP status code */
9591 cupsd_printer_t
*printer
) /* I - Printer, if any */
9593 ipp_attribute_t
*uri
; /* Request URI, if any */
9596 if ((uri
= ippFindAttribute(con
->request
, "printer-uri",
9597 IPP_TAG_URI
)) == NULL
)
9598 uri
= ippFindAttribute(con
->request
, "job-uri", IPP_TAG_URI
);
9600 cupsdLogMessage(status
== HTTP_FORBIDDEN
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
9601 "[Client %d] Returning HTTP %s for %s (%s) from %s",
9602 con
->http
.fd
, httpStatus(status
),
9604 ippOpString(con
->request
->request
.op
.operation_id
) :
9606 uri
? uri
->values
[0].string
.text
: "no URI",
9607 con
->http
.hostname
);
9611 int auth_type
; /* Type of authentication required */
9614 auth_type
= CUPSD_AUTH_NONE
;
9616 if (status
== HTTP_UNAUTHORIZED
&&
9617 printer
->num_auth_info_required
> 0 &&
9618 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
9620 (con
->request
->request
.op
.operation_id
== IPP_PRINT_JOB
||
9621 con
->request
->request
.op
.operation_id
== IPP_CREATE_JOB
||
9622 con
->request
->request
.op
.operation_id
== CUPS_AUTHENTICATE_JOB
))
9625 * Creating and authenticating jobs requires Kerberos...
9628 auth_type
= CUPSD_AUTH_NEGOTIATE
;
9633 * Use policy/location-defined authentication requirements...
9636 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9637 cupsd_location_t
*auth
; /* Pointer to authentication element */
9640 if (printer
->type
& CUPS_PRINTER_CLASS
)
9641 snprintf(resource
, sizeof(resource
), "/classes/%s", printer
->name
);
9643 snprintf(resource
, sizeof(resource
), "/printers/%s", printer
->name
);
9645 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
9646 auth
->type
== CUPSD_AUTH_NONE
)
9647 auth
= cupsdFindPolicyOp(printer
->op_policy_ptr
,
9649 con
->request
->request
.op
.operation_id
:
9654 if (auth
->type
== CUPSD_AUTH_DEFAULT
)
9655 auth_type
= cupsdDefaultAuthType();
9657 auth_type
= auth
->type
;
9661 cupsdSendError(con
, status
, auth_type
);
9664 cupsdSendError(con
, status
, CUPSD_AUTH_NONE
);
9666 ippDelete(con
->response
);
9667 con
->response
= NULL
;
9674 * 'send_ipp_status()' - Send a status back to the IPP client.
9678 send_ipp_status(cupsd_client_t
*con
, /* I - Client connection */
9679 ipp_status_t status
, /* I - IPP status code */
9680 const char *message
,/* I - Status message */
9681 ...) /* I - Additional args as needed */
9683 va_list ap
; /* Pointer to additional args */
9684 char formatted
[1024]; /* Formatted errror message */
9687 va_start(ap
, message
);
9688 vsnprintf(formatted
, sizeof(formatted
),
9689 _cupsLangString(con
->language
, message
), ap
);
9692 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s: %s",
9693 ippOpString(con
->request
->request
.op
.operation_id
),
9694 ippErrorString(status
), formatted
);
9696 con
->response
->request
.status
.status_code
= status
;
9698 if (ippFindAttribute(con
->response
, "attributes-charset",
9699 IPP_TAG_ZERO
) == NULL
)
9700 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
9701 "attributes-charset", NULL
, "utf-8");
9703 if (ippFindAttribute(con
->response
, "attributes-natural-language",
9704 IPP_TAG_ZERO
) == NULL
)
9705 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
9706 "attributes-natural-language", NULL
, DefaultLanguage
);
9708 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
9709 "status-message", NULL
, formatted
);
9714 * 'set_default()' - Set the default destination...
9718 set_default(cupsd_client_t
*con
, /* I - Client connection */
9719 ipp_attribute_t
*uri
) /* I - Printer URI */
9721 http_status_t status
; /* Policy status */
9722 cups_ptype_t dtype
; /* Destination type (printer/class) */
9723 cupsd_printer_t
*printer
, /* Printer */
9724 *oldprinter
; /* Old default printer */
9727 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_default(%p[%d], %s)", con
,
9728 con
->http
.fd
, uri
->values
[0].string
.text
);
9731 * Is the destination valid?
9734 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9740 send_ipp_status(con
, IPP_NOT_FOUND
,
9741 _("The printer or class does not exist."));
9749 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
9751 send_http_error(con
, status
, NULL
);
9756 * Set it as the default...
9759 oldprinter
= DefaultPrinter
;
9760 DefaultPrinter
= printer
;
9763 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, oldprinter
, NULL
,
9764 "%s is no longer the default printer.", oldprinter
->name
);
9766 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
9767 "%s is now the default printer.", printer
->name
);
9769 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
| CUPSD_DIRTY_CLASSES
|
9770 CUPSD_DIRTY_PRINTCAP
);
9772 cupsdLogMessage(CUPSD_LOG_INFO
,
9773 "Default destination set to \"%s\" by \"%s\".",
9774 printer
->name
, get_username(con
));
9777 * Everything was ok, so return OK status...
9780 con
->response
->request
.status
.status_code
= IPP_OK
;
9785 * 'set_job_attrs()' - Set job attributes.
9789 set_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
9790 ipp_attribute_t
*uri
) /* I - Job URI */
9792 ipp_attribute_t
*attr
, /* Current attribute */
9793 *attr2
; /* Job attribute */
9794 int jobid
; /* Job ID */
9795 cupsd_job_t
*job
; /* Current job */
9796 char scheme
[HTTP_MAX_URI
],
9797 /* Method portion of URI */
9798 username
[HTTP_MAX_URI
],
9799 /* Username portion of URI */
9801 /* Host portion of URI */
9802 resource
[HTTP_MAX_URI
];
9803 /* Resource portion of URI */
9804 int port
; /* Port portion of URI */
9805 int event
; /* Events? */
9806 int check_jobs
; /* Check jobs? */
9809 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_job_attrs(%p[%d], %s)", con
,
9810 con
->http
.fd
, uri
->values
[0].string
.text
);
9813 * Start with "everything is OK" status...
9816 con
->response
->request
.status
.status_code
= IPP_OK
;
9819 * See if we have a job URI or a printer URI...
9822 if (!strcmp(uri
->name
, "printer-uri"))
9825 * Got a printer URI; see if we also have a job-id attribute...
9828 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9829 IPP_TAG_INTEGER
)) == NULL
)
9831 send_ipp_status(con
, IPP_BAD_REQUEST
,
9832 _("Got a printer-uri attribute but no job-id."));
9836 jobid
= attr
->values
[0].integer
;
9841 * Got a job URI; parse it to get the job ID...
9844 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9845 sizeof(scheme
), username
, sizeof(username
), host
,
9846 sizeof(host
), &port
, resource
, sizeof(resource
));
9848 if (strncmp(resource
, "/jobs/", 6))
9854 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9855 uri
->values
[0].string
.text
);
9859 jobid
= atoi(resource
+ 6);
9863 * See if the job exists...
9866 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9869 * Nope - return a "not found" error...
9872 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9877 * See if the job has been completed...
9880 if (job
->state_value
> IPP_JOB_STOPPED
)
9883 * Return a "not-possible" error...
9886 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9887 _("Job #%d is finished and cannot be altered."), jobid
);
9892 * See if the job is owned by the requesting user...
9895 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9897 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9898 cupsdFindDest(job
->dest
));
9903 * See what the user wants to change.
9911 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
9913 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
9916 if (!strcmp(attr
->name
, "attributes-charset") ||
9917 !strcmp(attr
->name
, "attributes-natural-language") ||
9918 !strcmp(attr
->name
, "document-compression") ||
9919 !strcmp(attr
->name
, "document-format") ||
9920 !strcmp(attr
->name
, "job-detailed-status-messages") ||
9921 !strcmp(attr
->name
, "job-document-access-errors") ||
9922 !strcmp(attr
->name
, "job-id") ||
9923 !strcmp(attr
->name
, "job-impressions-completed") ||
9924 !strcmp(attr
->name
, "job-k-octets") ||
9925 !strcmp(attr
->name
, "job-originating-host-name") ||
9926 !strcmp(attr
->name
, "job-originating-user-name") ||
9927 !strcmp(attr
->name
, "job-printer-up-time") ||
9928 !strcmp(attr
->name
, "job-printer-uri") ||
9929 !strcmp(attr
->name
, "job-sheets") ||
9930 !strcmp(attr
->name
, "job-state-message") ||
9931 !strcmp(attr
->name
, "job-state-reasons") ||
9932 !strcmp(attr
->name
, "job-uri") ||
9933 !strcmp(attr
->name
, "number-of-documents") ||
9934 !strcmp(attr
->name
, "number-of-intervening-jobs") ||
9935 !strcmp(attr
->name
, "output-device-assigned") ||
9936 !strncmp(attr
->name
, "date-time-at-", 13) ||
9937 !strncmp(attr
->name
, "job-k-octets", 12) ||
9938 !strncmp(attr
->name
, "job-media-sheets", 16) ||
9939 !strncmp(attr
->name
, "time-at-", 8))
9945 send_ipp_status(con
, IPP_ATTRIBUTES_NOT_SETTABLE
,
9946 _("%s cannot be changed."), attr
->name
);
9948 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
9949 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
9953 if (!strcmp(attr
->name
, "job-priority"))
9956 * Change the job priority...
9959 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
9961 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-priority value."));
9963 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
9964 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
9966 else if (job
->state_value
>= IPP_JOB_PROCESSING
)
9968 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9969 _("Job is completed and cannot be changed."));
9972 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
9974 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-priority to %d",
9975 attr
->values
[0].integer
);
9976 cupsdSetJobPriority(job
, attr
->values
[0].integer
);
9979 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
|
9980 CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
;
9983 else if (!strcmp(attr
->name
, "job-state"))
9986 * Change the job state...
9989 if (attr
->value_tag
!= IPP_TAG_ENUM
)
9991 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-state value."));
9993 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
9994 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
9998 switch (attr
->values
[0].integer
)
10000 case IPP_JOB_PENDING
:
10001 case IPP_JOB_HELD
:
10002 if (job
->state_value
> IPP_JOB_HELD
)
10004 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10005 _("Job state cannot be changed."));
10008 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10010 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10011 attr
->values
[0].integer
);
10012 cupsdSetJobState(job
, attr
->values
[0].integer
,
10014 "Job state changed by \"%s\"", username
);
10019 case IPP_JOB_PROCESSING
:
10020 case IPP_JOB_STOPPED
:
10021 if (job
->state_value
!= attr
->values
[0].integer
)
10023 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10024 _("Job state cannot be changed."));
10029 case IPP_JOB_CANCELED
:
10030 case IPP_JOB_ABORTED
:
10031 case IPP_JOB_COMPLETED
:
10032 if (job
->state_value
> IPP_JOB_PROCESSING
)
10034 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10035 _("Job state cannot be changed."));
10038 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10040 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10041 attr
->values
[0].integer
);
10042 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
,
10044 "Job state changed by \"%s\"", username
);
10051 else if (con
->response
->request
.status
.status_code
!= IPP_OK
)
10053 else if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10054 IPP_TAG_ZERO
)) != NULL
)
10057 * Some other value; first free the old value...
10060 if (job
->attrs
->prev
)
10061 job
->attrs
->prev
->next
= attr2
->next
;
10063 job
->attrs
->attrs
= attr2
->next
;
10065 if (job
->attrs
->last
== attr2
)
10066 job
->attrs
->last
= job
->attrs
->prev
;
10068 ippDeleteAttribute(NULL
, attr2
);
10071 * Then copy the attribute...
10074 ippCopyAttribute(job
->attrs
, attr
, 0);
10077 * See if the job-name or job-hold-until is being changed.
10080 if (!strcmp(attr
->name
, "job-hold-until"))
10082 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-hold-until to %s",
10083 attr
->values
[0].string
.text
);
10084 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
10086 if (!strcmp(attr
->values
[0].string
.text
, "no-hold"))
10088 cupsdReleaseJob(job
);
10092 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
,
10093 "Job held by \"%s\".", username
);
10095 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
;
10098 else if (attr
->value_tag
== IPP_TAG_DELETEATTR
)
10101 * Delete the attribute...
10104 if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10105 IPP_TAG_ZERO
)) != NULL
)
10107 if (job
->attrs
->prev
)
10108 job
->attrs
->prev
->next
= attr2
->next
;
10110 job
->attrs
->attrs
= attr2
->next
;
10112 if (attr2
== job
->attrs
->last
)
10113 job
->attrs
->last
= job
->attrs
->prev
;
10115 ippDeleteAttribute(NULL
, attr2
);
10117 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10123 * Add new option by copying it...
10126 ippCopyAttribute(job
->attrs
, attr
, 0);
10128 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10137 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10140 * Send events as needed...
10143 if (event
& CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
)
10144 cupsdAddEvent(CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
,
10145 cupsdFindDest(job
->dest
), job
,
10146 "Job priority changed by user.");
10148 if (event
& CUPSD_EVENT_JOB_STATE
)
10149 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
10150 job
->state_value
== IPP_JOB_HELD
?
10151 "Job held by user." : "Job restarted by user.");
10153 if (event
& CUPSD_EVENT_JOB_CONFIG_CHANGED
)
10154 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
10155 "Job options changed by user.");
10158 * Start jobs if possible...
10167 * 'set_printer_attrs()' - Set printer attributes.
10171 set_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
10172 ipp_attribute_t
*uri
) /* I - Printer */
10174 http_status_t status
; /* Policy status */
10175 cups_ptype_t dtype
; /* Destination type (printer/class) */
10176 cupsd_printer_t
*printer
; /* Printer/class */
10177 ipp_attribute_t
*attr
; /* Printer attribute */
10178 int changed
= 0; /* Was anything changed? */
10181 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_attrs(%p[%d], %s)", con
,
10182 con
->http
.fd
, uri
->values
[0].string
.text
);
10185 * Is the destination valid?
10188 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10194 send_ipp_status(con
, IPP_NOT_FOUND
,
10195 _("The printer or class does not exist."));
10203 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10205 send_http_error(con
, status
, printer
);
10210 * Return a list of attributes that can be set via Set-Printer-Attributes.
10213 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
10214 IPP_TAG_TEXT
)) != NULL
)
10216 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
10220 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
10221 IPP_TAG_TEXT
)) != NULL
)
10223 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
10228 * Update the printer attributes and return...
10233 cupsdSetPrinterAttrs(printer
);
10234 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
10236 cupsdAddEvent(CUPSD_EVENT_PRINTER_CONFIG
, printer
, NULL
,
10237 "Printer \"%s\" description or location changed by \"%s\".",
10238 printer
->name
, get_username(con
));
10240 cupsdLogMessage(CUPSD_LOG_INFO
,
10241 "Printer \"%s\" description or location changed by \"%s\".",
10242 printer
->name
, get_username(con
));
10245 con
->response
->request
.status
.status_code
= IPP_OK
;
10250 * 'set_printer_defaults()' - Set printer default options from a request.
10254 set_printer_defaults(
10255 cupsd_client_t
*con
, /* I - Client connection */
10256 cupsd_printer_t
*printer
) /* I - Printer */
10258 int i
; /* Looping var */
10259 ipp_attribute_t
*attr
; /* Current attribute */
10260 int namelen
; /* Length of attribute name */
10261 char name
[256], /* New attribute name */
10262 value
[256]; /* String version of integer attrs */
10265 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10268 * Skip non-printer attributes...
10271 if (attr
->group_tag
!= IPP_TAG_PRINTER
|| !attr
->name
)
10274 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_defaults: %s", attr
->name
);
10276 if (!strcmp(attr
->name
, "job-sheets-default"))
10279 * Only allow keywords and names...
10282 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10286 * Only allow job-sheets-default to be set when running without a
10287 * system high classification level...
10290 if (Classification
)
10293 cupsdSetString(&printer
->job_sheets
[0], attr
->values
[0].string
.text
);
10295 if (attr
->num_values
> 1)
10296 cupsdSetString(&printer
->job_sheets
[1], attr
->values
[1].string
.text
);
10298 cupsdSetString(&printer
->job_sheets
[1], "none");
10300 else if (!strcmp(attr
->name
, "requesting-user-name-allowed"))
10302 cupsdFreeStrings(&(printer
->users
));
10304 printer
->deny_users
= 0;
10306 if (attr
->value_tag
== IPP_TAG_NAME
&&
10307 (attr
->num_values
> 1 ||
10308 strcmp(attr
->values
[0].string
.text
, "all")))
10310 for (i
= 0; i
< attr
->num_values
; i
++)
10311 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
10314 else if (!strcmp(attr
->name
, "requesting-user-name-denied"))
10316 cupsdFreeStrings(&(printer
->users
));
10318 printer
->deny_users
= 1;
10320 if (attr
->value_tag
== IPP_TAG_NAME
&&
10321 (attr
->num_values
> 1 ||
10322 strcmp(attr
->values
[0].string
.text
, "none")))
10324 for (i
= 0; i
< attr
->num_values
; i
++)
10325 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
10328 else if (!strcmp(attr
->name
, "job-quota-period"))
10330 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10333 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-quota-period to %d...",
10334 attr
->values
[0].integer
);
10335 cupsdFreeQuotas(printer
);
10337 printer
->quota_period
= attr
->values
[0].integer
;
10339 else if (!strcmp(attr
->name
, "job-k-limit"))
10341 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10344 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-k-limit to %d...",
10345 attr
->values
[0].integer
);
10346 cupsdFreeQuotas(printer
);
10348 printer
->k_limit
= attr
->values
[0].integer
;
10350 else if (!strcmp(attr
->name
, "job-page-limit"))
10352 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10355 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-page-limit to %d...",
10356 attr
->values
[0].integer
);
10357 cupsdFreeQuotas(printer
);
10359 printer
->page_limit
= attr
->values
[0].integer
;
10361 else if (!strcmp(attr
->name
, "printer-op-policy"))
10363 cupsd_policy_t
*p
; /* Policy */
10366 if (attr
->value_tag
!= IPP_TAG_NAME
)
10369 if ((p
= cupsdFindPolicy(attr
->values
[0].string
.text
)) != NULL
)
10371 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10372 "Setting printer-op-policy to \"%s\"...",
10373 attr
->values
[0].string
.text
);
10374 cupsdSetString(&printer
->op_policy
, attr
->values
[0].string
.text
);
10375 printer
->op_policy_ptr
= p
;
10379 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10380 _("Unknown printer-op-policy \"%s\"."),
10381 attr
->values
[0].string
.text
);
10385 else if (!strcmp(attr
->name
, "printer-error-policy"))
10387 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10390 if (strcmp(attr
->values
[0].string
.text
, "retry-current-job") &&
10391 ((printer
->type
& CUPS_PRINTER_CLASS
) ||
10392 (strcmp(attr
->values
[0].string
.text
, "abort-job") &&
10393 strcmp(attr
->values
[0].string
.text
, "retry-job") &&
10394 strcmp(attr
->values
[0].string
.text
, "stop-printer"))))
10396 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10397 _("Unknown printer-error-policy \"%s\"."),
10398 attr
->values
[0].string
.text
);
10402 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10403 "Setting printer-error-policy to \"%s\"...",
10404 attr
->values
[0].string
.text
);
10405 cupsdSetString(&printer
->error_policy
, attr
->values
[0].string
.text
);
10409 * Skip any other non-default attributes...
10412 namelen
= strlen(attr
->name
);
10413 if (namelen
< 9 || strcmp(attr
->name
+ namelen
- 8, "-default") ||
10414 namelen
> (sizeof(name
) - 1) || attr
->num_values
!= 1)
10418 * OK, anything else must be a user-defined default...
10421 strlcpy(name
, attr
->name
, sizeof(name
));
10422 name
[namelen
- 8] = '\0'; /* Strip "-default" */
10424 switch (attr
->value_tag
)
10426 case IPP_TAG_DELETEATTR
:
10427 printer
->num_options
= cupsRemoveOption(name
,
10428 printer
->num_options
,
10429 &(printer
->options
));
10430 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10431 "Deleting %s", attr
->name
);
10434 case IPP_TAG_NAME
:
10435 case IPP_TAG_TEXT
:
10436 case IPP_TAG_KEYWORD
:
10438 printer
->num_options
= cupsAddOption(name
,
10439 attr
->values
[0].string
.text
,
10440 printer
->num_options
,
10441 &(printer
->options
));
10442 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10443 "Setting %s to \"%s\"...", attr
->name
,
10444 attr
->values
[0].string
.text
);
10447 case IPP_TAG_BOOLEAN
:
10448 printer
->num_options
= cupsAddOption(name
,
10449 attr
->values
[0].boolean
?
10451 printer
->num_options
,
10452 &(printer
->options
));
10453 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10454 "Setting %s to %s...", attr
->name
,
10455 attr
->values
[0].boolean
? "true" : "false");
10458 case IPP_TAG_INTEGER
:
10459 case IPP_TAG_ENUM
:
10460 sprintf(value
, "%d", attr
->values
[0].integer
);
10461 printer
->num_options
= cupsAddOption(name
, value
,
10462 printer
->num_options
,
10463 &(printer
->options
));
10464 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10465 "Setting %s to %s...", attr
->name
, value
);
10468 case IPP_TAG_RANGE
:
10469 sprintf(value
, "%d-%d", attr
->values
[0].range
.lower
,
10470 attr
->values
[0].range
.upper
);
10471 printer
->num_options
= cupsAddOption(name
, value
,
10472 printer
->num_options
,
10473 &(printer
->options
));
10474 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10475 "Setting %s to %s...", attr
->name
, value
);
10478 case IPP_TAG_RESOLUTION
:
10479 sprintf(value
, "%dx%d%s", attr
->values
[0].resolution
.xres
,
10480 attr
->values
[0].resolution
.yres
,
10481 attr
->values
[0].resolution
.units
== IPP_RES_PER_INCH
?
10483 printer
->num_options
= cupsAddOption(name
, value
,
10484 printer
->num_options
,
10485 &(printer
->options
));
10486 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10487 "Setting %s to %s...", attr
->name
, value
);
10491 /* Do nothing for other values */
10499 * 'start_printer()' - Start a printer.
10503 start_printer(cupsd_client_t
*con
, /* I - Client connection */
10504 ipp_attribute_t
*uri
) /* I - Printer URI */
10506 int i
; /* Temporary variable */
10507 http_status_t status
; /* Policy status */
10508 cups_ptype_t dtype
; /* Destination type (printer/class) */
10509 cupsd_printer_t
*printer
; /* Printer data */
10512 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_printer(%p[%d], %s)", con
,
10513 con
->http
.fd
, uri
->values
[0].string
.text
);
10516 * Is the destination valid?
10519 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10525 send_ipp_status(con
, IPP_NOT_FOUND
,
10526 _("The printer or class does not exist."));
10534 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10536 send_http_error(con
, status
, printer
);
10541 * Start the printer...
10544 printer
->state_message
[0] = '\0';
10546 cupsdStartPrinter(printer
, 1);
10548 if (dtype
& CUPS_PRINTER_CLASS
)
10549 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" started by \"%s\".",
10550 printer
->name
, get_username(con
));
10552 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" started by \"%s\".",
10553 printer
->name
, get_username(con
));
10561 if ((i
= check_quotas(con
, printer
)) < 0)
10563 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
10568 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
10573 * Everything was ok, so return OK status...
10576 con
->response
->request
.status
.status_code
= IPP_OK
;
10581 * 'stop_printer()' - Stop a printer.
10585 stop_printer(cupsd_client_t
*con
, /* I - Client connection */
10586 ipp_attribute_t
*uri
) /* I - Printer URI */
10588 http_status_t status
; /* Policy status */
10589 cups_ptype_t dtype
; /* Destination type (printer/class) */
10590 cupsd_printer_t
*printer
; /* Printer data */
10591 ipp_attribute_t
*attr
; /* printer-state-message attribute */
10594 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "stop_printer(%p[%d], %s)", con
,
10595 con
->http
.fd
, uri
->values
[0].string
.text
);
10598 * Is the destination valid?
10601 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10607 send_ipp_status(con
, IPP_NOT_FOUND
,
10608 _("The printer or class does not exist."));
10616 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10618 send_http_error(con
, status
, printer
);
10623 * Stop the printer...
10626 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
10627 IPP_TAG_TEXT
)) == NULL
)
10628 strlcpy(printer
->state_message
, "Paused", sizeof(printer
->state_message
));
10631 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
10632 sizeof(printer
->state_message
));
10635 cupsdStopPrinter(printer
, 1);
10637 if (dtype
& CUPS_PRINTER_CLASS
)
10638 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" stopped by \"%s\".",
10639 printer
->name
, get_username(con
));
10641 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" stopped by \"%s\".",
10642 printer
->name
, get_username(con
));
10645 * Everything was ok, so return OK status...
10648 con
->response
->request
.status
.status_code
= IPP_OK
;
10653 * 'url_encode_attr()' - URL-encode a string attribute.
10657 url_encode_attr(ipp_attribute_t
*attr
, /* I - Attribute */
10658 char *buffer
,/* I - String buffer */
10659 int bufsize
)/* I - Size of buffer */
10661 int i
; /* Looping var */
10662 char *bufptr
, /* Pointer into buffer */
10663 *bufend
; /* End of buffer */
10666 strlcpy(buffer
, attr
->name
, bufsize
);
10667 bufptr
= buffer
+ strlen(buffer
);
10668 bufend
= buffer
+ bufsize
- 1;
10670 for (i
= 0; i
< attr
->num_values
; i
++)
10672 if (bufptr
>= bufend
)
10680 if (bufptr
>= bufend
)
10685 bufptr
= url_encode_string(attr
->values
[i
].string
.text
,
10686 bufptr
, bufend
- bufptr
+ 1);
10688 if (bufptr
>= bufend
)
10699 * 'url_encode_string()' - URL-encode a string.
10702 static char * /* O - End of string */
10703 url_encode_string(const char *s
, /* I - String */
10704 char *buffer
, /* I - String buffer */
10705 int bufsize
) /* I - Size of buffer */
10707 char *bufptr
, /* Pointer into buffer */
10708 *bufend
; /* End of buffer */
10709 static const char *hex
= "0123456789ABCDEF";
10714 bufend
= buffer
+ bufsize
- 1;
10716 while (*s
&& bufptr
< bufend
)
10718 if (*s
== ' ' || *s
== '%' || *s
== '+')
10720 if (bufptr
>= (bufend
- 2))
10724 *bufptr
++ = hex
[(*s
>> 4) & 15];
10725 *bufptr
++ = hex
[*s
& 15];
10729 else if (*s
== '\'' || *s
== '\\')
10731 if (bufptr
>= (bufend
- 1))
10748 * 'user_allowed()' - See if a user is allowed to print to a queue.
10751 static int /* O - 0 if not allowed, 1 if allowed */
10752 user_allowed(cupsd_printer_t
*p
, /* I - Printer or class */
10753 const char *username
) /* I - Username */
10755 struct passwd
*pw
; /* User password data */
10756 char baseuser
[256], /* Base username */
10757 *baseptr
, /* Pointer to "@" in base username */
10758 *name
; /* Current user name */
10761 if (cupsArrayCount(p
->users
) == 0)
10764 if (!strcmp(username
, "root"))
10767 if (strchr(username
, '@'))
10770 * Strip @REALM for username check...
10773 strlcpy(baseuser
, username
, sizeof(baseuser
));
10775 if ((baseptr
= strchr(baseuser
, '@')) != NULL
)
10778 username
= baseuser
;
10781 pw
= getpwnam(username
);
10784 for (name
= (char *)cupsArrayFirst(p
->users
);
10786 name
= (char *)cupsArrayNext(p
->users
))
10788 if (name
[0] == '@')
10791 * Check group membership...
10794 if (cupsdCheckGroup(username
, pw
, name
+ 1))
10797 else if (name
[0] == '#')
10803 if (cupsdCheckGroup(username
, pw
, name
))
10806 else if (!_cups_strcasecmp(username
, name
))
10810 return ((name
!= NULL
) != p
->deny_users
);
10815 * 'validate_job()' - Validate printer options and destination.
10819 validate_job(cupsd_client_t
*con
, /* I - Client connection */
10820 ipp_attribute_t
*uri
) /* I - Printer URI */
10822 http_status_t status
; /* Policy status */
10823 ipp_attribute_t
*attr
, /* Current attribute */
10824 *auth_info
; /* auth-info attribute */
10825 ipp_attribute_t
*format
, /* Document-format attribute */
10826 *name
; /* Job-name attribute */
10827 cups_ptype_t dtype
; /* Destination type (printer/class) */
10828 char super
[MIME_MAX_SUPER
],
10829 /* Supertype of file */
10830 type
[MIME_MAX_TYPE
];
10831 /* Subtype of file */
10832 cupsd_printer_t
*printer
; /* Printer */
10835 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_job(%p[%d], %s)", con
,
10836 con
->http
.fd
, uri
->values
[0].string
.text
);
10839 * OK, see if the client is sending the document compressed - CUPS
10840 * doesn't support compression yet...
10843 if ((attr
= ippFindAttribute(con
->request
, "compression",
10844 IPP_TAG_KEYWORD
)) != NULL
)
10846 if (strcmp(attr
->values
[0].string
.text
, "none")
10848 && strcmp(attr
->values
[0].string
.text
, "gzip")
10849 #endif /* HAVE_LIBZ */
10852 send_ipp_status(con
, IPP_ATTRIBUTES
,
10853 _("Unsupported 'compression' value \"%s\"."),
10854 attr
->values
[0].string
.text
);
10855 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
10856 "compression", NULL
, attr
->values
[0].string
.text
);
10862 * Is it a format we support?
10865 if ((format
= ippFindAttribute(con
->request
, "document-format",
10866 IPP_TAG_MIMETYPE
)) != NULL
)
10868 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%255[^;]",
10871 send_ipp_status(con
, IPP_BAD_REQUEST
,
10872 _("Bad 'document-format' value \"%s\"."),
10873 format
->values
[0].string
.text
);
10877 if ((strcmp(super
, "application") || strcmp(type
, "octet-stream")) &&
10878 !mimeType(MimeDatabase
, super
, type
))
10880 cupsdLogMessage(CUPSD_LOG_INFO
,
10881 "Hint: Do you have the raw file printing rules enabled?");
10882 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
10883 _("Unsupported 'document-format' value \"%s\"."),
10884 format
->values
[0].string
.text
);
10885 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
10886 "document-format", NULL
, format
->values
[0].string
.text
);
10892 * Is the job-name valid?
10895 if ((name
= ippFindAttribute(con
->request
, "job-name", IPP_TAG_ZERO
)) != NULL
)
10897 int bad_name
= 0; /* Is the job-name value bad? */
10899 if ((name
->value_tag
!= IPP_TAG_NAME
&& name
->value_tag
!= IPP_TAG_NAMELANG
) ||
10900 name
->num_values
!= 1)
10907 * Validate that job-name conforms to RFC 5198 (Network Unicode) and
10908 * IPP Everywhere requirements for "name" values...
10911 const unsigned char *nameptr
; /* Pointer into "job-name" attribute */
10913 for (nameptr
= (unsigned char *)name
->values
[0].string
.text
;
10917 if (*nameptr
< ' ' && *nameptr
!= '\t')
10919 else if (*nameptr
== 0x7f)
10921 else if ((*nameptr
& 0xe0) == 0xc0)
10923 if ((nameptr
[1] & 0xc0) != 0x80)
10928 else if ((*nameptr
& 0xf0) == 0xe0)
10930 if ((nameptr
[1] & 0xc0) != 0x80 ||
10931 (nameptr
[2] & 0xc0) != 0x80)
10936 else if ((*nameptr
& 0xf8) == 0xf0)
10938 if ((nameptr
[1] & 0xc0) != 0x80 ||
10939 (nameptr
[2] & 0xc0) != 0x80 ||
10940 (nameptr
[3] & 0xc0) != 0x80)
10945 else if (*nameptr
& 0x80)
10955 if (StrictConformance
)
10957 send_ipp_status(con
, IPP_ATTRIBUTES
,
10958 _("Unsupported 'job-name' value."));
10959 ippCopyAttribute(con
->response
, name
, 0);
10964 cupsdLogMessage(CUPSD_LOG_WARN
,
10965 "Unsupported 'job-name' value, deleting from request.");
10966 ippDeleteAttribute(con
->request
, name
);
10972 * Is the destination valid?
10975 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10981 send_ipp_status(con
, IPP_NOT_FOUND
,
10982 _("The printer or class does not exist."));
10990 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
10992 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10994 send_http_error(con
, status
, printer
);
10997 else if (printer
->num_auth_info_required
== 1 &&
10998 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
11001 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
11005 else if (auth_info
&& !con
->http
.tls
&&
11006 !httpAddrLocalhost(con
->http
.hostaddr
))
11009 * Require encryption of auth-info over non-local connections...
11012 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
11015 #endif /* HAVE_SSL */
11018 * Everything was ok, so return OK status...
11021 con
->response
->request
.status
.status_code
= IPP_OK
;
11026 * 'validate_name()' - Make sure the printer name only contains valid chars.
11029 static int /* O - 0 if name is no good, 1 if good */
11030 validate_name(const char *name
) /* I - Name to check */
11032 const char *ptr
; /* Pointer into name */
11036 * Scan the whole name...
11039 for (ptr
= name
; *ptr
; ptr
++)
11040 if ((*ptr
> 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
11044 * All the characters are good; validate the length, too...
11047 return ((ptr
- name
) < 128);
11052 * 'validate_user()' - Validate the user for the request.
11055 static int /* O - 1 if permitted, 0 otherwise */
11056 validate_user(cupsd_job_t
*job
, /* I - Job */
11057 cupsd_client_t
*con
, /* I - Client connection */
11058 const char *owner
, /* I - Owner of job/resource */
11059 char *username
, /* O - Authenticated username */
11060 int userlen
) /* I - Length of username */
11062 cupsd_printer_t
*printer
; /* Printer for job */
11065 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
11066 "validate_user(job=%d, con=%d, owner=\"%s\", username=%p, "
11068 job
->id
, con
? con
->http
.fd
: 0,
11069 owner
? owner
: "(null)", username
, userlen
);
11072 * Validate input...
11075 if (!con
|| !owner
|| !username
|| userlen
<= 0)
11079 * Get the best authenticated username that is available.
11082 strlcpy(username
, get_username(con
), userlen
);
11085 * Check the username against the owner...
11088 printer
= cupsdFindDest(job
->dest
);
11090 return (cupsdCheckPolicy(printer
? printer
->op_policy_ptr
: DefaultPolicyPtr
,
11091 con
, owner
) == HTTP_OK
);