4 * IPP routines for the CUPS scheduler.
6 * Copyright 2007-2014 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 * Include necessary headers...
24 #include <cups/ppd-private.h>
27 /*# include <ApplicationServices/ApplicationServices.h>
28 extern CFUUIDRef ColorSyncCreateUUIDFromUInt32(unsigned id);
29 # include <CoreFoundation/CoreFoundation.h>*/
30 # ifdef HAVE_MEMBERSHIP_H
31 # include <membership.h>
32 # endif /* HAVE_MEMBERSHIP_H */
33 # ifdef HAVE_MEMBERSHIPPRIV_H
34 # include <membershipPriv.h>
36 extern int mbr_user_name_to_uuid(const char* name
, uuid_t uu
);
37 extern int mbr_group_name_to_uuid(const char* name
, uuid_t uu
);
38 extern int mbr_check_membership_by_id(uuid_t user
, gid_t group
, int* ismember
);
39 # endif /* HAVE_MEMBERSHIPPRIV_H */
40 #endif /* __APPLE__ */
47 static void accept_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
48 static void add_class(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
49 static int add_file(cupsd_client_t
*con
, cupsd_job_t
*job
,
50 mime_type_t
*filetype
, int compression
);
51 static cupsd_job_t
*add_job(cupsd_client_t
*con
, cupsd_printer_t
*printer
,
52 mime_type_t
*filetype
);
53 static void add_job_subscriptions(cupsd_client_t
*con
, cupsd_job_t
*job
);
54 static void add_job_uuid(cupsd_job_t
*job
);
55 static void add_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
56 static void add_printer_state_reasons(cupsd_client_t
*con
,
58 static void add_queued_job_count(cupsd_client_t
*con
, cupsd_printer_t
*p
);
59 static void apply_printer_defaults(cupsd_printer_t
*printer
,
61 static void authenticate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
62 static void cancel_all_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
63 static void cancel_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
64 static void cancel_subscription(cupsd_client_t
*con
, int id
);
65 static int check_rss_recipient(const char *recipient
);
66 static int check_quotas(cupsd_client_t
*con
, cupsd_printer_t
*p
);
67 static void close_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
68 static void copy_attrs(ipp_t
*to
, ipp_t
*from
, cups_array_t
*ra
,
69 ipp_tag_t group
, int quickcopy
,
70 cups_array_t
*exclude
);
71 static int copy_banner(cupsd_client_t
*con
, cupsd_job_t
*job
,
73 static int copy_file(const char *from
, const char *to
);
74 static int copy_model(cupsd_client_t
*con
, const char *from
,
76 static void copy_job_attrs(cupsd_client_t
*con
,
78 cups_array_t
*ra
, cups_array_t
*exclude
);
79 static void copy_printer_attrs(cupsd_client_t
*con
,
80 cupsd_printer_t
*printer
,
82 static void copy_subscription_attrs(cupsd_client_t
*con
,
83 cupsd_subscription_t
*sub
,
85 cups_array_t
*exclude
);
86 static void create_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
87 static cups_array_t
*create_requested_array(ipp_t
*request
);
88 static void create_subscriptions(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
89 static void delete_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
90 static void get_default(cupsd_client_t
*con
);
91 static void get_devices(cupsd_client_t
*con
);
92 static void get_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
93 static void get_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
94 static void get_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
95 static void get_notifications(cupsd_client_t
*con
);
96 static void get_ppd(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
97 static void get_ppds(cupsd_client_t
*con
);
98 static void get_printers(cupsd_client_t
*con
, int type
);
99 static void get_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
100 static void get_printer_supported(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
101 static void get_subscription_attrs(cupsd_client_t
*con
, int sub_id
);
102 static void get_subscriptions(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
103 static const char *get_username(cupsd_client_t
*con
);
104 static void hold_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
105 static void hold_new_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
106 static void move_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
107 static int ppd_parse_line(const char *line
, char *option
, int olen
,
108 char *choice
, int clen
);
109 static void print_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
110 static void read_job_ticket(cupsd_client_t
*con
);
111 static void reject_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
112 static void release_held_new_jobs(cupsd_client_t
*con
,
113 ipp_attribute_t
*uri
);
114 static void release_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
115 static void renew_subscription(cupsd_client_t
*con
, int sub_id
);
116 static void restart_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
117 static void save_auth_info(cupsd_client_t
*con
, cupsd_job_t
*job
,
118 ipp_attribute_t
*auth_info
);
119 static void send_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
120 static void send_http_error(cupsd_client_t
*con
, http_status_t status
,
121 cupsd_printer_t
*printer
);
122 static void send_ipp_status(cupsd_client_t
*con
, ipp_status_t status
,
123 const char *message
, ...)
124 __attribute__((__format__(__printf__
, 3, 4)));
125 static void set_default(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
126 static void set_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
127 static void set_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
128 static void set_printer_defaults(cupsd_client_t
*con
,
129 cupsd_printer_t
*printer
);
130 static void start_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
131 static void stop_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
132 static void url_encode_attr(ipp_attribute_t
*attr
, char *buffer
, size_t bufsize
);
133 static char *url_encode_string(const char *s
, char *buffer
, size_t bufsize
);
134 static int user_allowed(cupsd_printer_t
*p
, const char *username
);
135 static void validate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
136 static int validate_name(const char *name
);
137 static int validate_user(cupsd_job_t
*job
, cupsd_client_t
*con
, const char *owner
, char *username
, size_t userlen
);
141 * 'cupsdProcessIPPRequest()' - Process an incoming IPP request.
144 int /* O - 1 on success, 0 on failure */
145 cupsdProcessIPPRequest(
146 cupsd_client_t
*con
) /* I - Client connection */
148 ipp_tag_t group
; /* Current group tag */
149 ipp_attribute_t
*attr
; /* Current attribute */
150 ipp_attribute_t
*charset
; /* Character set attribute */
151 ipp_attribute_t
*language
; /* Language attribute */
152 ipp_attribute_t
*uri
= NULL
; /* Printer or job URI attribute */
153 ipp_attribute_t
*username
; /* requesting-user-name attr */
154 int sub_id
; /* Subscription ID */
157 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
158 "cupsdProcessIPPRequest(%p[%d]): operation_id = %04x",
159 con
, con
->number
, con
->request
->request
.op
.operation_id
);
162 * First build an empty response message for this request...
165 con
->response
= ippNew();
167 con
->response
->request
.status
.version
[0] =
168 con
->request
->request
.op
.version
[0];
169 con
->response
->request
.status
.version
[1] =
170 con
->request
->request
.op
.version
[1];
171 con
->response
->request
.status
.request_id
=
172 con
->request
->request
.op
.request_id
;
175 * Then validate the request header and required attributes...
178 if (con
->request
->request
.any
.version
[0] != 1 &&
179 con
->request
->request
.any
.version
[0] != 2)
182 * Return an error, since we only support IPP 1.x and 2.x.
185 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
186 "%04X %s Bad request version number %d.%d",
187 IPP_VERSION_NOT_SUPPORTED
, con
->http
->hostname
,
188 con
->request
->request
.any
.version
[0],
189 con
->request
->request
.any
.version
[1]);
191 send_ipp_status(con
, IPP_VERSION_NOT_SUPPORTED
,
192 _("Bad request version number %d.%d."),
193 con
->request
->request
.any
.version
[0],
194 con
->request
->request
.any
.version
[1]);
196 else if (con
->request
->request
.any
.request_id
< 1)
199 * Return an error, since request IDs must be between 1 and 2^31-1
202 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
203 "%04X %s Bad request ID %d",
204 IPP_BAD_REQUEST
, con
->http
->hostname
,
205 con
->request
->request
.any
.request_id
);
207 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad request ID %d."),
208 con
->request
->request
.any
.request_id
);
210 else if (!con
->request
->attrs
)
212 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
213 "%04X %s No attributes in request",
214 IPP_BAD_REQUEST
, con
->http
->hostname
);
216 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No attributes in request."));
221 * Make sure that the attributes are provided in the correct order and
222 * don't repeat groups...
225 for (attr
= con
->request
->attrs
, group
= attr
->group_tag
;
228 if (attr
->group_tag
< group
&& attr
->group_tag
!= IPP_TAG_ZERO
)
231 * Out of order; return an error...
234 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
235 "%04X %s Attribute groups are out of order",
236 IPP_BAD_REQUEST
, con
->http
->hostname
);
238 send_ipp_status(con
, IPP_BAD_REQUEST
,
239 _("Attribute groups are out of order (%x < %x)."),
240 attr
->group_tag
, group
);
244 group
= attr
->group_tag
;
249 * Then make sure that the first three attributes are:
252 * attributes-natural-language
253 * printer-uri/job-uri
256 attr
= con
->request
->attrs
;
257 if (attr
&& attr
->name
&&
258 !strcmp(attr
->name
, "attributes-charset") &&
259 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_CHARSET
)
267 if (attr
&& attr
->name
&&
268 !strcmp(attr
->name
, "attributes-natural-language") &&
269 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_LANGUAGE
)
274 * Reset language for this request if different from Accept-Language.
277 if (!con
->language
||
278 strcmp(attr
->values
[0].string
.text
, con
->language
->language
))
280 cupsLangFree(con
->language
);
281 con
->language
= cupsLangGet(attr
->values
[0].string
.text
);
287 if ((attr
= ippFindAttribute(con
->request
, "printer-uri",
288 IPP_TAG_URI
)) != NULL
)
290 else if ((attr
= ippFindAttribute(con
->request
, "job-uri",
291 IPP_TAG_URI
)) != NULL
)
293 else if (con
->request
->request
.op
.operation_id
== CUPS_GET_PPD
)
294 uri
= ippFindAttribute(con
->request
, "ppd-name", IPP_TAG_NAME
);
299 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
300 "attributes-charset", NULL
,
301 charset
->values
[0].string
.text
);
303 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
304 "attributes-charset", NULL
, "utf-8");
307 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
308 "attributes-natural-language", NULL
,
309 language
->values
[0].string
.text
);
311 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
312 "attributes-natural-language", NULL
, DefaultLanguage
);
315 _cups_strcasecmp(charset
->values
[0].string
.text
, "us-ascii") &&
316 _cups_strcasecmp(charset
->values
[0].string
.text
, "utf-8"))
319 * Bad character set...
322 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unsupported character set \"%s\"",
323 charset
->values
[0].string
.text
);
324 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
325 "%04X %s Unsupported attributes-charset value \"%s\"",
326 IPP_CHARSET
, con
->http
->hostname
,
327 charset
->values
[0].string
.text
);
328 send_ipp_status(con
, IPP_BAD_REQUEST
,
329 _("Unsupported character set \"%s\"."),
330 charset
->values
[0].string
.text
);
332 else if (!charset
|| !language
||
334 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEFAULT
&&
335 con
->request
->request
.op
.operation_id
!= CUPS_GET_PRINTERS
&&
336 con
->request
->request
.op
.operation_id
!= CUPS_GET_CLASSES
&&
337 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEVICES
&&
338 con
->request
->request
.op
.operation_id
!= CUPS_GET_PPDS
))
341 * Return an error, since attributes-charset,
342 * attributes-natural-language, and printer-uri/job-uri are required
343 * for all operations.
348 cupsdLogMessage(CUPSD_LOG_ERROR
,
349 "Missing attributes-charset attribute");
351 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
352 "%04X %s Missing attributes-charset attribute",
353 IPP_BAD_REQUEST
, con
->http
->hostname
);
358 cupsdLogMessage(CUPSD_LOG_ERROR
,
359 "Missing attributes-natural-language attribute");
361 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
362 "%04X %s Missing attributes-natural-language attribute",
363 IPP_BAD_REQUEST
, con
->http
->hostname
);
368 cupsdLogMessage(CUPSD_LOG_ERROR
,
369 "Missing printer-uri, job-uri, or ppd-name "
372 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
373 "%04X %s Missing printer-uri, job-uri, or ppd-name "
374 "attribute", IPP_BAD_REQUEST
, con
->http
->hostname
);
377 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Request attributes follow...");
379 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
380 cupsdLogMessage(CUPSD_LOG_DEBUG
,
381 "attr \"%s\": group_tag = %x, value_tag = %x",
382 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
385 cupsdLogMessage(CUPSD_LOG_DEBUG
, "End of attributes...");
387 send_ipp_status(con
, IPP_BAD_REQUEST
,
388 _("Missing required attributes."));
393 * OK, all the checks pass so far; make sure requesting-user-name is
394 * not "root" from a remote host...
397 if ((username
= ippFindAttribute(con
->request
, "requesting-user-name",
398 IPP_TAG_NAME
)) != NULL
)
401 * Check for root user...
404 if (!strcmp(username
->values
[0].string
.text
, "root") &&
405 _cups_strcasecmp(con
->http
->hostname
, "localhost") &&
406 strcmp(con
->username
, "root"))
409 * Remote unauthenticated user masquerading as local root...
412 _cupsStrFree(username
->values
[0].string
.text
);
413 username
->values
[0].string
.text
= _cupsStrAlloc(RemoteRoot
);
417 if ((attr
= ippFindAttribute(con
->request
, "notify-subscription-id",
418 IPP_TAG_INTEGER
)) != NULL
)
419 sub_id
= attr
->values
[0].integer
;
424 * Then try processing the operation...
428 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s",
429 ippOpString(con
->request
->request
.op
.operation_id
),
430 uri
->values
[0].string
.text
);
432 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s",
433 ippOpString(con
->request
->request
.op
.operation_id
));
435 switch (con
->request
->request
.op
.operation_id
)
437 case IPP_OP_PRINT_JOB
:
441 case IPP_OP_VALIDATE_JOB
:
442 validate_job(con
, uri
);
445 case IPP_OP_CREATE_JOB
:
446 create_job(con
, uri
);
449 case IPP_OP_SEND_DOCUMENT
:
450 send_document(con
, uri
);
453 case IPP_OP_CANCEL_JOB
:
454 cancel_job(con
, uri
);
457 case IPP_OP_GET_JOB_ATTRIBUTES
:
458 get_job_attrs(con
, uri
);
461 case IPP_OP_GET_JOBS
:
465 case IPP_OP_GET_PRINTER_ATTRIBUTES
:
466 get_printer_attrs(con
, uri
);
469 case IPP_OP_GET_PRINTER_SUPPORTED_VALUES
:
470 get_printer_supported(con
, uri
);
473 case IPP_OP_HOLD_JOB
:
477 case IPP_OP_RELEASE_JOB
:
478 release_job(con
, uri
);
481 case IPP_OP_RESTART_JOB
:
482 restart_job(con
, uri
);
485 case IPP_OP_PAUSE_PRINTER
:
486 stop_printer(con
, uri
);
489 case IPP_OP_RESUME_PRINTER
:
490 start_printer(con
, uri
);
493 case IPP_OP_PURGE_JOBS
:
494 case IPP_OP_CANCEL_JOBS
:
495 case IPP_OP_CANCEL_MY_JOBS
:
496 cancel_all_jobs(con
, uri
);
499 case IPP_OP_SET_JOB_ATTRIBUTES
:
500 set_job_attrs(con
, uri
);
503 case IPP_OP_SET_PRINTER_ATTRIBUTES
:
504 set_printer_attrs(con
, uri
);
507 case IPP_OP_HOLD_NEW_JOBS
:
508 hold_new_jobs(con
, uri
);
511 case IPP_OP_RELEASE_HELD_NEW_JOBS
:
512 release_held_new_jobs(con
, uri
);
515 case IPP_OP_CLOSE_JOB
:
519 case IPP_OP_CUPS_GET_DEFAULT
:
523 case IPP_OP_CUPS_GET_PRINTERS
:
524 get_printers(con
, 0);
527 case IPP_OP_CUPS_GET_CLASSES
:
528 get_printers(con
, CUPS_PRINTER_CLASS
);
531 case IPP_OP_CUPS_ADD_MODIFY_PRINTER
:
532 add_printer(con
, uri
);
535 case IPP_OP_CUPS_DELETE_PRINTER
:
536 delete_printer(con
, uri
);
539 case IPP_OP_CUPS_ADD_MODIFY_CLASS
:
543 case IPP_OP_CUPS_DELETE_CLASS
:
544 delete_printer(con
, uri
);
547 case IPP_OP_CUPS_ACCEPT_JOBS
:
548 case IPP_OP_ENABLE_PRINTER
:
549 accept_jobs(con
, uri
);
552 case IPP_OP_CUPS_REJECT_JOBS
:
553 case IPP_OP_DISABLE_PRINTER
:
554 reject_jobs(con
, uri
);
557 case IPP_OP_CUPS_SET_DEFAULT
:
558 set_default(con
, uri
);
561 case IPP_OP_CUPS_GET_DEVICES
:
565 case IPP_OP_CUPS_GET_DOCUMENT
:
566 get_document(con
, uri
);
569 case IPP_OP_CUPS_GET_PPD
:
573 case IPP_OP_CUPS_GET_PPDS
:
577 case IPP_OP_CUPS_MOVE_JOB
:
581 case IPP_OP_CUPS_AUTHENTICATE_JOB
:
582 authenticate_job(con
, uri
);
585 case IPP_OP_CREATE_PRINTER_SUBSCRIPTIONS
:
586 case IPP_OP_CREATE_JOB_SUBSCRIPTIONS
:
587 create_subscriptions(con
, uri
);
590 case IPP_OP_GET_SUBSCRIPTION_ATTRIBUTES
:
591 get_subscription_attrs(con
, sub_id
);
594 case IPP_OP_GET_SUBSCRIPTIONS
:
595 get_subscriptions(con
, uri
);
598 case IPP_OP_RENEW_SUBSCRIPTION
:
599 renew_subscription(con
, sub_id
);
602 case IPP_OP_CANCEL_SUBSCRIPTION
:
603 cancel_subscription(con
, sub_id
);
606 case IPP_OP_GET_NOTIFICATIONS
:
607 get_notifications(con
);
611 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
612 "%04X %s Operation %04X (%s) not supported",
613 IPP_OPERATION_NOT_SUPPORTED
, con
->http
->hostname
,
614 con
->request
->request
.op
.operation_id
,
615 ippOpString(con
->request
->request
.op
.operation_id
));
617 send_ipp_status(con
, IPP_OPERATION_NOT_SUPPORTED
,
618 _("%s not supported."),
620 con
->request
->request
.op
.operation_id
));
630 * Sending data from the scheduler...
633 cupsdLogMessage(con
->response
->request
.status
.status_code
634 >= IPP_BAD_REQUEST
&&
635 con
->response
->request
.status
.status_code
636 != IPP_NOT_FOUND
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
637 "[Client %d] Returning IPP %s for %s (%s) from %s",
639 ippErrorString(con
->response
->request
.status
.status_code
),
640 ippOpString(con
->request
->request
.op
.operation_id
),
641 uri
? uri
->values
[0].string
.text
: "no URI",
642 con
->http
->hostname
);
644 httpClearFields(con
->http
);
646 #ifdef CUPSD_USE_CHUNKING
648 * Because older versions of CUPS (1.1.17 and older) and some IPP
649 * clients do not implement chunking properly, we cannot use
650 * chunking by default. This may become the default in future
651 * CUPS releases, or we might add a configuration directive for
655 if (con
->http
->version
== HTTP_1_1
)
657 cupsdLogMessage(CUPSD_LOG_DEBUG
,
658 "[Client %d] Transfer-Encoding: chunked",
661 cupsdSetLength(con
->http
, 0);
664 #endif /* CUPSD_USE_CHUNKING */
666 size_t length
; /* Length of response */
669 length
= ippLength(con
->response
);
671 if (con
->file
>= 0 && !con
->pipe_pid
)
673 struct stat fileinfo
; /* File information */
675 if (!fstat(con
->file
, &fileinfo
))
676 length
+= (size_t)fileinfo
.st_size
;
679 cupsdLogMessage(CUPSD_LOG_DEBUG
,
680 "[Client %d] Content-Length: " CUPS_LLFMT
,
681 con
->number
, CUPS_LLCAST length
);
682 httpSetLength(con
->http
, length
);
685 if (cupsdSendHeader(con
, HTTP_OK
, "application/ipp", CUPSD_AUTH_NONE
))
688 * Tell the caller the response header was sent successfully...
691 cupsdAddSelect(httpGetFd(con
->http
), (cupsd_selfunc_t
)cupsdReadClient
,
692 (cupsd_selfunc_t
)cupsdWriteClient
, con
);
699 * Tell the caller the response header could not be sent...
708 * Sending data from a subprocess like cups-deviced; tell the caller
709 * everything is A-OK so far...
718 * 'cupsdTimeoutJob()' - Timeout a job waiting on job files.
721 int /* O - 0 on success, -1 on error */
722 cupsdTimeoutJob(cupsd_job_t
*job
) /* I - Job to timeout */
724 cupsd_printer_t
*printer
; /* Destination printer or class */
725 ipp_attribute_t
*attr
; /* job-sheets attribute */
726 int kbytes
; /* Kilobytes in banner */
729 job
->pending_timeout
= 0;
732 * See if we need to add the ending sheet...
735 if (!cupsdLoadJob(job
))
738 printer
= cupsdFindDest(job
->dest
);
739 attr
= ippFindAttribute(job
->attrs
, "job-sheets", IPP_TAG_NAME
);
741 if (printer
&& !(printer
->type
& CUPS_PRINTER_REMOTE
) &&
742 attr
&& attr
->num_values
> 1)
748 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding end banner page \"%s\".",
749 attr
->values
[1].string
.text
);
751 if ((kbytes
= copy_banner(NULL
, job
, attr
->values
[1].string
.text
)) < 0)
754 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
762 * 'accept_jobs()' - Accept print jobs to a printer.
766 accept_jobs(cupsd_client_t
*con
, /* I - Client connection */
767 ipp_attribute_t
*uri
) /* I - Printer or class URI */
769 http_status_t status
; /* Policy status */
770 cups_ptype_t dtype
; /* Destination type (printer/class) */
771 cupsd_printer_t
*printer
; /* Printer data */
774 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "accept_jobs(%p[%d], %s)", con
,
775 con
->number
, uri
->values
[0].string
.text
);
778 * Is the destination valid?
781 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
787 send_ipp_status(con
, IPP_NOT_FOUND
,
788 _("The printer or class does not exist."));
796 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
798 send_http_error(con
, status
, printer
);
803 * Accept jobs sent to the printer...
806 printer
->accepting
= 1;
807 printer
->state_message
[0] = '\0';
809 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
810 "Now accepting jobs.");
812 if (dtype
& CUPS_PRINTER_CLASS
)
814 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
816 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" now accepting jobs (\"%s\").",
817 printer
->name
, get_username(con
));
821 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
823 cupsdLogMessage(CUPSD_LOG_INFO
,
824 "Printer \"%s\" now accepting jobs (\"%s\").",
825 printer
->name
, get_username(con
));
829 * Everything was ok, so return OK status...
832 con
->response
->request
.status
.status_code
= IPP_OK
;
837 * 'add_class()' - Add a class to the system.
841 add_class(cupsd_client_t
*con
, /* I - Client connection */
842 ipp_attribute_t
*uri
) /* I - URI of class */
844 http_status_t status
; /* Policy status */
845 int i
; /* Looping var */
846 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
847 username
[HTTP_MAX_URI
], /* Username portion of URI */
848 host
[HTTP_MAX_URI
], /* Host portion of URI */
849 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
850 int port
; /* Port portion of URI */
851 cupsd_printer_t
*pclass
, /* Class */
852 *member
; /* Member printer/class */
853 cups_ptype_t dtype
; /* Destination type */
854 ipp_attribute_t
*attr
; /* Printer attribute */
855 int modify
; /* Non-zero if we just modified */
856 int need_restart_job
; /* Need to restart job? */
859 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_class(%p[%d], %s)", con
,
860 con
->number
, uri
->values
[0].string
.text
);
863 * Do we have a valid URI?
866 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
867 sizeof(scheme
), username
, sizeof(username
), host
,
868 sizeof(host
), &port
, resource
, sizeof(resource
));
871 if (strncmp(resource
, "/classes/", 9) || strlen(resource
) == 9)
874 * No, return an error...
877 send_ipp_status(con
, IPP_BAD_REQUEST
,
878 _("The printer-uri must be of the form "
879 "\"ipp://HOSTNAME/classes/CLASSNAME\"."));
884 * Do we have a valid printer name?
887 if (!validate_name(resource
+ 9))
890 * No, return an error...
893 send_ipp_status(con
, IPP_BAD_REQUEST
,
894 _("The printer-uri \"%s\" contains invalid characters."),
895 uri
->values
[0].string
.text
);
900 * See if the class already exists; if not, create a new class...
903 if ((pclass
= cupsdFindClass(resource
+ 9)) == NULL
)
906 * Class doesn't exist; see if we have a printer of the same name...
909 if ((pclass
= cupsdFindPrinter(resource
+ 9)) != NULL
)
912 * Yes, return an error...
915 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
916 _("A printer named \"%s\" already exists."),
922 * No, check the default policy and then add the class...
925 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
927 send_http_error(con
, status
, NULL
);
931 pclass
= cupsdAddClass(resource
+ 9);
934 else if ((status
= cupsdCheckPolicy(pclass
->op_policy_ptr
, con
,
937 send_http_error(con
, status
, pclass
);
944 * Look for attributes and copy them over as needed...
947 need_restart_job
= 0;
949 if ((attr
= ippFindAttribute(con
->request
, "printer-location", IPP_TAG_TEXT
)) != NULL
)
950 cupsdSetString(&pclass
->location
, attr
->values
[0].string
.text
);
952 if ((attr
= ippFindAttribute(con
->request
, "printer-geo-location", IPP_TAG_URI
)) != NULL
&& !strncmp(attr
->values
[0].string
.text
, "geo:", 4))
953 cupsdSetString(&pclass
->geo_location
, attr
->values
[0].string
.text
);
955 if ((attr
= ippFindAttribute(con
->request
, "printer-organization", IPP_TAG_TEXT
)) != NULL
)
956 cupsdSetString(&pclass
->organization
, attr
->values
[0].string
.text
);
958 if ((attr
= ippFindAttribute(con
->request
, "printer-organizational-unit", IPP_TAG_TEXT
)) != NULL
)
959 cupsdSetString(&pclass
->organizational_unit
, attr
->values
[0].string
.text
);
961 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
962 IPP_TAG_TEXT
)) != NULL
)
963 cupsdSetString(&pclass
->info
, attr
->values
[0].string
.text
);
965 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
966 IPP_TAG_BOOLEAN
)) != NULL
&&
967 attr
->values
[0].boolean
!= pclass
->accepting
)
969 cupsdLogMessage(CUPSD_LOG_INFO
,
970 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
971 pclass
->name
, attr
->values
[0].boolean
, pclass
->accepting
);
973 pclass
->accepting
= attr
->values
[0].boolean
;
975 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s accepting jobs.",
976 pclass
->accepting
? "Now" : "No longer");
979 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
980 IPP_TAG_BOOLEAN
)) != NULL
)
982 if (pclass
->shared
&& !attr
->values
[0].boolean
)
983 cupsdDeregisterPrinter(pclass
, 1);
985 cupsdLogMessage(CUPSD_LOG_INFO
,
986 "Setting %s printer-is-shared to %d (was %d.)",
987 pclass
->name
, attr
->values
[0].boolean
, pclass
->shared
);
989 pclass
->shared
= attr
->values
[0].boolean
;
992 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
993 IPP_TAG_ENUM
)) != NULL
)
995 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
996 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
998 send_ipp_status(con
, IPP_BAD_REQUEST
,
999 _("Attempt to set %s printer-state to bad value %d."),
1000 pclass
->name
, attr
->values
[0].integer
);
1004 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
1005 pclass
->name
, attr
->values
[0].integer
, pclass
->state
);
1007 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
1008 cupsdStopPrinter(pclass
, 0);
1011 cupsdSetPrinterState(pclass
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
1012 need_restart_job
= 1;
1015 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
1016 IPP_TAG_TEXT
)) != NULL
)
1018 strlcpy(pclass
->state_message
, attr
->values
[0].string
.text
,
1019 sizeof(pclass
->state_message
));
1021 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s",
1022 pclass
->state_message
);
1024 if ((attr
= ippFindAttribute(con
->request
, "member-uris",
1025 IPP_TAG_URI
)) != NULL
)
1028 * Clear the printer array as needed...
1031 need_restart_job
= 1;
1033 if (pclass
->num_printers
> 0)
1035 free(pclass
->printers
);
1036 pclass
->num_printers
= 0;
1040 * Add each printer or class that is listed...
1043 for (i
= 0; i
< attr
->num_values
; i
++)
1046 * Search for the printer or class URI...
1049 if (!cupsdValidateDest(attr
->values
[i
].string
.text
, &dtype
, &member
))
1055 send_ipp_status(con
, IPP_NOT_FOUND
,
1056 _("The printer or class does not exist."));
1059 else if (dtype
& CUPS_PRINTER_CLASS
)
1061 send_ipp_status(con
, IPP_BAD_REQUEST
,
1062 _("Nested classes are not allowed."));
1067 * Add it to the class...
1070 cupsdAddPrinterToClass(pclass
, member
);
1074 set_printer_defaults(con
, pclass
);
1076 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
1077 IPP_TAG_KEYWORD
)) != NULL
)
1078 cupsdSetAuthInfoRequired(pclass
, NULL
, attr
);
1080 pclass
->config_time
= time(NULL
);
1083 * Update the printer class attributes and return...
1086 cupsdSetPrinterAttrs(pclass
);
1087 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
1089 if (need_restart_job
&& pclass
->job
)
1092 * Reset the current job to a "pending" status...
1095 cupsdSetJobState(pclass
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
1096 "Job restarted because the class was modified.");
1099 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1103 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
1104 pclass
, NULL
, "Class \"%s\" modified by \"%s\".",
1105 pclass
->name
, get_username(con
));
1107 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" modified by \"%s\".",
1108 pclass
->name
, get_username(con
));
1112 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
1113 pclass
, NULL
, "New class \"%s\" added by \"%s\".",
1114 pclass
->name
, get_username(con
));
1116 cupsdLogMessage(CUPSD_LOG_INFO
, "New class \"%s\" added by \"%s\".",
1117 pclass
->name
, get_username(con
));
1120 con
->response
->request
.status
.status_code
= IPP_OK
;
1125 * 'add_file()' - Add a file to a job.
1128 static int /* O - 0 on success, -1 on error */
1129 add_file(cupsd_client_t
*con
, /* I - Connection to client */
1130 cupsd_job_t
*job
, /* I - Job to add to */
1131 mime_type_t
*filetype
, /* I - Type of file */
1132 int compression
) /* I - Compression */
1134 mime_type_t
**filetypes
; /* New filetypes array... */
1135 int *compressions
; /* New compressions array... */
1138 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1139 "add_file(con=%p[%d], job=%d, filetype=%s/%s, "
1140 "compression=%d)", con
, con
? con
->number
: -1, job
->id
,
1141 filetype
->super
, filetype
->type
, compression
);
1144 * Add the file to the job...
1147 if (job
->num_files
== 0)
1149 compressions
= (int *)malloc(sizeof(int));
1150 filetypes
= (mime_type_t
**)malloc(sizeof(mime_type_t
*));
1154 compressions
= (int *)realloc(job
->compressions
,
1155 (size_t)(job
->num_files
+ 1) * sizeof(int));
1156 filetypes
= (mime_type_t
**)realloc(job
->filetypes
,
1157 (size_t)(job
->num_files
+ 1) *
1158 sizeof(mime_type_t
*));
1162 job
->compressions
= compressions
;
1165 job
->filetypes
= filetypes
;
1167 if (!compressions
|| !filetypes
)
1169 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1170 "Job aborted because the scheduler ran out of memory.");
1173 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1174 _("Unable to allocate memory for file types."));
1179 job
->compressions
[job
->num_files
] = compression
;
1180 job
->filetypes
[job
->num_files
] = filetype
;
1185 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1192 * 'add_job()' - Add a job to a print queue.
1195 static cupsd_job_t
* /* O - Job object */
1196 add_job(cupsd_client_t
*con
, /* I - Client connection */
1197 cupsd_printer_t
*printer
, /* I - Destination printer */
1198 mime_type_t
*filetype
) /* I - First print file type, if any */
1200 http_status_t status
; /* Policy status */
1201 ipp_attribute_t
*attr
, /* Current attribute */
1202 *auth_info
; /* auth-info attribute */
1203 const char *mandatory
; /* Current mandatory job attribute */
1204 const char *val
; /* Default option value */
1205 int priority
; /* Job priority */
1206 cupsd_job_t
*job
; /* Current job */
1207 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
1208 int kbytes
; /* Size of print file */
1209 int i
; /* Looping var */
1210 int lowerpagerange
; /* Page range bound */
1211 int exact
; /* Did we have an exact match? */
1212 ipp_attribute_t
*media_col
, /* media-col attribute */
1213 *media_margin
; /* media-*-margin attribute */
1214 ipp_t
*unsup_col
; /* media-col in unsupported response */
1215 static const char * const readonly
[] =/* List of read-only attributes */
1217 "date-time-at-completed",
1218 "date-time-at-creation",
1219 "date-time-at-processing",
1220 "job-detailed-status-messages",
1221 "job-document-access-errors",
1223 "job-impressions-completed",
1224 "job-k-octets-completed",
1225 "job-media-sheets-completed",
1226 "job-pages-completed",
1227 "job-printer-up-time",
1230 "job-state-message",
1231 "job-state-reasons",
1233 "number-of-documents",
1234 "number-of-intervening-jobs",
1235 "output-device-assigned",
1236 "time-at-completed",
1238 "time-at-processing"
1242 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job(%p[%d], %p(%s), %p(%s/%s))",
1243 con
, con
->number
, printer
, printer
->name
,
1244 filetype
, filetype
? filetype
->super
: "none",
1245 filetype
? filetype
->type
: "none");
1248 * Check remote printing to non-shared printer...
1251 if (!printer
->shared
&&
1252 _cups_strcasecmp(con
->http
->hostname
, "localhost") &&
1253 _cups_strcasecmp(con
->http
->hostname
, ServerName
))
1255 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
1256 _("The printer or class is not shared."));
1264 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
1266 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
1268 send_http_error(con
, status
, printer
);
1271 else if (printer
->num_auth_info_required
== 1 &&
1272 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
1275 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
1279 else if (auth_info
&& !con
->http
->tls
&&
1280 !httpAddrLocalhost(con
->http
->hostaddr
))
1283 * Require encryption of auth-info over non-local connections...
1286 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
1289 #endif /* HAVE_SSL */
1292 * See if the printer is accepting jobs...
1295 if (!printer
->accepting
)
1297 send_ipp_status(con
, IPP_NOT_ACCEPTING
,
1298 _("Destination \"%s\" is not accepting jobs."),
1304 * Validate job template attributes; for now just document-format,
1305 * copies, job-sheets, number-up, page-ranges, mandatory attributes, and
1309 for (i
= 0; i
< (int)(sizeof(readonly
) / sizeof(readonly
[0])); i
++)
1311 if ((attr
= ippFindAttribute(con
->request
, readonly
[i
], IPP_TAG_ZERO
)) != NULL
)
1313 ippDeleteAttribute(con
->request
, attr
);
1315 if (StrictConformance
)
1317 send_ipp_status(con
, IPP_BAD_REQUEST
, _("The '%s' Job Status attribute cannot be supplied in a job creation request."), readonly
[i
]);
1321 cupsdLogMessage(CUPSD_LOG_INFO
, "Unexpected '%s' Job Status attribute in a job creation request.", readonly
[i
]);
1327 for (mandatory
= (char *)cupsArrayFirst(printer
->pc
->mandatory
);
1329 mandatory
= (char *)cupsArrayNext(printer
->pc
->mandatory
))
1331 if (!ippFindAttribute(con
->request
, mandatory
, IPP_TAG_ZERO
))
1334 * Missing a required attribute...
1337 send_ipp_status(con
, IPP_CONFLICT
,
1338 _("The \"%s\" attribute is required for print jobs."),
1345 if (filetype
&& printer
->filetypes
&&
1346 !cupsArrayFind(printer
->filetypes
, filetype
))
1348 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
1349 /* MIME media type string */
1352 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
1355 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
1356 _("Unsupported format \"%s\"."), mimetype
);
1358 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
1359 "document-format", NULL
, mimetype
);
1364 if ((attr
= ippFindAttribute(con
->request
, "copies",
1365 IPP_TAG_INTEGER
)) != NULL
)
1367 if (attr
->values
[0].integer
< 1 || attr
->values
[0].integer
> MaxCopies
)
1369 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad copies value %d."),
1370 attr
->values
[0].integer
);
1371 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1372 "copies", attr
->values
[0].integer
);
1377 if ((attr
= ippFindAttribute(con
->request
, "job-sheets",
1378 IPP_TAG_ZERO
)) != NULL
)
1380 if (attr
->value_tag
!= IPP_TAG_KEYWORD
&&
1381 attr
->value_tag
!= IPP_TAG_NAME
)
1383 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value type."));
1387 if (attr
->num_values
> 2)
1389 send_ipp_status(con
, IPP_BAD_REQUEST
,
1390 _("Too many job-sheets values (%d > 2)."),
1395 for (i
= 0; i
< attr
->num_values
; i
++)
1396 if (strcmp(attr
->values
[i
].string
.text
, "none") &&
1397 !cupsdFindBanner(attr
->values
[i
].string
.text
))
1399 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value \"%s\"."),
1400 attr
->values
[i
].string
.text
);
1405 if ((attr
= ippFindAttribute(con
->request
, "number-up",
1406 IPP_TAG_INTEGER
)) != NULL
)
1408 if (attr
->values
[0].integer
!= 1 &&
1409 attr
->values
[0].integer
!= 2 &&
1410 attr
->values
[0].integer
!= 4 &&
1411 attr
->values
[0].integer
!= 6 &&
1412 attr
->values
[0].integer
!= 9 &&
1413 attr
->values
[0].integer
!= 16)
1415 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad number-up value %d."),
1416 attr
->values
[0].integer
);
1417 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1418 "number-up", attr
->values
[0].integer
);
1423 if ((attr
= ippFindAttribute(con
->request
, "page-ranges",
1424 IPP_TAG_RANGE
)) != NULL
)
1426 for (i
= 0, lowerpagerange
= 1; i
< attr
->num_values
; i
++)
1428 if (attr
->values
[i
].range
.lower
< lowerpagerange
||
1429 attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
1431 send_ipp_status(con
, IPP_BAD_REQUEST
,
1432 _("Bad page-ranges values %d-%d."),
1433 attr
->values
[i
].range
.lower
,
1434 attr
->values
[i
].range
.upper
);
1438 lowerpagerange
= attr
->values
[i
].range
.upper
+ 1;
1443 * Do media selection as needed...
1446 if (!ippFindAttribute(con
->request
, "PageRegion", IPP_TAG_ZERO
) &&
1447 !ippFindAttribute(con
->request
, "PageSize", IPP_TAG_ZERO
) &&
1448 _ppdCacheGetPageSize(printer
->pc
, con
->request
, NULL
, &exact
))
1451 (media_col
= ippFindAttribute(con
->request
, "media-col",
1452 IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
1454 send_ipp_status(con
, IPP_OK_SUBST
, _("Unsupported margins."));
1456 unsup_col
= ippNew();
1457 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1458 "media-bottom-margin",
1459 IPP_TAG_INTEGER
)) != NULL
)
1460 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1461 "media-bottom-margin", media_margin
->values
[0].integer
);
1463 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1464 "media-left-margin",
1465 IPP_TAG_INTEGER
)) != NULL
)
1466 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1467 "media-left-margin", media_margin
->values
[0].integer
);
1469 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1470 "media-right-margin",
1471 IPP_TAG_INTEGER
)) != NULL
)
1472 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1473 "media-right-margin", media_margin
->values
[0].integer
);
1475 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1477 IPP_TAG_INTEGER
)) != NULL
)
1478 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1479 "media-top-margin", media_margin
->values
[0].integer
);
1481 ippAddCollection(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, "media-col",
1483 ippDelete(unsup_col
);
1488 * Make sure we aren't over our limit...
1491 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1494 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1496 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Too many active jobs."));
1500 if ((i
= check_quotas(con
, printer
)) < 0)
1502 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
1507 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
1512 * Create the job and set things up...
1515 if ((attr
= ippFindAttribute(con
->request
, "job-priority",
1516 IPP_TAG_INTEGER
)) != NULL
)
1517 priority
= attr
->values
[0].integer
;
1520 if ((val
= cupsGetOption("job-priority", printer
->num_options
,
1521 printer
->options
)) != NULL
)
1522 priority
= atoi(val
);
1526 ippAddInteger(con
->request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-priority",
1530 if ((attr
= ippFindAttribute(con
->request
, "job-name", IPP_TAG_ZERO
)) == NULL
)
1531 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
, "Untitled");
1532 else if ((attr
->value_tag
!= IPP_TAG_NAME
&&
1533 attr
->value_tag
!= IPP_TAG_NAMELANG
) ||
1534 attr
->num_values
!= 1)
1536 send_ipp_status(con
, IPP_ATTRIBUTES
,
1537 _("Bad job-name value: Wrong type or count."));
1538 if ((attr
= ippCopyAttribute(con
->response
, attr
, 0)) != NULL
)
1539 attr
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
1542 else if (!ippValidateAttribute(attr
))
1544 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad job-name value: %s"),
1545 cupsLastErrorString());
1546 if ((attr
= ippCopyAttribute(con
->response
, attr
, 0)) != NULL
)
1547 attr
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
1551 if ((job
= cupsdAddJob(priority
, printer
->name
)) == NULL
)
1553 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1554 _("Unable to add job for destination \"%s\"."),
1559 job
->dtype
= printer
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
1560 job
->attrs
= con
->request
;
1562 con
->request
= ippNewRequest(job
->attrs
->request
.op
.operation_id
);
1564 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1567 apply_printer_defaults(printer
, job
);
1569 attr
= ippFindAttribute(job
->attrs
, "requesting-user-name", IPP_TAG_NAME
);
1571 if (con
->username
[0])
1573 cupsdSetString(&job
->username
, con
->username
);
1576 cupsdSetString(&attr
->values
[0].string
.text
, con
->username
);
1580 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1581 "add_job: requesting-user-name=\"%s\"",
1582 attr
->values
[0].string
.text
);
1584 cupsdSetString(&job
->username
, attr
->values
[0].string
.text
);
1587 cupsdSetString(&job
->username
, "anonymous");
1590 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1591 "job-originating-user-name", NULL
, job
->username
);
1594 attr
->group_tag
= IPP_TAG_JOB
;
1595 _cupsStrFree(attr
->name
);
1596 attr
->name
= _cupsStrAlloc("job-originating-user-name");
1599 if (con
->username
[0] || auth_info
)
1601 save_auth_info(con
, job
, auth_info
);
1604 * Remove the auth-info attribute from the attribute data...
1608 ippDeleteAttribute(job
->attrs
, auth_info
);
1611 if ((attr
= ippFindAttribute(con
->request
, "job-name", IPP_TAG_NAME
)) != NULL
)
1612 cupsdSetString(&(job
->name
), attr
->values
[0].string
.text
);
1614 if ((attr
= ippFindAttribute(job
->attrs
, "job-originating-host-name",
1615 IPP_TAG_ZERO
)) != NULL
)
1618 * Request contains a job-originating-host-name attribute; validate it...
1621 if (attr
->value_tag
!= IPP_TAG_NAME
||
1622 attr
->num_values
!= 1 ||
1623 strcmp(con
->http
->hostname
, "localhost"))
1626 * Can't override the value if we aren't connected via localhost.
1627 * Also, we can only have 1 value and it must be a name value.
1630 switch (attr
->value_tag
)
1632 case IPP_TAG_STRING
:
1633 case IPP_TAG_TEXTLANG
:
1634 case IPP_TAG_NAMELANG
:
1637 case IPP_TAG_KEYWORD
:
1639 case IPP_TAG_URISCHEME
:
1640 case IPP_TAG_CHARSET
:
1641 case IPP_TAG_LANGUAGE
:
1642 case IPP_TAG_MIMETYPE
:
1644 * Free old strings...
1647 for (i
= 0; i
< attr
->num_values
; i
++)
1649 _cupsStrFree(attr
->values
[i
].string
.text
);
1650 attr
->values
[i
].string
.text
= NULL
;
1651 if (attr
->values
[i
].string
.language
)
1653 _cupsStrFree(attr
->values
[i
].string
.language
);
1654 attr
->values
[i
].string
.language
= NULL
;
1663 * Use the default connection hostname instead...
1666 attr
->value_tag
= IPP_TAG_NAME
;
1667 attr
->num_values
= 1;
1668 attr
->values
[0].string
.text
= _cupsStrAlloc(con
->http
->hostname
);
1671 attr
->group_tag
= IPP_TAG_JOB
;
1676 * No job-originating-host-name attribute, so use the hostname from
1680 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1681 "job-originating-host-name", NULL
, con
->http
->hostname
);
1684 ippAddOutOfBand(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NOVALUE
, "date-time-at-completed");
1685 ippAddDate(job
->attrs
, IPP_TAG_JOB
, "date-time-at-creation", ippTimeToDate(time(NULL
)));
1686 ippAddOutOfBand(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NOVALUE
, "date-time-at-processing");
1687 ippAddOutOfBand(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NOVALUE
, "time-at-completed");
1688 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation", time(NULL
));
1689 ippAddOutOfBand(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NOVALUE
, "time-at-processing");
1692 * Add remaining job attributes...
1695 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1696 job
->state
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_ENUM
,
1697 "job-state", IPP_JOB_STOPPED
);
1698 job
->state_value
= (ipp_jstate_t
)job
->state
->values
[0].integer
;
1699 job
->reasons
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1700 "job-state-reasons", NULL
, "job-incoming");
1701 job
->impressions
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-impressions-completed", 0);
1702 job
->sheets
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1703 "job-media-sheets-completed", 0);
1704 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-printer-uri", NULL
,
1707 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets", IPP_TAG_INTEGER
)) != NULL
)
1708 attr
->values
[0].integer
= 0;
1710 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-k-octets", 0);
1712 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
1713 IPP_TAG_KEYWORD
)) == NULL
)
1714 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
1717 if ((val
= cupsGetOption("job-hold-until", printer
->num_options
,
1718 printer
->options
)) == NULL
)
1721 attr
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1722 "job-hold-until", NULL
, val
);
1724 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
1727 * Hold job until specified time...
1730 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
1732 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1733 job
->state_value
= IPP_JOB_HELD
;
1735 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-hold-until-specified");
1737 else if (job
->attrs
->request
.op
.operation_id
== IPP_CREATE_JOB
)
1739 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
1740 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1741 job
->state_value
= IPP_JOB_HELD
;
1745 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1746 job
->state_value
= IPP_JOB_PENDING
;
1748 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
1751 if (!(printer
->type
& CUPS_PRINTER_REMOTE
) || Classification
)
1754 * Add job sheets options...
1757 if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1758 IPP_TAG_ZERO
)) == NULL
)
1760 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1761 "Adding default job-sheets values \"%s,%s\"...",
1762 printer
->job_sheets
[0], printer
->job_sheets
[1]);
1764 attr
= ippAddStrings(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-sheets",
1766 attr
->values
[0].string
.text
= _cupsStrRetain(printer
->job_sheets
[0]);
1767 attr
->values
[1].string
.text
= _cupsStrRetain(printer
->job_sheets
[1]);
1770 job
->job_sheets
= attr
;
1773 * Enforce classification level if set...
1778 cupsdLogMessage(CUPSD_LOG_INFO
,
1779 "Classification=\"%s\", ClassifyOverride=%d",
1780 Classification
? Classification
: "(null)",
1783 if (ClassifyOverride
)
1785 if (!strcmp(attr
->values
[0].string
.text
, "none") &&
1786 (attr
->num_values
== 1 ||
1787 !strcmp(attr
->values
[1].string
.text
, "none")))
1790 * Force the leading banner to have the classification on it...
1793 cupsdSetString(&attr
->values
[0].string
.text
, Classification
);
1795 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1796 "job-sheets=\"%s,none\", "
1797 "job-originating-user-name=\"%s\"",
1798 Classification
, job
->username
);
1800 else if (attr
->num_values
== 2 &&
1801 strcmp(attr
->values
[0].string
.text
,
1802 attr
->values
[1].string
.text
) &&
1803 strcmp(attr
->values
[0].string
.text
, "none") &&
1804 strcmp(attr
->values
[1].string
.text
, "none"))
1807 * Can't put two different security markings on the same document!
1810 cupsdSetString(&attr
->values
[1].string
.text
, attr
->values
[0].string
.text
);
1812 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1813 "job-sheets=\"%s,%s\", "
1814 "job-originating-user-name=\"%s\"",
1815 attr
->values
[0].string
.text
,
1816 attr
->values
[1].string
.text
, job
->username
);
1818 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1819 strcmp(attr
->values
[0].string
.text
, "none") &&
1820 (attr
->num_values
== 1 ||
1821 (strcmp(attr
->values
[1].string
.text
, Classification
) &&
1822 strcmp(attr
->values
[1].string
.text
, "none"))))
1824 if (attr
->num_values
== 1)
1825 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1826 "CLASSIFICATION OVERRIDDEN "
1827 "job-sheets=\"%s\", "
1828 "job-originating-user-name=\"%s\"",
1829 attr
->values
[0].string
.text
, job
->username
);
1831 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1832 "CLASSIFICATION OVERRIDDEN "
1833 "job-sheets=\"%s,%s\",fffff "
1834 "job-originating-user-name=\"%s\"",
1835 attr
->values
[0].string
.text
,
1836 attr
->values
[1].string
.text
, job
->username
);
1839 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1840 (attr
->num_values
== 1 ||
1841 strcmp(attr
->values
[1].string
.text
, Classification
)))
1844 * Force the banner to have the classification on it...
1847 if (attr
->num_values
> 1 &&
1848 !strcmp(attr
->values
[0].string
.text
, attr
->values
[1].string
.text
))
1850 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1851 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1855 if (attr
->num_values
== 1 ||
1856 strcmp(attr
->values
[0].string
.text
, "none"))
1857 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1859 if (attr
->num_values
> 1 &&
1860 strcmp(attr
->values
[1].string
.text
, "none"))
1861 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1864 if (attr
->num_values
> 1)
1865 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1866 "CLASSIFICATION FORCED "
1867 "job-sheets=\"%s,%s\", "
1868 "job-originating-user-name=\"%s\"",
1869 attr
->values
[0].string
.text
,
1870 attr
->values
[1].string
.text
, job
->username
);
1872 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1873 "CLASSIFICATION FORCED "
1874 "job-sheets=\"%s\", "
1875 "job-originating-user-name=\"%s\"",
1876 Classification
, job
->username
);
1881 * See if we need to add the starting sheet...
1884 if (!(printer
->type
& CUPS_PRINTER_REMOTE
))
1886 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding start banner page \"%s\".",
1887 attr
->values
[0].string
.text
);
1889 if ((kbytes
= copy_banner(con
, job
, attr
->values
[0].string
.text
)) < 0)
1891 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1892 "Aborting job because the start banner could not be "
1897 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
1900 else if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1901 IPP_TAG_ZERO
)) != NULL
)
1902 job
->job_sheets
= attr
;
1905 * Fill in the response info...
1908 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
1909 con
->clientname
, con
->clientport
, "/jobs/%d", job
->id
);
1910 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
1913 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1915 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
1917 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_TEXT
, "job-state-message", NULL
, "");
1918 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons",
1919 NULL
, job
->reasons
->values
[0].string
.text
);
1921 con
->response
->request
.status
.status_code
= IPP_OK
;
1924 * Add any job subscriptions...
1927 add_job_subscriptions(con
, job
);
1930 * Set all but the first two attributes to the job attributes group...
1933 for (attr
= job
->attrs
->attrs
->next
->next
; attr
; attr
= attr
->next
)
1934 attr
->group_tag
= IPP_TAG_JOB
;
1937 * Fire the "job created" event...
1940 cupsdAddEvent(CUPSD_EVENT_JOB_CREATED
, printer
, job
, "Job created.");
1943 * Return the new job...
1951 * 'add_job_subscriptions()' - Add any subscriptions for a job.
1955 add_job_subscriptions(
1956 cupsd_client_t
*con
, /* I - Client connection */
1957 cupsd_job_t
*job
) /* I - Newly created job */
1959 int i
; /* Looping var */
1960 ipp_attribute_t
*prev
, /* Previous attribute */
1961 *next
, /* Next attribute */
1962 *attr
; /* Current attribute */
1963 cupsd_subscription_t
*sub
; /* Subscription object */
1964 const char *recipient
, /* notify-recipient-uri */
1965 *pullmethod
; /* notify-pull-method */
1966 ipp_attribute_t
*user_data
; /* notify-user-data */
1967 int interval
; /* notify-time-interval */
1968 unsigned mask
; /* notify-events */
1972 * Find the first subscription group attribute; return if we have
1976 for (attr
= job
->attrs
->attrs
; attr
; attr
= attr
->next
)
1977 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
1984 * Process the subscription attributes in the request...
1993 mask
= CUPSD_EVENT_NONE
;
1995 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
1997 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
1998 attr
->value_tag
== IPP_TAG_URI
)
2001 * Validate the recipient scheme against the ServerBin/notifier
2005 char notifier
[1024], /* Notifier filename */
2006 scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
2007 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
2008 host
[HTTP_MAX_URI
], /* Host portion of URI */
2009 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2010 int port
; /* Port portion of URI */
2013 recipient
= attr
->values
[0].string
.text
;
2015 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
2016 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
2017 host
, sizeof(host
), &port
,
2018 resource
, sizeof(resource
)) < HTTP_URI_OK
)
2020 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2021 _("Bad notify-recipient-uri \"%s\"."), recipient
);
2022 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2023 "notify-status-code", IPP_URI_SCHEME
);
2027 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
2029 if (access(notifier
, X_OK
))
2031 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2032 _("notify-recipient-uri URI \"%s\" uses unknown "
2033 "scheme."), recipient
);
2034 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2035 "notify-status-code", IPP_URI_SCHEME
);
2039 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
2041 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2042 _("notify-recipient-uri URI \"%s\" is already used."),
2044 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2045 "notify-status-code", IPP_ATTRIBUTES
);
2049 else if (!strcmp(attr
->name
, "notify-pull-method") &&
2050 attr
->value_tag
== IPP_TAG_KEYWORD
)
2052 pullmethod
= attr
->values
[0].string
.text
;
2054 if (strcmp(pullmethod
, "ippget"))
2056 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2057 _("Bad notify-pull-method \"%s\"."), pullmethod
);
2058 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2059 "notify-status-code", IPP_ATTRIBUTES
);
2063 else if (!strcmp(attr
->name
, "notify-charset") &&
2064 attr
->value_tag
== IPP_TAG_CHARSET
&&
2065 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
2066 strcmp(attr
->values
[0].string
.text
, "utf-8"))
2068 send_ipp_status(con
, IPP_CHARSET
,
2069 _("Character set \"%s\" not supported."),
2070 attr
->values
[0].string
.text
);
2073 else if (!strcmp(attr
->name
, "notify-natural-language") &&
2074 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
2075 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
2077 send_ipp_status(con
, IPP_CHARSET
,
2078 _("Language \"%s\" not supported."),
2079 attr
->values
[0].string
.text
);
2082 else if (!strcmp(attr
->name
, "notify-user-data") &&
2083 attr
->value_tag
== IPP_TAG_STRING
)
2085 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
2087 send_ipp_status(con
, IPP_REQUEST_VALUE
,
2088 _("The notify-user-data value is too large "
2089 "(%d > 63 octets)."),
2090 attr
->values
[0].unknown
.length
);
2096 else if (!strcmp(attr
->name
, "notify-events") &&
2097 attr
->value_tag
== IPP_TAG_KEYWORD
)
2099 for (i
= 0; i
< attr
->num_values
; i
++)
2100 mask
|= cupsdEventValue(attr
->values
[i
].string
.text
);
2102 else if (!strcmp(attr
->name
, "notify-lease-duration"))
2104 send_ipp_status(con
, IPP_BAD_REQUEST
,
2105 _("The notify-lease-duration attribute cannot be "
2106 "used with job subscriptions."));
2109 else if (!strcmp(attr
->name
, "notify-time-interval") &&
2110 attr
->value_tag
== IPP_TAG_INTEGER
)
2111 interval
= attr
->values
[0].integer
;
2116 if (!recipient
&& !pullmethod
)
2119 if (mask
== CUPSD_EVENT_NONE
)
2120 mask
= CUPSD_EVENT_JOB_COMPLETED
;
2122 if ((sub
= cupsdAddSubscription(mask
, cupsdFindDest(job
->dest
), job
,
2123 recipient
, 0)) != NULL
)
2125 sub
->interval
= interval
;
2127 cupsdSetString(&sub
->owner
, job
->username
);
2131 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
2132 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
2133 (size_t)sub
->user_data_len
);
2136 ippAddSeparator(con
->response
);
2137 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
2138 "notify-subscription-id", sub
->id
);
2140 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
2148 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
2151 * Remove all of the subscription attributes from the job request...
2153 * TODO: Optimize this since subscription groups have to come at the
2154 * end of the request...
2157 for (attr
= job
->attrs
->attrs
, prev
= NULL
; attr
; attr
= next
)
2161 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
||
2162 attr
->group_tag
== IPP_TAG_ZERO
)
2165 * Free and remove this attribute...
2168 ippDeleteAttribute(NULL
, attr
);
2173 job
->attrs
->attrs
= next
;
2179 job
->attrs
->last
= prev
;
2180 job
->attrs
->current
= prev
;
2185 * 'add_job_uuid()' - Add job-uuid attribute to a job.
2187 * See RFC 4122 for the definition of UUIDs and the format.
2191 add_job_uuid(cupsd_job_t
*job
) /* I - Job */
2193 char uuid
[64]; /* job-uuid string */
2197 * Add a job-uuid attribute if none exists...
2200 if (!ippFindAttribute(job
->attrs
, "job-uuid", IPP_TAG_URI
))
2201 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uuid", NULL
,
2202 httpAssembleUUID(ServerName
, RemotePort
, job
->dest
, job
->id
,
2203 uuid
, sizeof(uuid
)));
2208 * 'add_printer()' - Add a printer to the system.
2212 add_printer(cupsd_client_t
*con
, /* I - Client connection */
2213 ipp_attribute_t
*uri
) /* I - URI of printer */
2215 http_status_t status
; /* Policy status */
2216 int i
; /* Looping var */
2217 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
2218 username
[HTTP_MAX_URI
], /* Username portion of URI */
2219 host
[HTTP_MAX_URI
], /* Host portion of URI */
2220 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2221 int port
; /* Port portion of URI */
2222 cupsd_printer_t
*printer
; /* Printer/class */
2223 ipp_attribute_t
*attr
; /* Printer attribute */
2224 cups_file_t
*fp
; /* Script/PPD file */
2225 char line
[1024]; /* Line from file... */
2226 char srcfile
[1024], /* Source Script/PPD file */
2227 dstfile
[1024]; /* Destination Script/PPD file */
2228 int modify
; /* Non-zero if we are modifying */
2229 int changed_driver
, /* Changed the PPD/interface script? */
2230 need_restart_job
, /* Need to restart job? */
2231 set_device_uri
, /* Did we set the device URI? */
2232 set_port_monitor
; /* Did we set the port monitor? */
2235 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer(%p[%d], %s)", con
,
2236 con
->number
, uri
->values
[0].string
.text
);
2239 * Do we have a valid URI?
2242 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
2243 sizeof(scheme
), username
, sizeof(username
), host
,
2244 sizeof(host
), &port
, resource
, sizeof(resource
));
2246 if (strncmp(resource
, "/printers/", 10) || strlen(resource
) == 10)
2249 * No, return an error...
2252 send_ipp_status(con
, IPP_BAD_REQUEST
,
2253 _("The printer-uri must be of the form "
2254 "\"ipp://HOSTNAME/printers/PRINTERNAME\"."));
2259 * Do we have a valid printer name?
2262 if (!validate_name(resource
+ 10))
2265 * No, return an error...
2268 send_ipp_status(con
, IPP_BAD_REQUEST
,
2269 _("The printer-uri \"%s\" contains invalid characters."),
2270 uri
->values
[0].string
.text
);
2275 * See if the printer already exists; if not, create a new printer...
2278 if ((printer
= cupsdFindPrinter(resource
+ 10)) == NULL
)
2281 * Printer doesn't exist; see if we have a class of the same name...
2284 if ((printer
= cupsdFindClass(resource
+ 10)) != NULL
)
2287 * Yes, return an error...
2290 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2291 _("A class named \"%s\" already exists."),
2297 * No, check the default policy then add the printer...
2300 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2302 send_http_error(con
, status
, NULL
);
2306 printer
= cupsdAddPrinter(resource
+ 10);
2309 else if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
2312 send_http_error(con
, status
, printer
);
2319 * Look for attributes and copy them over as needed...
2323 need_restart_job
= 0;
2325 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
2326 IPP_TAG_TEXT
)) != NULL
)
2327 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
2329 if ((attr
= ippFindAttribute(con
->request
, "printer-geo-location", IPP_TAG_URI
)) != NULL
&& !strncmp(attr
->values
[0].string
.text
, "geo:", 4))
2330 cupsdSetString(&printer
->geo_location
, attr
->values
[0].string
.text
);
2332 if ((attr
= ippFindAttribute(con
->request
, "printer-organization", IPP_TAG_TEXT
)) != NULL
)
2333 cupsdSetString(&printer
->organization
, attr
->values
[0].string
.text
);
2335 if ((attr
= ippFindAttribute(con
->request
, "printer-organizational-unit", IPP_TAG_TEXT
)) != NULL
)
2336 cupsdSetString(&printer
->organizational_unit
, attr
->values
[0].string
.text
);
2338 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
2339 IPP_TAG_TEXT
)) != NULL
)
2340 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
2344 if ((attr
= ippFindAttribute(con
->request
, "device-uri",
2345 IPP_TAG_URI
)) != NULL
)
2348 * Do we have a valid device URI?
2351 http_uri_status_t uri_status
; /* URI separation status */
2352 char old_device_uri
[1024];
2353 /* Old device URI */
2354 static const char * const uri_status_strings
[] =
2357 "Bad arguments to function.",
2358 "Bad resource path.",
2360 "Bad hostname/address.",
2361 "Bad username/password.",
2365 "Missing URI scheme.",
2366 "Unknown URI scheme",
2367 "Missing resource path."
2371 need_restart_job
= 1;
2373 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
,
2374 attr
->values
[0].string
.text
,
2375 scheme
, sizeof(scheme
),
2376 username
, sizeof(username
),
2377 host
, sizeof(host
), &port
,
2378 resource
, sizeof(resource
));
2380 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2381 "%s device-uri: %s", printer
->name
,
2382 uri_status_strings
[uri_status
- HTTP_URI_STATUS_OVERFLOW
]);
2384 if (uri_status
< HTTP_URI_OK
)
2386 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri \"%s\"."),
2387 attr
->values
[0].string
.text
);
2391 if (!strcmp(scheme
, "file"))
2394 * See if the administrator has enabled file devices...
2397 if (!FileDevice
&& strcmp(resource
, "/dev/null"))
2400 * File devices are disabled and the URL is not file:/dev/null...
2403 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2404 _("File device URIs have been disabled. "
2405 "To enable, see the FileDevice directive in "
2406 "\"%s/cups-files.conf\"."),
2414 * See if the backend exists and is executable...
2417 snprintf(srcfile
, sizeof(srcfile
), "%s/backend/%s", ServerBin
, scheme
);
2418 if (access(srcfile
, X_OK
))
2421 * Could not find device in list!
2424 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2425 _("Bad device-uri scheme \"%s\"."), scheme
);
2430 if (printer
->sanitized_device_uri
)
2431 strlcpy(old_device_uri
, printer
->sanitized_device_uri
,
2432 sizeof(old_device_uri
));
2434 old_device_uri
[0] = '\0';
2436 cupsdSetDeviceURI(printer
, attr
->values
[0].string
.text
);
2438 cupsdLogMessage(CUPSD_LOG_INFO
,
2439 "Setting %s device-uri to \"%s\" (was \"%s\".)",
2440 printer
->name
, printer
->sanitized_device_uri
,
2446 set_port_monitor
= 0;
2448 if ((attr
= ippFindAttribute(con
->request
, "port-monitor",
2449 IPP_TAG_NAME
)) != NULL
)
2451 ipp_attribute_t
*supported
; /* port-monitor-supported attribute */
2454 need_restart_job
= 1;
2456 supported
= ippFindAttribute(printer
->ppd_attrs
, "port-monitor-supported",
2460 for (i
= 0; i
< supported
->num_values
; i
++)
2461 if (!strcmp(supported
->values
[i
].string
.text
,
2462 attr
->values
[0].string
.text
))
2466 if (!supported
|| i
>= supported
->num_values
)
2468 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad port-monitor \"%s\"."),
2469 attr
->values
[0].string
.text
);
2473 cupsdLogMessage(CUPSD_LOG_INFO
,
2474 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2475 printer
->name
, attr
->values
[0].string
.text
,
2476 printer
->port_monitor
? printer
->port_monitor
: "none");
2478 if (strcmp(attr
->values
[0].string
.text
, "none"))
2479 cupsdSetString(&printer
->port_monitor
, attr
->values
[0].string
.text
);
2481 cupsdClearString(&printer
->port_monitor
);
2483 set_port_monitor
= 1;
2486 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
2487 IPP_TAG_BOOLEAN
)) != NULL
&&
2488 attr
->values
[0].boolean
!= printer
->accepting
)
2490 cupsdLogMessage(CUPSD_LOG_INFO
,
2491 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
2492 printer
->name
, attr
->values
[0].boolean
, printer
->accepting
);
2494 printer
->accepting
= attr
->values
[0].boolean
;
2496 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2497 "%s accepting jobs.",
2498 printer
->accepting
? "Now" : "No longer");
2501 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
2502 IPP_TAG_BOOLEAN
)) != NULL
)
2504 if (attr
->values
[0].boolean
&&
2505 printer
->num_auth_info_required
== 1 &&
2506 !strcmp(printer
->auth_info_required
[0], "negotiate"))
2508 send_ipp_status(con
, IPP_BAD_REQUEST
,
2509 _("Cannot share a remote Kerberized printer."));
2513 if (printer
->shared
&& !attr
->values
[0].boolean
)
2514 cupsdDeregisterPrinter(printer
, 1);
2516 cupsdLogMessage(CUPSD_LOG_INFO
,
2517 "Setting %s printer-is-shared to %d (was %d.)",
2518 printer
->name
, attr
->values
[0].boolean
, printer
->shared
);
2520 printer
->shared
= attr
->values
[0].boolean
;
2523 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
2524 IPP_TAG_ENUM
)) != NULL
)
2526 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
2527 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
2529 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad printer-state value %d."),
2530 attr
->values
[0].integer
);
2534 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
2535 printer
->name
, attr
->values
[0].integer
, printer
->state
);
2537 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
2538 cupsdStopPrinter(printer
, 0);
2541 need_restart_job
= 1;
2542 cupsdSetPrinterState(printer
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
2546 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
2547 IPP_TAG_TEXT
)) != NULL
)
2549 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
2550 sizeof(printer
->state_message
));
2552 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
, "%s",
2553 printer
->state_message
);
2556 if ((attr
= ippFindAttribute(con
->request
, "printer-state-reasons",
2557 IPP_TAG_KEYWORD
)) != NULL
)
2559 if (attr
->num_values
>
2560 (int)(sizeof(printer
->reasons
) / sizeof(printer
->reasons
[0])))
2562 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2563 _("Too many printer-state-reasons values (%d > %d)."),
2565 (int)(sizeof(printer
->reasons
) /
2566 sizeof(printer
->reasons
[0])));
2570 for (i
= 0; i
< printer
->num_reasons
; i
++)
2571 _cupsStrFree(printer
->reasons
[i
]);
2573 printer
->num_reasons
= 0;
2574 for (i
= 0; i
< attr
->num_values
; i
++)
2576 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
2579 printer
->reasons
[printer
->num_reasons
] =
2580 _cupsStrRetain(attr
->values
[i
].string
.text
);
2581 printer
->num_reasons
++;
2583 if (!strcmp(attr
->values
[i
].string
.text
, "paused") &&
2584 printer
->state
!= IPP_PRINTER_STOPPED
)
2586 cupsdLogMessage(CUPSD_LOG_INFO
,
2587 "Setting %s printer-state to %d (was %d.)",
2588 printer
->name
, IPP_PRINTER_STOPPED
, printer
->state
);
2589 cupsdStopPrinter(printer
, 0);
2593 if (PrintcapFormat
== PRINTCAP_PLIST
)
2594 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2596 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2597 "Printer \"%s\" state changed.", printer
->name
);
2600 set_printer_defaults(con
, printer
);
2602 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
2603 IPP_TAG_KEYWORD
)) != NULL
)
2604 cupsdSetAuthInfoRequired(printer
, NULL
, attr
);
2607 * See if we have all required attributes...
2610 if (!printer
->device_uri
)
2611 cupsdSetString(&printer
->device_uri
, "file:///dev/null");
2614 * See if we have an interface script or PPD file attached to the request...
2619 need_restart_job
= 1;
2622 strlcpy(srcfile
, con
->filename
, sizeof(srcfile
));
2624 if ((fp
= cupsFileOpen(srcfile
, "rb")))
2627 * Yes; get the first line from it...
2631 cupsFileGets(fp
, line
, sizeof(line
));
2635 * Then see what kind of file it is...
2638 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2641 if (!strncmp(line
, "*PPD-Adobe", 10))
2644 * The new file is a PPD file, so remove any old interface script
2645 * that might be lying around...
2653 * This must be an interface script, so move the file over to the
2654 * interfaces directory and make it executable...
2657 if (copy_file(srcfile
, dstfile
))
2659 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2660 _("Unable to copy interface script - %s"),
2665 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2666 "Copied interface script successfully");
2667 chmod(dstfile
, 0755);
2670 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2673 if (!strncmp(line
, "*PPD-Adobe", 10))
2676 * The new file is a PPD file, so move the file over to the
2677 * ppd directory and make it readable by all...
2680 if (copy_file(srcfile
, dstfile
))
2682 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2683 _("Unable to copy PPD file - %s"),
2688 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2689 "Copied PPD file successfully");
2690 chmod(dstfile
, 0644);
2695 * This must be an interface script, so remove any old PPD file that
2696 * may be lying around...
2703 else if ((attr
= ippFindAttribute(con
->request
, "ppd-name",
2704 IPP_TAG_NAME
)) != NULL
)
2706 need_restart_job
= 1;
2709 if (!strcmp(attr
->values
[0].string
.text
, "raw"))
2712 * Raw driver, remove any existing PPD or interface script files.
2715 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2719 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2729 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2733 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2736 if (copy_model(con
, attr
->values
[0].string
.text
, dstfile
))
2738 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file."));
2742 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2743 "Copied PPD file successfully");
2750 * If we changed the PPD/interface script, then remove the printer's cache
2751 * file and clear the printer-state-reasons...
2754 char cache_name
[1024]; /* Cache filename for printer attrs */
2756 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.data", CacheDir
,
2760 cupsdSetPrinterReasons(printer
, "none");
2763 * (Re)register color profiles...
2766 cupsdRegisterColor(printer
);
2770 * If we set the device URI but not the port monitor, check which port
2771 * monitor to use by default...
2774 if (set_device_uri
&& !set_port_monitor
)
2776 ppd_file_t
*ppd
; /* PPD file */
2777 ppd_attr_t
*ppdattr
; /* cupsPortMonitor attribute */
2780 httpSeparateURI(HTTP_URI_CODING_ALL
, printer
->device_uri
, scheme
,
2781 sizeof(scheme
), username
, sizeof(username
), host
,
2782 sizeof(host
), &port
, resource
, sizeof(resource
));
2784 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
,
2786 if ((ppd
= _ppdOpenFile(srcfile
, _PPD_LOCALIZATION_NONE
)) != NULL
)
2788 for (ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2790 ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
2791 if (!strcmp(scheme
, ppdattr
->spec
))
2793 cupsdLogMessage(CUPSD_LOG_INFO
,
2794 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2795 printer
->name
, ppdattr
->value
,
2796 printer
->port_monitor
? printer
->port_monitor
2799 if (strcmp(ppdattr
->value
, "none"))
2800 cupsdSetString(&printer
->port_monitor
, ppdattr
->value
);
2802 cupsdClearString(&printer
->port_monitor
);
2811 printer
->config_time
= time(NULL
);
2814 * Update the printer attributes and return...
2817 cupsdSetPrinterAttrs(printer
);
2818 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2820 if (need_restart_job
&& printer
->job
)
2823 * Restart the current job...
2826 cupsdSetJobState(printer
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
2827 "Job restarted because the printer was modified.");
2830 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2834 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
2835 printer
, NULL
, "Printer \"%s\" modified by \"%s\".",
2836 printer
->name
, get_username(con
));
2838 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" modified by \"%s\".",
2839 printer
->name
, get_username(con
));
2843 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
2844 printer
, NULL
, "New printer \"%s\" added by \"%s\".",
2845 printer
->name
, get_username(con
));
2847 cupsdLogMessage(CUPSD_LOG_INFO
, "New printer \"%s\" added by \"%s\".",
2848 printer
->name
, get_username(con
));
2851 con
->response
->request
.status
.status_code
= IPP_OK
;
2856 * 'add_printer_state_reasons()' - Add the "printer-state-reasons" attribute
2857 * based upon the printer state...
2861 add_printer_state_reasons(
2862 cupsd_client_t
*con
, /* I - Client connection */
2863 cupsd_printer_t
*p
) /* I - Printer info */
2865 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2866 "add_printer_state_reasons(%p[%d], %p[%s])",
2867 con
, con
->number
, p
, p
->name
);
2869 if (p
->num_reasons
== 0)
2870 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2871 "printer-state-reasons", NULL
, "none");
2873 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2874 "printer-state-reasons", p
->num_reasons
, NULL
,
2875 (const char * const *)p
->reasons
);
2880 * 'add_queued_job_count()' - Add the "queued-job-count" attribute for
2881 * the specified printer or class.
2885 add_queued_job_count(
2886 cupsd_client_t
*con
, /* I - Client connection */
2887 cupsd_printer_t
*p
) /* I - Printer or class */
2889 int count
; /* Number of jobs on destination */
2892 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_queued_job_count(%p[%d], %p[%s])",
2893 con
, con
->number
, p
, p
->name
);
2895 count
= cupsdGetPrinterJobCount(p
->name
);
2897 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2898 "queued-job-count", count
);
2903 * 'apply_printer_defaults()' - Apply printer default options to a job.
2907 apply_printer_defaults(
2908 cupsd_printer_t
*printer
, /* I - Printer */
2909 cupsd_job_t
*job
) /* I - Job */
2911 int i
, /* Looping var */
2912 num_options
; /* Number of default options */
2913 cups_option_t
*options
, /* Default options */
2914 *option
; /* Current option */
2918 * Collect all of the default options and add the missing ones to the
2922 for (i
= printer
->num_options
, num_options
= 0, options
= NULL
,
2923 option
= printer
->options
;
2926 if (!ippFindAttribute(job
->attrs
, option
->name
, IPP_TAG_ZERO
))
2928 num_options
= cupsAddOption(option
->name
, option
->value
, num_options
,
2933 * Encode these options as attributes in the job object...
2936 cupsEncodeOptions2(job
->attrs
, num_options
, options
, IPP_TAG_JOB
);
2937 cupsFreeOptions(num_options
, options
);
2942 * 'authenticate_job()' - Set job authentication info.
2946 authenticate_job(cupsd_client_t
*con
, /* I - Client connection */
2947 ipp_attribute_t
*uri
) /* I - Job URI */
2949 ipp_attribute_t
*attr
, /* job-id attribute */
2950 *auth_info
; /* auth-info attribute */
2951 int jobid
; /* Job ID */
2952 cupsd_job_t
*job
; /* Current job */
2953 char scheme
[HTTP_MAX_URI
],
2954 /* Method portion of URI */
2955 username
[HTTP_MAX_URI
],
2956 /* Username portion of URI */
2958 /* Host portion of URI */
2959 resource
[HTTP_MAX_URI
];
2960 /* Resource portion of URI */
2961 int port
; /* Port portion of URI */
2964 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "authenticate_job(%p[%d], %s)",
2965 con
, con
->number
, uri
->values
[0].string
.text
);
2968 * Start with "everything is OK" status...
2971 con
->response
->request
.status
.status_code
= IPP_OK
;
2974 * See if we have a job URI or a printer URI...
2977 if (!strcmp(uri
->name
, "printer-uri"))
2980 * Got a printer URI; see if we also have a job-id attribute...
2983 if ((attr
= ippFindAttribute(con
->request
, "job-id",
2984 IPP_TAG_INTEGER
)) == NULL
)
2986 send_ipp_status(con
, IPP_BAD_REQUEST
,
2987 _("Got a printer-uri attribute but no job-id."));
2991 jobid
= attr
->values
[0].integer
;
2996 * Got a job URI; parse it to get the job ID...
2999 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
3000 sizeof(scheme
), username
, sizeof(username
), host
,
3001 sizeof(host
), &port
, resource
, sizeof(resource
));
3003 if (strncmp(resource
, "/jobs/", 6))
3009 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
3010 uri
->values
[0].string
.text
);
3014 jobid
= atoi(resource
+ 6);
3018 * See if the job exists...
3021 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3024 * Nope - return a "not found" error...
3027 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
3032 * See if the job has been completed...
3035 if (job
->state_value
!= IPP_JOB_HELD
)
3038 * Return a "not-possible" error...
3041 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3042 _("Job #%d is not held for authentication."),
3048 * See if we have already authenticated...
3051 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
3053 if (!con
->username
[0] && !auth_info
)
3055 cupsd_printer_t
*printer
; /* Job destination */
3058 * No auth data. If we need to authenticate via Kerberos, send a
3059 * HTTP auth challenge, otherwise just return an IPP error...
3062 printer
= cupsdFindDest(job
->dest
);
3064 if (printer
&& printer
->num_auth_info_required
> 0 &&
3065 !strcmp(printer
->auth_info_required
[0], "negotiate"))
3066 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
3068 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
3069 _("No authentication information provided."));
3074 * See if the job is owned by the requesting user...
3077 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3079 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3080 cupsdFindDest(job
->dest
));
3085 * Save the authentication information for this job...
3088 save_auth_info(con
, job
, auth_info
);
3091 * Reset the job-hold-until value to "no-hold"...
3094 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
3095 IPP_TAG_KEYWORD
)) == NULL
)
3096 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
3100 attr
->value_tag
= IPP_TAG_KEYWORD
;
3101 cupsdSetString(&(attr
->values
[0].string
.text
), "no-hold");
3105 * Release the job and return...
3108 cupsdReleaseJob(job
);
3110 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, NULL
, job
, "Job authenticated by user");
3112 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Authenticated by \"%s\".", con
->username
);
3119 * 'cancel_all_jobs()' - Cancel all or selected print jobs.
3123 cancel_all_jobs(cupsd_client_t
*con
, /* I - Client connection */
3124 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3126 int i
; /* Looping var */
3127 http_status_t status
; /* Policy status */
3128 cups_ptype_t dtype
; /* Destination type */
3129 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3130 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
3131 hostname
[HTTP_MAX_URI
], /* Host portion of URI */
3132 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3133 int port
; /* Port portion of URI */
3134 ipp_attribute_t
*attr
; /* Attribute in request */
3135 const char *username
= NULL
; /* Username */
3136 cupsd_jobaction_t purge
= CUPSD_JOB_DEFAULT
;
3138 cupsd_printer_t
*printer
; /* Printer */
3139 ipp_attribute_t
*job_ids
; /* job-ids attribute */
3140 cupsd_job_t
*job
; /* Job */
3143 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_all_jobs(%p[%d], %s)", con
,
3144 con
->number
, uri
->values
[0].string
.text
);
3147 * Get the jobs to cancel/purge...
3150 switch (con
->request
->request
.op
.operation_id
)
3152 case IPP_PURGE_JOBS
:
3154 * Get the username (if any) for the jobs we want to cancel (only if
3155 * "my-jobs" is specified...
3158 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
3159 IPP_TAG_BOOLEAN
)) != NULL
&&
3160 attr
->values
[0].boolean
)
3162 if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3163 IPP_TAG_NAME
)) != NULL
)
3164 username
= attr
->values
[0].string
.text
;
3167 send_ipp_status(con
, IPP_BAD_REQUEST
,
3168 _("Missing requesting-user-name attribute."));
3174 * Look for the "purge-jobs" attribute...
3177 if ((attr
= ippFindAttribute(con
->request
, "purge-jobs",
3178 IPP_TAG_BOOLEAN
)) != NULL
)
3179 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
3181 purge
= CUPSD_JOB_PURGE
;
3184 case IPP_CANCEL_MY_JOBS
:
3185 if (con
->username
[0])
3186 username
= con
->username
;
3187 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3188 IPP_TAG_NAME
)) != NULL
)
3189 username
= attr
->values
[0].string
.text
;
3192 send_ipp_status(con
, IPP_BAD_REQUEST
,
3193 _("Missing requesting-user-name attribute."));
3201 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
3204 * See if we have a printer URI...
3207 if (strcmp(uri
->name
, "printer-uri"))
3209 send_ipp_status(con
, IPP_BAD_REQUEST
,
3210 _("The printer-uri attribute is required."));
3215 * And if the destination is valid...
3218 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3224 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
,
3225 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
3226 hostname
, sizeof(hostname
), &port
,
3227 resource
, sizeof(resource
));
3229 if ((!strncmp(resource
, "/printers/", 10) && resource
[10]) ||
3230 (!strncmp(resource
, "/classes/", 9) && resource
[9]))
3232 send_ipp_status(con
, IPP_NOT_FOUND
,
3233 _("The printer or class does not exist."));
3241 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
3243 send_http_error(con
, status
, NULL
);
3249 for (i
= 0; i
< job_ids
->num_values
; i
++)
3251 if ((job
= cupsdFindJob(job_ids
->values
[i
].integer
)) == NULL
)
3254 if (con
->request
->request
.op
.operation_id
== IPP_CANCEL_MY_JOBS
&&
3255 _cups_strcasecmp(job
->username
, username
))
3259 if (i
< job_ids
->num_values
)
3261 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3262 job_ids
->values
[i
].integer
);
3266 for (i
= 0; i
< job_ids
->num_values
; i
++)
3268 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
3270 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3271 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
3272 "Job canceled by user.");
3275 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
3276 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3282 * Cancel all jobs on all printers...
3285 cupsdCancelJobs(NULL
, username
, purge
);
3287 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs were %s by \"%s\".",
3288 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3298 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
3301 send_http_error(con
, status
, printer
);
3307 for (i
= 0; i
< job_ids
->num_values
; i
++)
3309 if ((job
= cupsdFindJob(job_ids
->values
[i
].integer
)) == NULL
||
3310 _cups_strcasecmp(job
->dest
, printer
->name
))
3313 if (con
->request
->request
.op
.operation_id
== IPP_CANCEL_MY_JOBS
&&
3314 _cups_strcasecmp(job
->username
, username
))
3318 if (i
< job_ids
->num_values
)
3320 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3321 job_ids
->values
[i
].integer
);
3325 for (i
= 0; i
< job_ids
->num_values
; i
++)
3327 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
3329 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3330 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
3331 "Job canceled by user.");
3334 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
3335 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3341 * Cancel all of the jobs on the named printer...
3344 cupsdCancelJobs(printer
->name
, username
, purge
);
3346 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs on \"%s\" were %s by \"%s\".",
3348 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3353 con
->response
->request
.status
.status_code
= IPP_OK
;
3358 * 'cancel_job()' - Cancel a print job.
3362 cancel_job(cupsd_client_t
*con
, /* I - Client connection */
3363 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3365 ipp_attribute_t
*attr
; /* Current attribute */
3366 int jobid
; /* Job ID */
3367 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3368 username
[HTTP_MAX_URI
], /* Username portion of URI */
3369 host
[HTTP_MAX_URI
], /* Host portion of URI */
3370 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3371 int port
; /* Port portion of URI */
3372 cupsd_job_t
*job
; /* Job information */
3373 cups_ptype_t dtype
; /* Destination type (printer/class) */
3374 cupsd_printer_t
*printer
; /* Printer data */
3375 cupsd_jobaction_t purge
; /* Purge the job? */
3378 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_job(%p[%d], %s)", con
,
3379 con
->number
, uri
->values
[0].string
.text
);
3382 * See if we have a job URI or a printer URI...
3385 if (!strcmp(uri
->name
, "printer-uri"))
3388 * Got a printer URI; see if we also have a job-id attribute...
3391 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3392 IPP_TAG_INTEGER
)) == NULL
)
3394 send_ipp_status(con
, IPP_BAD_REQUEST
,
3395 _("Got a printer-uri attribute but no job-id."));
3399 if ((jobid
= attr
->values
[0].integer
) == 0)
3402 * Find the current job on the specified printer...
3405 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3411 send_ipp_status(con
, IPP_NOT_FOUND
,
3412 _("The printer or class does not exist."));
3417 * See if there are any pending jobs...
3420 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3422 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3423 if (job
->state_value
<= IPP_JOB_PROCESSING
&&
3424 !_cups_strcasecmp(job
->dest
, printer
->name
))
3432 * No, try stopped jobs...
3435 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3437 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3438 if (job
->state_value
== IPP_JOB_STOPPED
&&
3439 !_cups_strcasecmp(job
->dest
, printer
->name
))
3446 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("No active jobs on %s."),
3456 * Got a job URI; parse it to get the job ID...
3459 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
3460 sizeof(scheme
), username
, sizeof(username
), host
,
3461 sizeof(host
), &port
, resource
, sizeof(resource
));
3463 if (strncmp(resource
, "/jobs/", 6))
3469 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
3470 uri
->values
[0].string
.text
);
3474 jobid
= atoi(resource
+ 6);
3478 * Look for the "purge-job" attribute...
3481 if ((attr
= ippFindAttribute(con
->request
, "purge-job",
3482 IPP_TAG_BOOLEAN
)) != NULL
)
3483 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
3485 purge
= CUPSD_JOB_DEFAULT
;
3488 * See if the job exists...
3491 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3494 * Nope - return a "not found" error...
3497 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
3502 * See if the job is owned by the requesting user...
3505 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3507 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3508 cupsdFindDest(job
->dest
));
3513 * See if the job is already completed, canceled, or aborted; if so,
3514 * we can't cancel...
3517 if (job
->state_value
>= IPP_JOB_CANCELED
&& purge
!= CUPSD_JOB_PURGE
)
3519 switch (job
->state_value
)
3521 case IPP_JOB_CANCELED
:
3522 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3523 _("Job #%d is already canceled - can\'t cancel."),
3527 case IPP_JOB_ABORTED
:
3528 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3529 _("Job #%d is already aborted - can\'t cancel."),
3534 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3535 _("Job #%d is already completed - can\'t cancel."),
3544 * Cancel the job and return...
3547 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3548 purge
== CUPSD_JOB_PURGE
? "Job purged by \"%s\"" :
3549 "Job canceled by \"%s\"",
3553 if (purge
== CUPSD_JOB_PURGE
)
3554 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Purged by \"%s\".", jobid
,
3557 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Canceled by \"%s\".", jobid
,
3560 con
->response
->request
.status
.status_code
= IPP_OK
;
3565 * 'cancel_subscription()' - Cancel a subscription.
3569 cancel_subscription(
3570 cupsd_client_t
*con
, /* I - Client connection */
3571 int sub_id
) /* I - Subscription ID */
3573 http_status_t status
; /* Policy status */
3574 cupsd_subscription_t
*sub
; /* Subscription */
3577 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3578 "cancel_subscription(con=%p[%d], sub_id=%d)",
3579 con
, con
->number
, sub_id
);
3582 * Is the subscription ID valid?
3585 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
3588 * Bad subscription ID...
3591 send_ipp_status(con
, IPP_NOT_FOUND
,
3592 _("Subscription #%d does not exist."), sub_id
);
3600 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
3602 con
, sub
->owner
)) != HTTP_OK
)
3604 send_http_error(con
, status
, sub
->dest
);
3609 * Cancel the subscription...
3612 cupsdDeleteSubscription(sub
, 1);
3614 con
->response
->request
.status
.status_code
= IPP_OK
;
3619 * 'check_rss_recipient()' - Check that we do not have a duplicate RSS feed URI.
3622 static int /* O - 1 if OK, 0 if not */
3623 check_rss_recipient(
3624 const char *recipient
) /* I - Recipient URI */
3626 cupsd_subscription_t
*sub
; /* Current subscription */
3629 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
);
3631 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
3635 * Compare the URIs up to the first ?...
3638 const char *r1
, *r2
;
3640 for (r1
= recipient
, r2
= sub
->recipient
;
3641 *r1
== *r2
&& *r1
&& *r1
!= '?' && *r2
&& *r2
!= '?';
3653 * 'check_quotas()' - Check quotas for a printer and user.
3656 static int /* O - 1 if OK, 0 if forbidden,
3657 -1 if limit reached */
3658 check_quotas(cupsd_client_t
*con
, /* I - Client connection */
3659 cupsd_printer_t
*p
) /* I - Printer or class */
3661 char username
[33], /* Username */
3662 *name
; /* Current user name */
3663 cupsd_quota_t
*q
; /* Quota data */
3664 #ifdef HAVE_MBR_UID_TO_UUID
3666 * Use Apple membership APIs which require that all names represent
3667 * valid user account or group records accessible by the server.
3670 uuid_t usr_uuid
; /* UUID for job requesting user */
3671 uuid_t usr2_uuid
; /* UUID for ACL user name entry */
3672 uuid_t grp_uuid
; /* UUID for ACL group name entry */
3673 int mbr_err
; /* Error from membership function */
3674 int is_member
; /* Is this user a member? */
3677 * Use standard POSIX APIs for checking users and groups...
3680 struct passwd
*pw
; /* User password data */
3681 #endif /* HAVE_MBR_UID_TO_UUID */
3684 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "check_quotas(%p[%d], %p[%s])",
3685 con
, con
->number
, p
, p
->name
);
3688 * Figure out who is printing...
3691 strlcpy(username
, get_username(con
), sizeof(username
));
3693 if ((name
= strchr(username
, '@')) != NULL
)
3694 *name
= '\0'; /* Strip @REALM */
3697 * Check global active job limits for printers and users...
3700 if (MaxJobsPerPrinter
)
3703 * Check if there are too many pending jobs on this printer...
3706 if (cupsdGetPrinterJobCount(p
->name
) >= MaxJobsPerPrinter
)
3708 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for printer \"%s\"...",
3717 * Check if there are too many pending jobs for this user...
3720 if (cupsdGetUserJobCount(username
) >= MaxJobsPerUser
)
3722 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for user \"%s\"...",
3729 * Check against users...
3732 if (cupsArrayCount(p
->users
) == 0 && p
->k_limit
== 0 && p
->page_limit
== 0)
3735 if (cupsArrayCount(p
->users
))
3737 #ifdef HAVE_MBR_UID_TO_UUID
3739 * Get UUID for job requesting user...
3742 if (mbr_user_name_to_uuid((char *)username
, usr_uuid
))
3748 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3749 "check_quotas: UUID lookup failed for user \"%s\"",
3751 cupsdLogMessage(CUPSD_LOG_INFO
,
3752 "Denying user \"%s\" access to printer \"%s\" "
3753 "(unknown user)...",
3759 * Get UID and GID of requesting user...
3762 pw
= getpwnam(username
);
3764 #endif /* HAVE_MBR_UID_TO_UUID */
3766 for (name
= (char *)cupsArrayFirst(p
->users
);
3768 name
= (char *)cupsArrayNext(p
->users
))
3772 * Check group membership...
3775 #ifdef HAVE_MBR_UID_TO_UUID
3778 if (uuid_parse(name
+ 2, grp_uuid
))
3779 uuid_clear(grp_uuid
);
3781 else if ((mbr_err
= mbr_group_name_to_uuid(name
+ 1, grp_uuid
)) != 0)
3784 * Invalid ACL entries are ignored for matching; just record a
3785 * warning in the log...
3788 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3789 "check_quotas: UUID lookup failed for ACL entry "
3790 "\"%s\" (err=%d)", name
, mbr_err
);
3791 cupsdLogMessage(CUPSD_LOG_WARN
,
3792 "Access control entry \"%s\" not a valid group name; "
3793 "entry ignored", name
);
3796 if ((mbr_err
= mbr_check_membership(usr_uuid
, grp_uuid
,
3800 * At this point, there should be no errors, but check anyways...
3803 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3804 "check_quotas: group \"%s\" membership check "
3805 "failed (err=%d)", name
+ 1, mbr_err
);
3810 * Stop if we found a match...
3817 if (cupsdCheckGroup(username
, pw
, name
+ 1))
3819 #endif /* HAVE_MBR_UID_TO_UUID */
3821 #ifdef HAVE_MBR_UID_TO_UUID
3826 if (uuid_parse(name
+ 1, usr2_uuid
))
3827 uuid_clear(usr2_uuid
);
3829 else if ((mbr_err
= mbr_user_name_to_uuid(name
, usr2_uuid
)) != 0)
3832 * Invalid ACL entries are ignored for matching; just record a
3833 * warning in the log...
3836 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3837 "check_quotas: UUID lookup failed for ACL entry "
3838 "\"%s\" (err=%d)", name
, mbr_err
);
3839 cupsdLogMessage(CUPSD_LOG_WARN
,
3840 "Access control entry \"%s\" not a valid user name; "
3841 "entry ignored", name
);
3844 if (!uuid_compare(usr_uuid
, usr2_uuid
))
3848 else if (!_cups_strcasecmp(username
, name
))
3850 #endif /* HAVE_MBR_UID_TO_UUID */
3852 if ((name
!= NULL
) == p
->deny_users
)
3854 cupsdLogMessage(CUPSD_LOG_INFO
,
3855 "Denying user \"%s\" access to printer \"%s\"...",
3865 if (p
->k_limit
|| p
->page_limit
)
3867 if ((q
= cupsdUpdateQuota(p
, username
, 0, 0)) == NULL
)
3869 cupsdLogMessage(CUPSD_LOG_ERROR
,
3870 "Unable to allocate quota data for user \"%s\"",
3875 if ((q
->k_count
>= p
->k_limit
&& p
->k_limit
) ||
3876 (q
->page_count
>= p
->page_limit
&& p
->page_limit
))
3878 cupsdLogMessage(CUPSD_LOG_INFO
, "User \"%s\" is over the quota limit...",
3885 * If we have gotten this far, we're done!
3893 * 'close_job()' - Close a multi-file job.
3897 close_job(cupsd_client_t
*con
, /* I - Client connection */
3898 ipp_attribute_t
*uri
) /* I - Printer URI */
3900 cupsd_job_t
*job
; /* Job */
3901 ipp_attribute_t
*attr
; /* Attribute */
3902 char job_uri
[HTTP_MAX_URI
],
3904 username
[256]; /* User name */
3907 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "close_job(%p[%d], %s)", con
,
3908 con
->number
, uri
->values
[0].string
.text
);
3911 * See if we have a job URI or a printer URI...
3914 if (strcmp(uri
->name
, "printer-uri"))
3917 * job-uri is not supported by Close-Job!
3920 send_ipp_status(con
, IPP_BAD_REQUEST
,
3921 _("Close-Job doesn't support the job-uri attribute."));
3926 * Got a printer URI; see if we also have a job-id attribute...
3929 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3930 IPP_TAG_INTEGER
)) == NULL
)
3932 send_ipp_status(con
, IPP_BAD_REQUEST
,
3933 _("Got a printer-uri attribute but no job-id."));
3937 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
3940 * Nope - return a "not found" error...
3943 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3944 attr
->values
[0].integer
);
3949 * See if the job is owned by the requesting user...
3952 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3954 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3955 cupsdFindDest(job
->dest
));
3960 * Add any ending sheet...
3963 if (cupsdTimeoutJob(job
))
3966 if (job
->state_value
== IPP_JOB_STOPPED
)
3968 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
3969 job
->state_value
= IPP_JOB_PENDING
;
3971 else if (job
->state_value
== IPP_JOB_HELD
)
3973 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
3974 IPP_TAG_KEYWORD
)) == NULL
)
3975 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
3977 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
3979 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
3980 job
->state_value
= IPP_JOB_PENDING
;
3985 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
3988 * Fill in the response info...
3991 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
3992 con
->clientname
, con
->clientport
, "/jobs/%d", job
->id
);
3993 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
3996 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
3998 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
4001 con
->response
->request
.status
.status_code
= IPP_OK
;
4004 * Start the job if necessary...
4012 * 'copy_attrs()' - Copy attributes from one request to another.
4016 copy_attrs(ipp_t
*to
, /* I - Destination request */
4017 ipp_t
*from
, /* I - Source request */
4018 cups_array_t
*ra
, /* I - Requested attributes */
4019 ipp_tag_t group
, /* I - Group to copy */
4020 int quickcopy
, /* I - Do a quick copy? */
4021 cups_array_t
*exclude
) /* I - Attributes to exclude? */
4023 ipp_attribute_t
*fromattr
; /* Source attribute */
4026 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4027 "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)",
4028 to
, from
, ra
, group
, quickcopy
);
4033 for (fromattr
= from
->attrs
; fromattr
; fromattr
= fromattr
->next
)
4036 * Filter attributes as needed...
4039 if ((group
!= IPP_TAG_ZERO
&& fromattr
->group_tag
!= group
&&
4040 fromattr
->group_tag
!= IPP_TAG_ZERO
) || !fromattr
->name
)
4043 if (!strcmp(fromattr
->name
, "document-password") ||
4044 !strcmp(fromattr
->name
, "job-authorization-uri") ||
4045 !strcmp(fromattr
->name
, "job-password") ||
4046 !strcmp(fromattr
->name
, "job-password-encryption") ||
4047 !strcmp(fromattr
->name
, "job-printer-uri"))
4051 (cupsArrayFind(exclude
, fromattr
->name
) ||
4052 cupsArrayFind(exclude
, "all")))
4055 * We need to exclude this attribute for security reasons; we require the
4056 * job-id attribute regardless of the security settings for IPP
4059 * The job-printer-uri attribute is handled by copy_job_attrs().
4061 * Subscription attribute security is handled by copy_subscription_attrs().
4064 if (strcmp(fromattr
->name
, "job-id"))
4068 if (!ra
|| cupsArrayFind(ra
, fromattr
->name
))
4071 * Don't send collection attributes by default to IPP/1.x clients
4072 * since many do not support collections. Also don't send
4073 * media-col-database unless specifically requested by the client.
4076 if (fromattr
->value_tag
== IPP_TAG_BEGIN_COLLECTION
&&
4078 (to
->request
.status
.version
[0] == 1 ||
4079 !strcmp(fromattr
->name
, "media-col-database")))
4082 ippCopyAttribute(to
, fromattr
, quickcopy
);
4089 * 'copy_banner()' - Copy a banner file to the requests directory for the
4093 static int /* O - Size of banner file in kbytes */
4094 copy_banner(cupsd_client_t
*con
, /* I - Client connection */
4095 cupsd_job_t
*job
, /* I - Job information */
4096 const char *name
) /* I - Name of banner */
4098 int i
; /* Looping var */
4099 int kbytes
; /* Size of banner file in kbytes */
4100 char filename
[1024]; /* Job filename */
4101 cupsd_banner_t
*banner
; /* Pointer to banner */
4102 cups_file_t
*in
; /* Input file */
4103 cups_file_t
*out
; /* Output file */
4104 int ch
; /* Character from file */
4105 char attrname
[255], /* Name of attribute */
4106 *s
; /* Pointer into name */
4107 ipp_attribute_t
*attr
; /* Attribute */
4110 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4111 "copy_banner(con=%p[%d], job=%p[%d], name=\"%s\")",
4112 con
, con
? con
->number
: -1, job
, job
->id
,
4113 name
? name
: "(null)");
4116 * Find the banner; return if not found or "none"...
4119 if (!name
|| !strcmp(name
, "none") ||
4120 (banner
= cupsdFindBanner(name
)) == NULL
)
4124 * Open the banner and job files...
4127 if (add_file(con
, job
, banner
->filetype
, 0))
4130 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
4132 if ((out
= cupsFileOpen(filename
, "w")) == NULL
)
4134 cupsdLogMessage(CUPSD_LOG_ERROR
,
4135 "Unable to create banner job file %s - %s",
4136 filename
, strerror(errno
));
4141 fchmod(cupsFileNumber(out
), 0640);
4142 fchown(cupsFileNumber(out
), RunUser
, Group
);
4145 * Try the localized banner file under the subdirectory...
4148 strlcpy(attrname
, job
->attrs
->attrs
->next
->values
[0].string
.text
,
4150 if (strlen(attrname
) > 2 && attrname
[2] == '-')
4153 * Convert ll-cc to ll_CC...
4157 attrname
[3] = (char)toupper(attrname
[3] & 255);
4158 attrname
[4] = (char)toupper(attrname
[4] & 255);
4161 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4164 if (access(filename
, 0) && strlen(attrname
) > 2)
4167 * Wasn't able to find "ll_CC" locale file; try the non-national
4168 * localization banner directory.
4173 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4177 if (access(filename
, 0))
4180 * Use the non-localized banner file.
4183 snprintf(filename
, sizeof(filename
), "%s/banners/%s", DataDir
, name
);
4186 if ((in
= cupsFileOpen(filename
, "r")) == NULL
)
4190 cupsdLogMessage(CUPSD_LOG_ERROR
,
4191 "Unable to open banner template file %s - %s",
4192 filename
, strerror(errno
));
4198 * Parse the file to the end...
4201 while ((ch
= cupsFileGetChar(in
)) != EOF
)
4205 * Get an attribute name...
4208 for (s
= attrname
; (ch
= cupsFileGetChar(in
)) != EOF
;)
4209 if (!isalpha(ch
& 255) && ch
!= '-' && ch
!= '?')
4211 else if (s
< (attrname
+ sizeof(attrname
) - 1))
4221 * Ignore { followed by stuff that is not an attribute name...
4224 cupsFilePrintf(out
, "{%s%c", attrname
, ch
);
4229 * See if it is defined...
4232 if (attrname
[0] == '?')
4237 if (!strcmp(s
, "printer-name"))
4239 cupsFilePuts(out
, job
->dest
);
4242 else if ((attr
= ippFindAttribute(job
->attrs
, s
, IPP_TAG_ZERO
)) == NULL
)
4245 * See if we have a leading question mark...
4248 if (attrname
[0] != '?')
4251 * Nope, write to file as-is; probably a PostScript procedure...
4254 cupsFilePrintf(out
, "{%s}", attrname
);
4261 * Output value(s)...
4264 for (i
= 0; i
< attr
->num_values
; i
++)
4267 cupsFilePutChar(out
, ',');
4269 switch (attr
->value_tag
)
4271 case IPP_TAG_INTEGER
:
4273 if (!strncmp(s
, "time-at-", 8))
4275 struct timeval tv
; /* Time value */
4277 tv
.tv_sec
= attr
->values
[i
].integer
;
4280 cupsFilePuts(out
, cupsdGetDateTime(&tv
, CUPSD_TIME_STANDARD
));
4283 cupsFilePrintf(out
, "%d", attr
->values
[i
].integer
);
4286 case IPP_TAG_BOOLEAN
:
4287 cupsFilePrintf(out
, "%d", attr
->values
[i
].boolean
);
4290 case IPP_TAG_NOVALUE
:
4291 cupsFilePuts(out
, "novalue");
4294 case IPP_TAG_RANGE
:
4295 cupsFilePrintf(out
, "%d-%d", attr
->values
[i
].range
.lower
,
4296 attr
->values
[i
].range
.upper
);
4299 case IPP_TAG_RESOLUTION
:
4300 cupsFilePrintf(out
, "%dx%d%s", attr
->values
[i
].resolution
.xres
,
4301 attr
->values
[i
].resolution
.yres
,
4302 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
4307 case IPP_TAG_STRING
:
4310 case IPP_TAG_KEYWORD
:
4311 case IPP_TAG_CHARSET
:
4312 case IPP_TAG_LANGUAGE
:
4313 if (!_cups_strcasecmp(banner
->filetype
->type
, "postscript"))
4316 * Need to quote strings for PS banners...
4321 for (p
= attr
->values
[i
].string
.text
; *p
; p
++)
4323 if (*p
== '(' || *p
== ')' || *p
== '\\')
4325 cupsFilePutChar(out
, '\\');
4326 cupsFilePutChar(out
, *p
);
4328 else if (*p
< 32 || *p
> 126)
4329 cupsFilePrintf(out
, "\\%03o", *p
& 255);
4331 cupsFilePutChar(out
, *p
);
4335 cupsFilePuts(out
, attr
->values
[i
].string
.text
);
4339 break; /* anti-compiler-warning-code */
4343 else if (ch
== '\\') /* Quoted char */
4345 ch
= cupsFileGetChar(in
);
4347 if (ch
!= '{') /* Only do special handling for \{ */
4348 cupsFilePutChar(out
, '\\');
4350 cupsFilePutChar(out
, ch
);
4353 cupsFilePutChar(out
, ch
);
4357 kbytes
= (cupsFileTell(out
) + 1023) / 1024;
4359 job
->koctets
+= kbytes
;
4361 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets", IPP_TAG_INTEGER
)) != NULL
)
4362 attr
->values
[0].integer
+= kbytes
;
4371 * 'copy_file()' - Copy a PPD file or interface script...
4374 static int /* O - 0 = success, -1 = error */
4375 copy_file(const char *from
, /* I - Source file */
4376 const char *to
) /* I - Destination file */
4378 cups_file_t
*src
, /* Source file */
4379 *dst
; /* Destination file */
4380 int bytes
; /* Bytes to read/write */
4381 char buffer
[2048]; /* Copy buffer */
4384 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_file(\"%s\", \"%s\")", from
, to
);
4387 * Open the source and destination file for a copy...
4390 if ((src
= cupsFileOpen(from
, "rb")) == NULL
)
4393 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
4400 * Copy the source file to the destination...
4403 while ((bytes
= cupsFileRead(src
, buffer
, sizeof(buffer
))) > 0)
4404 if (cupsFileWrite(dst
, buffer
, (size_t)bytes
) < bytes
)
4412 * Close both files and return...
4417 return (cupsFileClose(dst
));
4422 * 'copy_model()' - Copy a PPD model file, substituting default values
4426 static int /* O - 0 = success, -1 = error */
4427 copy_model(cupsd_client_t
*con
, /* I - Client connection */
4428 const char *from
, /* I - Source file */
4429 const char *to
) /* I - Destination file */
4431 fd_set input
; /* select() input set */
4432 struct timeval timeout
; /* select() timeout */
4433 int maxfd
; /* Max file descriptor for select() */
4434 char tempfile
[1024]; /* Temporary PPD file */
4435 int tempfd
; /* Temporary PPD file descriptor */
4436 int temppid
; /* Process ID of cups-driverd */
4437 int temppipe
[2]; /* Temporary pipes */
4438 char *argv
[4], /* Command-line arguments */
4439 *envp
[MAX_ENV
]; /* Environment */
4440 cups_file_t
*src
, /* Source file */
4441 *dst
; /* Destination file */
4442 ppd_file_t
*ppd
; /* PPD file */
4443 int bytes
, /* Bytes from pipe */
4444 total
; /* Total bytes from pipe */
4445 char buffer
[2048]; /* Copy buffer */
4446 int i
; /* Looping var */
4447 char option
[PPD_MAX_NAME
], /* Option name */
4448 choice
[PPD_MAX_NAME
]; /* Choice name */
4449 ppd_size_t
*size
; /* Default size */
4450 int num_defaults
; /* Number of default options */
4451 cups_option_t
*defaults
; /* Default options */
4452 char cups_protocol
[PPD_MAX_LINE
];
4453 /* cupsProtocol attribute */
4456 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4457 "copy_model(con=%p, from=\"%s\", to=\"%s\")",
4461 * Run cups-driverd to get the PPD file...
4464 argv
[0] = "cups-driverd";
4466 argv
[2] = (char *)from
;
4469 cupsdLoadEnv(envp
, (int)(sizeof(envp
) / sizeof(envp
[0])));
4471 snprintf(buffer
, sizeof(buffer
), "%s/daemon/cups-driverd", ServerBin
);
4472 snprintf(tempfile
, sizeof(tempfile
), "%s/%d.ppd", TempDir
, con
->number
);
4473 tempfd
= open(tempfile
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
4474 if (tempfd
< 0 || cupsdOpenPipe(temppipe
))
4477 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4478 "copy_model: Running \"cups-driverd cat %s\"...", from
);
4480 if (!cupsdStartProcess(buffer
, argv
, envp
, -1, temppipe
[1], CGIPipes
[1],
4481 -1, -1, 0, DefaultProfile
, NULL
, &temppid
))
4492 * Wait up to 30 seconds for the PPD file to be copied...
4497 if (temppipe
[0] > CGIPipes
[0])
4498 maxfd
= temppipe
[0] + 1;
4500 maxfd
= CGIPipes
[0] + 1;
4505 * See if we have data ready...
4509 FD_SET(temppipe
[0], &input
);
4510 FD_SET(CGIPipes
[0], &input
);
4512 timeout
.tv_sec
= 30;
4513 timeout
.tv_usec
= 0;
4515 if ((i
= select(maxfd
, &input
, NULL
, NULL
, &timeout
)) < 0)
4525 * We have timed out...
4531 if (FD_ISSET(temppipe
[0], &input
))
4534 * Read the PPD file from the pipe, and write it to the PPD file.
4537 if ((bytes
= read(temppipe
[0], buffer
, sizeof(buffer
))) > 0)
4539 if (write(tempfd
, buffer
, (size_t)bytes
) < bytes
)
4548 if (FD_ISSET(CGIPipes
[0], &input
))
4558 * No data from cups-deviced...
4561 cupsdLogMessage(CUPSD_LOG_ERROR
, "copy_model: empty PPD file");
4567 * Open the source file for a copy...
4570 if ((src
= cupsFileOpen(tempfile
, "rb")) == NULL
)
4577 * Read the source file and see what page sizes are supported...
4580 if ((ppd
= _ppdOpen(src
, _PPD_LOCALIZATION_NONE
)) == NULL
)
4588 * Open the destination (if possible) and set the default options...
4593 cups_protocol
[0] = '\0';
4595 if ((dst
= cupsFileOpen(to
, "rb")) != NULL
)
4598 * Read all of the default lines from the old PPD...
4601 while (cupsFileGets(dst
, buffer
, sizeof(buffer
)))
4602 if (!strncmp(buffer
, "*Default", 8))
4605 * Add the default option...
4608 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
4609 choice
, sizeof(choice
)))
4611 ppd_option_t
*ppdo
; /* PPD option */
4615 * Only add the default if the default hasn't already been
4616 * set and the choice exists in the new PPD...
4619 if (!cupsGetOption(option
, num_defaults
, defaults
) &&
4620 (ppdo
= ppdFindOption(ppd
, option
)) != NULL
&&
4621 ppdFindChoice(ppdo
, choice
))
4622 num_defaults
= cupsAddOption(option
, choice
, num_defaults
,
4626 else if (!strncmp(buffer
, "*cupsProtocol:", 14))
4627 strlcpy(cups_protocol
, buffer
, sizeof(cups_protocol
));
4631 else if ((size
= ppdPageSize(ppd
, DefaultPaperSize
)) != NULL
)
4634 * Add the default media sizes...
4637 num_defaults
= cupsAddOption("PageSize", size
->name
,
4638 num_defaults
, &defaults
);
4639 num_defaults
= cupsAddOption("PageRegion", size
->name
,
4640 num_defaults
, &defaults
);
4641 num_defaults
= cupsAddOption("PaperDimension", size
->name
,
4642 num_defaults
, &defaults
);
4643 num_defaults
= cupsAddOption("ImageableArea", size
->name
,
4644 num_defaults
, &defaults
);
4650 * Open the destination file for a copy...
4653 if ((dst
= cupsdCreateConfFile(to
, ConfigFilePerm
)) == NULL
)
4655 cupsFreeOptions(num_defaults
, defaults
);
4662 * Copy the source file to the destination...
4665 cupsFileRewind(src
);
4667 while (cupsFileGets(src
, buffer
, sizeof(buffer
)))
4669 if (!strncmp(buffer
, "*Default", 8))
4672 * Check for an previous default option choice...
4675 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
4676 choice
, sizeof(choice
)))
4678 const char *val
; /* Default option value */
4681 if ((val
= cupsGetOption(option
, num_defaults
, defaults
)) != NULL
)
4684 * Substitute the previous choice...
4687 snprintf(buffer
, sizeof(buffer
), "*Default%s: %s", option
, val
);
4692 cupsFilePrintf(dst
, "%s\n", buffer
);
4695 if (cups_protocol
[0])
4696 cupsFilePrintf(dst
, "%s\n", cups_protocol
);
4698 cupsFreeOptions(num_defaults
, defaults
);
4701 * Close both files and return...
4708 return (cupsdCloseCreatedConfFile(dst
, to
));
4713 * 'copy_job_attrs()' - Copy job attributes.
4717 copy_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
4718 cupsd_job_t
*job
, /* I - Job */
4719 cups_array_t
*ra
, /* I - Requested attributes array */
4720 cups_array_t
*exclude
) /* I - Private attributes array */
4722 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
4726 * Send the requested attributes for each job...
4729 if (!cupsArrayFind(exclude
, "all"))
4731 if ((!exclude
|| !cupsArrayFind(exclude
, "number-of-documents")) &&
4732 (!ra
|| cupsArrayFind(ra
, "number-of-documents")))
4733 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4734 "number-of-documents", job
->num_files
);
4736 if ((!exclude
|| !cupsArrayFind(exclude
, "job-media-progress")) &&
4737 (!ra
|| cupsArrayFind(ra
, "job-media-progress")))
4738 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4739 "job-media-progress", job
->progress
);
4741 if ((!exclude
|| !cupsArrayFind(exclude
, "job-more-info")) &&
4742 (!ra
|| cupsArrayFind(ra
, "job-more-info")))
4744 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "http",
4745 NULL
, con
->clientname
, con
->clientport
, "/jobs/%d",
4747 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4748 "job-more-info", NULL
, job_uri
);
4751 if (job
->state_value
> IPP_JOB_PROCESSING
&&
4752 (!exclude
|| !cupsArrayFind(exclude
, "job-preserved")) &&
4753 (!ra
|| cupsArrayFind(ra
, "job-preserved")))
4754 ippAddBoolean(con
->response
, IPP_TAG_JOB
, "job-preserved",
4755 job
->num_files
> 0);
4757 if ((!exclude
|| !cupsArrayFind(exclude
, "job-printer-up-time")) &&
4758 (!ra
|| cupsArrayFind(ra
, "job-printer-up-time")))
4759 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4760 "job-printer-up-time", time(NULL
));
4763 if (!ra
|| cupsArrayFind(ra
, "job-printer-uri"))
4765 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
4766 con
->clientname
, con
->clientport
,
4767 (job
->dtype
& CUPS_PRINTER_CLASS
) ? "/classes/%s" :
4770 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4771 "job-printer-uri", NULL
, job_uri
);
4774 if (!ra
|| cupsArrayFind(ra
, "job-uri"))
4776 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
4777 con
->clientname
, con
->clientport
, "/jobs/%d",
4779 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4780 "job-uri", NULL
, job_uri
);
4785 copy_attrs(con
->response
, job
->attrs
, ra
, IPP_TAG_JOB
, 0, exclude
);
4790 * Generate attributes from the job structure...
4793 if (job
->completed_time
&& (!ra
|| cupsArrayFind(ra
, "date-time-at-completed")))
4794 ippAddDate(con
->response
, IPP_TAG_JOB
, "date-time-at-completed", ippTimeToDate(job
->completed_time
));
4796 if (job
->creation_time
&& (!ra
|| cupsArrayFind(ra
, "date-time-at-creation")))
4797 ippAddDate(con
->response
, IPP_TAG_JOB
, "date-time-at-creation", ippTimeToDate(job
->creation_time
));
4799 if (!ra
|| cupsArrayFind(ra
, "job-id"))
4800 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
4802 if (!ra
|| cupsArrayFind(ra
, "job-k-octets"))
4803 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-k-octets", job
->koctets
);
4805 if (job
->name
&& (!ra
|| cupsArrayFind(ra
, "job-name")))
4806 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_CONST_TAG(IPP_TAG_NAME
), "job-name", NULL
, job
->name
);
4808 if (job
->username
&& (!ra
|| cupsArrayFind(ra
, "job-originating-user-name")))
4809 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_CONST_TAG(IPP_TAG_NAME
), "job-originating-user-name", NULL
, job
->username
);
4811 if (!ra
|| cupsArrayFind(ra
, "job-state"))
4812 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state", (int)job
->state_value
);
4814 if (!ra
|| cupsArrayFind(ra
, "job-state-reasons"))
4816 switch (job
->state_value
)
4818 default : /* Should never get here for processing, pending, held, or stopped jobs since they don't get unloaded... */
4820 case IPP_JSTATE_ABORTED
:
4821 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons", NULL
, "job-aborted-by-system");
4823 case IPP_JSTATE_CANCELED
:
4824 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons", NULL
, "job-canceled-by-user");
4826 case IPP_JSTATE_COMPLETED
:
4827 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons", NULL
, "job-completed-successfully");
4832 if (job
->completed_time
&& (!ra
|| cupsArrayFind(ra
, "time-at-completed")))
4833 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-completed", (int)job
->completed_time
);
4835 if (job
->creation_time
&& (!ra
|| cupsArrayFind(ra
, "time-at-creation")))
4836 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation", (int)job
->creation_time
);
4842 * 'copy_printer_attrs()' - Copy printer attributes.
4847 cupsd_client_t
*con
, /* I - Client connection */
4848 cupsd_printer_t
*printer
, /* I - Printer */
4849 cups_array_t
*ra
) /* I - Requested attributes array */
4851 char printer_uri
[HTTP_MAX_URI
];
4853 char printer_icons
[HTTP_MAX_URI
];
4855 time_t curtime
; /* Current time */
4856 int i
; /* Looping var */
4860 * Copy the printer attributes to the response using requested-attributes
4861 * and document-format attributes that may be provided by the client.
4864 curtime
= time(NULL
);
4866 if (!ra
|| cupsArrayFind(ra
, "marker-change-time"))
4867 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4868 "marker-change-time", printer
->marker_time
);
4870 if (printer
->num_printers
> 0 &&
4871 (!ra
|| cupsArrayFind(ra
, "member-uris")))
4873 ipp_attribute_t
*member_uris
; /* member-uris attribute */
4874 cupsd_printer_t
*p2
; /* Printer in class */
4875 ipp_attribute_t
*p2_uri
; /* printer-uri-supported for class printer */
4878 if ((member_uris
= ippAddStrings(con
->response
, IPP_TAG_PRINTER
,
4879 IPP_TAG_URI
, "member-uris",
4880 printer
->num_printers
, NULL
,
4883 for (i
= 0; i
< printer
->num_printers
; i
++)
4885 p2
= printer
->printers
[i
];
4887 if ((p2_uri
= ippFindAttribute(p2
->attrs
, "printer-uri-supported",
4888 IPP_TAG_URI
)) != NULL
)
4889 member_uris
->values
[i
].string
.text
=
4890 _cupsStrRetain(p2_uri
->values
[0].string
.text
);
4893 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
,
4894 sizeof(printer_uri
), "ipp", NULL
, con
->clientname
,
4896 (p2
->type
& CUPS_PRINTER_CLASS
) ?
4897 "/classes/%s" : "/printers/%s", p2
->name
);
4898 member_uris
->values
[i
].string
.text
= _cupsStrAlloc(printer_uri
);
4904 if (printer
->alert
&& (!ra
|| cupsArrayFind(ra
, "printer-alert")))
4905 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_STRING
,
4906 "printer-alert", NULL
, printer
->alert
);
4908 if (printer
->alert_description
&&
4909 (!ra
|| cupsArrayFind(ra
, "printer-alert-description")))
4910 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4911 "printer-alert-description", NULL
,
4912 printer
->alert_description
);
4914 if (!ra
|| cupsArrayFind(ra
, "printer-config-change-date-time"))
4915 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-config-change-date-time", ippTimeToDate(printer
->config_time
));
4917 if (!ra
|| cupsArrayFind(ra
, "printer-config-change-time"))
4918 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4919 "printer-config-change-time", printer
->config_time
);
4921 if (!ra
|| cupsArrayFind(ra
, "printer-current-time"))
4922 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-current-time",
4923 ippTimeToDate(curtime
));
4925 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
4926 if (!ra
|| cupsArrayFind(ra
, "printer-dns-sd-name"))
4928 if (printer
->reg_name
)
4929 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4930 "printer-dns-sd-name", NULL
, printer
->reg_name
);
4932 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
4933 "printer-dns-sd-name", 0);
4935 #endif /* HAVE_DNSSD || HAVE_AVAHI */
4937 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy"))
4938 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4939 "printer-error-policy", NULL
, printer
->error_policy
);
4941 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy-supported"))
4943 static const char * const errors
[] =/* printer-error-policy-supported values */
4946 "retry-current-job",
4951 if (printer
->type
& CUPS_PRINTER_CLASS
)
4952 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
4953 "printer-error-policy-supported", NULL
, "retry-current-job");
4955 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
4956 "printer-error-policy-supported",
4957 sizeof(errors
) / sizeof(errors
[0]), NULL
, errors
);
4960 if (!ra
|| cupsArrayFind(ra
, "printer-icons"))
4962 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_icons
, sizeof(printer_icons
),
4963 "http", NULL
, con
->clientname
, con
->clientport
,
4964 "/icons/%s.png", printer
->name
);
4965 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-icons",
4966 NULL
, printer_icons
);
4967 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-icons=\"%s\"", printer_icons
);
4970 if (!ra
|| cupsArrayFind(ra
, "printer-is-accepting-jobs"))
4971 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs", (char)printer
->accepting
);
4973 if (!ra
|| cupsArrayFind(ra
, "printer-is-shared"))
4974 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-shared", (char)printer
->shared
);
4976 if (!ra
|| cupsArrayFind(ra
, "printer-more-info"))
4978 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
4979 "http", NULL
, con
->clientname
, con
->clientport
,
4980 (printer
->type
& CUPS_PRINTER_CLASS
) ?
4981 "/classes/%s" : "/printers/%s", printer
->name
);
4982 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
4983 "printer-more-info", NULL
, printer_uri
);
4986 if (!ra
|| cupsArrayFind(ra
, "printer-op-policy"))
4987 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4988 "printer-op-policy", NULL
, printer
->op_policy
);
4990 if (!ra
|| cupsArrayFind(ra
, "printer-state"))
4991 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
4994 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-date-time"))
4995 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-state-change-date-time", ippTimeToDate(printer
->state_time
));
4997 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-time"))
4998 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4999 "printer-state-change-time", printer
->state_time
);
5001 if (!ra
|| cupsArrayFind(ra
, "printer-state-message"))
5002 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5003 "printer-state-message", NULL
, printer
->state_message
);
5005 if (!ra
|| cupsArrayFind(ra
, "printer-state-reasons"))
5006 add_printer_state_reasons(con
, printer
);
5008 if (!ra
|| cupsArrayFind(ra
, "printer-type"))
5010 cups_ptype_t type
; /* printer-type value */
5013 * Add the CUPS-specific printer-type attribute...
5016 type
= printer
->type
;
5018 if (printer
== DefaultPrinter
)
5019 type
|= CUPS_PRINTER_DEFAULT
;
5021 if (!printer
->accepting
)
5022 type
|= CUPS_PRINTER_REJECTING
;
5024 if (!printer
->shared
)
5025 type
|= CUPS_PRINTER_NOT_SHARED
;
5027 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-type", (int)type
);
5030 if (!ra
|| cupsArrayFind(ra
, "printer-up-time"))
5031 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5032 "printer-up-time", curtime
);
5034 if (!ra
|| cupsArrayFind(ra
, "printer-uri-supported"))
5036 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5037 "ipp", NULL
, con
->clientname
, con
->clientport
,
5038 (printer
->type
& CUPS_PRINTER_CLASS
) ?
5039 "/classes/%s" : "/printers/%s", printer
->name
);
5040 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5041 "printer-uri-supported", NULL
, printer_uri
);
5042 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-uri-supported=\"%s\"",
5046 if (!ra
|| cupsArrayFind(ra
, "queued-job-count"))
5047 add_queued_job_count(con
, printer
);
5049 copy_attrs(con
->response
, printer
->attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
5050 if (printer
->ppd_attrs
)
5051 copy_attrs(con
->response
, printer
->ppd_attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
5052 copy_attrs(con
->response
, CommonData
, ra
, IPP_TAG_ZERO
, IPP_TAG_COPY
, NULL
);
5057 * 'copy_subscription_attrs()' - Copy subscription attributes.
5061 copy_subscription_attrs(
5062 cupsd_client_t
*con
, /* I - Client connection */
5063 cupsd_subscription_t
*sub
, /* I - Subscription */
5064 cups_array_t
*ra
, /* I - Requested attributes array */
5065 cups_array_t
*exclude
) /* I - Private attributes array */
5067 ipp_attribute_t
*attr
; /* Current attribute */
5068 char printer_uri
[HTTP_MAX_URI
];
5070 int count
; /* Number of events */
5071 unsigned mask
; /* Current event mask */
5072 const char *name
; /* Current event name */
5075 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5076 "copy_subscription_attrs(con=%p, sub=%p, ra=%p, exclude=%p)",
5077 con
, sub
, ra
, exclude
);
5080 * Copy the subscription attributes to the response using the
5081 * requested-attributes attribute that may be provided by the client.
5084 if (!exclude
|| !cupsArrayFind(exclude
, "all"))
5086 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-events")) &&
5087 (!ra
|| cupsArrayFind(ra
, "notify-events")))
5089 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_subscription_attrs: notify-events");
5091 if ((name
= cupsdEventName((cupsd_eventmask_t
)sub
->mask
)) != NULL
)
5094 * Simple event list...
5097 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
,
5098 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5099 "notify-events", NULL
, name
);
5104 * Complex event list...
5107 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5108 if (sub
->mask
& mask
)
5111 attr
= ippAddStrings(con
->response
, IPP_TAG_SUBSCRIPTION
,
5112 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5113 "notify-events", count
, NULL
, NULL
);
5115 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5116 if (sub
->mask
& mask
)
5118 attr
->values
[count
].string
.text
=
5119 (char *)cupsdEventName((cupsd_eventmask_t
)mask
);
5126 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-lease-duration")) &&
5127 (!sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-lease-duration"))))
5128 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5129 "notify-lease-duration", sub
->lease
);
5131 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-recipient-uri")) &&
5132 (sub
->recipient
&& (!ra
|| cupsArrayFind(ra
, "notify-recipient-uri"))))
5133 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5134 "notify-recipient-uri", NULL
, sub
->recipient
);
5135 else if ((!exclude
|| !cupsArrayFind(exclude
, "notify-pull-method")) &&
5136 (!ra
|| cupsArrayFind(ra
, "notify-pull-method")))
5137 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_KEYWORD
,
5138 "notify-pull-method", NULL
, "ippget");
5140 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-subscriber-user-name")) &&
5141 (!ra
|| cupsArrayFind(ra
, "notify-subscriber-user-name")))
5142 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_NAME
,
5143 "notify-subscriber-user-name", NULL
, sub
->owner
);
5145 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-time-interval")) &&
5146 (!ra
|| cupsArrayFind(ra
, "notify-time-interval")))
5147 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5148 "notify-time-interval", sub
->interval
);
5150 if (sub
->user_data_len
> 0 &&
5151 (!exclude
|| !cupsArrayFind(exclude
, "notify-user-data")) &&
5152 (!ra
|| cupsArrayFind(ra
, "notify-user-data")))
5153 ippAddOctetString(con
->response
, IPP_TAG_SUBSCRIPTION
, "notify-user-data",
5154 sub
->user_data
, sub
->user_data_len
);
5157 if (sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-job-id")))
5158 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5159 "notify-job-id", sub
->job
->id
);
5161 if (sub
->dest
&& (!ra
|| cupsArrayFind(ra
, "notify-printer-uri")))
5163 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5164 "ipp", NULL
, con
->clientname
, con
->clientport
,
5165 "/printers/%s", sub
->dest
->name
);
5166 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5167 "notify-printer-uri", NULL
, printer_uri
);
5170 if (!ra
|| cupsArrayFind(ra
, "notify-subscription-id"))
5171 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5172 "notify-subscription-id", sub
->id
);
5177 * 'create_job()' - Print a file to a printer or class.
5181 create_job(cupsd_client_t
*con
, /* I - Client connection */
5182 ipp_attribute_t
*uri
) /* I - Printer URI */
5184 int i
; /* Looping var */
5185 cupsd_printer_t
*printer
; /* Printer */
5186 cupsd_job_t
*job
; /* New job */
5187 static const char * const forbidden_attrs
[] =
5188 { /* List of forbidden attributes */
5192 "document-natural-language"
5196 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "create_job(%p[%d], %s)", con
,
5197 con
->number
, uri
->values
[0].string
.text
);
5200 * Is the destination valid?
5203 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
5209 send_ipp_status(con
, IPP_NOT_FOUND
,
5210 _("The printer or class does not exist."));
5215 * Check for invalid Create-Job attributes and log a warning or error depending
5216 * on whether cupsd is running in "strict conformance" mode...
5220 i
< (int)(sizeof(forbidden_attrs
) / sizeof(forbidden_attrs
[0]));
5222 if (ippFindAttribute(con
->request
, forbidden_attrs
[i
], IPP_TAG_ZERO
))
5224 if (StrictConformance
)
5226 send_ipp_status(con
, IPP_BAD_REQUEST
,
5227 _("The '%s' operation attribute cannot be supplied in a "
5228 "Create-Job request."), forbidden_attrs
[i
]);
5232 cupsdLogMessage(CUPSD_LOG_WARN
,
5233 "Unexpected '%s' operation attribute in a Create-Job "
5234 "request.", forbidden_attrs
[i
]);
5238 * Create the job object...
5241 if ((job
= add_job(con
, printer
, NULL
)) == NULL
)
5244 job
->pending_timeout
= 1;
5247 * Save and log the job...
5250 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
5251 job
->dest
, job
->username
);
5256 * 'create_requested_array()' - Create an array for the requested-attributes.
5259 static cups_array_t
* /* O - Array of attributes or NULL */
5260 create_requested_array(ipp_t
*request
) /* I - IPP request */
5262 cups_array_t
*ra
; /* Requested attributes array */
5266 * Create the array for standard attributes...
5269 ra
= ippCreateRequestedArray(request
);
5272 * Add CUPS defaults as needed...
5275 if (cupsArrayFind(ra
, "printer-defaults"))
5278 * Include user-set defaults...
5281 char *name
; /* Option name */
5283 cupsArrayRemove(ra
, "printer-defaults");
5285 for (name
= (char *)cupsArrayFirst(CommonDefaults
);
5287 name
= (char *)cupsArrayNext(CommonDefaults
))
5288 if (!cupsArrayFind(ra
, name
))
5289 cupsArrayAdd(ra
, name
);
5297 * 'create_subscriptions()' - Create one or more notification subscriptions.
5301 create_subscriptions(
5302 cupsd_client_t
*con
, /* I - Client connection */
5303 ipp_attribute_t
*uri
) /* I - Printer URI */
5305 http_status_t status
; /* Policy status */
5306 int i
; /* Looping var */
5307 ipp_attribute_t
*attr
; /* Current attribute */
5308 cups_ptype_t dtype
; /* Destination type (printer/class) */
5309 char scheme
[HTTP_MAX_URI
],
5310 /* Scheme portion of URI */
5311 userpass
[HTTP_MAX_URI
],
5312 /* Username portion of URI */
5314 /* Host portion of URI */
5315 resource
[HTTP_MAX_URI
];
5316 /* Resource portion of URI */
5317 int port
; /* Port portion of URI */
5318 cupsd_printer_t
*printer
; /* Printer/class */
5319 cupsd_job_t
*job
; /* Job */
5320 int jobid
; /* Job ID */
5321 cupsd_subscription_t
*sub
; /* Subscription object */
5322 const char *username
, /* requesting-user-name or
5323 authenticated username */
5324 *recipient
, /* notify-recipient-uri */
5325 *pullmethod
; /* notify-pull-method */
5326 ipp_attribute_t
*user_data
; /* notify-user-data */
5327 int interval
, /* notify-time-interval */
5328 lease
; /* notify-lease-duration */
5329 unsigned mask
; /* notify-events */
5330 ipp_attribute_t
*notify_events
,/* notify-events(-default) */
5331 *notify_lease
; /* notify-lease-duration(-default) */
5335 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
5337 if (attr
->group_tag
!= IPP_TAG_ZERO
)
5338 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "g%04x v%04x %s", attr
->group_tag
,
5339 attr
->value_tag
, attr
->name
);
5341 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "----SEP----");
5346 * Is the destination valid?
5349 cupsdLogMessage(CUPSD_LOG_DEBUG
, "create_subscriptions(con=%p(%d), uri=\"%s\")", con
, con
->number
, uri
->values
[0].string
.text
);
5351 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
5352 sizeof(scheme
), userpass
, sizeof(userpass
), host
,
5353 sizeof(host
), &port
, resource
, sizeof(resource
));
5355 if (!strcmp(resource
, "/"))
5357 dtype
= (cups_ptype_t
)0;
5360 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
5362 dtype
= (cups_ptype_t
)0;
5365 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
5367 dtype
= CUPS_PRINTER_CLASS
;
5370 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
5376 send_ipp_status(con
, IPP_NOT_FOUND
,
5377 _("The printer or class does not exist."));
5387 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
5390 send_http_error(con
, status
, printer
);
5394 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5396 send_http_error(con
, status
, NULL
);
5401 * Get the user that is requesting the subscription...
5404 username
= get_username(con
);
5407 * Find the first subscription group attribute; return if we have
5411 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
5412 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
5417 send_ipp_status(con
, IPP_BAD_REQUEST
,
5418 _("No subscription attributes in request."));
5423 * Process the subscription attributes in the request...
5426 con
->response
->request
.status
.status_code
= IPP_BAD_REQUEST
;
5434 lease
= DefaultLeaseDuration
;
5436 mask
= CUPSD_EVENT_NONE
;
5440 notify_events
= ippFindAttribute(printer
->attrs
, "notify-events-default",
5442 notify_lease
= ippFindAttribute(printer
->attrs
,
5443 "notify-lease-duration-default",
5447 lease
= notify_lease
->values
[0].integer
;
5451 notify_events
= NULL
;
5452 notify_lease
= NULL
;
5455 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
5457 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
5458 attr
->value_tag
== IPP_TAG_URI
)
5461 * Validate the recipient scheme against the ServerBin/notifier
5465 char notifier
[1024]; /* Notifier filename */
5468 recipient
= attr
->values
[0].string
.text
;
5470 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
5471 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
5472 host
, sizeof(host
), &port
,
5473 resource
, sizeof(resource
)) < HTTP_URI_OK
)
5475 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5476 _("Bad notify-recipient-uri \"%s\"."), recipient
);
5477 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5478 "notify-status-code", IPP_URI_SCHEME
);
5482 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
5484 if (access(notifier
, X_OK
))
5486 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5487 _("notify-recipient-uri URI \"%s\" uses unknown "
5488 "scheme."), recipient
);
5489 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5490 "notify-status-code", IPP_URI_SCHEME
);
5494 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
5496 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5497 _("notify-recipient-uri URI \"%s\" is already used."),
5499 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5500 "notify-status-code", IPP_ATTRIBUTES
);
5504 else if (!strcmp(attr
->name
, "notify-pull-method") &&
5505 attr
->value_tag
== IPP_TAG_KEYWORD
)
5507 pullmethod
= attr
->values
[0].string
.text
;
5509 if (strcmp(pullmethod
, "ippget"))
5511 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5512 _("Bad notify-pull-method \"%s\"."), pullmethod
);
5513 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5514 "notify-status-code", IPP_ATTRIBUTES
);
5518 else if (!strcmp(attr
->name
, "notify-charset") &&
5519 attr
->value_tag
== IPP_TAG_CHARSET
&&
5520 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
5521 strcmp(attr
->values
[0].string
.text
, "utf-8"))
5523 send_ipp_status(con
, IPP_CHARSET
,
5524 _("Character set \"%s\" not supported."),
5525 attr
->values
[0].string
.text
);
5528 else if (!strcmp(attr
->name
, "notify-natural-language") &&
5529 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
5530 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
5532 send_ipp_status(con
, IPP_CHARSET
,
5533 _("Language \"%s\" not supported."),
5534 attr
->values
[0].string
.text
);
5537 else if (!strcmp(attr
->name
, "notify-user-data") &&
5538 attr
->value_tag
== IPP_TAG_STRING
)
5540 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
5542 send_ipp_status(con
, IPP_REQUEST_VALUE
,
5543 _("The notify-user-data value is too large "
5544 "(%d > 63 octets)."),
5545 attr
->values
[0].unknown
.length
);
5551 else if (!strcmp(attr
->name
, "notify-events") &&
5552 attr
->value_tag
== IPP_TAG_KEYWORD
)
5553 notify_events
= attr
;
5554 else if (!strcmp(attr
->name
, "notify-lease-duration") &&
5555 attr
->value_tag
== IPP_TAG_INTEGER
)
5556 lease
= attr
->values
[0].integer
;
5557 else if (!strcmp(attr
->name
, "notify-time-interval") &&
5558 attr
->value_tag
== IPP_TAG_INTEGER
)
5559 interval
= attr
->values
[0].integer
;
5560 else if (!strcmp(attr
->name
, "notify-job-id") &&
5561 attr
->value_tag
== IPP_TAG_INTEGER
)
5562 jobid
= attr
->values
[0].integer
;
5569 for (i
= 0; i
< notify_events
->num_values
; i
++)
5570 mask
|= cupsdEventValue(notify_events
->values
[i
].string
.text
);
5574 cupsdLogMessage(CUPSD_LOG_DEBUG
, "recipient=\"%s\"", recipient
);
5576 cupsdLogMessage(CUPSD_LOG_DEBUG
, "pullmethod=\"%s\"", pullmethod
);
5577 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-lease-duration=%d", lease
);
5578 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-time-interval=%d", interval
);
5580 if (!recipient
&& !pullmethod
)
5583 if (mask
== CUPSD_EVENT_NONE
)
5586 mask
= CUPSD_EVENT_JOB_COMPLETED
;
5588 mask
= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
5591 send_ipp_status(con
, IPP_BAD_REQUEST
,
5592 _("notify-events not specified."));
5597 if (MaxLeaseDuration
&& (lease
== 0 || lease
> MaxLeaseDuration
))
5599 cupsdLogMessage(CUPSD_LOG_INFO
,
5600 "create_subscriptions: Limiting notify-lease-duration to "
5603 lease
= MaxLeaseDuration
;
5608 if ((job
= cupsdFindJob(jobid
)) == NULL
)
5610 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
5618 if ((sub
= cupsdAddSubscription(mask
, printer
, job
, recipient
, 0)) == NULL
)
5620 send_ipp_status(con
, IPP_TOO_MANY_SUBSCRIPTIONS
,
5621 _("There are too many subscriptions."));
5626 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription #%d for job %d.",
5629 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5630 "Added subscription #%d for printer \"%s\".",
5631 sub
->id
, printer
->name
);
5633 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription #%d for server.",
5636 sub
->interval
= interval
;
5638 sub
->expire
= lease
? time(NULL
) + lease
: 0;
5640 cupsdSetString(&sub
->owner
, username
);
5644 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
5645 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
5646 (size_t)sub
->user_data_len
);
5649 ippAddSeparator(con
->response
);
5650 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5651 "notify-subscription-id", sub
->id
);
5653 con
->response
->request
.status
.status_code
= IPP_OK
;
5659 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
5664 * 'delete_printer()' - Remove a printer or class from the system.
5668 delete_printer(cupsd_client_t
*con
, /* I - Client connection */
5669 ipp_attribute_t
*uri
) /* I - URI of printer or class */
5671 http_status_t status
; /* Policy status */
5672 cups_ptype_t dtype
; /* Destination type (printer/class) */
5673 cupsd_printer_t
*printer
; /* Printer/class */
5674 char filename
[1024]; /* Script/PPD filename */
5677 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "delete_printer(%p[%d], %s)", con
,
5678 con
->number
, uri
->values
[0].string
.text
);
5681 * Do we have a valid URI?
5684 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
5690 send_ipp_status(con
, IPP_NOT_FOUND
,
5691 _("The printer or class does not exist."));
5699 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5701 send_http_error(con
, status
, NULL
);
5706 * Remove old jobs...
5709 cupsdCancelJobs(printer
->name
, NULL
, 1);
5712 * Remove old subscriptions and send a "deleted printer" event...
5715 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED
, printer
, NULL
,
5716 "%s \"%s\" deleted by \"%s\".",
5717 (dtype
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
5718 printer
->name
, get_username(con
));
5720 cupsdExpireSubscriptions(printer
, NULL
);
5723 * Remove any old PPD or script files...
5726 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
,
5729 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s.O", ServerRoot
,
5733 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
5736 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd.O", ServerRoot
,
5740 snprintf(filename
, sizeof(filename
), "%s/%s.png", CacheDir
, printer
->name
);
5743 snprintf(filename
, sizeof(filename
), "%s/%s.data", CacheDir
, printer
->name
);
5747 * Unregister color profiles...
5750 cupsdUnregisterColor(printer
);
5752 if (dtype
& CUPS_PRINTER_CLASS
)
5754 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" deleted by \"%s\".",
5755 printer
->name
, get_username(con
));
5757 cupsdDeletePrinter(printer
, 0);
5758 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
5762 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" deleted by \"%s\".",
5763 printer
->name
, get_username(con
));
5765 if (cupsdDeletePrinter(printer
, 0))
5766 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
5768 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
5771 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
5774 * Return with no errors...
5777 con
->response
->request
.status
.status_code
= IPP_OK
;
5782 * 'get_default()' - Get the default destination.
5786 get_default(cupsd_client_t
*con
) /* I - Client connection */
5788 http_status_t status
; /* Policy status */
5789 cups_array_t
*ra
; /* Requested attributes array */
5792 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_default(%p[%d])", con
, con
->number
);
5798 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5800 send_http_error(con
, status
, NULL
);
5806 ra
= create_requested_array(con
->request
);
5808 copy_printer_attrs(con
, DefaultPrinter
, ra
);
5810 cupsArrayDelete(ra
);
5812 con
->response
->request
.status
.status_code
= IPP_OK
;
5815 send_ipp_status(con
, IPP_NOT_FOUND
, _("No default printer."));
5820 * 'get_devices()' - Get the list of available devices on the local system.
5824 get_devices(cupsd_client_t
*con
) /* I - Client connection */
5826 http_status_t status
; /* Policy status */
5827 ipp_attribute_t
*limit
, /* limit attribute */
5828 *timeout
, /* timeout attribute */
5829 *requested
, /* requested-attributes attribute */
5830 *exclude
, /* exclude-schemes attribute */
5831 *include
; /* include-schemes attribute */
5832 char command
[1024], /* cups-deviced command */
5833 options
[2048], /* Options to pass to command */
5835 /* String for requested attributes */
5837 /* String for excluded schemes */
5839 /* String for included schemes */
5842 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_devices(%p[%d])", con
, con
->number
);
5848 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5850 send_http_error(con
, status
, NULL
);
5855 * Run cups-deviced command with the given options...
5858 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
5859 timeout
= ippFindAttribute(con
->request
, "timeout", IPP_TAG_INTEGER
);
5860 requested
= ippFindAttribute(con
->request
, "requested-attributes",
5862 exclude
= ippFindAttribute(con
->request
, "exclude-schemes", IPP_TAG_NAME
);
5863 include
= ippFindAttribute(con
->request
, "include-schemes", IPP_TAG_NAME
);
5866 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
5868 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
5871 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
5873 exclude_str
[0] = '\0';
5876 url_encode_attr(include
, include_str
, sizeof(include_str
));
5878 include_str
[0] = '\0';
5880 snprintf(command
, sizeof(command
), "%s/daemon/cups-deviced", ServerBin
);
5881 snprintf(options
, sizeof(options
),
5882 "%d+%d+%d+%d+%s%s%s%s%s",
5883 con
->request
->request
.op
.request_id
,
5884 limit
? limit
->values
[0].integer
: 0,
5885 timeout
? timeout
->values
[0].integer
: 15,
5888 exclude_str
[0] ? "%20" : "", exclude_str
,
5889 include_str
[0] ? "%20" : "", include_str
);
5891 if (cupsdSendCommand(con
, command
, options
, 1))
5894 * Command started successfully, don't send an IPP response here...
5897 ippDelete(con
->response
);
5898 con
->response
= NULL
;
5903 * Command failed, return "internal error" so the user knows something
5907 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
5908 _("cups-deviced failed to execute."));
5914 * 'get_document()' - Get a copy of a job file.
5918 get_document(cupsd_client_t
*con
, /* I - Client connection */
5919 ipp_attribute_t
*uri
) /* I - Job URI */
5921 http_status_t status
; /* Policy status */
5922 ipp_attribute_t
*attr
; /* Current attribute */
5923 int jobid
; /* Job ID */
5924 int docnum
; /* Document number */
5925 cupsd_job_t
*job
; /* Current job */
5926 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
5927 username
[HTTP_MAX_URI
], /* Username portion of URI */
5928 host
[HTTP_MAX_URI
], /* Host portion of URI */
5929 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
5930 int port
; /* Port portion of URI */
5931 char filename
[1024], /* Filename for document */
5932 format
[1024]; /* Format for document */
5935 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_document(%p[%d], %s)", con
,
5936 con
->number
, uri
->values
[0].string
.text
);
5939 * See if we have a job URI or a printer URI...
5942 if (!strcmp(uri
->name
, "printer-uri"))
5945 * Got a printer URI; see if we also have a job-id attribute...
5948 if ((attr
= ippFindAttribute(con
->request
, "job-id",
5949 IPP_TAG_INTEGER
)) == NULL
)
5951 send_ipp_status(con
, IPP_BAD_REQUEST
,
5952 _("Got a printer-uri attribute but no job-id."));
5956 jobid
= attr
->values
[0].integer
;
5961 * Got a job URI; parse it to get the job ID...
5964 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
5965 sizeof(scheme
), username
, sizeof(username
), host
,
5966 sizeof(host
), &port
, resource
, sizeof(resource
));
5968 if (strncmp(resource
, "/jobs/", 6))
5974 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
5975 uri
->values
[0].string
.text
);
5979 jobid
= atoi(resource
+ 6);
5983 * See if the job exists...
5986 if ((job
= cupsdFindJob(jobid
)) == NULL
)
5989 * Nope - return a "not found" error...
5992 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
6000 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
,
6001 job
->username
)) != HTTP_OK
)
6003 send_http_error(con
, status
, NULL
);
6008 * Get the document number...
6011 if ((attr
= ippFindAttribute(con
->request
, "document-number",
6012 IPP_TAG_INTEGER
)) == NULL
)
6014 send_ipp_status(con
, IPP_BAD_REQUEST
,
6015 _("Missing document-number attribute."));
6019 if ((docnum
= attr
->values
[0].integer
) < 1 || docnum
> job
->num_files
||
6020 attr
->num_values
> 1)
6022 send_ipp_status(con
, IPP_NOT_FOUND
,
6023 _("Document #%d does not exist in job #%d."), docnum
,
6028 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, jobid
,
6030 if ((con
->file
= open(filename
, O_RDONLY
)) == -1)
6032 cupsdLogMessage(CUPSD_LOG_ERROR
,
6033 "Unable to open document %d in job %d - %s", docnum
, jobid
,
6035 send_ipp_status(con
, IPP_NOT_FOUND
,
6036 _("Unable to open document #%d in job #%d."), docnum
,
6041 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
6045 snprintf(format
, sizeof(format
), "%s/%s", job
->filetypes
[docnum
- 1]->super
,
6046 job
->filetypes
[docnum
- 1]->type
);
6048 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format",
6050 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "document-number",
6052 if ((attr
= ippFindAttribute(job
->attrs
, "document-name",
6053 IPP_TAG_NAME
)) != NULL
)
6054 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name",
6055 NULL
, attr
->values
[0].string
.text
);
6060 * 'get_job_attrs()' - Get job attributes.
6064 get_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
6065 ipp_attribute_t
*uri
) /* I - Job URI */
6067 http_status_t status
; /* Policy status */
6068 ipp_attribute_t
*attr
; /* Current attribute */
6069 int jobid
; /* Job ID */
6070 cupsd_job_t
*job
; /* Current job */
6071 cupsd_printer_t
*printer
; /* Current printer */
6072 cupsd_policy_t
*policy
; /* Current security policy */
6073 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6074 username
[HTTP_MAX_URI
], /* Username portion of URI */
6075 host
[HTTP_MAX_URI
], /* Host portion of URI */
6076 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6077 int port
; /* Port portion of URI */
6078 cups_array_t
*ra
, /* Requested attributes array */
6079 *exclude
; /* Private attributes array */
6082 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_job_attrs(%p[%d], %s)", con
,
6083 con
->number
, uri
->values
[0].string
.text
);
6086 * See if we have a job URI or a printer URI...
6089 if (!strcmp(uri
->name
, "printer-uri"))
6092 * Got a printer URI; see if we also have a job-id attribute...
6095 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6096 IPP_TAG_INTEGER
)) == NULL
)
6098 send_ipp_status(con
, IPP_BAD_REQUEST
,
6099 _("Got a printer-uri attribute but no job-id."));
6103 jobid
= attr
->values
[0].integer
;
6108 * Got a job URI; parse it to get the job ID...
6111 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6112 sizeof(scheme
), username
, sizeof(username
), host
,
6113 sizeof(host
), &port
, resource
, sizeof(resource
));
6115 if (strncmp(resource
, "/jobs/", 6))
6121 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
6122 uri
->values
[0].string
.text
);
6126 jobid
= atoi(resource
+ 6);
6130 * See if the job exists...
6133 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6136 * Nope - return a "not found" error...
6139 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
6147 if ((printer
= job
->printer
) == NULL
)
6148 printer
= cupsdFindDest(job
->dest
);
6151 policy
= printer
->op_policy_ptr
;
6153 policy
= DefaultPolicyPtr
;
6155 if ((status
= cupsdCheckPolicy(policy
, con
, job
->username
)) != HTTP_OK
)
6157 send_http_error(con
, status
, NULL
);
6161 exclude
= cupsdGetPrivateAttrs(policy
, con
, printer
, job
->username
);
6164 * Copy attributes...
6169 ra
= create_requested_array(con
->request
);
6170 copy_job_attrs(con
, job
, ra
, exclude
);
6171 cupsArrayDelete(ra
);
6173 con
->response
->request
.status
.status_code
= IPP_OK
;
6178 * 'get_jobs()' - Get a list of jobs for the specified printer.
6182 get_jobs(cupsd_client_t
*con
, /* I - Client connection */
6183 ipp_attribute_t
*uri
) /* I - Printer URI */
6185 http_status_t status
; /* Policy status */
6186 ipp_attribute_t
*attr
; /* Current attribute */
6187 const char *dest
; /* Destination */
6188 cups_ptype_t dtype
; /* Destination type (printer/class) */
6189 cups_ptype_t dmask
; /* Destination type mask */
6190 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6191 username
[HTTP_MAX_URI
], /* Username portion of URI */
6192 host
[HTTP_MAX_URI
], /* Host portion of URI */
6193 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6194 int port
; /* Port portion of URI */
6195 int job_comparison
; /* Job comparison */
6196 ipp_jstate_t job_state
; /* job-state value */
6197 int first_job_id
= 1, /* First job ID */
6198 first_index
= 1, /* First index */
6199 current_index
= 0; /* Current index */
6200 int limit
= 0; /* Maximum number of jobs to return */
6201 int count
; /* Number of jobs that match */
6202 int need_load_job
= 0; /* Do we need to load the job? */
6203 const char *job_attr
; /* Job attribute requested */
6204 ipp_attribute_t
*job_ids
; /* job-ids attribute */
6205 cupsd_job_t
*job
; /* Current job pointer */
6206 cupsd_printer_t
*printer
; /* Printer */
6207 cups_array_t
*list
; /* Which job list... */
6208 int delete_list
= 0; /* Delete the list afterwards? */
6209 cups_array_t
*ra
, /* Requested attributes array */
6210 *exclude
; /* Private attributes array */
6211 cupsd_policy_t
*policy
; /* Current policy */
6214 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs(%p[%d], %s)", con
, con
->number
,
6215 uri
->values
[0].string
.text
);
6218 * Is the destination valid?
6221 if (strcmp(uri
->name
, "printer-uri"))
6223 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No printer-uri in request."));
6227 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6228 sizeof(scheme
), username
, sizeof(username
), host
,
6229 sizeof(host
), &port
, resource
, sizeof(resource
));
6231 if (!strcmp(resource
, "/") || !strcmp(resource
, "/jobs"))
6234 dtype
= (cups_ptype_t
)0;
6235 dmask
= (cups_ptype_t
)0;
6238 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6241 dtype
= (cups_ptype_t
)0;
6242 dmask
= CUPS_PRINTER_CLASS
;
6245 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6248 dtype
= CUPS_PRINTER_CLASS
;
6249 dmask
= CUPS_PRINTER_CLASS
;
6252 else if ((dest
= cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
,
6259 send_ipp_status(con
, IPP_NOT_FOUND
,
6260 _("The printer or class does not exist."));
6265 dtype
&= CUPS_PRINTER_CLASS
;
6266 dmask
= CUPS_PRINTER_CLASS
;
6274 policy
= printer
->op_policy_ptr
;
6276 policy
= DefaultPolicyPtr
;
6278 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
6280 send_http_error(con
, status
, NULL
);
6284 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
6287 * See if the "which-jobs" attribute have been specified...
6290 if ((attr
= ippFindAttribute(con
->request
, "which-jobs",
6291 IPP_TAG_KEYWORD
)) != NULL
&& job_ids
)
6293 send_ipp_status(con
, IPP_CONFLICT
,
6294 _("The %s attribute cannot be provided with job-ids."),
6298 else if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "not-completed"))
6300 job_comparison
= -1;
6301 job_state
= IPP_JOB_STOPPED
;
6304 else if (!strcmp(attr
->values
[0].string
.text
, "completed"))
6307 job_state
= IPP_JOB_CANCELED
;
6308 list
= cupsdGetCompletedJobs(printer
);
6311 else if (!strcmp(attr
->values
[0].string
.text
, "aborted"))
6314 job_state
= IPP_JOB_ABORTED
;
6315 list
= cupsdGetCompletedJobs(printer
);
6318 else if (!strcmp(attr
->values
[0].string
.text
, "all"))
6321 job_state
= IPP_JOB_PENDING
;
6324 else if (!strcmp(attr
->values
[0].string
.text
, "canceled"))
6327 job_state
= IPP_JOB_CANCELED
;
6328 list
= cupsdGetCompletedJobs(printer
);
6331 else if (!strcmp(attr
->values
[0].string
.text
, "pending"))
6334 job_state
= IPP_JOB_PENDING
;
6337 else if (!strcmp(attr
->values
[0].string
.text
, "pending-held"))
6340 job_state
= IPP_JOB_HELD
;
6343 else if (!strcmp(attr
->values
[0].string
.text
, "processing"))
6346 job_state
= IPP_JOB_PROCESSING
;
6347 list
= PrintingJobs
;
6349 else if (!strcmp(attr
->values
[0].string
.text
, "processing-stopped"))
6352 job_state
= IPP_JOB_STOPPED
;
6357 send_ipp_status(con
, IPP_ATTRIBUTES
,
6358 _("The which-jobs value \"%s\" is not supported."),
6359 attr
->values
[0].string
.text
);
6360 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
6361 "which-jobs", NULL
, attr
->values
[0].string
.text
);
6366 * See if they want to limit the number of jobs reported...
6369 if ((attr
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
)) != NULL
)
6373 send_ipp_status(con
, IPP_CONFLICT
,
6374 _("The %s attribute cannot be provided with job-ids."),
6379 limit
= attr
->values
[0].integer
;
6382 if ((attr
= ippFindAttribute(con
->request
, "first-index", IPP_TAG_INTEGER
)) != NULL
)
6386 send_ipp_status(con
, IPP_CONFLICT
,
6387 _("The %s attribute cannot be provided with job-ids."),
6392 first_index
= attr
->values
[0].integer
;
6394 else if ((attr
= ippFindAttribute(con
->request
, "first-job-id", IPP_TAG_INTEGER
)) != NULL
)
6398 send_ipp_status(con
, IPP_CONFLICT
,
6399 _("The %s attribute cannot be provided with job-ids."),
6404 first_job_id
= attr
->values
[0].integer
;
6408 * See if we only want to see jobs for a specific user...
6411 if ((attr
= ippFindAttribute(con
->request
, "my-jobs", IPP_TAG_BOOLEAN
)) != NULL
&& job_ids
)
6413 send_ipp_status(con
, IPP_CONFLICT
,
6414 _("The %s attribute cannot be provided with job-ids."),
6418 else if (attr
&& attr
->values
[0].boolean
)
6419 strlcpy(username
, get_username(con
), sizeof(username
));
6423 ra
= create_requested_array(con
->request
);
6424 for (job_attr
= (char *)cupsArrayFirst(ra
); job_attr
; job_attr
= (char *)cupsArrayNext(ra
))
6425 if (strcmp(job_attr
, "job-id") &&
6426 strcmp(job_attr
, "job-k-octets") &&
6427 strcmp(job_attr
, "job-media-progress") &&
6428 strcmp(job_attr
, "job-more-info") &&
6429 strcmp(job_attr
, "job-name") &&
6430 strcmp(job_attr
, "job-originating-user-name") &&
6431 strcmp(job_attr
, "job-preserved") &&
6432 strcmp(job_attr
, "job-printer-up-time") &&
6433 strcmp(job_attr
, "job-printer-uri") &&
6434 strcmp(job_attr
, "job-state") &&
6435 strcmp(job_attr
, "job-state-reasons") &&
6436 strcmp(job_attr
, "job-uri") &&
6437 strcmp(job_attr
, "time-at-completed") &&
6438 strcmp(job_attr
, "time-at-creation") &&
6439 strcmp(job_attr
, "number-of-documents"))
6445 if (need_load_job
&& (limit
== 0 || limit
> 500) && (list
== Jobs
|| delete_list
))
6448 * Limit expensive Get-Jobs for job history to 500 jobs...
6451 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
, "limit", 500);
6454 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
, "limit", limit
);
6458 cupsdLogClient(con
, CUPSD_LOG_INFO
, "Limiting Get-Jobs response to %d jobs.", limit
);
6462 * OK, build a list of jobs for this printer...
6467 int i
; /* Looping var */
6469 for (i
= 0; i
< job_ids
->num_values
; i
++)
6471 if (!cupsdFindJob(job_ids
->values
[i
].integer
))
6475 if (i
< job_ids
->num_values
)
6477 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
6478 job_ids
->values
[i
].integer
);
6482 for (i
= 0; i
< job_ids
->num_values
; i
++)
6484 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
6486 if (need_load_job
&& !job
->attrs
)
6492 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d", job
->id
);
6498 ippAddSeparator(con
->response
);
6500 exclude
= cupsdGetPrivateAttrs(job
->printer
?
6501 job
->printer
->op_policy_ptr
:
6502 policy
, con
, job
->printer
,
6505 copy_job_attrs(con
, job
, ra
, exclude
);
6510 for (count
= 0, job
= (cupsd_job_t
*)cupsArrayFirst(list
);
6511 (limit
<= 0 || count
< limit
) && job
;
6512 job
= (cupsd_job_t
*)cupsArrayNext(list
))
6515 * Filter out jobs that don't match...
6518 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
6519 "get_jobs: job->id=%d, dest=\"%s\", username=\"%s\", "
6520 "state_value=%d, attrs=%p", job
->id
, job
->dest
,
6521 job
->username
, job
->state_value
, job
->attrs
);
6523 if (!job
->dest
|| !job
->username
)
6526 if (!job
->dest
|| !job
->username
)
6529 if ((dest
&& strcmp(job
->dest
, dest
)) &&
6530 (!job
->printer
|| !dest
|| strcmp(job
->printer
->name
, dest
)))
6532 if ((job
->dtype
& dmask
) != dtype
&&
6533 (!job
->printer
|| (job
->printer
->type
& dmask
) != dtype
))
6536 if ((job_comparison
< 0 && job
->state_value
> job_state
) ||
6537 (job_comparison
== 0 && job
->state_value
!= job_state
) ||
6538 (job_comparison
> 0 && job
->state_value
< job_state
))
6541 if (job
->id
< first_job_id
)
6545 if (current_index
< first_index
)
6548 if (need_load_job
&& !job
->attrs
)
6554 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d", job
->id
);
6559 if (username
[0] && _cups_strcasecmp(username
, job
->username
))
6563 ippAddSeparator(con
->response
);
6567 exclude
= cupsdGetPrivateAttrs(job
->printer
?
6568 job
->printer
->op_policy_ptr
:
6569 policy
, con
, job
->printer
,
6572 copy_job_attrs(con
, job
, ra
, exclude
);
6575 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: count=%d", count
);
6578 cupsArrayDelete(ra
);
6581 cupsArrayDelete(list
);
6583 con
->response
->request
.status
.status_code
= IPP_OK
;
6588 * 'get_notifications()' - Get events for a subscription.
6592 get_notifications(cupsd_client_t
*con
) /* I - Client connection */
6594 int i
, j
; /* Looping vars */
6595 http_status_t status
; /* Policy status */
6596 cupsd_subscription_t
*sub
; /* Subscription */
6597 ipp_attribute_t
*ids
, /* notify-subscription-ids */
6598 *sequences
; /* notify-sequence-numbers */
6599 int min_seq
; /* Minimum sequence number */
6600 int interval
; /* Poll interval */
6603 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_notifications(con=%p[%d])",
6607 * Get subscription attributes...
6610 ids
= ippFindAttribute(con
->request
, "notify-subscription-ids",
6612 sequences
= ippFindAttribute(con
->request
, "notify-sequence-numbers",
6617 send_ipp_status(con
, IPP_BAD_REQUEST
,
6618 _("Missing notify-subscription-ids attribute."));
6623 * Are the subscription IDs valid?
6626 for (i
= 0, interval
= 60; i
< ids
->num_values
; i
++)
6628 if ((sub
= cupsdFindSubscription(ids
->values
[i
].integer
)) == NULL
)
6631 * Bad subscription ID...
6634 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
6635 ids
->values
[i
].integer
);
6643 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
6645 con
, sub
->owner
)) != HTTP_OK
)
6647 send_http_error(con
, status
, sub
->dest
);
6652 * Check the subscription type and update the interval accordingly.
6655 if (sub
->job
&& sub
->job
->state_value
== IPP_JOB_PROCESSING
&&
6658 else if (sub
->job
&& sub
->job
->state_value
>= IPP_JOB_STOPPED
)
6660 else if (sub
->dest
&& sub
->dest
->state
== IPP_PRINTER_PROCESSING
&&
6666 * Tell the client to poll again in N seconds...
6670 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
6671 "notify-get-interval", interval
);
6673 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
6674 "printer-up-time", time(NULL
));
6677 * Copy the subscription event attributes to the response.
6680 con
->response
->request
.status
.status_code
=
6681 interval
? IPP_OK
: IPP_OK_EVENTS_COMPLETE
;
6683 for (i
= 0; i
< ids
->num_values
; i
++)
6686 * Get the subscription and sequence number...
6689 sub
= cupsdFindSubscription(ids
->values
[i
].integer
);
6691 if (sequences
&& i
< sequences
->num_values
)
6692 min_seq
= sequences
->values
[i
].integer
;
6697 * If we don't have any new events, nothing to do here...
6700 if (min_seq
> (sub
->first_event_id
+ cupsArrayCount(sub
->events
)))
6704 * Otherwise copy all of the new events...
6707 if (sub
->first_event_id
> min_seq
)
6710 j
= min_seq
- sub
->first_event_id
;
6712 for (; j
< cupsArrayCount(sub
->events
); j
++)
6714 ippAddSeparator(con
->response
);
6716 copy_attrs(con
->response
,
6717 ((cupsd_event_t
*)cupsArrayIndex(sub
->events
, j
))->attrs
, NULL
,
6718 IPP_TAG_EVENT_NOTIFICATION
, 0, NULL
);
6725 * 'get_ppd()' - Get a named PPD from the local system.
6729 get_ppd(cupsd_client_t
*con
, /* I - Client connection */
6730 ipp_attribute_t
*uri
) /* I - Printer URI or PPD name */
6732 http_status_t status
; /* Policy status */
6733 cupsd_printer_t
*dest
; /* Destination */
6734 cups_ptype_t dtype
; /* Destination type */
6737 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppd(%p[%d], %p[%s=%s])", con
,
6738 con
->number
, uri
, uri
->name
, uri
->values
[0].string
.text
);
6740 if (!strcmp(uri
->name
, "ppd-name"))
6743 * Return a PPD file from cups-driverd...
6746 char command
[1024], /* cups-driverd command */
6747 options
[1024], /* Options to pass to command */
6748 ppd_name
[1024]; /* ppd-name */
6755 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6757 send_http_error(con
, status
, NULL
);
6762 * Run cups-driverd command with the given options...
6765 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
6766 url_encode_string(uri
->values
[0].string
.text
, ppd_name
, sizeof(ppd_name
));
6767 snprintf(options
, sizeof(options
), "get+%d+%s",
6768 con
->request
->request
.op
.request_id
, ppd_name
);
6770 if (cupsdSendCommand(con
, command
, options
, 0))
6773 * Command started successfully, don't send an IPP response here...
6776 ippDelete(con
->response
);
6777 con
->response
= NULL
;
6782 * Command failed, return "internal error" so the user knows something
6786 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
6787 _("cups-driverd failed to execute."));
6790 else if (!strcmp(uri
->name
, "printer-uri") &&
6791 cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &dest
))
6793 int i
; /* Looping var */
6794 char filename
[1024]; /* PPD filename */
6801 if ((status
= cupsdCheckPolicy(dest
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
6803 send_http_error(con
, status
, dest
);
6808 * See if we need the PPD for a class or remote printer...
6811 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
6814 if ((dtype
& CUPS_PRINTER_REMOTE
) && access(filename
, 0))
6816 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
6817 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
6818 "printer-uri", NULL
, dest
->uri
);
6821 else if (dtype
& CUPS_PRINTER_CLASS
)
6823 for (i
= 0; i
< dest
->num_printers
; i
++)
6824 if (!(dest
->printers
[i
]->type
& CUPS_PRINTER_CLASS
))
6826 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
6827 dest
->printers
[i
]->name
);
6829 if (!access(filename
, 0))
6833 if (i
< dest
->num_printers
)
6834 dest
= dest
->printers
[i
];
6837 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
6838 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
6839 "printer-uri", NULL
, dest
->printers
[0]->uri
);
6845 * Found the printer with the PPD file, now see if there is one...
6848 if ((con
->file
= open(filename
, O_RDONLY
)) < 0)
6850 send_ipp_status(con
, IPP_NOT_FOUND
,
6851 _("The PPD file \"%s\" could not be opened: %s"),
6852 uri
->values
[0].string
.text
, strerror(errno
));
6856 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
6860 con
->response
->request
.status
.status_code
= IPP_OK
;
6863 send_ipp_status(con
, IPP_NOT_FOUND
,
6864 _("The PPD file \"%s\" could not be found."),
6865 uri
->values
[0].string
.text
);
6870 * 'get_ppds()' - Get the list of PPD files on the local system.
6874 get_ppds(cupsd_client_t
*con
) /* I - Client connection */
6876 http_status_t status
; /* Policy status */
6877 ipp_attribute_t
*limit
, /* Limit attribute */
6878 *device
, /* ppd-device-id attribute */
6879 *language
, /* ppd-natural-language attribute */
6880 *make
, /* ppd-make attribute */
6881 *model
, /* ppd-make-and-model attribute */
6882 *model_number
, /* ppd-model-number attribute */
6883 *product
, /* ppd-product attribute */
6884 *psversion
, /* ppd-psverion attribute */
6885 *type
, /* ppd-type attribute */
6886 *requested
, /* requested-attributes attribute */
6887 *exclude
, /* exclude-schemes attribute */
6888 *include
; /* include-schemes attribute */
6889 char command
[1024], /* cups-driverd command */
6890 options
[4096], /* Options to pass to command */
6891 device_str
[256],/* Escaped ppd-device-id string */
6893 /* Escaped ppd-natural-language */
6894 make_str
[256], /* Escaped ppd-make string */
6895 model_str
[256], /* Escaped ppd-make-and-model string */
6896 model_number_str
[256],
6897 /* ppd-model-number string */
6899 /* Escaped ppd-product string */
6901 /* Escaped ppd-psversion string */
6902 type_str
[256], /* Escaped ppd-type string */
6904 /* String for requested attributes */
6906 /* String for excluded schemes */
6908 /* String for included schemes */
6911 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppds(%p[%d])", con
, con
->number
);
6917 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6919 send_http_error(con
, status
, NULL
);
6924 * Run cups-driverd command with the given options...
6927 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
6928 device
= ippFindAttribute(con
->request
, "ppd-device-id", IPP_TAG_TEXT
);
6929 language
= ippFindAttribute(con
->request
, "ppd-natural-language",
6931 make
= ippFindAttribute(con
->request
, "ppd-make", IPP_TAG_TEXT
);
6932 model
= ippFindAttribute(con
->request
, "ppd-make-and-model",
6934 model_number
= ippFindAttribute(con
->request
, "ppd-model-number",
6936 product
= ippFindAttribute(con
->request
, "ppd-product", IPP_TAG_TEXT
);
6937 psversion
= ippFindAttribute(con
->request
, "ppd-psversion", IPP_TAG_TEXT
);
6938 type
= ippFindAttribute(con
->request
, "ppd-type", IPP_TAG_KEYWORD
);
6939 requested
= ippFindAttribute(con
->request
, "requested-attributes",
6941 exclude
= ippFindAttribute(con
->request
, "exclude-schemes",
6943 include
= ippFindAttribute(con
->request
, "include-schemes",
6947 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
6949 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
6952 url_encode_attr(device
, device_str
, sizeof(device_str
));
6954 device_str
[0] = '\0';
6957 url_encode_attr(language
, language_str
, sizeof(language_str
));
6959 language_str
[0] = '\0';
6962 url_encode_attr(make
, make_str
, sizeof(make_str
));
6967 url_encode_attr(model
, model_str
, sizeof(model_str
));
6969 model_str
[0] = '\0';
6972 snprintf(model_number_str
, sizeof(model_number_str
), "ppd-model-number=%d",
6973 model_number
->values
[0].integer
);
6975 model_number_str
[0] = '\0';
6978 url_encode_attr(product
, product_str
, sizeof(product_str
));
6980 product_str
[0] = '\0';
6983 url_encode_attr(psversion
, psversion_str
, sizeof(psversion_str
));
6985 psversion_str
[0] = '\0';
6988 url_encode_attr(type
, type_str
, sizeof(type_str
));
6993 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
6995 exclude_str
[0] = '\0';
6998 url_encode_attr(include
, include_str
, sizeof(include_str
));
7000 include_str
[0] = '\0';
7002 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7003 snprintf(options
, sizeof(options
),
7004 "list+%d+%d+%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
7005 con
->request
->request
.op
.request_id
,
7006 limit
? limit
->values
[0].integer
: 0,
7008 device
? "%20" : "", device_str
,
7009 language
? "%20" : "", language_str
,
7010 make
? "%20" : "", make_str
,
7011 model
? "%20" : "", model_str
,
7012 model_number
? "%20" : "", model_number_str
,
7013 product
? "%20" : "", product_str
,
7014 psversion
? "%20" : "", psversion_str
,
7015 type
? "%20" : "", type_str
,
7016 exclude_str
[0] ? "%20" : "", exclude_str
,
7017 include_str
[0] ? "%20" : "", include_str
);
7019 if (cupsdSendCommand(con
, command
, options
, 0))
7022 * Command started successfully, don't send an IPP response here...
7025 ippDelete(con
->response
);
7026 con
->response
= NULL
;
7031 * Command failed, return "internal error" so the user knows something
7035 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7036 _("cups-driverd failed to execute."));
7042 * 'get_printer_attrs()' - Get printer attributes.
7046 get_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
7047 ipp_attribute_t
*uri
) /* I - Printer URI */
7049 http_status_t status
; /* Policy status */
7050 cups_ptype_t dtype
; /* Destination type (printer/class) */
7051 cupsd_printer_t
*printer
; /* Printer/class */
7052 cups_array_t
*ra
; /* Requested attributes array */
7055 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_attrs(%p[%d], %s)", con
,
7056 con
->number
, uri
->values
[0].string
.text
);
7059 * Is the destination valid?
7062 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7068 send_ipp_status(con
, IPP_NOT_FOUND
,
7069 _("The printer or class does not exist."));
7077 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7079 send_http_error(con
, status
, printer
);
7084 * Send the attributes...
7087 ra
= create_requested_array(con
->request
);
7089 copy_printer_attrs(con
, printer
, ra
);
7091 cupsArrayDelete(ra
);
7093 con
->response
->request
.status
.status_code
= IPP_OK
;
7098 * 'get_printer_supported()' - Get printer supported values.
7102 get_printer_supported(
7103 cupsd_client_t
*con
, /* I - Client connection */
7104 ipp_attribute_t
*uri
) /* I - Printer URI */
7106 http_status_t status
; /* Policy status */
7107 cups_ptype_t dtype
; /* Destination type (printer/class) */
7108 cupsd_printer_t
*printer
; /* Printer/class */
7111 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_supported(%p[%d], %s)", con
,
7112 con
->number
, uri
->values
[0].string
.text
);
7115 * Is the destination valid?
7118 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7124 send_ipp_status(con
, IPP_NOT_FOUND
,
7125 _("The printer or class does not exist."));
7133 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7135 send_http_error(con
, status
, printer
);
7140 * Return a list of attributes that can be set via Set-Printer-Attributes.
7143 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7144 "printer-geo-location", 0);
7145 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7147 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7148 "printer-location", 0);
7149 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7150 "printer-organization", 0);
7151 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7152 "printer-organizational-unit", 0);
7154 con
->response
->request
.status
.status_code
= IPP_OK
;
7159 * 'get_printers()' - Get a list of printers or classes.
7163 get_printers(cupsd_client_t
*con
, /* I - Client connection */
7164 int type
) /* I - 0 or CUPS_PRINTER_CLASS */
7166 http_status_t status
; /* Policy status */
7167 ipp_attribute_t
*attr
; /* Current attribute */
7168 int limit
; /* Max number of printers to return */
7169 int count
; /* Number of printers that match */
7170 cupsd_printer_t
*printer
; /* Current printer pointer */
7171 cups_ptype_t printer_type
, /* printer-type attribute */
7172 printer_mask
; /* printer-type-mask attribute */
7173 char *location
; /* Location string */
7174 const char *username
; /* Current user */
7175 char *first_printer_name
; /* first-printer-name attribute */
7176 cups_array_t
*ra
; /* Requested attributes array */
7177 int local
; /* Local connection? */
7180 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printers(%p[%d], %x)", con
,
7187 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7189 send_http_error(con
, status
, NULL
);
7194 * Check for printers...
7197 if (!Printers
|| !cupsArrayCount(Printers
))
7199 send_ipp_status(con
, IPP_NOT_FOUND
, _("No destinations added."));
7204 * See if they want to limit the number of printers reported...
7207 if ((attr
= ippFindAttribute(con
->request
, "limit",
7208 IPP_TAG_INTEGER
)) != NULL
)
7209 limit
= attr
->values
[0].integer
;
7213 if ((attr
= ippFindAttribute(con
->request
, "first-printer-name",
7214 IPP_TAG_NAME
)) != NULL
)
7215 first_printer_name
= attr
->values
[0].string
.text
;
7217 first_printer_name
= NULL
;
7220 * Support filtering...
7223 if ((attr
= ippFindAttribute(con
->request
, "printer-type",
7224 IPP_TAG_ENUM
)) != NULL
)
7225 printer_type
= (cups_ptype_t
)attr
->values
[0].integer
;
7227 printer_type
= (cups_ptype_t
)0;
7229 if ((attr
= ippFindAttribute(con
->request
, "printer-type-mask",
7230 IPP_TAG_ENUM
)) != NULL
)
7231 printer_mask
= (cups_ptype_t
)attr
->values
[0].integer
;
7233 printer_mask
= (cups_ptype_t
)0;
7235 local
= httpAddrLocalhost(&(con
->clientaddr
));
7237 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
7238 IPP_TAG_TEXT
)) != NULL
)
7239 location
= attr
->values
[0].string
.text
;
7243 if (con
->username
[0])
7244 username
= con
->username
;
7245 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7246 IPP_TAG_NAME
)) != NULL
)
7247 username
= attr
->values
[0].string
.text
;
7251 ra
= create_requested_array(con
->request
);
7254 * OK, build a list of printers for this printer...
7257 if (first_printer_name
)
7259 if ((printer
= cupsdFindDest(first_printer_name
)) == NULL
)
7260 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7263 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7266 count
< limit
&& printer
;
7267 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
7269 if (!local
&& !printer
->shared
)
7272 if ((!type
|| (printer
->type
& CUPS_PRINTER_CLASS
) == type
) &&
7273 (printer
->type
& printer_mask
) == printer_type
&&
7275 (printer
->location
&& !_cups_strcasecmp(printer
->location
, location
))))
7278 * If a username is specified, see if it is allowed or denied
7282 if (cupsArrayCount(printer
->users
) && username
&&
7283 !user_allowed(printer
, username
))
7287 * Add the group separator as needed...
7291 ippAddSeparator(con
->response
);
7296 * Send the attributes...
7299 copy_printer_attrs(con
, printer
, ra
);
7303 cupsArrayDelete(ra
);
7305 con
->response
->request
.status
.status_code
= IPP_OK
;
7310 * 'get_subscription_attrs()' - Get subscription attributes.
7314 get_subscription_attrs(
7315 cupsd_client_t
*con
, /* I - Client connection */
7316 int sub_id
) /* I - Subscription ID */
7318 http_status_t status
; /* Policy status */
7319 cupsd_subscription_t
*sub
; /* Subscription */
7320 cupsd_policy_t
*policy
; /* Current security policy */
7321 cups_array_t
*ra
, /* Requested attributes array */
7322 *exclude
; /* Private attributes array */
7325 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7326 "get_subscription_attrs(con=%p[%d], sub_id=%d)",
7327 con
, con
->number
, sub_id
);
7330 * Is the subscription ID valid?
7333 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
7336 * Bad subscription ID...
7339 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
7349 policy
= sub
->dest
->op_policy_ptr
;
7351 policy
= DefaultPolicyPtr
;
7353 if ((status
= cupsdCheckPolicy(policy
, con
, sub
->owner
)) != HTTP_OK
)
7355 send_http_error(con
, status
, sub
->dest
);
7359 exclude
= cupsdGetPrivateAttrs(policy
, con
, sub
->dest
, sub
->owner
);
7362 * Copy the subscription attributes to the response using the
7363 * requested-attributes attribute that may be provided by the client.
7366 ra
= create_requested_array(con
->request
);
7368 copy_subscription_attrs(con
, sub
, ra
, exclude
);
7370 cupsArrayDelete(ra
);
7372 con
->response
->request
.status
.status_code
= IPP_OK
;
7377 * 'get_subscriptions()' - Get subscriptions.
7381 get_subscriptions(cupsd_client_t
*con
, /* I - Client connection */
7382 ipp_attribute_t
*uri
) /* I - Printer/job URI */
7384 http_status_t status
; /* Policy status */
7385 int count
; /* Number of subscriptions */
7386 int limit
; /* Limit */
7387 cupsd_subscription_t
*sub
; /* Subscription */
7388 cups_array_t
*ra
; /* Requested attributes array */
7389 ipp_attribute_t
*attr
; /* Attribute */
7390 cups_ptype_t dtype
; /* Destination type (printer/class) */
7391 char scheme
[HTTP_MAX_URI
],
7392 /* Scheme portion of URI */
7393 username
[HTTP_MAX_URI
],
7394 /* Username portion of URI */
7396 /* Host portion of URI */
7397 resource
[HTTP_MAX_URI
];
7398 /* Resource portion of URI */
7399 int port
; /* Port portion of URI */
7400 cupsd_job_t
*job
; /* Job pointer */
7401 cupsd_printer_t
*printer
; /* Printer */
7402 cupsd_policy_t
*policy
; /* Policy */
7403 cups_array_t
*exclude
; /* Private attributes array */
7406 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7407 "get_subscriptions(con=%p[%d], uri=%s)",
7408 con
, con
->number
, uri
->values
[0].string
.text
);
7411 * Is the destination valid?
7414 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7415 sizeof(scheme
), username
, sizeof(username
), host
,
7416 sizeof(host
), &port
, resource
, sizeof(resource
));
7418 if (!strcmp(resource
, "/") ||
7419 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6) ||
7420 (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10) ||
7421 (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9))
7426 else if (!strncmp(resource
, "/jobs/", 6) && resource
[6])
7429 job
= cupsdFindJob(atoi(resource
+ 6));
7433 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
7434 atoi(resource
+ 6));
7438 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7444 send_ipp_status(con
, IPP_NOT_FOUND
,
7445 _("The printer or class does not exist."));
7448 else if ((attr
= ippFindAttribute(con
->request
, "notify-job-id",
7449 IPP_TAG_INTEGER
)) != NULL
)
7451 job
= cupsdFindJob(attr
->values
[0].integer
);
7455 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
7456 attr
->values
[0].integer
);
7468 policy
= printer
->op_policy_ptr
;
7470 policy
= DefaultPolicyPtr
;
7472 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
7474 send_http_error(con
, status
, printer
);
7479 * Copy the subscription attributes to the response using the
7480 * requested-attributes attribute that may be provided by the client.
7483 ra
= create_requested_array(con
->request
);
7485 if ((attr
= ippFindAttribute(con
->request
, "limit",
7486 IPP_TAG_INTEGER
)) != NULL
)
7487 limit
= attr
->values
[0].integer
;
7492 * See if we only want to see subscriptions for a specific user...
7495 if ((attr
= ippFindAttribute(con
->request
, "my-subscriptions",
7496 IPP_TAG_BOOLEAN
)) != NULL
&&
7497 attr
->values
[0].boolean
)
7498 strlcpy(username
, get_username(con
), sizeof(username
));
7502 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
), count
= 0;
7504 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
7505 if ((!printer
|| sub
->dest
== printer
) && (!job
|| sub
->job
== job
) &&
7506 (!username
[0] || !_cups_strcasecmp(username
, sub
->owner
)))
7508 ippAddSeparator(con
->response
);
7510 exclude
= cupsdGetPrivateAttrs(sub
->dest
? sub
->dest
->op_policy_ptr
:
7511 policy
, con
, sub
->dest
,
7514 copy_subscription_attrs(con
, sub
, ra
, exclude
);
7517 if (limit
&& count
>= limit
)
7521 cupsArrayDelete(ra
);
7524 con
->response
->request
.status
.status_code
= IPP_OK
;
7526 send_ipp_status(con
, IPP_NOT_FOUND
, _("No subscriptions found."));
7531 * 'get_username()' - Get the username associated with a request.
7534 static const char * /* O - Username */
7535 get_username(cupsd_client_t
*con
) /* I - Connection */
7537 ipp_attribute_t
*attr
; /* Attribute */
7540 if (con
->username
[0])
7541 return (con
->username
);
7542 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7543 IPP_TAG_NAME
)) != NULL
)
7544 return (attr
->values
[0].string
.text
);
7546 return ("anonymous");
7551 * 'hold_job()' - Hold a print job.
7555 hold_job(cupsd_client_t
*con
, /* I - Client connection */
7556 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
7558 ipp_attribute_t
*attr
; /* Current job-hold-until */
7559 const char *when
; /* New value */
7560 int jobid
; /* Job ID */
7561 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
7562 username
[HTTP_MAX_URI
], /* Username portion of URI */
7563 host
[HTTP_MAX_URI
], /* Host portion of URI */
7564 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7565 int port
; /* Port portion of URI */
7566 cupsd_job_t
*job
; /* Job information */
7569 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_job(%p[%d], %s)", con
, con
->number
,
7570 uri
->values
[0].string
.text
);
7573 * See if we have a job URI or a printer URI...
7576 if (!strcmp(uri
->name
, "printer-uri"))
7579 * Got a printer URI; see if we also have a job-id attribute...
7582 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7583 IPP_TAG_INTEGER
)) == NULL
)
7585 send_ipp_status(con
, IPP_BAD_REQUEST
,
7586 _("Got a printer-uri attribute but no job-id."));
7590 jobid
= attr
->values
[0].integer
;
7595 * Got a job URI; parse it to get the job ID...
7598 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7599 sizeof(scheme
), username
, sizeof(username
), host
,
7600 sizeof(host
), &port
, resource
, sizeof(resource
));
7602 if (strncmp(resource
, "/jobs/", 6))
7608 send_ipp_status(con
, IPP_BAD_REQUEST
,
7609 _("Bad job-uri \"%s\"."),
7610 uri
->values
[0].string
.text
);
7614 jobid
= atoi(resource
+ 6);
7618 * See if the job exists...
7621 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7624 * Nope - return a "not found" error...
7627 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
7632 * See if the job is owned by the requesting user...
7635 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7637 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
7638 cupsdFindDest(job
->dest
));
7643 * See if the job is in a state that allows holding...
7646 if (job
->state_value
> IPP_JOB_STOPPED
)
7649 * Return a "not-possible" error...
7652 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
7653 _("Job #%d is finished and cannot be altered."),
7659 * Hold the job and return...
7662 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
7663 IPP_TAG_KEYWORD
)) == NULL
)
7664 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
7668 when
= attr
->values
[0].string
.text
;
7670 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
7671 "Job job-hold-until value changed by user.");
7674 when
= "indefinite";
7676 cupsdSetJobHoldUntil(job
, when
, 1);
7677 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
, "Job held by \"%s\".",
7680 con
->response
->request
.status
.status_code
= IPP_OK
;
7685 * 'hold_new_jobs()' - Hold pending/new jobs on a printer or class.
7689 hold_new_jobs(cupsd_client_t
*con
, /* I - Connection */
7690 ipp_attribute_t
*uri
) /* I - Printer URI */
7692 http_status_t status
; /* Policy status */
7693 cups_ptype_t dtype
; /* Destination type (printer/class) */
7694 cupsd_printer_t
*printer
; /* Printer data */
7697 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_new_jobs(%p[%d], %s)", con
,
7698 con
->number
, uri
->values
[0].string
.text
);
7701 * Is the destination valid?
7704 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7710 send_ipp_status(con
, IPP_NOT_FOUND
,
7711 _("The printer or class does not exist."));
7719 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7721 send_http_error(con
, status
, printer
);
7726 * Hold pending/new jobs sent to the printer...
7729 printer
->holding_new_jobs
= 1;
7731 cupsdSetPrinterReasons(printer
, "+hold-new-jobs");
7733 if (dtype
& CUPS_PRINTER_CLASS
)
7734 cupsdLogMessage(CUPSD_LOG_INFO
,
7735 "Class \"%s\" now holding pending/new jobs (\"%s\").",
7736 printer
->name
, get_username(con
));
7738 cupsdLogMessage(CUPSD_LOG_INFO
,
7739 "Printer \"%s\" now holding pending/new jobs (\"%s\").",
7740 printer
->name
, get_username(con
));
7743 * Everything was ok, so return OK status...
7746 con
->response
->request
.status
.status_code
= IPP_OK
;
7751 * 'move_job()' - Move a job to a new destination.
7755 move_job(cupsd_client_t
*con
, /* I - Client connection */
7756 ipp_attribute_t
*uri
) /* I - Job URI */
7758 http_status_t status
; /* Policy status */
7759 ipp_attribute_t
*attr
; /* Current attribute */
7760 int jobid
; /* Job ID */
7761 cupsd_job_t
*job
; /* Current job */
7762 const char *src
; /* Source printer/class */
7763 cups_ptype_t stype
, /* Source type (printer or class) */
7764 dtype
; /* Destination type (printer/class) */
7765 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
7766 username
[HTTP_MAX_URI
], /* Username portion of URI */
7767 host
[HTTP_MAX_URI
], /* Host portion of URI */
7768 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7769 int port
; /* Port portion of URI */
7770 cupsd_printer_t
*sprinter
, /* Source printer */
7771 *dprinter
; /* Destination printer */
7774 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "move_job(%p[%d], %s)", con
, con
->number
,
7775 uri
->values
[0].string
.text
);
7778 * Get the new printer or class...
7781 if ((attr
= ippFindAttribute(con
->request
, "job-printer-uri",
7782 IPP_TAG_URI
)) == NULL
)
7785 * Need job-printer-uri...
7788 send_ipp_status(con
, IPP_BAD_REQUEST
,
7789 _("job-printer-uri attribute missing."));
7793 if (!cupsdValidateDest(attr
->values
[0].string
.text
, &dtype
, &dprinter
))
7799 send_ipp_status(con
, IPP_NOT_FOUND
,
7800 _("The printer or class does not exist."));
7805 * See if we have a job URI or a printer URI...
7808 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7809 sizeof(scheme
), username
, sizeof(username
), host
,
7810 sizeof(host
), &port
, resource
, sizeof(resource
));
7812 if (!strcmp(uri
->name
, "printer-uri"))
7815 * Got a printer URI; see if we also have a job-id attribute...
7818 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7819 IPP_TAG_INTEGER
)) == NULL
)
7825 if ((src
= cupsdValidateDest(uri
->values
[0].string
.text
, &stype
,
7826 &sprinter
)) == NULL
)
7832 send_ipp_status(con
, IPP_NOT_FOUND
,
7833 _("The printer or class does not exist."));
7842 * Otherwise, just move a single job...
7845 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
7848 * Nope - return a "not found" error...
7851 send_ipp_status(con
, IPP_NOT_FOUND
,
7852 _("Job #%d does not exist."), attr
->values
[0].integer
);
7858 * Job found, initialize source pointers...
7869 * Got a job URI; parse it to get the job ID...
7872 if (strncmp(resource
, "/jobs/", 6))
7878 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
7879 uri
->values
[0].string
.text
);
7884 * See if the job exists...
7887 jobid
= atoi(resource
+ 6);
7889 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7892 * Nope - return a "not found" error...
7895 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
7901 * Job found, initialize source pointers...
7910 * Check the policy of the destination printer...
7913 if ((status
= cupsdCheckPolicy(dprinter
->op_policy_ptr
, con
,
7914 job
? job
->username
: NULL
)) != HTTP_OK
)
7916 send_http_error(con
, status
, dprinter
);
7921 * Now move the job or jobs...
7927 * See if the job has been completed...
7930 if (job
->state_value
> IPP_JOB_STOPPED
)
7933 * Return a "not-possible" error...
7936 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
7937 _("Job #%d is finished and cannot be altered."),
7943 * See if the job is owned by the requesting user...
7946 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7948 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
7949 cupsdFindDest(job
->dest
));
7954 * Move the job to a different printer or class...
7957 cupsdMoveJob(job
, dprinter
);
7962 * Got the source printer, now look through the jobs...
7965 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
7967 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
7970 * See if the job is pointing at the source printer or has not been
7974 if (_cups_strcasecmp(job
->dest
, src
) ||
7975 job
->state_value
> IPP_JOB_STOPPED
)
7979 * See if the job can be moved by the requesting user...
7982 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7986 * Move the job to a different printer or class...
7989 cupsdMoveJob(job
, dprinter
);
7994 * Start jobs if possible...
8000 * Return with "everything is OK" status...
8003 con
->response
->request
.status
.status_code
= IPP_OK
;
8008 * 'ppd_parse_line()' - Parse a PPD default line.
8011 static int /* O - 0 on success, -1 on failure */
8012 ppd_parse_line(const char *line
, /* I - Line */
8013 char *option
, /* O - Option name */
8014 int olen
, /* I - Size of option name */
8015 char *choice
, /* O - Choice name */
8016 int clen
) /* I - Size of choice name */
8019 * Verify this is a default option line...
8022 if (strncmp(line
, "*Default", 8))
8026 * Read the option name...
8029 for (line
+= 8, olen
--;
8030 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
8041 * Skip everything else up to the colon (:)...
8044 while (*line
&& *line
!= ':')
8053 * Now grab the option choice, skipping leading whitespace...
8056 while (isspace(*line
& 255))
8060 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
8071 * Return with no errors...
8079 * 'print_job()' - Print a file to a printer or class.
8083 print_job(cupsd_client_t
*con
, /* I - Client connection */
8084 ipp_attribute_t
*uri
) /* I - Printer URI */
8086 ipp_attribute_t
*attr
; /* Current attribute */
8087 ipp_attribute_t
*doc_name
; /* document-name attribute */
8088 ipp_attribute_t
*format
; /* Document-format attribute */
8089 const char *default_format
; /* document-format-default value */
8090 cupsd_job_t
*job
; /* New job */
8091 char filename
[1024]; /* Job filename */
8092 mime_type_t
*filetype
; /* Type of file */
8093 char super
[MIME_MAX_SUPER
], /* Supertype of file */
8094 type
[MIME_MAX_TYPE
], /* Subtype of file */
8095 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
8096 /* Textual name of mime type */
8097 cupsd_printer_t
*printer
; /* Printer data */
8098 struct stat fileinfo
; /* File information */
8099 int kbytes
; /* Size of file */
8100 int compression
; /* Document compression */
8103 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "print_job(%p[%d], %s)", con
, con
->number
,
8104 uri
->values
[0].string
.text
);
8107 * Validate print file attributes, for now just document-format and
8108 * compression (CUPS only supports "none" and "gzip")...
8111 compression
= CUPS_FILE_NONE
;
8113 if ((attr
= ippFindAttribute(con
->request
, "compression",
8114 IPP_TAG_KEYWORD
)) != NULL
)
8116 if (strcmp(attr
->values
[0].string
.text
, "none")
8118 && strcmp(attr
->values
[0].string
.text
, "gzip")
8119 #endif /* HAVE_LIBZ */
8122 send_ipp_status(con
, IPP_ATTRIBUTES
,
8123 _("Unsupported compression \"%s\"."),
8124 attr
->values
[0].string
.text
);
8125 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
8126 "compression", NULL
, attr
->values
[0].string
.text
);
8131 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
8132 compression
= CUPS_FILE_GZIP
;
8133 #endif /* HAVE_LIBZ */
8137 * Do we have a file to print?
8142 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file in print request."));
8147 * Is the destination valid?
8150 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
8156 send_ipp_status(con
, IPP_NOT_FOUND
,
8157 _("The printer or class does not exist."));
8162 * Is it a format we support?
8165 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
8167 ippSetName(con
->request
, &doc_name
, "document-name-supplied");
8169 if ((format
= ippFindAttribute(con
->request
, "document-format",
8170 IPP_TAG_MIMETYPE
)) != NULL
)
8173 * Grab format from client...
8176 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%255[^;]", super
,
8179 send_ipp_status(con
, IPP_BAD_REQUEST
,
8180 _("Bad document-format \"%s\"."),
8181 format
->values
[0].string
.text
);
8185 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format-supplied", NULL
, ippGetString(format
, 0, NULL
));
8187 else if ((default_format
= cupsGetOption("document-format",
8188 printer
->num_options
,
8189 printer
->options
)) != NULL
)
8192 * Use default document format...
8195 if (sscanf(default_format
, "%15[^/]/%255[^;]", super
, type
) != 2)
8197 send_ipp_status(con
, IPP_BAD_REQUEST
,
8198 _("Bad document-format \"%s\"."),
8209 strlcpy(super
, "application", sizeof(super
));
8210 strlcpy(type
, "octet-stream", sizeof(type
));
8213 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
8216 * Auto-type the file...
8219 cupsdLogMessage(CUPSD_LOG_DEBUG
, "[Job ???] Auto-typing file...");
8222 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
8223 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
8227 filetype
= mimeType(MimeDatabase
, super
, type
);
8229 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job ???] Request file type is %s/%s.",
8230 filetype
->super
, filetype
->type
);
8232 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
, filetype
->type
);
8233 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format-detected", NULL
, mimetype
);
8236 filetype
= mimeType(MimeDatabase
, super
, type
);
8240 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
8243 * Replace the document-format attribute value with the auto-typed or
8247 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
8252 _cupsStrFree(format
->values
[0].string
.text
);
8254 format
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
8257 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
8258 "document-format", NULL
, mimetype
);
8262 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
8263 _("Unsupported document-format \"%s\"."),
8264 format
? format
->values
[0].string
.text
:
8265 "application/octet-stream");
8266 cupsdLogMessage(CUPSD_LOG_INFO
,
8267 "Hint: Do you have the raw file printing rules enabled?");
8270 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
8271 "document-format", NULL
, format
->values
[0].string
.text
);
8277 * Read any embedded job ticket info from PS files...
8280 if (!_cups_strcasecmp(filetype
->super
, "application") &&
8281 (!_cups_strcasecmp(filetype
->type
, "postscript") ||
8282 !_cups_strcasecmp(filetype
->type
, "pdf")))
8283 read_job_ticket(con
);
8286 * Create the job object...
8289 if ((job
= add_job(con
, printer
, filetype
)) == NULL
)
8293 * Update quota data...
8296 if (stat(con
->filename
, &fileinfo
))
8299 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
8301 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
8303 job
->koctets
+= kbytes
;
8305 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets", IPP_TAG_INTEGER
)) != NULL
)
8306 attr
->values
[0].integer
+= kbytes
;
8309 * Add the job file...
8312 if (add_file(con
, job
, filetype
, compression
))
8315 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
, job
->num_files
);
8316 if (rename(con
->filename
, filename
))
8318 cupsdLogJob(job
, CUPSD_LOG_ERROR
, "Unable to rename job document file \"%s\": %s", filename
, strerror(errno
));
8320 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to rename job document file."));
8324 cupsdClearString(&con
->filename
);
8327 * See if we need to add the ending sheet...
8330 if (cupsdTimeoutJob(job
))
8334 * Log and save the job...
8337 cupsdLogJob(job
, CUPSD_LOG_INFO
,
8338 "File of type %s/%s queued by \"%s\".",
8339 filetype
->super
, filetype
->type
, job
->username
);
8340 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "hold_until=%d", (int)job
->hold_until
);
8341 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
8342 job
->dest
, job
->username
);
8345 * Start the job if possible...
8353 * 'read_job_ticket()' - Read a job ticket embedded in a print file.
8355 * This function only gets called when printing a single PDF or PostScript
8356 * file using the Print-Job operation. It doesn't work for Create-Job +
8357 * Send-File, since the job attributes need to be set at job creation
8358 * time for banners to work. The embedded job ticket stuff is here
8359 * primarily to allow the Windows printer driver for CUPS to pass in JCL
8360 * options and IPP attributes which otherwise would be lost.
8362 * The format of a job ticket is simple:
8364 * %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
8366 * %cupsJobTicket: attr1=value1
8367 * %cupsJobTicket: attr2=value2
8369 * %cupsJobTicket: attrN=valueN
8371 * Job ticket lines must appear immediately after the first line that
8372 * specifies PostScript (%!PS-Adobe-3.0) or PDF (%PDF) format, and CUPS
8373 * stops looking for job ticket info when it finds a line that does not begin
8374 * with "%cupsJobTicket:".
8376 * The maximum length of a job ticket line, including the prefix, is
8377 * 255 characters to conform with the Adobe DSC.
8379 * Read-only attributes are rejected with a notice to the error log in
8380 * case a malicious user tries anything. Since the job ticket is read
8381 * prior to attribute validation in print_job(), job ticket attributes
8382 * will go through the same validation as IPP attributes...
8386 read_job_ticket(cupsd_client_t
*con
) /* I - Client connection */
8388 cups_file_t
*fp
; /* File to read from */
8389 char line
[256]; /* Line data */
8390 int num_options
; /* Number of options */
8391 cups_option_t
*options
; /* Options */
8392 ipp_t
*ticket
; /* New attributes */
8393 ipp_attribute_t
*attr
, /* Current attribute */
8394 *attr2
, /* Job attribute */
8395 *prev2
; /* Previous job attribute */
8399 * First open the print file...
8402 if ((fp
= cupsFileOpen(con
->filename
, "rb")) == NULL
)
8404 cupsdLogMessage(CUPSD_LOG_ERROR
,
8405 "Unable to open print file for job ticket - %s",
8411 * Skip the first line...
8414 if (cupsFileGets(fp
, line
, sizeof(line
)) == NULL
)
8416 cupsdLogMessage(CUPSD_LOG_ERROR
,
8417 "Unable to read from print file for job ticket - %s",
8423 if (strncmp(line
, "%!PS-Adobe-", 11) && strncmp(line
, "%PDF-", 5))
8426 * Not a DSC-compliant file, so no job ticket info will be available...
8434 * Read job ticket info from the file...
8440 while (cupsFileGets(fp
, line
, sizeof(line
)))
8443 * Stop at the first non-ticket line...
8446 if (strncmp(line
, "%cupsJobTicket:", 15))
8450 * Add the options to the option array...
8453 num_options
= cupsParseOptions(line
+ 15, num_options
, &options
);
8457 * Done with the file; see if we have any options...
8462 if (num_options
== 0)
8466 * OK, convert the options to an attribute list, and apply them to
8471 cupsEncodeOptions(ticket
, num_options
, options
);
8474 * See what the user wants to change.
8477 for (attr
= ticket
->attrs
; attr
; attr
= attr
->next
)
8479 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
8482 if (!strncmp(attr
->name
, "date-time-at-", 13) ||
8483 !strcmp(attr
->name
, "job-impressions-completed") ||
8484 !strcmp(attr
->name
, "job-media-sheets-completed") ||
8485 !strncmp(attr
->name
, "job-k-octets", 12) ||
8486 !strcmp(attr
->name
, "job-id") ||
8487 !strcmp(attr
->name
, "job-originating-host-name") ||
8488 !strcmp(attr
->name
, "job-originating-user-name") ||
8489 !strcmp(attr
->name
, "job-pages-completed") ||
8490 !strcmp(attr
->name
, "job-printer-uri") ||
8491 !strncmp(attr
->name
, "job-state", 9) ||
8492 !strcmp(attr
->name
, "job-uri") ||
8493 !strncmp(attr
->name
, "time-at-", 8))
8494 continue; /* Read-only attrs */
8496 if ((attr2
= ippFindAttribute(con
->request
, attr
->name
,
8497 IPP_TAG_ZERO
)) != NULL
)
8500 * Some other value; first free the old value...
8503 if (con
->request
->attrs
== attr2
)
8505 con
->request
->attrs
= attr2
->next
;
8510 for (prev2
= con
->request
->attrs
; prev2
; prev2
= prev2
->next
)
8511 if (prev2
->next
== attr2
)
8513 prev2
->next
= attr2
->next
;
8518 if (con
->request
->last
== attr2
)
8519 con
->request
->last
= prev2
;
8521 ippDeleteAttribute(NULL
, attr2
);
8525 * Add new option by copying it...
8528 ippCopyAttribute(con
->request
, attr
, 0);
8532 * Then free the attribute list and option array...
8536 cupsFreeOptions(num_options
, options
);
8541 * 'reject_jobs()' - Reject print jobs to a printer.
8545 reject_jobs(cupsd_client_t
*con
, /* I - Client connection */
8546 ipp_attribute_t
*uri
) /* I - Printer or class URI */
8548 http_status_t status
; /* Policy status */
8549 cups_ptype_t dtype
; /* Destination type (printer/class) */
8550 cupsd_printer_t
*printer
; /* Printer data */
8551 ipp_attribute_t
*attr
; /* printer-state-message text */
8554 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "reject_jobs(%p[%d], %s)", con
,
8555 con
->number
, uri
->values
[0].string
.text
);
8558 * Is the destination valid?
8561 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8567 send_ipp_status(con
, IPP_NOT_FOUND
,
8568 _("The printer or class does not exist."));
8576 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8578 send_http_error(con
, status
, printer
);
8583 * Reject jobs sent to the printer...
8586 printer
->accepting
= 0;
8588 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
8589 IPP_TAG_TEXT
)) == NULL
)
8590 strlcpy(printer
->state_message
, "Rejecting Jobs",
8591 sizeof(printer
->state_message
));
8593 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
8594 sizeof(printer
->state_message
));
8596 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
8597 "No longer accepting jobs.");
8599 if (dtype
& CUPS_PRINTER_CLASS
)
8601 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
8603 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" rejecting jobs (\"%s\").",
8604 printer
->name
, get_username(con
));
8608 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
8610 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" rejecting jobs (\"%s\").",
8611 printer
->name
, get_username(con
));
8615 * Everything was ok, so return OK status...
8618 con
->response
->request
.status
.status_code
= IPP_OK
;
8623 * 'release_held_new_jobs()' - Release pending/new jobs on a printer or class.
8627 release_held_new_jobs(
8628 cupsd_client_t
*con
, /* I - Connection */
8629 ipp_attribute_t
*uri
) /* I - Printer URI */
8631 http_status_t status
; /* Policy status */
8632 cups_ptype_t dtype
; /* Destination type (printer/class) */
8633 cupsd_printer_t
*printer
; /* Printer data */
8636 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_held_new_jobs(%p[%d], %s)", con
,
8637 con
->number
, uri
->values
[0].string
.text
);
8640 * Is the destination valid?
8643 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8649 send_ipp_status(con
, IPP_NOT_FOUND
,
8650 _("The printer or class does not exist."));
8658 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8660 send_http_error(con
, status
, printer
);
8665 * Hold pending/new jobs sent to the printer...
8668 printer
->holding_new_jobs
= 0;
8670 cupsdSetPrinterReasons(printer
, "-hold-new-jobs");
8672 if (dtype
& CUPS_PRINTER_CLASS
)
8673 cupsdLogMessage(CUPSD_LOG_INFO
,
8674 "Class \"%s\" now printing pending/new jobs (\"%s\").",
8675 printer
->name
, get_username(con
));
8677 cupsdLogMessage(CUPSD_LOG_INFO
,
8678 "Printer \"%s\" now printing pending/new jobs (\"%s\").",
8679 printer
->name
, get_username(con
));
8682 * Everything was ok, so return OK status...
8685 con
->response
->request
.status
.status_code
= IPP_OK
;
8690 * 'release_job()' - Release a held print job.
8694 release_job(cupsd_client_t
*con
, /* I - Client connection */
8695 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
8697 ipp_attribute_t
*attr
; /* Current attribute */
8698 int jobid
; /* Job ID */
8699 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
8700 username
[HTTP_MAX_URI
], /* Username portion of URI */
8701 host
[HTTP_MAX_URI
], /* Host portion of URI */
8702 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8703 int port
; /* Port portion of URI */
8704 cupsd_job_t
*job
; /* Job information */
8707 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_job(%p[%d], %s)", con
,
8708 con
->number
, uri
->values
[0].string
.text
);
8711 * See if we have a job URI or a printer URI...
8714 if (!strcmp(uri
->name
, "printer-uri"))
8717 * Got a printer URI; see if we also have a job-id attribute...
8720 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8721 IPP_TAG_INTEGER
)) == NULL
)
8723 send_ipp_status(con
, IPP_BAD_REQUEST
,
8724 _("Got a printer-uri attribute but no job-id."));
8728 jobid
= attr
->values
[0].integer
;
8733 * Got a job URI; parse it to get the job ID...
8736 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8737 sizeof(scheme
), username
, sizeof(username
), host
,
8738 sizeof(host
), &port
, resource
, sizeof(resource
));
8740 if (strncmp(resource
, "/jobs/", 6))
8746 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
8747 uri
->values
[0].string
.text
);
8751 jobid
= atoi(resource
+ 6);
8755 * See if the job exists...
8758 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8761 * Nope - return a "not found" error...
8764 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
8769 * See if job is "held"...
8772 if (job
->state_value
!= IPP_JOB_HELD
)
8775 * Nope - return a "not possible" error...
8778 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not held."), jobid
);
8783 * See if the job is owned by the requesting user...
8786 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8788 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8789 cupsdFindDest(job
->dest
));
8794 * Reset the job-hold-until value to "no-hold"...
8797 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
8798 IPP_TAG_KEYWORD
)) == NULL
)
8799 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
8803 _cupsStrFree(attr
->values
[0].string
.text
);
8805 attr
->value_tag
= IPP_TAG_KEYWORD
;
8806 attr
->values
[0].string
.text
= _cupsStrAlloc("no-hold");
8808 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
8809 "Job job-hold-until value changed by user.");
8810 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
8814 * Release the job and return...
8817 cupsdReleaseJob(job
);
8819 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
8820 "Job released by user.");
8822 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Released by \"%s\".", username
);
8824 con
->response
->request
.status
.status_code
= IPP_OK
;
8831 * 'renew_subscription()' - Renew an existing subscription...
8836 cupsd_client_t
*con
, /* I - Client connection */
8837 int sub_id
) /* I - Subscription ID */
8839 http_status_t status
; /* Policy status */
8840 cupsd_subscription_t
*sub
; /* Subscription */
8841 ipp_attribute_t
*lease
; /* notify-lease-duration */
8844 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
8845 "renew_subscription(con=%p[%d], sub_id=%d)",
8846 con
, con
->number
, sub_id
);
8849 * Is the subscription ID valid?
8852 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
8855 * Bad subscription ID...
8858 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
8866 * Job subscriptions cannot be renewed...
8869 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8870 _("Job subscriptions cannot be renewed."));
8878 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
8880 con
, sub
->owner
)) != HTTP_OK
)
8882 send_http_error(con
, status
, sub
->dest
);
8887 * Renew the subscription...
8890 lease
= ippFindAttribute(con
->request
, "notify-lease-duration",
8893 sub
->lease
= lease
? lease
->values
[0].integer
: DefaultLeaseDuration
;
8895 if (MaxLeaseDuration
&& (sub
->lease
== 0 || sub
->lease
> MaxLeaseDuration
))
8897 cupsdLogMessage(CUPSD_LOG_INFO
,
8898 "renew_subscription: Limiting notify-lease-duration to "
8901 sub
->lease
= MaxLeaseDuration
;
8904 sub
->expire
= sub
->lease
? time(NULL
) + sub
->lease
: 0;
8906 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
8908 con
->response
->request
.status
.status_code
= IPP_OK
;
8910 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
8911 "notify-lease-duration", sub
->lease
);
8916 * 'restart_job()' - Restart an old print job.
8920 restart_job(cupsd_client_t
*con
, /* I - Client connection */
8921 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
8923 ipp_attribute_t
*attr
; /* Current attribute */
8924 int jobid
; /* Job ID */
8925 cupsd_job_t
*job
; /* Job information */
8926 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
8927 username
[HTTP_MAX_URI
], /* Username portion of URI */
8928 host
[HTTP_MAX_URI
], /* Host portion of URI */
8929 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8930 int port
; /* Port portion of URI */
8933 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "restart_job(%p[%d], %s)", con
,
8934 con
->number
, uri
->values
[0].string
.text
);
8937 * See if we have a job URI or a printer URI...
8940 if (!strcmp(uri
->name
, "printer-uri"))
8943 * Got a printer URI; see if we also have a job-id attribute...
8946 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8947 IPP_TAG_INTEGER
)) == NULL
)
8949 send_ipp_status(con
, IPP_BAD_REQUEST
,
8950 _("Got a printer-uri attribute but no job-id."));
8954 jobid
= attr
->values
[0].integer
;
8959 * Got a job URI; parse it to get the job ID...
8962 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8963 sizeof(scheme
), username
, sizeof(username
), host
,
8964 sizeof(host
), &port
, resource
, sizeof(resource
));
8966 if (strncmp(resource
, "/jobs/", 6))
8972 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
8973 uri
->values
[0].string
.text
);
8977 jobid
= atoi(resource
+ 6);
8981 * See if the job exists...
8984 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8987 * Nope - return a "not found" error...
8990 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
8995 * See if job is in any of the "completed" states...
8998 if (job
->state_value
<= IPP_JOB_PROCESSING
)
9001 * Nope - return a "not possible" error...
9004 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not complete."),
9010 * See if we have retained the job files...
9015 if (!job
->attrs
|| job
->num_files
== 0)
9018 * Nope - return a "not possible" error...
9021 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9022 _("Job #%d cannot be restarted - no files."), jobid
);
9027 * See if the job is owned by the requesting user...
9030 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9032 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9033 cupsdFindDest(job
->dest
));
9038 * See if the job-hold-until attribute is specified...
9041 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
9042 IPP_TAG_KEYWORD
)) == NULL
)
9043 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
9045 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
9048 * Return the job to a held state...
9051 cupsdLogJob(job
, CUPSD_LOG_DEBUG
,
9052 "Restarted by \"%s\" with job-hold-until=%s.",
9053 username
, attr
->values
[0].string
.text
);
9054 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
9056 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
,
9057 NULL
, job
, "Job restarted by user with job-hold-until=%s",
9058 attr
->values
[0].string
.text
);
9063 * Restart the job...
9066 cupsdRestartJob(job
);
9070 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Restarted by \"%s\".", username
);
9072 con
->response
->request
.status
.status_code
= IPP_OK
;
9077 * 'save_auth_info()' - Save authentication information for a job.
9082 cupsd_client_t
*con
, /* I - Client connection */
9083 cupsd_job_t
*job
, /* I - Job */
9084 ipp_attribute_t
*auth_info
) /* I - auth-info attribute, if any */
9086 int i
; /* Looping var */
9087 char filename
[1024]; /* Job authentication filename */
9088 cups_file_t
*fp
; /* Job authentication file */
9089 char line
[65536]; /* Line for file */
9090 cupsd_printer_t
*dest
; /* Destination printer/class */
9094 * This function saves the in-memory authentication information for
9095 * a job so that it can be used to authenticate with a remote host.
9096 * The information is stored in a file that is readable only by the
9097 * root user. The fields are Base-64 encoded, each on a separate line,
9098 * followed by random number (up to 1024) of newlines to limit the
9099 * amount of information that is exposed.
9101 * Because of the potential for exposing of authentication information,
9102 * this functionality is only enabled when running cupsd as root.
9104 * This caching only works for the Basic and BasicDigest authentication
9105 * types. Digest authentication cannot be cached this way, and in
9106 * the future Kerberos authentication may make all of this obsolete.
9108 * Authentication information is saved whenever an authenticated
9109 * Print-Job, Create-Job, or CUPS-Authenticate-Job operation is
9112 * This information is deleted after a job is completed or canceled,
9113 * so reprints may require subsequent re-authentication.
9119 if ((dest
= cupsdFindDest(job
->dest
)) == NULL
)
9123 * Create the authentication file and change permissions...
9126 snprintf(filename
, sizeof(filename
), "%s/a%05d", RequestRoot
, job
->id
);
9127 if ((fp
= cupsFileOpen(filename
, "w")) == NULL
)
9129 cupsdLogMessage(CUPSD_LOG_ERROR
,
9130 "Unable to save authentication info to \"%s\" - %s",
9131 filename
, strerror(errno
));
9135 fchown(cupsFileNumber(fp
), 0, 0);
9136 fchmod(cupsFileNumber(fp
), 0400);
9138 cupsFilePuts(fp
, "CUPSD-AUTH-V3\n");
9141 i
< (int)(sizeof(job
->auth_env
) / sizeof(job
->auth_env
[0]));
9143 cupsdClearString(job
->auth_env
+ i
);
9145 if (auth_info
&& auth_info
->num_values
== dest
->num_auth_info_required
)
9148 * Write 1 to 3 auth values...
9152 i
< auth_info
->num_values
&&
9153 i
< (int)(sizeof(job
->auth_env
) / sizeof(job
->auth_env
[0]));
9156 if (strcmp(dest
->auth_info_required
[i
], "negotiate"))
9158 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[i
].string
.text
, (int)strlen(auth_info
->values
[i
].string
.text
));
9159 cupsFilePutConf(fp
, dest
->auth_info_required
[i
], line
);
9162 cupsFilePutConf(fp
, dest
->auth_info_required
[i
],
9163 auth_info
->values
[i
].string
.text
);
9165 if (!strcmp(dest
->auth_info_required
[i
], "username"))
9166 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_USERNAME=%s",
9167 auth_info
->values
[i
].string
.text
);
9168 else if (!strcmp(dest
->auth_info_required
[i
], "domain"))
9169 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_DOMAIN=%s",
9170 auth_info
->values
[i
].string
.text
);
9171 else if (!strcmp(dest
->auth_info_required
[i
], "password"))
9172 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_PASSWORD=%s",
9173 auth_info
->values
[i
].string
.text
);
9174 else if (!strcmp(dest
->auth_info_required
[i
], "negotiate"))
9175 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_NEGOTIATE=%s",
9176 auth_info
->values
[i
].string
.text
);
9181 else if (auth_info
&& auth_info
->num_values
== 2 &&
9182 dest
->num_auth_info_required
== 1 &&
9183 !strcmp(dest
->auth_info_required
[0], "negotiate"))
9186 * Allow fallback to username+password for Kerberized queues...
9189 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[0].string
.text
, (int)strlen(auth_info
->values
[0].string
.text
));
9190 cupsFilePutConf(fp
, "username", line
);
9192 cupsdSetStringf(job
->auth_env
+ 0, "AUTH_USERNAME=%s",
9193 auth_info
->values
[0].string
.text
);
9195 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[1].string
.text
, (int)strlen(auth_info
->values
[1].string
.text
));
9196 cupsFilePutConf(fp
, "password", line
);
9198 cupsdSetStringf(job
->auth_env
+ 1, "AUTH_PASSWORD=%s",
9199 auth_info
->values
[1].string
.text
);
9201 else if (con
->username
[0])
9204 * Write the authenticated username...
9207 httpEncode64_2(line
, sizeof(line
), con
->username
, (int)strlen(con
->username
));
9208 cupsFilePutConf(fp
, "username", line
);
9210 cupsdSetStringf(job
->auth_env
+ 0, "AUTH_USERNAME=%s", con
->username
);
9213 * Write the authenticated password...
9216 httpEncode64_2(line
, sizeof(line
), con
->password
, (int)strlen(con
->password
));
9217 cupsFilePutConf(fp
, "password", line
);
9219 cupsdSetStringf(job
->auth_env
+ 1, "AUTH_PASSWORD=%s", con
->password
);
9223 if (con
->gss_uid
> 0)
9225 cupsFilePrintf(fp
, "uid %d\n", (int)con
->gss_uid
);
9226 cupsdSetStringf(&job
->auth_uid
, "AUTH_UID=%d", (int)con
->gss_uid
);
9228 #endif /* HAVE_GSSAPI */
9231 * Write a random number of newlines to the end of the file...
9234 for (i
= (CUPS_RAND() % 1024); i
>= 0; i
--)
9235 cupsFilePutChar(fp
, '\n');
9238 * Close the file and return...
9246 * 'send_document()' - Send a file to a printer or class.
9250 send_document(cupsd_client_t
*con
, /* I - Client connection */
9251 ipp_attribute_t
*uri
) /* I - Printer URI */
9253 ipp_attribute_t
*attr
; /* Current attribute */
9254 ipp_attribute_t
*format
; /* Request's document-format attribute */
9255 ipp_attribute_t
*jformat
; /* Job's document-format attribute */
9256 const char *default_format
;/* document-format-default value */
9257 int jobid
; /* Job ID number */
9258 cupsd_job_t
*job
; /* Current job */
9259 char job_uri
[HTTP_MAX_URI
],
9261 scheme
[HTTP_MAX_URI
],
9262 /* Method portion of URI */
9263 username
[HTTP_MAX_URI
],
9264 /* Username portion of URI */
9266 /* Host portion of URI */
9267 resource
[HTTP_MAX_URI
];
9268 /* Resource portion of URI */
9269 int port
; /* Port portion of URI */
9270 mime_type_t
*filetype
; /* Type of file */
9271 char super
[MIME_MAX_SUPER
],
9272 /* Supertype of file */
9273 type
[MIME_MAX_TYPE
],
9274 /* Subtype of file */
9275 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
9276 /* Textual name of mime type */
9277 char filename
[1024]; /* Job filename */
9278 cupsd_printer_t
*printer
; /* Current printer */
9279 struct stat fileinfo
; /* File information */
9280 int kbytes
; /* Size of file */
9281 int compression
; /* Type of compression */
9282 int start_job
; /* Start the job? */
9285 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "send_document(%p[%d], %s)", con
,
9286 con
->number
, uri
->values
[0].string
.text
);
9289 * See if we have a job URI or a printer URI...
9292 if (!strcmp(uri
->name
, "printer-uri"))
9295 * Got a printer URI; see if we also have a job-id attribute...
9298 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9299 IPP_TAG_INTEGER
)) == NULL
)
9301 send_ipp_status(con
, IPP_BAD_REQUEST
,
9302 _("Got a printer-uri attribute but no job-id."));
9306 jobid
= attr
->values
[0].integer
;
9311 * Got a job URI; parse it to get the job ID...
9314 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9315 sizeof(scheme
), username
, sizeof(username
), host
,
9316 sizeof(host
), &port
, resource
, sizeof(resource
));
9318 if (strncmp(resource
, "/jobs/", 6))
9324 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9325 uri
->values
[0].string
.text
);
9329 jobid
= atoi(resource
+ 6);
9333 * See if the job exists...
9336 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9339 * Nope - return a "not found" error...
9342 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9346 printer
= cupsdFindDest(job
->dest
);
9349 * See if the job is owned by the requesting user...
9352 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9354 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9355 cupsdFindDest(job
->dest
));
9360 * OK, see if the client is sending the document compressed - CUPS
9361 * only supports "none" and "gzip".
9364 compression
= CUPS_FILE_NONE
;
9366 if ((attr
= ippFindAttribute(con
->request
, "compression",
9367 IPP_TAG_KEYWORD
)) != NULL
)
9369 if (strcmp(attr
->values
[0].string
.text
, "none")
9371 && strcmp(attr
->values
[0].string
.text
, "gzip")
9372 #endif /* HAVE_LIBZ */
9375 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Unsupported compression \"%s\"."),
9376 attr
->values
[0].string
.text
);
9377 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
9378 "compression", NULL
, attr
->values
[0].string
.text
);
9383 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
9384 compression
= CUPS_FILE_GZIP
;
9385 #endif /* HAVE_LIBZ */
9389 * Do we have a file to print?
9392 if ((attr
= ippFindAttribute(con
->request
, "last-document",
9393 IPP_TAG_BOOLEAN
)) == NULL
)
9395 send_ipp_status(con
, IPP_BAD_REQUEST
,
9396 _("Missing last-document attribute in request."));
9403 * Check for an empty request with "last-document" set to true, which is
9404 * used to close an "open" job by RFC 2911, section 3.3.2.
9407 if (job
->num_files
> 0 && attr
->values
[0].boolean
)
9410 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file in print request."));
9415 * Is it a format we support?
9420 if ((format
= ippFindAttribute(con
->request
, "document-format",
9421 IPP_TAG_MIMETYPE
)) != NULL
)
9424 * Grab format from client...
9427 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%255[^;]",
9430 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"."),
9431 format
->values
[0].string
.text
);
9435 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format-supplied", NULL
, ippGetString(format
, 0, NULL
));
9437 else if ((default_format
= cupsGetOption("document-format",
9438 printer
->num_options
,
9439 printer
->options
)) != NULL
)
9442 * Use default document format...
9445 if (sscanf(default_format
, "%15[^/]/%255[^;]", super
, type
) != 2)
9447 send_ipp_status(con
, IPP_BAD_REQUEST
,
9448 _("Bad document-format-default \"%s\"."), default_format
);
9455 * No document format attribute? Auto-type it!
9458 strlcpy(super
, "application", sizeof(super
));
9459 strlcpy(type
, "octet-stream", sizeof(type
));
9462 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
9465 * Auto-type the file...
9468 ipp_attribute_t
*doc_name
; /* document-name attribute */
9471 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Auto-typing file...");
9473 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
9474 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
9475 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
9479 filetype
= mimeType(MimeDatabase
, super
, type
);
9482 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Request file type is %s/%s.",
9483 filetype
->super
, filetype
->type
);
9485 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
, filetype
->type
);
9486 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format-detected", NULL
, mimetype
);
9489 filetype
= mimeType(MimeDatabase
, super
, type
);
9494 * Replace the document-format attribute value with the auto-typed or
9498 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9501 if ((jformat
= ippFindAttribute(job
->attrs
, "document-format",
9502 IPP_TAG_MIMETYPE
)) != NULL
)
9504 _cupsStrFree(jformat
->values
[0].string
.text
);
9506 jformat
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
9509 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
9510 "document-format", NULL
, mimetype
);
9514 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9515 _("Unsupported document-format \"%s/%s\"."), super
, type
);
9516 cupsdLogMessage(CUPSD_LOG_INFO
,
9517 "Hint: Do you have the raw file printing rules enabled?");
9520 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9521 "document-format", NULL
, format
->values
[0].string
.text
);
9526 if (printer
->filetypes
&& !cupsArrayFind(printer
->filetypes
, filetype
))
9528 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9531 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9532 _("Unsupported document-format \"%s\"."), mimetype
);
9534 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9535 "document-format", NULL
, mimetype
);
9541 * Add the file to the job...
9544 if (add_file(con
, job
, filetype
, compression
))
9547 if ((attr
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
)) != NULL
)
9548 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name-supplied", NULL
, ippGetString(attr
, 0, NULL
));
9550 if (stat(con
->filename
, &fileinfo
))
9553 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
9555 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
9557 job
->koctets
+= kbytes
;
9559 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets", IPP_TAG_INTEGER
)) != NULL
)
9560 attr
->values
[0].integer
+= kbytes
;
9562 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
, job
->num_files
);
9563 if (rename(con
->filename
, filename
))
9565 cupsdLogJob(job
, CUPSD_LOG_ERROR
, "Unable to rename job document file \"%s\": %s", filename
, strerror(errno
));
9567 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to rename job document file."));
9571 cupsdClearString(&con
->filename
);
9573 cupsdLogJob(job
, CUPSD_LOG_INFO
, "File of type %s/%s queued by \"%s\".",
9574 filetype
->super
, filetype
->type
, job
->username
);
9577 * Start the job if this is the last document...
9582 if ((attr
= ippFindAttribute(con
->request
, "last-document",
9583 IPP_TAG_BOOLEAN
)) != NULL
&&
9584 attr
->values
[0].boolean
)
9587 * See if we need to add the ending sheet...
9590 if (cupsdTimeoutJob(job
))
9593 if (job
->state_value
== IPP_JOB_STOPPED
)
9595 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9596 job
->state_value
= IPP_JOB_PENDING
;
9598 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
9600 else if (job
->state_value
== IPP_JOB_HELD
)
9602 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9603 IPP_TAG_KEYWORD
)) == NULL
)
9604 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9606 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9608 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9609 job
->state_value
= IPP_JOB_PENDING
;
9611 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
9614 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-hold-until-specified");
9618 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
9624 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9625 IPP_TAG_KEYWORD
)) == NULL
)
9626 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9628 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9630 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
9631 job
->state_value
= IPP_JOB_HELD
;
9632 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
9634 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-incoming");
9637 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
9644 * Fill in the response info...
9647 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
9648 con
->clientname
, con
->clientport
, "/jobs/%d", jobid
);
9649 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
9652 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", jobid
);
9654 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
9656 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons",
9657 NULL
, job
->reasons
->values
[0].string
.text
);
9659 con
->response
->request
.status
.status_code
= IPP_OK
;
9662 * Start the job if necessary...
9671 * 'send_http_error()' - Send a HTTP error back to the IPP client.
9676 cupsd_client_t
*con
, /* I - Client connection */
9677 http_status_t status
, /* I - HTTP status code */
9678 cupsd_printer_t
*printer
) /* I - Printer, if any */
9680 ipp_attribute_t
*uri
; /* Request URI, if any */
9683 if ((uri
= ippFindAttribute(con
->request
, "printer-uri",
9684 IPP_TAG_URI
)) == NULL
)
9685 uri
= ippFindAttribute(con
->request
, "job-uri", IPP_TAG_URI
);
9687 cupsdLogMessage(status
== HTTP_FORBIDDEN
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
9688 "[Client %d] Returning HTTP %s for %s (%s) from %s",
9689 con
->number
, httpStatus(status
),
9691 ippOpString(con
->request
->request
.op
.operation_id
) :
9693 uri
? uri
->values
[0].string
.text
: "no URI",
9694 con
->http
->hostname
);
9698 int auth_type
; /* Type of authentication required */
9701 auth_type
= CUPSD_AUTH_NONE
;
9703 if (status
== HTTP_UNAUTHORIZED
&&
9704 printer
->num_auth_info_required
> 0 &&
9705 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
9707 (con
->request
->request
.op
.operation_id
== IPP_PRINT_JOB
||
9708 con
->request
->request
.op
.operation_id
== IPP_CREATE_JOB
||
9709 con
->request
->request
.op
.operation_id
== CUPS_AUTHENTICATE_JOB
))
9712 * Creating and authenticating jobs requires Kerberos...
9715 auth_type
= CUPSD_AUTH_NEGOTIATE
;
9720 * Use policy/location-defined authentication requirements...
9723 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9724 cupsd_location_t
*auth
; /* Pointer to authentication element */
9727 if (printer
->type
& CUPS_PRINTER_CLASS
)
9728 snprintf(resource
, sizeof(resource
), "/classes/%s", printer
->name
);
9730 snprintf(resource
, sizeof(resource
), "/printers/%s", printer
->name
);
9732 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
9733 auth
->type
== CUPSD_AUTH_NONE
)
9734 auth
= cupsdFindPolicyOp(printer
->op_policy_ptr
,
9736 con
->request
->request
.op
.operation_id
:
9741 if (auth
->type
== CUPSD_AUTH_DEFAULT
)
9742 auth_type
= cupsdDefaultAuthType();
9744 auth_type
= auth
->type
;
9748 cupsdSendError(con
, status
, auth_type
);
9751 cupsdSendError(con
, status
, CUPSD_AUTH_NONE
);
9753 ippDelete(con
->response
);
9754 con
->response
= NULL
;
9761 * 'send_ipp_status()' - Send a status back to the IPP client.
9765 send_ipp_status(cupsd_client_t
*con
, /* I - Client connection */
9766 ipp_status_t status
, /* I - IPP status code */
9767 const char *message
,/* I - Status message */
9768 ...) /* I - Additional args as needed */
9770 va_list ap
; /* Pointer to additional args */
9771 char formatted
[1024]; /* Formatted errror message */
9774 va_start(ap
, message
);
9775 vsnprintf(formatted
, sizeof(formatted
),
9776 _cupsLangString(con
->language
, message
), ap
);
9779 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s: %s",
9780 ippOpString(con
->request
->request
.op
.operation_id
),
9781 ippErrorString(status
), formatted
);
9783 con
->response
->request
.status
.status_code
= status
;
9785 if (ippFindAttribute(con
->response
, "attributes-charset",
9786 IPP_TAG_ZERO
) == NULL
)
9787 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
9788 "attributes-charset", NULL
, "utf-8");
9790 if (ippFindAttribute(con
->response
, "attributes-natural-language",
9791 IPP_TAG_ZERO
) == NULL
)
9792 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
9793 "attributes-natural-language", NULL
, DefaultLanguage
);
9795 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
9796 "status-message", NULL
, formatted
);
9801 * 'set_default()' - Set the default destination...
9805 set_default(cupsd_client_t
*con
, /* I - Client connection */
9806 ipp_attribute_t
*uri
) /* I - Printer URI */
9808 http_status_t status
; /* Policy status */
9809 cups_ptype_t dtype
; /* Destination type (printer/class) */
9810 cupsd_printer_t
*printer
, /* Printer */
9811 *oldprinter
; /* Old default printer */
9814 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_default(%p[%d], %s)", con
,
9815 con
->number
, uri
->values
[0].string
.text
);
9818 * Is the destination valid?
9821 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9827 send_ipp_status(con
, IPP_NOT_FOUND
,
9828 _("The printer or class does not exist."));
9836 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
9838 send_http_error(con
, status
, NULL
);
9843 * Set it as the default...
9846 oldprinter
= DefaultPrinter
;
9847 DefaultPrinter
= printer
;
9850 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, oldprinter
, NULL
,
9851 "%s is no longer the default printer.", oldprinter
->name
);
9853 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
9854 "%s is now the default printer.", printer
->name
);
9856 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
| CUPSD_DIRTY_CLASSES
|
9857 CUPSD_DIRTY_PRINTCAP
);
9859 cupsdLogMessage(CUPSD_LOG_INFO
,
9860 "Default destination set to \"%s\" by \"%s\".",
9861 printer
->name
, get_username(con
));
9864 * Everything was ok, so return OK status...
9867 con
->response
->request
.status
.status_code
= IPP_OK
;
9872 * 'set_job_attrs()' - Set job attributes.
9876 set_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
9877 ipp_attribute_t
*uri
) /* I - Job URI */
9879 ipp_attribute_t
*attr
, /* Current attribute */
9880 *attr2
; /* Job attribute */
9881 int jobid
; /* Job ID */
9882 cupsd_job_t
*job
; /* Current job */
9883 char scheme
[HTTP_MAX_URI
],
9884 /* Method portion of URI */
9885 username
[HTTP_MAX_URI
],
9886 /* Username portion of URI */
9888 /* Host portion of URI */
9889 resource
[HTTP_MAX_URI
];
9890 /* Resource portion of URI */
9891 int port
; /* Port portion of URI */
9892 int event
; /* Events? */
9893 int check_jobs
; /* Check jobs? */
9896 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_job_attrs(%p[%d], %s)", con
,
9897 con
->number
, uri
->values
[0].string
.text
);
9900 * Start with "everything is OK" status...
9903 con
->response
->request
.status
.status_code
= IPP_OK
;
9906 * See if we have a job URI or a printer URI...
9909 if (!strcmp(uri
->name
, "printer-uri"))
9912 * Got a printer URI; see if we also have a job-id attribute...
9915 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9916 IPP_TAG_INTEGER
)) == NULL
)
9918 send_ipp_status(con
, IPP_BAD_REQUEST
,
9919 _("Got a printer-uri attribute but no job-id."));
9923 jobid
= attr
->values
[0].integer
;
9928 * Got a job URI; parse it to get the job ID...
9931 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9932 sizeof(scheme
), username
, sizeof(username
), host
,
9933 sizeof(host
), &port
, resource
, sizeof(resource
));
9935 if (strncmp(resource
, "/jobs/", 6))
9941 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9942 uri
->values
[0].string
.text
);
9946 jobid
= atoi(resource
+ 6);
9950 * See if the job exists...
9953 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9956 * Nope - return a "not found" error...
9959 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9964 * See if the job has been completed...
9967 if (job
->state_value
> IPP_JOB_STOPPED
)
9970 * Return a "not-possible" error...
9973 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9974 _("Job #%d is finished and cannot be altered."), jobid
);
9979 * See if the job is owned by the requesting user...
9982 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9984 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9985 cupsdFindDest(job
->dest
));
9990 * See what the user wants to change.
9998 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10000 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
10003 if (!strcmp(attr
->name
, "attributes-charset") ||
10004 !strcmp(attr
->name
, "attributes-natural-language") ||
10005 !strncmp(attr
->name
, "date-time-at-", 13) ||
10006 !strncmp(attr
->name
, "document-compression", 20) ||
10007 !strncmp(attr
->name
, "document-format", 15) ||
10008 !strcmp(attr
->name
, "job-detailed-status-messages") ||
10009 !strcmp(attr
->name
, "job-document-access-errors") ||
10010 !strcmp(attr
->name
, "job-id") ||
10011 !strcmp(attr
->name
, "job-impressions-completed") ||
10012 !strcmp(attr
->name
, "job-k-octets-completed") ||
10013 !strcmp(attr
->name
, "job-media-sheets-completed") ||
10014 !strcmp(attr
->name
, "job-originating-host-name") ||
10015 !strcmp(attr
->name
, "job-originating-user-name") ||
10016 !strcmp(attr
->name
, "job-pages-completed") ||
10017 !strcmp(attr
->name
, "job-printer-up-time") ||
10018 !strcmp(attr
->name
, "job-printer-uri") ||
10019 !strcmp(attr
->name
, "job-sheets") ||
10020 !strcmp(attr
->name
, "job-state-message") ||
10021 !strcmp(attr
->name
, "job-state-reasons") ||
10022 !strcmp(attr
->name
, "job-uri") ||
10023 !strcmp(attr
->name
, "number-of-documents") ||
10024 !strcmp(attr
->name
, "number-of-intervening-jobs") ||
10025 !strcmp(attr
->name
, "output-device-assigned") ||
10026 !strncmp(attr
->name
, "time-at-", 8))
10032 send_ipp_status(con
, IPP_ATTRIBUTES_NOT_SETTABLE
,
10033 _("%s cannot be changed."), attr
->name
);
10035 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
10036 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
10040 if (!strcmp(attr
->name
, "job-priority"))
10043 * Change the job priority...
10046 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10048 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-priority value."));
10050 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
10051 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
10053 else if (job
->state_value
>= IPP_JOB_PROCESSING
)
10055 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10056 _("Job is completed and cannot be changed."));
10059 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10061 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-priority to %d",
10062 attr
->values
[0].integer
);
10063 cupsdSetJobPriority(job
, attr
->values
[0].integer
);
10066 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
|
10067 CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
;
10070 else if (!strcmp(attr
->name
, "job-state"))
10073 * Change the job state...
10076 if (attr
->value_tag
!= IPP_TAG_ENUM
)
10078 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-state value."));
10080 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
10081 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
10085 switch (attr
->values
[0].integer
)
10087 case IPP_JOB_PENDING
:
10088 case IPP_JOB_HELD
:
10089 if (job
->state_value
> IPP_JOB_HELD
)
10091 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10092 _("Job state cannot be changed."));
10095 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10097 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10098 attr
->values
[0].integer
);
10099 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
, CUPSD_JOB_DEFAULT
, "Job state changed by \"%s\"", username
);
10104 case IPP_JOB_PROCESSING
:
10105 case IPP_JOB_STOPPED
:
10106 if (job
->state_value
!= attr
->values
[0].integer
)
10108 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10109 _("Job state cannot be changed."));
10114 case IPP_JOB_CANCELED
:
10115 case IPP_JOB_ABORTED
:
10116 case IPP_JOB_COMPLETED
:
10117 if (job
->state_value
> IPP_JOB_PROCESSING
)
10119 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10120 _("Job state cannot be changed."));
10123 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10125 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10126 attr
->values
[0].integer
);
10127 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
,
10129 "Job state changed by \"%s\"", username
);
10136 else if (con
->response
->request
.status
.status_code
!= IPP_OK
)
10138 else if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10139 IPP_TAG_ZERO
)) != NULL
)
10142 * Some other value; first free the old value...
10145 if (job
->attrs
->prev
)
10146 job
->attrs
->prev
->next
= attr2
->next
;
10148 job
->attrs
->attrs
= attr2
->next
;
10150 if (job
->attrs
->last
== attr2
)
10151 job
->attrs
->last
= job
->attrs
->prev
;
10153 ippDeleteAttribute(NULL
, attr2
);
10156 * Then copy the attribute...
10159 ippCopyAttribute(job
->attrs
, attr
, 0);
10162 * See if the job-name or job-hold-until is being changed.
10165 if (!strcmp(attr
->name
, "job-hold-until"))
10167 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-hold-until to %s",
10168 attr
->values
[0].string
.text
);
10169 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
10171 if (!strcmp(attr
->values
[0].string
.text
, "no-hold"))
10173 cupsdReleaseJob(job
);
10177 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
,
10178 "Job held by \"%s\".", username
);
10180 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
;
10183 else if (attr
->value_tag
== IPP_TAG_DELETEATTR
)
10186 * Delete the attribute...
10189 if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10190 IPP_TAG_ZERO
)) != NULL
)
10192 if (job
->attrs
->prev
)
10193 job
->attrs
->prev
->next
= attr2
->next
;
10195 job
->attrs
->attrs
= attr2
->next
;
10197 if (attr2
== job
->attrs
->last
)
10198 job
->attrs
->last
= job
->attrs
->prev
;
10200 ippDeleteAttribute(NULL
, attr2
);
10202 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10208 * Add new option by copying it...
10211 ippCopyAttribute(job
->attrs
, attr
, 0);
10213 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10222 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10225 * Send events as needed...
10228 if (event
& CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
)
10229 cupsdAddEvent(CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
,
10230 cupsdFindDest(job
->dest
), job
,
10231 "Job priority changed by user.");
10233 if (event
& CUPSD_EVENT_JOB_STATE
)
10234 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
10235 job
->state_value
== IPP_JOB_HELD
?
10236 "Job held by user." : "Job restarted by user.");
10238 if (event
& CUPSD_EVENT_JOB_CONFIG_CHANGED
)
10239 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
10240 "Job options changed by user.");
10243 * Start jobs if possible...
10252 * 'set_printer_attrs()' - Set printer attributes.
10256 set_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
10257 ipp_attribute_t
*uri
) /* I - Printer */
10259 http_status_t status
; /* Policy status */
10260 cups_ptype_t dtype
; /* Destination type (printer/class) */
10261 cupsd_printer_t
*printer
; /* Printer/class */
10262 ipp_attribute_t
*attr
; /* Printer attribute */
10263 int changed
= 0; /* Was anything changed? */
10266 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_attrs(%p[%d], %s)", con
,
10267 con
->number
, uri
->values
[0].string
.text
);
10270 * Is the destination valid?
10273 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10279 send_ipp_status(con
, IPP_NOT_FOUND
,
10280 _("The printer or class does not exist."));
10288 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10290 send_http_error(con
, status
, printer
);
10295 * Return a list of attributes that can be set via Set-Printer-Attributes.
10298 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
10299 IPP_TAG_TEXT
)) != NULL
)
10301 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
10305 if ((attr
= ippFindAttribute(con
->request
, "printer-geo-location", IPP_TAG_URI
)) != NULL
&& !strncmp(attr
->values
[0].string
.text
, "geo:", 4))
10307 cupsdSetString(&printer
->geo_location
, attr
->values
[0].string
.text
);
10311 if ((attr
= ippFindAttribute(con
->request
, "printer-organization", IPP_TAG_TEXT
)) != NULL
)
10313 cupsdSetString(&printer
->organization
, attr
->values
[0].string
.text
);
10317 if ((attr
= ippFindAttribute(con
->request
, "printer-organizational-unit", IPP_TAG_TEXT
)) != NULL
)
10319 cupsdSetString(&printer
->organizational_unit
, attr
->values
[0].string
.text
);
10323 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
10324 IPP_TAG_TEXT
)) != NULL
)
10326 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
10331 * Update the printer attributes and return...
10336 printer
->config_time
= time(NULL
);
10338 cupsdSetPrinterAttrs(printer
);
10339 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
10341 cupsdAddEvent(CUPSD_EVENT_PRINTER_CONFIG
, printer
, NULL
,
10342 "Printer \"%s\" description or location changed by \"%s\".",
10343 printer
->name
, get_username(con
));
10345 cupsdLogMessage(CUPSD_LOG_INFO
,
10346 "Printer \"%s\" description or location changed by \"%s\".",
10347 printer
->name
, get_username(con
));
10350 con
->response
->request
.status
.status_code
= IPP_OK
;
10355 * 'set_printer_defaults()' - Set printer default options from a request.
10359 set_printer_defaults(
10360 cupsd_client_t
*con
, /* I - Client connection */
10361 cupsd_printer_t
*printer
) /* I - Printer */
10363 int i
; /* Looping var */
10364 ipp_attribute_t
*attr
; /* Current attribute */
10365 size_t namelen
; /* Length of attribute name */
10366 char name
[256], /* New attribute name */
10367 value
[256]; /* String version of integer attrs */
10370 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10373 * Skip non-printer attributes...
10376 if (attr
->group_tag
!= IPP_TAG_PRINTER
|| !attr
->name
)
10379 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_defaults: %s", attr
->name
);
10381 if (!strcmp(attr
->name
, "job-sheets-default"))
10384 * Only allow keywords and names...
10387 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10391 * Only allow job-sheets-default to be set when running without a
10392 * system high classification level...
10395 if (Classification
)
10398 cupsdSetString(&printer
->job_sheets
[0], attr
->values
[0].string
.text
);
10400 if (attr
->num_values
> 1)
10401 cupsdSetString(&printer
->job_sheets
[1], attr
->values
[1].string
.text
);
10403 cupsdSetString(&printer
->job_sheets
[1], "none");
10405 else if (!strcmp(attr
->name
, "requesting-user-name-allowed"))
10407 cupsdFreeStrings(&(printer
->users
));
10409 printer
->deny_users
= 0;
10411 if (attr
->value_tag
== IPP_TAG_NAME
&&
10412 (attr
->num_values
> 1 ||
10413 strcmp(attr
->values
[0].string
.text
, "all")))
10415 for (i
= 0; i
< attr
->num_values
; i
++)
10416 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
10419 else if (!strcmp(attr
->name
, "requesting-user-name-denied"))
10421 cupsdFreeStrings(&(printer
->users
));
10423 printer
->deny_users
= 1;
10425 if (attr
->value_tag
== IPP_TAG_NAME
&&
10426 (attr
->num_values
> 1 ||
10427 strcmp(attr
->values
[0].string
.text
, "none")))
10429 for (i
= 0; i
< attr
->num_values
; i
++)
10430 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
10433 else if (!strcmp(attr
->name
, "job-quota-period"))
10435 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10438 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-quota-period to %d...",
10439 attr
->values
[0].integer
);
10440 cupsdFreeQuotas(printer
);
10442 printer
->quota_period
= attr
->values
[0].integer
;
10444 else if (!strcmp(attr
->name
, "job-k-limit"))
10446 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10449 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-k-limit to %d...",
10450 attr
->values
[0].integer
);
10451 cupsdFreeQuotas(printer
);
10453 printer
->k_limit
= attr
->values
[0].integer
;
10455 else if (!strcmp(attr
->name
, "job-page-limit"))
10457 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10460 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-page-limit to %d...",
10461 attr
->values
[0].integer
);
10462 cupsdFreeQuotas(printer
);
10464 printer
->page_limit
= attr
->values
[0].integer
;
10466 else if (!strcmp(attr
->name
, "printer-op-policy"))
10468 cupsd_policy_t
*p
; /* Policy */
10471 if (attr
->value_tag
!= IPP_TAG_NAME
)
10474 if ((p
= cupsdFindPolicy(attr
->values
[0].string
.text
)) != NULL
)
10476 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10477 "Setting printer-op-policy to \"%s\"...",
10478 attr
->values
[0].string
.text
);
10479 cupsdSetString(&printer
->op_policy
, attr
->values
[0].string
.text
);
10480 printer
->op_policy_ptr
= p
;
10484 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10485 _("Unknown printer-op-policy \"%s\"."),
10486 attr
->values
[0].string
.text
);
10490 else if (!strcmp(attr
->name
, "printer-error-policy"))
10492 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10495 if (strcmp(attr
->values
[0].string
.text
, "retry-current-job") &&
10496 ((printer
->type
& CUPS_PRINTER_CLASS
) ||
10497 (strcmp(attr
->values
[0].string
.text
, "abort-job") &&
10498 strcmp(attr
->values
[0].string
.text
, "retry-job") &&
10499 strcmp(attr
->values
[0].string
.text
, "stop-printer"))))
10501 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10502 _("Unknown printer-error-policy \"%s\"."),
10503 attr
->values
[0].string
.text
);
10507 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10508 "Setting printer-error-policy to \"%s\"...",
10509 attr
->values
[0].string
.text
);
10510 cupsdSetString(&printer
->error_policy
, attr
->values
[0].string
.text
);
10514 * Skip any other non-default attributes...
10517 namelen
= strlen(attr
->name
);
10518 if (namelen
< 9 || strcmp(attr
->name
+ namelen
- 8, "-default") ||
10519 namelen
> (sizeof(name
) - 1) || attr
->num_values
!= 1)
10523 * OK, anything else must be a user-defined default...
10526 strlcpy(name
, attr
->name
, sizeof(name
));
10527 name
[namelen
- 8] = '\0'; /* Strip "-default" */
10529 switch (attr
->value_tag
)
10531 case IPP_TAG_DELETEATTR
:
10532 printer
->num_options
= cupsRemoveOption(name
,
10533 printer
->num_options
,
10534 &(printer
->options
));
10535 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10536 "Deleting %s", attr
->name
);
10539 case IPP_TAG_NAME
:
10540 case IPP_TAG_TEXT
:
10541 case IPP_TAG_KEYWORD
:
10543 printer
->num_options
= cupsAddOption(name
,
10544 attr
->values
[0].string
.text
,
10545 printer
->num_options
,
10546 &(printer
->options
));
10547 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10548 "Setting %s to \"%s\"...", attr
->name
,
10549 attr
->values
[0].string
.text
);
10552 case IPP_TAG_BOOLEAN
:
10553 printer
->num_options
= cupsAddOption(name
,
10554 attr
->values
[0].boolean
?
10556 printer
->num_options
,
10557 &(printer
->options
));
10558 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10559 "Setting %s to %s...", attr
->name
,
10560 attr
->values
[0].boolean
? "true" : "false");
10563 case IPP_TAG_INTEGER
:
10564 case IPP_TAG_ENUM
:
10565 sprintf(value
, "%d", attr
->values
[0].integer
);
10566 printer
->num_options
= cupsAddOption(name
, value
,
10567 printer
->num_options
,
10568 &(printer
->options
));
10569 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10570 "Setting %s to %s...", attr
->name
, value
);
10573 case IPP_TAG_RANGE
:
10574 sprintf(value
, "%d-%d", attr
->values
[0].range
.lower
,
10575 attr
->values
[0].range
.upper
);
10576 printer
->num_options
= cupsAddOption(name
, value
,
10577 printer
->num_options
,
10578 &(printer
->options
));
10579 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10580 "Setting %s to %s...", attr
->name
, value
);
10583 case IPP_TAG_RESOLUTION
:
10584 sprintf(value
, "%dx%d%s", attr
->values
[0].resolution
.xres
,
10585 attr
->values
[0].resolution
.yres
,
10586 attr
->values
[0].resolution
.units
== IPP_RES_PER_INCH
?
10588 printer
->num_options
= cupsAddOption(name
, value
,
10589 printer
->num_options
,
10590 &(printer
->options
));
10591 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10592 "Setting %s to %s...", attr
->name
, value
);
10596 /* Do nothing for other values */
10604 * 'start_printer()' - Start a printer.
10608 start_printer(cupsd_client_t
*con
, /* I - Client connection */
10609 ipp_attribute_t
*uri
) /* I - Printer URI */
10611 int i
; /* Temporary variable */
10612 http_status_t status
; /* Policy status */
10613 cups_ptype_t dtype
; /* Destination type (printer/class) */
10614 cupsd_printer_t
*printer
; /* Printer data */
10617 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_printer(%p[%d], %s)", con
,
10618 con
->number
, uri
->values
[0].string
.text
);
10621 * Is the destination valid?
10624 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10630 send_ipp_status(con
, IPP_NOT_FOUND
,
10631 _("The printer or class does not exist."));
10639 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10641 send_http_error(con
, status
, printer
);
10646 * Start the printer...
10649 printer
->state_message
[0] = '\0';
10651 cupsdStartPrinter(printer
, 1);
10653 if (dtype
& CUPS_PRINTER_CLASS
)
10654 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" started by \"%s\".",
10655 printer
->name
, get_username(con
));
10657 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" started by \"%s\".",
10658 printer
->name
, get_username(con
));
10666 if ((i
= check_quotas(con
, printer
)) < 0)
10668 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
10673 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
10678 * Everything was ok, so return OK status...
10681 con
->response
->request
.status
.status_code
= IPP_OK
;
10686 * 'stop_printer()' - Stop a printer.
10690 stop_printer(cupsd_client_t
*con
, /* I - Client connection */
10691 ipp_attribute_t
*uri
) /* I - Printer URI */
10693 http_status_t status
; /* Policy status */
10694 cups_ptype_t dtype
; /* Destination type (printer/class) */
10695 cupsd_printer_t
*printer
; /* Printer data */
10696 ipp_attribute_t
*attr
; /* printer-state-message attribute */
10699 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "stop_printer(%p[%d], %s)", con
,
10700 con
->number
, uri
->values
[0].string
.text
);
10703 * Is the destination valid?
10706 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10712 send_ipp_status(con
, IPP_NOT_FOUND
,
10713 _("The printer or class does not exist."));
10721 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10723 send_http_error(con
, status
, printer
);
10728 * Stop the printer...
10731 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
10732 IPP_TAG_TEXT
)) == NULL
)
10733 strlcpy(printer
->state_message
, "Paused", sizeof(printer
->state_message
));
10736 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
10737 sizeof(printer
->state_message
));
10740 cupsdStopPrinter(printer
, 1);
10742 if (dtype
& CUPS_PRINTER_CLASS
)
10743 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" stopped by \"%s\".",
10744 printer
->name
, get_username(con
));
10746 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" stopped by \"%s\".",
10747 printer
->name
, get_username(con
));
10750 * Everything was ok, so return OK status...
10753 con
->response
->request
.status
.status_code
= IPP_OK
;
10758 * 'url_encode_attr()' - URL-encode a string attribute.
10762 url_encode_attr(ipp_attribute_t
*attr
, /* I - Attribute */
10763 char *buffer
,/* I - String buffer */
10764 size_t bufsize
)/* I - Size of buffer */
10766 int i
; /* Looping var */
10767 char *bufptr
, /* Pointer into buffer */
10768 *bufend
; /* End of buffer */
10771 strlcpy(buffer
, attr
->name
, bufsize
);
10772 bufptr
= buffer
+ strlen(buffer
);
10773 bufend
= buffer
+ bufsize
- 1;
10775 for (i
= 0; i
< attr
->num_values
; i
++)
10777 if (bufptr
>= bufend
)
10785 if (bufptr
>= bufend
)
10790 bufptr
= url_encode_string(attr
->values
[i
].string
.text
, bufptr
, (size_t)(bufend
- bufptr
+ 1));
10792 if (bufptr
>= bufend
)
10803 * 'url_encode_string()' - URL-encode a string.
10806 static char * /* O - End of string */
10807 url_encode_string(const char *s
, /* I - String */
10808 char *buffer
, /* I - String buffer */
10809 size_t bufsize
) /* I - Size of buffer */
10811 char *bufptr
, /* Pointer into buffer */
10812 *bufend
; /* End of buffer */
10813 static const char *hex
= "0123456789ABCDEF";
10818 bufend
= buffer
+ bufsize
- 1;
10820 while (*s
&& bufptr
< bufend
)
10822 if (*s
== ' ' || *s
== '%' || *s
== '+')
10824 if (bufptr
>= (bufend
- 2))
10828 *bufptr
++ = hex
[(*s
>> 4) & 15];
10829 *bufptr
++ = hex
[*s
& 15];
10833 else if (*s
== '\'' || *s
== '\\')
10835 if (bufptr
>= (bufend
- 1))
10852 * 'user_allowed()' - See if a user is allowed to print to a queue.
10855 static int /* O - 0 if not allowed, 1 if allowed */
10856 user_allowed(cupsd_printer_t
*p
, /* I - Printer or class */
10857 const char *username
) /* I - Username */
10859 struct passwd
*pw
; /* User password data */
10860 char baseuser
[256], /* Base username */
10861 *baseptr
, /* Pointer to "@" in base username */
10862 *name
; /* Current user name */
10865 if (cupsArrayCount(p
->users
) == 0)
10868 if (!strcmp(username
, "root"))
10871 if (strchr(username
, '@'))
10874 * Strip @REALM for username check...
10877 strlcpy(baseuser
, username
, sizeof(baseuser
));
10879 if ((baseptr
= strchr(baseuser
, '@')) != NULL
)
10882 username
= baseuser
;
10885 pw
= getpwnam(username
);
10888 for (name
= (char *)cupsArrayFirst(p
->users
);
10890 name
= (char *)cupsArrayNext(p
->users
))
10892 if (name
[0] == '@')
10895 * Check group membership...
10898 if (cupsdCheckGroup(username
, pw
, name
+ 1))
10901 else if (name
[0] == '#')
10907 if (cupsdCheckGroup(username
, pw
, name
))
10910 else if (!_cups_strcasecmp(username
, name
))
10914 return ((name
!= NULL
) != p
->deny_users
);
10919 * 'validate_job()' - Validate printer options and destination.
10923 validate_job(cupsd_client_t
*con
, /* I - Client connection */
10924 ipp_attribute_t
*uri
) /* I - Printer URI */
10926 http_status_t status
; /* Policy status */
10927 ipp_attribute_t
*attr
; /* Current attribute */
10929 ipp_attribute_t
*auth_info
; /* auth-info attribute */
10930 #endif /* HAVE_SSL */
10931 ipp_attribute_t
*format
, /* Document-format attribute */
10932 *name
; /* Job-name attribute */
10933 cups_ptype_t dtype
; /* Destination type (printer/class) */
10934 char super
[MIME_MAX_SUPER
],
10935 /* Supertype of file */
10936 type
[MIME_MAX_TYPE
];
10937 /* Subtype of file */
10938 cupsd_printer_t
*printer
; /* Printer */
10941 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_job(%p[%d], %s)", con
,
10942 con
->number
, uri
->values
[0].string
.text
);
10945 * OK, see if the client is sending the document compressed - CUPS
10946 * doesn't support compression yet...
10949 if ((attr
= ippFindAttribute(con
->request
, "compression",
10950 IPP_TAG_KEYWORD
)) != NULL
)
10952 if (strcmp(attr
->values
[0].string
.text
, "none")
10954 && strcmp(attr
->values
[0].string
.text
, "gzip")
10955 #endif /* HAVE_LIBZ */
10958 send_ipp_status(con
, IPP_ATTRIBUTES
,
10959 _("Unsupported 'compression' value \"%s\"."),
10960 attr
->values
[0].string
.text
);
10961 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
10962 "compression", NULL
, attr
->values
[0].string
.text
);
10968 * Is it a format we support?
10971 if ((format
= ippFindAttribute(con
->request
, "document-format",
10972 IPP_TAG_MIMETYPE
)) != NULL
)
10974 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%255[^;]",
10977 send_ipp_status(con
, IPP_BAD_REQUEST
,
10978 _("Bad 'document-format' value \"%s\"."),
10979 format
->values
[0].string
.text
);
10983 if ((strcmp(super
, "application") || strcmp(type
, "octet-stream")) &&
10984 !mimeType(MimeDatabase
, super
, type
))
10986 cupsdLogMessage(CUPSD_LOG_INFO
,
10987 "Hint: Do you have the raw file printing rules enabled?");
10988 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
10989 _("Unsupported 'document-format' value \"%s\"."),
10990 format
->values
[0].string
.text
);
10991 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
10992 "document-format", NULL
, format
->values
[0].string
.text
);
10998 * Is the job-name valid?
11001 if ((name
= ippFindAttribute(con
->request
, "job-name", IPP_TAG_ZERO
)) != NULL
)
11003 int bad_name
= 0; /* Is the job-name value bad? */
11005 if ((name
->value_tag
!= IPP_TAG_NAME
&& name
->value_tag
!= IPP_TAG_NAMELANG
) ||
11006 name
->num_values
!= 1)
11013 * Validate that job-name conforms to RFC 5198 (Network Unicode) and
11014 * IPP Everywhere requirements for "name" values...
11017 const unsigned char *nameptr
; /* Pointer into "job-name" attribute */
11019 for (nameptr
= (unsigned char *)name
->values
[0].string
.text
;
11023 if (*nameptr
< ' ' && *nameptr
!= '\t')
11025 else if (*nameptr
== 0x7f)
11027 else if ((*nameptr
& 0xe0) == 0xc0)
11029 if ((nameptr
[1] & 0xc0) != 0x80)
11034 else if ((*nameptr
& 0xf0) == 0xe0)
11036 if ((nameptr
[1] & 0xc0) != 0x80 ||
11037 (nameptr
[2] & 0xc0) != 0x80)
11042 else if ((*nameptr
& 0xf8) == 0xf0)
11044 if ((nameptr
[1] & 0xc0) != 0x80 ||
11045 (nameptr
[2] & 0xc0) != 0x80 ||
11046 (nameptr
[3] & 0xc0) != 0x80)
11051 else if (*nameptr
& 0x80)
11061 if (StrictConformance
)
11063 send_ipp_status(con
, IPP_ATTRIBUTES
,
11064 _("Unsupported 'job-name' value."));
11065 ippCopyAttribute(con
->response
, name
, 0);
11070 cupsdLogMessage(CUPSD_LOG_WARN
,
11071 "Unsupported 'job-name' value, deleting from request.");
11072 ippDeleteAttribute(con
->request
, name
);
11078 * Is the destination valid?
11081 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11087 send_ipp_status(con
, IPP_NOT_FOUND
,
11088 _("The printer or class does not exist."));
11097 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
11098 #endif /* HAVE_SSL */
11100 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11102 send_http_error(con
, status
, printer
);
11105 else if (printer
->num_auth_info_required
== 1 &&
11106 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
11109 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
11113 else if (auth_info
&& !con
->http
->tls
&&
11114 !httpAddrLocalhost(con
->http
->hostaddr
))
11117 * Require encryption of auth-info over non-local connections...
11120 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
11123 #endif /* HAVE_SSL */
11126 * Everything was ok, so return OK status...
11129 con
->response
->request
.status
.status_code
= IPP_OK
;
11134 * 'validate_name()' - Make sure the printer name only contains valid chars.
11137 static int /* O - 0 if name is no good, 1 if good */
11138 validate_name(const char *name
) /* I - Name to check */
11140 const char *ptr
; /* Pointer into name */
11144 * Scan the whole name...
11147 for (ptr
= name
; *ptr
; ptr
++)
11148 if ((*ptr
> 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
11152 * All the characters are good; validate the length, too...
11155 return ((ptr
- name
) < 128);
11160 * 'validate_user()' - Validate the user for the request.
11163 static int /* O - 1 if permitted, 0 otherwise */
11164 validate_user(cupsd_job_t
*job
, /* I - Job */
11165 cupsd_client_t
*con
, /* I - Client connection */
11166 const char *owner
, /* I - Owner of job/resource */
11167 char *username
, /* O - Authenticated username */
11168 size_t userlen
) /* I - Length of username */
11170 cupsd_printer_t
*printer
; /* Printer for job */
11173 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_user(job=%d, con=%d, owner=\"%s\", username=%p, userlen=" CUPS_LLFMT
")", job
->id
, con
? con
->number
: 0, owner
? owner
: "(null)", username
, CUPS_LLCAST userlen
);
11176 * Validate input...
11179 if (!con
|| !owner
|| !username
|| userlen
<= 0)
11183 * Get the best authenticated username that is available.
11186 strlcpy(username
, get_username(con
), userlen
);
11189 * Check the username against the owner...
11192 printer
= cupsdFindDest(job
->dest
);
11194 return (cupsdCheckPolicy(printer
? printer
->op_policy_ptr
: DefaultPolicyPtr
,
11195 con
, owner
) == HTTP_OK
);