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",
1221 "job-k-octets-completed",
1222 "job-impressions-completed",
1223 "job-media-sheets-completed",
1225 "job-state-message",
1226 "job-state-reasons",
1227 "time-at-completed",
1229 "time-at-processing"
1233 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job(%p[%d], %p(%s), %p(%s/%s))",
1234 con
, con
->number
, printer
, printer
->name
,
1235 filetype
, filetype
? filetype
->super
: "none",
1236 filetype
? filetype
->type
: "none");
1239 * Check remote printing to non-shared printer...
1242 if (!printer
->shared
&&
1243 _cups_strcasecmp(con
->http
->hostname
, "localhost") &&
1244 _cups_strcasecmp(con
->http
->hostname
, ServerName
))
1246 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
1247 _("The printer or class is not shared."));
1255 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
1257 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
1259 send_http_error(con
, status
, printer
);
1262 else if (printer
->num_auth_info_required
== 1 &&
1263 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
1266 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
1270 else if (auth_info
&& !con
->http
->tls
&&
1271 !httpAddrLocalhost(con
->http
->hostaddr
))
1274 * Require encryption of auth-info over non-local connections...
1277 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
1280 #endif /* HAVE_SSL */
1283 * See if the printer is accepting jobs...
1286 if (!printer
->accepting
)
1288 send_ipp_status(con
, IPP_NOT_ACCEPTING
,
1289 _("Destination \"%s\" is not accepting jobs."),
1295 * Validate job template attributes; for now just document-format,
1296 * copies, job-sheets, number-up, page-ranges, mandatory attributes, and
1300 for (i
= 0; i
< (int)(sizeof(readonly
) / sizeof(readonly
[0])); i
++)
1302 if ((attr
= ippFindAttribute(con
->request
, readonly
[i
],
1303 IPP_TAG_ZERO
)) != NULL
)
1305 ippDeleteAttribute(con
->request
, attr
);
1307 if (StrictConformance
)
1309 send_ipp_status(con
, IPP_BAD_REQUEST
,
1310 _("The '%s' Job Description attribute cannot be "
1311 "supplied in a job creation request."), readonly
[i
]);
1315 cupsdLogMessage(CUPSD_LOG_INFO
,
1316 "Unexpected '%s' Job Description attribute in a job "
1317 "creation request.", readonly
[i
]);
1323 for (mandatory
= (char *)cupsArrayFirst(printer
->pc
->mandatory
);
1325 mandatory
= (char *)cupsArrayNext(printer
->pc
->mandatory
))
1327 if (!ippFindAttribute(con
->request
, mandatory
, IPP_TAG_ZERO
))
1330 * Missing a required attribute...
1333 send_ipp_status(con
, IPP_CONFLICT
,
1334 _("The \"%s\" attribute is required for print jobs."),
1341 if (filetype
&& printer
->filetypes
&&
1342 !cupsArrayFind(printer
->filetypes
, filetype
))
1344 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
1345 /* MIME media type string */
1348 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
1351 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
1352 _("Unsupported format \"%s\"."), mimetype
);
1354 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
1355 "document-format", NULL
, mimetype
);
1360 if ((attr
= ippFindAttribute(con
->request
, "copies",
1361 IPP_TAG_INTEGER
)) != NULL
)
1363 if (attr
->values
[0].integer
< 1 || attr
->values
[0].integer
> MaxCopies
)
1365 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad copies value %d."),
1366 attr
->values
[0].integer
);
1367 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1368 "copies", attr
->values
[0].integer
);
1373 if ((attr
= ippFindAttribute(con
->request
, "job-sheets",
1374 IPP_TAG_ZERO
)) != NULL
)
1376 if (attr
->value_tag
!= IPP_TAG_KEYWORD
&&
1377 attr
->value_tag
!= IPP_TAG_NAME
)
1379 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value type."));
1383 if (attr
->num_values
> 2)
1385 send_ipp_status(con
, IPP_BAD_REQUEST
,
1386 _("Too many job-sheets values (%d > 2)."),
1391 for (i
= 0; i
< attr
->num_values
; i
++)
1392 if (strcmp(attr
->values
[i
].string
.text
, "none") &&
1393 !cupsdFindBanner(attr
->values
[i
].string
.text
))
1395 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value \"%s\"."),
1396 attr
->values
[i
].string
.text
);
1401 if ((attr
= ippFindAttribute(con
->request
, "number-up",
1402 IPP_TAG_INTEGER
)) != NULL
)
1404 if (attr
->values
[0].integer
!= 1 &&
1405 attr
->values
[0].integer
!= 2 &&
1406 attr
->values
[0].integer
!= 4 &&
1407 attr
->values
[0].integer
!= 6 &&
1408 attr
->values
[0].integer
!= 9 &&
1409 attr
->values
[0].integer
!= 16)
1411 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad number-up value %d."),
1412 attr
->values
[0].integer
);
1413 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1414 "number-up", attr
->values
[0].integer
);
1419 if ((attr
= ippFindAttribute(con
->request
, "page-ranges",
1420 IPP_TAG_RANGE
)) != NULL
)
1422 for (i
= 0, lowerpagerange
= 1; i
< attr
->num_values
; i
++)
1424 if (attr
->values
[i
].range
.lower
< lowerpagerange
||
1425 attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
1427 send_ipp_status(con
, IPP_BAD_REQUEST
,
1428 _("Bad page-ranges values %d-%d."),
1429 attr
->values
[i
].range
.lower
,
1430 attr
->values
[i
].range
.upper
);
1434 lowerpagerange
= attr
->values
[i
].range
.upper
+ 1;
1439 * Do media selection as needed...
1442 if (!ippFindAttribute(con
->request
, "PageRegion", IPP_TAG_ZERO
) &&
1443 !ippFindAttribute(con
->request
, "PageSize", IPP_TAG_ZERO
) &&
1444 _ppdCacheGetPageSize(printer
->pc
, con
->request
, NULL
, &exact
))
1447 (media_col
= ippFindAttribute(con
->request
, "media-col",
1448 IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
1450 send_ipp_status(con
, IPP_OK_SUBST
, _("Unsupported margins."));
1452 unsup_col
= ippNew();
1453 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1454 "media-bottom-margin",
1455 IPP_TAG_INTEGER
)) != NULL
)
1456 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1457 "media-bottom-margin", media_margin
->values
[0].integer
);
1459 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1460 "media-left-margin",
1461 IPP_TAG_INTEGER
)) != NULL
)
1462 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1463 "media-left-margin", media_margin
->values
[0].integer
);
1465 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1466 "media-right-margin",
1467 IPP_TAG_INTEGER
)) != NULL
)
1468 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1469 "media-right-margin", media_margin
->values
[0].integer
);
1471 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1473 IPP_TAG_INTEGER
)) != NULL
)
1474 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1475 "media-top-margin", media_margin
->values
[0].integer
);
1477 ippAddCollection(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, "media-col",
1479 ippDelete(unsup_col
);
1484 * Make sure we aren't over our limit...
1487 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1490 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1492 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Too many active jobs."));
1496 if ((i
= check_quotas(con
, printer
)) < 0)
1498 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
1503 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
1508 * Create the job and set things up...
1511 if ((attr
= ippFindAttribute(con
->request
, "job-priority",
1512 IPP_TAG_INTEGER
)) != NULL
)
1513 priority
= attr
->values
[0].integer
;
1516 if ((val
= cupsGetOption("job-priority", printer
->num_options
,
1517 printer
->options
)) != NULL
)
1518 priority
= atoi(val
);
1522 ippAddInteger(con
->request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-priority",
1526 if ((attr
= ippFindAttribute(con
->request
, "job-name", IPP_TAG_ZERO
)) == NULL
)
1527 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
, "Untitled");
1528 else if ((attr
->value_tag
!= IPP_TAG_NAME
&&
1529 attr
->value_tag
!= IPP_TAG_NAMELANG
) ||
1530 attr
->num_values
!= 1)
1532 send_ipp_status(con
, IPP_ATTRIBUTES
,
1533 _("Bad job-name value: Wrong type or count."));
1534 if ((attr
= ippCopyAttribute(con
->response
, attr
, 0)) != NULL
)
1535 attr
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
1538 else if (!ippValidateAttribute(attr
))
1540 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad job-name value: %s"),
1541 cupsLastErrorString());
1542 if ((attr
= ippCopyAttribute(con
->response
, attr
, 0)) != NULL
)
1543 attr
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
1547 if ((job
= cupsdAddJob(priority
, printer
->name
)) == NULL
)
1549 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1550 _("Unable to add job for destination \"%s\"."),
1555 job
->dtype
= printer
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
1556 job
->attrs
= con
->request
;
1558 con
->request
= ippNewRequest(job
->attrs
->request
.op
.operation_id
);
1560 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1563 apply_printer_defaults(printer
, job
);
1565 attr
= ippFindAttribute(job
->attrs
, "requesting-user-name", IPP_TAG_NAME
);
1567 if (con
->username
[0])
1569 cupsdSetString(&job
->username
, con
->username
);
1572 cupsdSetString(&attr
->values
[0].string
.text
, con
->username
);
1576 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1577 "add_job: requesting-user-name=\"%s\"",
1578 attr
->values
[0].string
.text
);
1580 cupsdSetString(&job
->username
, attr
->values
[0].string
.text
);
1583 cupsdSetString(&job
->username
, "anonymous");
1586 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1587 "job-originating-user-name", NULL
, job
->username
);
1590 attr
->group_tag
= IPP_TAG_JOB
;
1591 _cupsStrFree(attr
->name
);
1592 attr
->name
= _cupsStrAlloc("job-originating-user-name");
1595 if (con
->username
[0] || auth_info
)
1597 save_auth_info(con
, job
, auth_info
);
1600 * Remove the auth-info attribute from the attribute data...
1604 ippDeleteAttribute(job
->attrs
, auth_info
);
1607 if ((attr
= ippFindAttribute(con
->request
, "job-name", IPP_TAG_NAME
)) != NULL
)
1608 cupsdSetString(&(job
->name
), attr
->values
[0].string
.text
);
1610 if ((attr
= ippFindAttribute(job
->attrs
, "job-originating-host-name",
1611 IPP_TAG_ZERO
)) != NULL
)
1614 * Request contains a job-originating-host-name attribute; validate it...
1617 if (attr
->value_tag
!= IPP_TAG_NAME
||
1618 attr
->num_values
!= 1 ||
1619 strcmp(con
->http
->hostname
, "localhost"))
1622 * Can't override the value if we aren't connected via localhost.
1623 * Also, we can only have 1 value and it must be a name value.
1626 switch (attr
->value_tag
)
1628 case IPP_TAG_STRING
:
1629 case IPP_TAG_TEXTLANG
:
1630 case IPP_TAG_NAMELANG
:
1633 case IPP_TAG_KEYWORD
:
1635 case IPP_TAG_URISCHEME
:
1636 case IPP_TAG_CHARSET
:
1637 case IPP_TAG_LANGUAGE
:
1638 case IPP_TAG_MIMETYPE
:
1640 * Free old strings...
1643 for (i
= 0; i
< attr
->num_values
; i
++)
1645 _cupsStrFree(attr
->values
[i
].string
.text
);
1646 attr
->values
[i
].string
.text
= NULL
;
1647 if (attr
->values
[i
].string
.language
)
1649 _cupsStrFree(attr
->values
[i
].string
.language
);
1650 attr
->values
[i
].string
.language
= NULL
;
1659 * Use the default connection hostname instead...
1662 attr
->value_tag
= IPP_TAG_NAME
;
1663 attr
->num_values
= 1;
1664 attr
->values
[0].string
.text
= _cupsStrAlloc(con
->http
->hostname
);
1667 attr
->group_tag
= IPP_TAG_JOB
;
1672 * No job-originating-host-name attribute, so use the hostname from
1676 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1677 "job-originating-host-name", NULL
, con
->http
->hostname
);
1680 ippAddOutOfBand(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NOVALUE
, "date-time-at-completed");
1681 ippAddDate(job
->attrs
, IPP_TAG_JOB
, "date-time-at-creation", ippTimeToDate(time(NULL
)));
1682 ippAddOutOfBand(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NOVALUE
, "date-time-at-processing");
1683 ippAddOutOfBand(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NOVALUE
, "time-at-completed");
1684 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation", time(NULL
));
1685 ippAddOutOfBand(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NOVALUE
, "time-at-processing");
1688 * Add remaining job attributes...
1691 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1692 job
->state
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_ENUM
,
1693 "job-state", IPP_JOB_STOPPED
);
1694 job
->state_value
= (ipp_jstate_t
)job
->state
->values
[0].integer
;
1695 job
->reasons
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1696 "job-state-reasons", NULL
, "job-incoming");
1697 job
->sheets
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1698 "job-media-sheets-completed", 0);
1699 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-printer-uri", NULL
,
1702 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets", IPP_TAG_INTEGER
)) != NULL
)
1703 attr
->values
[0].integer
= 0;
1705 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-k-octets", 0);
1707 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
1708 IPP_TAG_KEYWORD
)) == NULL
)
1709 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
1712 if ((val
= cupsGetOption("job-hold-until", printer
->num_options
,
1713 printer
->options
)) == NULL
)
1716 attr
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1717 "job-hold-until", NULL
, val
);
1719 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
1722 * Hold job until specified time...
1725 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
1727 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1728 job
->state_value
= IPP_JOB_HELD
;
1730 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-hold-until-specified");
1732 else if (job
->attrs
->request
.op
.operation_id
== IPP_CREATE_JOB
)
1734 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
1735 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1736 job
->state_value
= IPP_JOB_HELD
;
1740 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1741 job
->state_value
= IPP_JOB_PENDING
;
1743 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
1746 if (!(printer
->type
& CUPS_PRINTER_REMOTE
) || Classification
)
1749 * Add job sheets options...
1752 if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1753 IPP_TAG_ZERO
)) == NULL
)
1755 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1756 "Adding default job-sheets values \"%s,%s\"...",
1757 printer
->job_sheets
[0], printer
->job_sheets
[1]);
1759 attr
= ippAddStrings(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-sheets",
1761 attr
->values
[0].string
.text
= _cupsStrRetain(printer
->job_sheets
[0]);
1762 attr
->values
[1].string
.text
= _cupsStrRetain(printer
->job_sheets
[1]);
1765 job
->job_sheets
= attr
;
1768 * Enforce classification level if set...
1773 cupsdLogMessage(CUPSD_LOG_INFO
,
1774 "Classification=\"%s\", ClassifyOverride=%d",
1775 Classification
? Classification
: "(null)",
1778 if (ClassifyOverride
)
1780 if (!strcmp(attr
->values
[0].string
.text
, "none") &&
1781 (attr
->num_values
== 1 ||
1782 !strcmp(attr
->values
[1].string
.text
, "none")))
1785 * Force the leading banner to have the classification on it...
1788 cupsdSetString(&attr
->values
[0].string
.text
, Classification
);
1790 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1791 "job-sheets=\"%s,none\", "
1792 "job-originating-user-name=\"%s\"",
1793 Classification
, job
->username
);
1795 else if (attr
->num_values
== 2 &&
1796 strcmp(attr
->values
[0].string
.text
,
1797 attr
->values
[1].string
.text
) &&
1798 strcmp(attr
->values
[0].string
.text
, "none") &&
1799 strcmp(attr
->values
[1].string
.text
, "none"))
1802 * Can't put two different security markings on the same document!
1805 cupsdSetString(&attr
->values
[1].string
.text
, attr
->values
[0].string
.text
);
1807 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1808 "job-sheets=\"%s,%s\", "
1809 "job-originating-user-name=\"%s\"",
1810 attr
->values
[0].string
.text
,
1811 attr
->values
[1].string
.text
, job
->username
);
1813 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1814 strcmp(attr
->values
[0].string
.text
, "none") &&
1815 (attr
->num_values
== 1 ||
1816 (strcmp(attr
->values
[1].string
.text
, Classification
) &&
1817 strcmp(attr
->values
[1].string
.text
, "none"))))
1819 if (attr
->num_values
== 1)
1820 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1821 "CLASSIFICATION OVERRIDDEN "
1822 "job-sheets=\"%s\", "
1823 "job-originating-user-name=\"%s\"",
1824 attr
->values
[0].string
.text
, job
->username
);
1826 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1827 "CLASSIFICATION OVERRIDDEN "
1828 "job-sheets=\"%s,%s\",fffff "
1829 "job-originating-user-name=\"%s\"",
1830 attr
->values
[0].string
.text
,
1831 attr
->values
[1].string
.text
, job
->username
);
1834 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1835 (attr
->num_values
== 1 ||
1836 strcmp(attr
->values
[1].string
.text
, Classification
)))
1839 * Force the banner to have the classification on it...
1842 if (attr
->num_values
> 1 &&
1843 !strcmp(attr
->values
[0].string
.text
, attr
->values
[1].string
.text
))
1845 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1846 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1850 if (attr
->num_values
== 1 ||
1851 strcmp(attr
->values
[0].string
.text
, "none"))
1852 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1854 if (attr
->num_values
> 1 &&
1855 strcmp(attr
->values
[1].string
.text
, "none"))
1856 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1859 if (attr
->num_values
> 1)
1860 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1861 "CLASSIFICATION FORCED "
1862 "job-sheets=\"%s,%s\", "
1863 "job-originating-user-name=\"%s\"",
1864 attr
->values
[0].string
.text
,
1865 attr
->values
[1].string
.text
, job
->username
);
1867 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1868 "CLASSIFICATION FORCED "
1869 "job-sheets=\"%s\", "
1870 "job-originating-user-name=\"%s\"",
1871 Classification
, job
->username
);
1876 * See if we need to add the starting sheet...
1879 if (!(printer
->type
& CUPS_PRINTER_REMOTE
))
1881 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding start banner page \"%s\".",
1882 attr
->values
[0].string
.text
);
1884 if ((kbytes
= copy_banner(con
, job
, attr
->values
[0].string
.text
)) < 0)
1886 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1887 "Aborting job because the start banner could not be "
1892 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
1895 else if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1896 IPP_TAG_ZERO
)) != NULL
)
1897 job
->job_sheets
= attr
;
1900 * Fill in the response info...
1903 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
1904 con
->clientname
, con
->clientport
, "/jobs/%d", job
->id
);
1905 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
1908 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1910 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
1912 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_TEXT
, "job-state-message", NULL
, "");
1913 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons",
1914 NULL
, job
->reasons
->values
[0].string
.text
);
1916 con
->response
->request
.status
.status_code
= IPP_OK
;
1919 * Add any job subscriptions...
1922 add_job_subscriptions(con
, job
);
1925 * Set all but the first two attributes to the job attributes group...
1928 for (attr
= job
->attrs
->attrs
->next
->next
; attr
; attr
= attr
->next
)
1929 attr
->group_tag
= IPP_TAG_JOB
;
1932 * Fire the "job created" event...
1935 cupsdAddEvent(CUPSD_EVENT_JOB_CREATED
, printer
, job
, "Job created.");
1938 * Return the new job...
1946 * 'add_job_subscriptions()' - Add any subscriptions for a job.
1950 add_job_subscriptions(
1951 cupsd_client_t
*con
, /* I - Client connection */
1952 cupsd_job_t
*job
) /* I - Newly created job */
1954 int i
; /* Looping var */
1955 ipp_attribute_t
*prev
, /* Previous attribute */
1956 *next
, /* Next attribute */
1957 *attr
; /* Current attribute */
1958 cupsd_subscription_t
*sub
; /* Subscription object */
1959 const char *recipient
, /* notify-recipient-uri */
1960 *pullmethod
; /* notify-pull-method */
1961 ipp_attribute_t
*user_data
; /* notify-user-data */
1962 int interval
; /* notify-time-interval */
1963 unsigned mask
; /* notify-events */
1967 * Find the first subscription group attribute; return if we have
1971 for (attr
= job
->attrs
->attrs
; attr
; attr
= attr
->next
)
1972 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
1979 * Process the subscription attributes in the request...
1988 mask
= CUPSD_EVENT_NONE
;
1990 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
1992 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
1993 attr
->value_tag
== IPP_TAG_URI
)
1996 * Validate the recipient scheme against the ServerBin/notifier
2000 char notifier
[1024], /* Notifier filename */
2001 scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
2002 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
2003 host
[HTTP_MAX_URI
], /* Host portion of URI */
2004 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2005 int port
; /* Port portion of URI */
2008 recipient
= attr
->values
[0].string
.text
;
2010 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
2011 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
2012 host
, sizeof(host
), &port
,
2013 resource
, sizeof(resource
)) < HTTP_URI_OK
)
2015 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2016 _("Bad notify-recipient-uri \"%s\"."), recipient
);
2017 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2018 "notify-status-code", IPP_URI_SCHEME
);
2022 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
2024 if (access(notifier
, X_OK
))
2026 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2027 _("notify-recipient-uri URI \"%s\" uses unknown "
2028 "scheme."), recipient
);
2029 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2030 "notify-status-code", IPP_URI_SCHEME
);
2034 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
2036 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2037 _("notify-recipient-uri URI \"%s\" is already used."),
2039 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2040 "notify-status-code", IPP_ATTRIBUTES
);
2044 else if (!strcmp(attr
->name
, "notify-pull-method") &&
2045 attr
->value_tag
== IPP_TAG_KEYWORD
)
2047 pullmethod
= attr
->values
[0].string
.text
;
2049 if (strcmp(pullmethod
, "ippget"))
2051 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2052 _("Bad notify-pull-method \"%s\"."), pullmethod
);
2053 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2054 "notify-status-code", IPP_ATTRIBUTES
);
2058 else if (!strcmp(attr
->name
, "notify-charset") &&
2059 attr
->value_tag
== IPP_TAG_CHARSET
&&
2060 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
2061 strcmp(attr
->values
[0].string
.text
, "utf-8"))
2063 send_ipp_status(con
, IPP_CHARSET
,
2064 _("Character set \"%s\" not supported."),
2065 attr
->values
[0].string
.text
);
2068 else if (!strcmp(attr
->name
, "notify-natural-language") &&
2069 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
2070 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
2072 send_ipp_status(con
, IPP_CHARSET
,
2073 _("Language \"%s\" not supported."),
2074 attr
->values
[0].string
.text
);
2077 else if (!strcmp(attr
->name
, "notify-user-data") &&
2078 attr
->value_tag
== IPP_TAG_STRING
)
2080 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
2082 send_ipp_status(con
, IPP_REQUEST_VALUE
,
2083 _("The notify-user-data value is too large "
2084 "(%d > 63 octets)."),
2085 attr
->values
[0].unknown
.length
);
2091 else if (!strcmp(attr
->name
, "notify-events") &&
2092 attr
->value_tag
== IPP_TAG_KEYWORD
)
2094 for (i
= 0; i
< attr
->num_values
; i
++)
2095 mask
|= cupsdEventValue(attr
->values
[i
].string
.text
);
2097 else if (!strcmp(attr
->name
, "notify-lease-duration"))
2099 send_ipp_status(con
, IPP_BAD_REQUEST
,
2100 _("The notify-lease-duration attribute cannot be "
2101 "used with job subscriptions."));
2104 else if (!strcmp(attr
->name
, "notify-time-interval") &&
2105 attr
->value_tag
== IPP_TAG_INTEGER
)
2106 interval
= attr
->values
[0].integer
;
2111 if (!recipient
&& !pullmethod
)
2114 if (mask
== CUPSD_EVENT_NONE
)
2115 mask
= CUPSD_EVENT_JOB_COMPLETED
;
2117 if ((sub
= cupsdAddSubscription(mask
, cupsdFindDest(job
->dest
), job
,
2118 recipient
, 0)) != NULL
)
2120 sub
->interval
= interval
;
2122 cupsdSetString(&sub
->owner
, job
->username
);
2126 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
2127 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
2128 (size_t)sub
->user_data_len
);
2131 ippAddSeparator(con
->response
);
2132 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
2133 "notify-subscription-id", sub
->id
);
2135 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
2143 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
2146 * Remove all of the subscription attributes from the job request...
2148 * TODO: Optimize this since subscription groups have to come at the
2149 * end of the request...
2152 for (attr
= job
->attrs
->attrs
, prev
= NULL
; attr
; attr
= next
)
2156 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
||
2157 attr
->group_tag
== IPP_TAG_ZERO
)
2160 * Free and remove this attribute...
2163 ippDeleteAttribute(NULL
, attr
);
2168 job
->attrs
->attrs
= next
;
2174 job
->attrs
->last
= prev
;
2175 job
->attrs
->current
= prev
;
2180 * 'add_job_uuid()' - Add job-uuid attribute to a job.
2182 * See RFC 4122 for the definition of UUIDs and the format.
2186 add_job_uuid(cupsd_job_t
*job
) /* I - Job */
2188 char uuid
[64]; /* job-uuid string */
2192 * Add a job-uuid attribute if none exists...
2195 if (!ippFindAttribute(job
->attrs
, "job-uuid", IPP_TAG_URI
))
2196 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uuid", NULL
,
2197 httpAssembleUUID(ServerName
, RemotePort
, job
->dest
, job
->id
,
2198 uuid
, sizeof(uuid
)));
2203 * 'add_printer()' - Add a printer to the system.
2207 add_printer(cupsd_client_t
*con
, /* I - Client connection */
2208 ipp_attribute_t
*uri
) /* I - URI of printer */
2210 http_status_t status
; /* Policy status */
2211 int i
; /* Looping var */
2212 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
2213 username
[HTTP_MAX_URI
], /* Username portion of URI */
2214 host
[HTTP_MAX_URI
], /* Host portion of URI */
2215 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2216 int port
; /* Port portion of URI */
2217 cupsd_printer_t
*printer
; /* Printer/class */
2218 ipp_attribute_t
*attr
; /* Printer attribute */
2219 cups_file_t
*fp
; /* Script/PPD file */
2220 char line
[1024]; /* Line from file... */
2221 char srcfile
[1024], /* Source Script/PPD file */
2222 dstfile
[1024]; /* Destination Script/PPD file */
2223 int modify
; /* Non-zero if we are modifying */
2224 int changed_driver
, /* Changed the PPD/interface script? */
2225 need_restart_job
, /* Need to restart job? */
2226 set_device_uri
, /* Did we set the device URI? */
2227 set_port_monitor
; /* Did we set the port monitor? */
2230 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer(%p[%d], %s)", con
,
2231 con
->number
, uri
->values
[0].string
.text
);
2234 * Do we have a valid URI?
2237 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
2238 sizeof(scheme
), username
, sizeof(username
), host
,
2239 sizeof(host
), &port
, resource
, sizeof(resource
));
2241 if (strncmp(resource
, "/printers/", 10) || strlen(resource
) == 10)
2244 * No, return an error...
2247 send_ipp_status(con
, IPP_BAD_REQUEST
,
2248 _("The printer-uri must be of the form "
2249 "\"ipp://HOSTNAME/printers/PRINTERNAME\"."));
2254 * Do we have a valid printer name?
2257 if (!validate_name(resource
+ 10))
2260 * No, return an error...
2263 send_ipp_status(con
, IPP_BAD_REQUEST
,
2264 _("The printer-uri \"%s\" contains invalid characters."),
2265 uri
->values
[0].string
.text
);
2270 * See if the printer already exists; if not, create a new printer...
2273 if ((printer
= cupsdFindPrinter(resource
+ 10)) == NULL
)
2276 * Printer doesn't exist; see if we have a class of the same name...
2279 if ((printer
= cupsdFindClass(resource
+ 10)) != NULL
)
2282 * Yes, return an error...
2285 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2286 _("A class named \"%s\" already exists."),
2292 * No, check the default policy then add the printer...
2295 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2297 send_http_error(con
, status
, NULL
);
2301 printer
= cupsdAddPrinter(resource
+ 10);
2304 else if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
2307 send_http_error(con
, status
, printer
);
2314 * Look for attributes and copy them over as needed...
2318 need_restart_job
= 0;
2320 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
2321 IPP_TAG_TEXT
)) != NULL
)
2322 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
2324 if ((attr
= ippFindAttribute(con
->request
, "printer-geo-location", IPP_TAG_URI
)) != NULL
&& !strncmp(attr
->values
[0].string
.text
, "geo:", 4))
2325 cupsdSetString(&printer
->geo_location
, attr
->values
[0].string
.text
);
2327 if ((attr
= ippFindAttribute(con
->request
, "printer-organization", IPP_TAG_TEXT
)) != NULL
)
2328 cupsdSetString(&printer
->organization
, attr
->values
[0].string
.text
);
2330 if ((attr
= ippFindAttribute(con
->request
, "printer-organizational-unit", IPP_TAG_TEXT
)) != NULL
)
2331 cupsdSetString(&printer
->organizational_unit
, attr
->values
[0].string
.text
);
2333 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
2334 IPP_TAG_TEXT
)) != NULL
)
2335 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
2339 if ((attr
= ippFindAttribute(con
->request
, "device-uri",
2340 IPP_TAG_URI
)) != NULL
)
2343 * Do we have a valid device URI?
2346 http_uri_status_t uri_status
; /* URI separation status */
2347 char old_device_uri
[1024];
2348 /* Old device URI */
2349 static const char * const uri_status_strings
[] =
2352 "Bad arguments to function.",
2353 "Bad resource path.",
2355 "Bad hostname/address.",
2356 "Bad username/password.",
2360 "Missing URI scheme.",
2361 "Unknown URI scheme",
2362 "Missing resource path."
2366 need_restart_job
= 1;
2368 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
,
2369 attr
->values
[0].string
.text
,
2370 scheme
, sizeof(scheme
),
2371 username
, sizeof(username
),
2372 host
, sizeof(host
), &port
,
2373 resource
, sizeof(resource
));
2375 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2376 "%s device-uri: %s", printer
->name
,
2377 uri_status_strings
[uri_status
- HTTP_URI_STATUS_OVERFLOW
]);
2379 if (uri_status
< HTTP_URI_OK
)
2381 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri \"%s\"."),
2382 attr
->values
[0].string
.text
);
2386 if (!strcmp(scheme
, "file"))
2389 * See if the administrator has enabled file devices...
2392 if (!FileDevice
&& strcmp(resource
, "/dev/null"))
2395 * File devices are disabled and the URL is not file:/dev/null...
2398 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2399 _("File device URIs have been disabled. "
2400 "To enable, see the FileDevice directive in "
2401 "\"%s/cups-files.conf\"."),
2409 * See if the backend exists and is executable...
2412 snprintf(srcfile
, sizeof(srcfile
), "%s/backend/%s", ServerBin
, scheme
);
2413 if (access(srcfile
, X_OK
))
2416 * Could not find device in list!
2419 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2420 _("Bad device-uri scheme \"%s\"."), scheme
);
2425 if (printer
->sanitized_device_uri
)
2426 strlcpy(old_device_uri
, printer
->sanitized_device_uri
,
2427 sizeof(old_device_uri
));
2429 old_device_uri
[0] = '\0';
2431 cupsdSetDeviceURI(printer
, attr
->values
[0].string
.text
);
2433 cupsdLogMessage(CUPSD_LOG_INFO
,
2434 "Setting %s device-uri to \"%s\" (was \"%s\".)",
2435 printer
->name
, printer
->sanitized_device_uri
,
2441 set_port_monitor
= 0;
2443 if ((attr
= ippFindAttribute(con
->request
, "port-monitor",
2444 IPP_TAG_NAME
)) != NULL
)
2446 ipp_attribute_t
*supported
; /* port-monitor-supported attribute */
2449 need_restart_job
= 1;
2451 supported
= ippFindAttribute(printer
->ppd_attrs
, "port-monitor-supported",
2455 for (i
= 0; i
< supported
->num_values
; i
++)
2456 if (!strcmp(supported
->values
[i
].string
.text
,
2457 attr
->values
[0].string
.text
))
2461 if (!supported
|| i
>= supported
->num_values
)
2463 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad port-monitor \"%s\"."),
2464 attr
->values
[0].string
.text
);
2468 cupsdLogMessage(CUPSD_LOG_INFO
,
2469 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2470 printer
->name
, attr
->values
[0].string
.text
,
2471 printer
->port_monitor
? printer
->port_monitor
: "none");
2473 if (strcmp(attr
->values
[0].string
.text
, "none"))
2474 cupsdSetString(&printer
->port_monitor
, attr
->values
[0].string
.text
);
2476 cupsdClearString(&printer
->port_monitor
);
2478 set_port_monitor
= 1;
2481 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
2482 IPP_TAG_BOOLEAN
)) != NULL
&&
2483 attr
->values
[0].boolean
!= printer
->accepting
)
2485 cupsdLogMessage(CUPSD_LOG_INFO
,
2486 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
2487 printer
->name
, attr
->values
[0].boolean
, printer
->accepting
);
2489 printer
->accepting
= attr
->values
[0].boolean
;
2491 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2492 "%s accepting jobs.",
2493 printer
->accepting
? "Now" : "No longer");
2496 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
2497 IPP_TAG_BOOLEAN
)) != NULL
)
2499 if (attr
->values
[0].boolean
&&
2500 printer
->num_auth_info_required
== 1 &&
2501 !strcmp(printer
->auth_info_required
[0], "negotiate"))
2503 send_ipp_status(con
, IPP_BAD_REQUEST
,
2504 _("Cannot share a remote Kerberized printer."));
2508 if (printer
->shared
&& !attr
->values
[0].boolean
)
2509 cupsdDeregisterPrinter(printer
, 1);
2511 cupsdLogMessage(CUPSD_LOG_INFO
,
2512 "Setting %s printer-is-shared to %d (was %d.)",
2513 printer
->name
, attr
->values
[0].boolean
, printer
->shared
);
2515 printer
->shared
= attr
->values
[0].boolean
;
2518 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
2519 IPP_TAG_ENUM
)) != NULL
)
2521 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
2522 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
2524 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad printer-state value %d."),
2525 attr
->values
[0].integer
);
2529 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
2530 printer
->name
, attr
->values
[0].integer
, printer
->state
);
2532 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
2533 cupsdStopPrinter(printer
, 0);
2536 need_restart_job
= 1;
2537 cupsdSetPrinterState(printer
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
2541 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
2542 IPP_TAG_TEXT
)) != NULL
)
2544 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
2545 sizeof(printer
->state_message
));
2547 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
, "%s",
2548 printer
->state_message
);
2551 if ((attr
= ippFindAttribute(con
->request
, "printer-state-reasons",
2552 IPP_TAG_KEYWORD
)) != NULL
)
2554 if (attr
->num_values
>
2555 (int)(sizeof(printer
->reasons
) / sizeof(printer
->reasons
[0])))
2557 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2558 _("Too many printer-state-reasons values (%d > %d)."),
2560 (int)(sizeof(printer
->reasons
) /
2561 sizeof(printer
->reasons
[0])));
2565 for (i
= 0; i
< printer
->num_reasons
; i
++)
2566 _cupsStrFree(printer
->reasons
[i
]);
2568 printer
->num_reasons
= 0;
2569 for (i
= 0; i
< attr
->num_values
; i
++)
2571 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
2574 printer
->reasons
[printer
->num_reasons
] =
2575 _cupsStrRetain(attr
->values
[i
].string
.text
);
2576 printer
->num_reasons
++;
2578 if (!strcmp(attr
->values
[i
].string
.text
, "paused") &&
2579 printer
->state
!= IPP_PRINTER_STOPPED
)
2581 cupsdLogMessage(CUPSD_LOG_INFO
,
2582 "Setting %s printer-state to %d (was %d.)",
2583 printer
->name
, IPP_PRINTER_STOPPED
, printer
->state
);
2584 cupsdStopPrinter(printer
, 0);
2588 if (PrintcapFormat
== PRINTCAP_PLIST
)
2589 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2591 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2592 "Printer \"%s\" state changed.", printer
->name
);
2595 set_printer_defaults(con
, printer
);
2597 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
2598 IPP_TAG_KEYWORD
)) != NULL
)
2599 cupsdSetAuthInfoRequired(printer
, NULL
, attr
);
2602 * See if we have all required attributes...
2605 if (!printer
->device_uri
)
2606 cupsdSetString(&printer
->device_uri
, "file:///dev/null");
2609 * See if we have an interface script or PPD file attached to the request...
2614 need_restart_job
= 1;
2617 strlcpy(srcfile
, con
->filename
, sizeof(srcfile
));
2619 if ((fp
= cupsFileOpen(srcfile
, "rb")))
2622 * Yes; get the first line from it...
2626 cupsFileGets(fp
, line
, sizeof(line
));
2630 * Then see what kind of file it is...
2633 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2636 if (!strncmp(line
, "*PPD-Adobe", 10))
2639 * The new file is a PPD file, so remove any old interface script
2640 * that might be lying around...
2648 * This must be an interface script, so move the file over to the
2649 * interfaces directory and make it executable...
2652 if (copy_file(srcfile
, dstfile
))
2654 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2655 _("Unable to copy interface script - %s"),
2660 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2661 "Copied interface script successfully");
2662 chmod(dstfile
, 0755);
2665 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2668 if (!strncmp(line
, "*PPD-Adobe", 10))
2671 * The new file is a PPD file, so move the file over to the
2672 * ppd directory and make it readable by all...
2675 if (copy_file(srcfile
, dstfile
))
2677 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2678 _("Unable to copy PPD file - %s"),
2683 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2684 "Copied PPD file successfully");
2685 chmod(dstfile
, 0644);
2690 * This must be an interface script, so remove any old PPD file that
2691 * may be lying around...
2698 else if ((attr
= ippFindAttribute(con
->request
, "ppd-name",
2699 IPP_TAG_NAME
)) != NULL
)
2701 need_restart_job
= 1;
2704 if (!strcmp(attr
->values
[0].string
.text
, "raw"))
2707 * Raw driver, remove any existing PPD or interface script files.
2710 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2714 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2724 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2728 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2731 if (copy_model(con
, attr
->values
[0].string
.text
, dstfile
))
2733 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file."));
2737 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2738 "Copied PPD file successfully");
2745 * If we changed the PPD/interface script, then remove the printer's cache
2746 * file and clear the printer-state-reasons...
2749 char cache_name
[1024]; /* Cache filename for printer attrs */
2751 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.data", CacheDir
,
2755 cupsdSetPrinterReasons(printer
, "none");
2758 * (Re)register color profiles...
2761 cupsdRegisterColor(printer
);
2765 * If we set the device URI but not the port monitor, check which port
2766 * monitor to use by default...
2769 if (set_device_uri
&& !set_port_monitor
)
2771 ppd_file_t
*ppd
; /* PPD file */
2772 ppd_attr_t
*ppdattr
; /* cupsPortMonitor attribute */
2775 httpSeparateURI(HTTP_URI_CODING_ALL
, printer
->device_uri
, scheme
,
2776 sizeof(scheme
), username
, sizeof(username
), host
,
2777 sizeof(host
), &port
, resource
, sizeof(resource
));
2779 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
,
2781 if ((ppd
= _ppdOpenFile(srcfile
, _PPD_LOCALIZATION_NONE
)) != NULL
)
2783 for (ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2785 ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
2786 if (!strcmp(scheme
, ppdattr
->spec
))
2788 cupsdLogMessage(CUPSD_LOG_INFO
,
2789 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2790 printer
->name
, ppdattr
->value
,
2791 printer
->port_monitor
? printer
->port_monitor
2794 if (strcmp(ppdattr
->value
, "none"))
2795 cupsdSetString(&printer
->port_monitor
, ppdattr
->value
);
2797 cupsdClearString(&printer
->port_monitor
);
2806 printer
->config_time
= time(NULL
);
2809 * Update the printer attributes and return...
2812 cupsdSetPrinterAttrs(printer
);
2813 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2815 if (need_restart_job
&& printer
->job
)
2818 * Restart the current job...
2821 cupsdSetJobState(printer
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
2822 "Job restarted because the printer was modified.");
2825 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2829 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
2830 printer
, NULL
, "Printer \"%s\" modified by \"%s\".",
2831 printer
->name
, get_username(con
));
2833 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" modified by \"%s\".",
2834 printer
->name
, get_username(con
));
2838 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
2839 printer
, NULL
, "New printer \"%s\" added by \"%s\".",
2840 printer
->name
, get_username(con
));
2842 cupsdLogMessage(CUPSD_LOG_INFO
, "New printer \"%s\" added by \"%s\".",
2843 printer
->name
, get_username(con
));
2846 con
->response
->request
.status
.status_code
= IPP_OK
;
2851 * 'add_printer_state_reasons()' - Add the "printer-state-reasons" attribute
2852 * based upon the printer state...
2856 add_printer_state_reasons(
2857 cupsd_client_t
*con
, /* I - Client connection */
2858 cupsd_printer_t
*p
) /* I - Printer info */
2860 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2861 "add_printer_state_reasons(%p[%d], %p[%s])",
2862 con
, con
->number
, p
, p
->name
);
2864 if (p
->num_reasons
== 0)
2865 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2866 "printer-state-reasons", NULL
, "none");
2868 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2869 "printer-state-reasons", p
->num_reasons
, NULL
,
2870 (const char * const *)p
->reasons
);
2875 * 'add_queued_job_count()' - Add the "queued-job-count" attribute for
2876 * the specified printer or class.
2880 add_queued_job_count(
2881 cupsd_client_t
*con
, /* I - Client connection */
2882 cupsd_printer_t
*p
) /* I - Printer or class */
2884 int count
; /* Number of jobs on destination */
2887 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_queued_job_count(%p[%d], %p[%s])",
2888 con
, con
->number
, p
, p
->name
);
2890 count
= cupsdGetPrinterJobCount(p
->name
);
2892 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2893 "queued-job-count", count
);
2898 * 'apply_printer_defaults()' - Apply printer default options to a job.
2902 apply_printer_defaults(
2903 cupsd_printer_t
*printer
, /* I - Printer */
2904 cupsd_job_t
*job
) /* I - Job */
2906 int i
, /* Looping var */
2907 num_options
; /* Number of default options */
2908 cups_option_t
*options
, /* Default options */
2909 *option
; /* Current option */
2913 * Collect all of the default options and add the missing ones to the
2917 for (i
= printer
->num_options
, num_options
= 0, options
= NULL
,
2918 option
= printer
->options
;
2921 if (!ippFindAttribute(job
->attrs
, option
->name
, IPP_TAG_ZERO
))
2923 num_options
= cupsAddOption(option
->name
, option
->value
, num_options
,
2928 * Encode these options as attributes in the job object...
2931 cupsEncodeOptions2(job
->attrs
, num_options
, options
, IPP_TAG_JOB
);
2932 cupsFreeOptions(num_options
, options
);
2937 * 'authenticate_job()' - Set job authentication info.
2941 authenticate_job(cupsd_client_t
*con
, /* I - Client connection */
2942 ipp_attribute_t
*uri
) /* I - Job URI */
2944 ipp_attribute_t
*attr
, /* job-id attribute */
2945 *auth_info
; /* auth-info attribute */
2946 int jobid
; /* Job ID */
2947 cupsd_job_t
*job
; /* Current job */
2948 char scheme
[HTTP_MAX_URI
],
2949 /* Method portion of URI */
2950 username
[HTTP_MAX_URI
],
2951 /* Username portion of URI */
2953 /* Host portion of URI */
2954 resource
[HTTP_MAX_URI
];
2955 /* Resource portion of URI */
2956 int port
; /* Port portion of URI */
2959 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "authenticate_job(%p[%d], %s)",
2960 con
, con
->number
, uri
->values
[0].string
.text
);
2963 * Start with "everything is OK" status...
2966 con
->response
->request
.status
.status_code
= IPP_OK
;
2969 * See if we have a job URI or a printer URI...
2972 if (!strcmp(uri
->name
, "printer-uri"))
2975 * Got a printer URI; see if we also have a job-id attribute...
2978 if ((attr
= ippFindAttribute(con
->request
, "job-id",
2979 IPP_TAG_INTEGER
)) == NULL
)
2981 send_ipp_status(con
, IPP_BAD_REQUEST
,
2982 _("Got a printer-uri attribute but no job-id."));
2986 jobid
= attr
->values
[0].integer
;
2991 * Got a job URI; parse it to get the job ID...
2994 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
2995 sizeof(scheme
), username
, sizeof(username
), host
,
2996 sizeof(host
), &port
, resource
, sizeof(resource
));
2998 if (strncmp(resource
, "/jobs/", 6))
3004 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
3005 uri
->values
[0].string
.text
);
3009 jobid
= atoi(resource
+ 6);
3013 * See if the job exists...
3016 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3019 * Nope - return a "not found" error...
3022 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
3027 * See if the job has been completed...
3030 if (job
->state_value
!= IPP_JOB_HELD
)
3033 * Return a "not-possible" error...
3036 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3037 _("Job #%d is not held for authentication."),
3043 * See if we have already authenticated...
3046 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
3048 if (!con
->username
[0] && !auth_info
)
3050 cupsd_printer_t
*printer
; /* Job destination */
3053 * No auth data. If we need to authenticate via Kerberos, send a
3054 * HTTP auth challenge, otherwise just return an IPP error...
3057 printer
= cupsdFindDest(job
->dest
);
3059 if (printer
&& printer
->num_auth_info_required
> 0 &&
3060 !strcmp(printer
->auth_info_required
[0], "negotiate"))
3061 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
3063 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
3064 _("No authentication information provided."));
3069 * See if the job is owned by the requesting user...
3072 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3074 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3075 cupsdFindDest(job
->dest
));
3080 * Save the authentication information for this job...
3083 save_auth_info(con
, job
, auth_info
);
3086 * Reset the job-hold-until value to "no-hold"...
3089 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
3090 IPP_TAG_KEYWORD
)) == NULL
)
3091 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
3095 attr
->value_tag
= IPP_TAG_KEYWORD
;
3096 cupsdSetString(&(attr
->values
[0].string
.text
), "no-hold");
3100 * Release the job and return...
3103 cupsdReleaseJob(job
);
3105 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, NULL
, job
, "Job authenticated by user");
3107 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Authenticated by \"%s\".", con
->username
);
3114 * 'cancel_all_jobs()' - Cancel all or selected print jobs.
3118 cancel_all_jobs(cupsd_client_t
*con
, /* I - Client connection */
3119 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3121 int i
; /* Looping var */
3122 http_status_t status
; /* Policy status */
3123 cups_ptype_t dtype
; /* Destination type */
3124 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3125 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
3126 hostname
[HTTP_MAX_URI
], /* Host portion of URI */
3127 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3128 int port
; /* Port portion of URI */
3129 ipp_attribute_t
*attr
; /* Attribute in request */
3130 const char *username
= NULL
; /* Username */
3131 cupsd_jobaction_t purge
= CUPSD_JOB_DEFAULT
;
3133 cupsd_printer_t
*printer
; /* Printer */
3134 ipp_attribute_t
*job_ids
; /* job-ids attribute */
3135 cupsd_job_t
*job
; /* Job */
3138 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_all_jobs(%p[%d], %s)", con
,
3139 con
->number
, uri
->values
[0].string
.text
);
3142 * Get the jobs to cancel/purge...
3145 switch (con
->request
->request
.op
.operation_id
)
3147 case IPP_PURGE_JOBS
:
3149 * Get the username (if any) for the jobs we want to cancel (only if
3150 * "my-jobs" is specified...
3153 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
3154 IPP_TAG_BOOLEAN
)) != NULL
&&
3155 attr
->values
[0].boolean
)
3157 if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3158 IPP_TAG_NAME
)) != NULL
)
3159 username
= attr
->values
[0].string
.text
;
3162 send_ipp_status(con
, IPP_BAD_REQUEST
,
3163 _("Missing requesting-user-name attribute."));
3169 * Look for the "purge-jobs" attribute...
3172 if ((attr
= ippFindAttribute(con
->request
, "purge-jobs",
3173 IPP_TAG_BOOLEAN
)) != NULL
)
3174 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
3176 purge
= CUPSD_JOB_PURGE
;
3179 case IPP_CANCEL_MY_JOBS
:
3180 if (con
->username
[0])
3181 username
= con
->username
;
3182 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3183 IPP_TAG_NAME
)) != NULL
)
3184 username
= attr
->values
[0].string
.text
;
3187 send_ipp_status(con
, IPP_BAD_REQUEST
,
3188 _("Missing requesting-user-name attribute."));
3196 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
3199 * See if we have a printer URI...
3202 if (strcmp(uri
->name
, "printer-uri"))
3204 send_ipp_status(con
, IPP_BAD_REQUEST
,
3205 _("The printer-uri attribute is required."));
3210 * And if the destination is valid...
3213 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3219 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
,
3220 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
3221 hostname
, sizeof(hostname
), &port
,
3222 resource
, sizeof(resource
));
3224 if ((!strncmp(resource
, "/printers/", 10) && resource
[10]) ||
3225 (!strncmp(resource
, "/classes/", 9) && resource
[9]))
3227 send_ipp_status(con
, IPP_NOT_FOUND
,
3228 _("The printer or class does not exist."));
3236 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
3238 send_http_error(con
, status
, NULL
);
3244 for (i
= 0; i
< job_ids
->num_values
; i
++)
3246 if ((job
= cupsdFindJob(job_ids
->values
[i
].integer
)) == NULL
)
3249 if (con
->request
->request
.op
.operation_id
== IPP_CANCEL_MY_JOBS
&&
3250 _cups_strcasecmp(job
->username
, username
))
3254 if (i
< job_ids
->num_values
)
3256 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3257 job_ids
->values
[i
].integer
);
3261 for (i
= 0; i
< job_ids
->num_values
; i
++)
3263 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
3265 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3266 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
3267 "Job canceled by user.");
3270 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
3271 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3277 * Cancel all jobs on all printers...
3280 cupsdCancelJobs(NULL
, username
, purge
);
3282 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs were %s by \"%s\".",
3283 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3293 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
3296 send_http_error(con
, status
, printer
);
3302 for (i
= 0; i
< job_ids
->num_values
; i
++)
3304 if ((job
= cupsdFindJob(job_ids
->values
[i
].integer
)) == NULL
||
3305 _cups_strcasecmp(job
->dest
, printer
->name
))
3308 if (con
->request
->request
.op
.operation_id
== IPP_CANCEL_MY_JOBS
&&
3309 _cups_strcasecmp(job
->username
, username
))
3313 if (i
< job_ids
->num_values
)
3315 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3316 job_ids
->values
[i
].integer
);
3320 for (i
= 0; i
< job_ids
->num_values
; i
++)
3322 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
3324 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3325 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
3326 "Job canceled by user.");
3329 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
3330 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3336 * Cancel all of the jobs on the named printer...
3339 cupsdCancelJobs(printer
->name
, username
, purge
);
3341 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs on \"%s\" were %s by \"%s\".",
3343 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3348 con
->response
->request
.status
.status_code
= IPP_OK
;
3353 * 'cancel_job()' - Cancel a print job.
3357 cancel_job(cupsd_client_t
*con
, /* I - Client connection */
3358 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3360 ipp_attribute_t
*attr
; /* Current attribute */
3361 int jobid
; /* Job ID */
3362 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3363 username
[HTTP_MAX_URI
], /* Username portion of URI */
3364 host
[HTTP_MAX_URI
], /* Host portion of URI */
3365 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3366 int port
; /* Port portion of URI */
3367 cupsd_job_t
*job
; /* Job information */
3368 cups_ptype_t dtype
; /* Destination type (printer/class) */
3369 cupsd_printer_t
*printer
; /* Printer data */
3370 cupsd_jobaction_t purge
; /* Purge the job? */
3373 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_job(%p[%d], %s)", con
,
3374 con
->number
, uri
->values
[0].string
.text
);
3377 * See if we have a job URI or a printer URI...
3380 if (!strcmp(uri
->name
, "printer-uri"))
3383 * Got a printer URI; see if we also have a job-id attribute...
3386 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3387 IPP_TAG_INTEGER
)) == NULL
)
3389 send_ipp_status(con
, IPP_BAD_REQUEST
,
3390 _("Got a printer-uri attribute but no job-id."));
3394 if ((jobid
= attr
->values
[0].integer
) == 0)
3397 * Find the current job on the specified printer...
3400 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3406 send_ipp_status(con
, IPP_NOT_FOUND
,
3407 _("The printer or class does not exist."));
3412 * See if there are any pending jobs...
3415 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3417 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3418 if (job
->state_value
<= IPP_JOB_PROCESSING
&&
3419 !_cups_strcasecmp(job
->dest
, printer
->name
))
3427 * No, try stopped jobs...
3430 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3432 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3433 if (job
->state_value
== IPP_JOB_STOPPED
&&
3434 !_cups_strcasecmp(job
->dest
, printer
->name
))
3441 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("No active jobs on %s."),
3451 * Got a job URI; parse it to get the job ID...
3454 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
3455 sizeof(scheme
), username
, sizeof(username
), host
,
3456 sizeof(host
), &port
, resource
, sizeof(resource
));
3458 if (strncmp(resource
, "/jobs/", 6))
3464 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
3465 uri
->values
[0].string
.text
);
3469 jobid
= atoi(resource
+ 6);
3473 * Look for the "purge-job" attribute...
3476 if ((attr
= ippFindAttribute(con
->request
, "purge-job",
3477 IPP_TAG_BOOLEAN
)) != NULL
)
3478 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
3480 purge
= CUPSD_JOB_DEFAULT
;
3483 * See if the job exists...
3486 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3489 * Nope - return a "not found" error...
3492 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
3497 * See if the job is owned by the requesting user...
3500 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3502 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3503 cupsdFindDest(job
->dest
));
3508 * See if the job is already completed, canceled, or aborted; if so,
3509 * we can't cancel...
3512 if (job
->state_value
>= IPP_JOB_CANCELED
&& purge
!= CUPSD_JOB_PURGE
)
3514 switch (job
->state_value
)
3516 case IPP_JOB_CANCELED
:
3517 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3518 _("Job #%d is already canceled - can\'t cancel."),
3522 case IPP_JOB_ABORTED
:
3523 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3524 _("Job #%d is already aborted - can\'t cancel."),
3529 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3530 _("Job #%d is already completed - can\'t cancel."),
3539 * Cancel the job and return...
3542 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3543 purge
== CUPSD_JOB_PURGE
? "Job purged by \"%s\"" :
3544 "Job canceled by \"%s\"",
3548 if (purge
== CUPSD_JOB_PURGE
)
3549 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Purged by \"%s\".", jobid
,
3552 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Canceled by \"%s\".", jobid
,
3555 con
->response
->request
.status
.status_code
= IPP_OK
;
3560 * 'cancel_subscription()' - Cancel a subscription.
3564 cancel_subscription(
3565 cupsd_client_t
*con
, /* I - Client connection */
3566 int sub_id
) /* I - Subscription ID */
3568 http_status_t status
; /* Policy status */
3569 cupsd_subscription_t
*sub
; /* Subscription */
3572 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3573 "cancel_subscription(con=%p[%d], sub_id=%d)",
3574 con
, con
->number
, sub_id
);
3577 * Is the subscription ID valid?
3580 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
3583 * Bad subscription ID...
3586 send_ipp_status(con
, IPP_NOT_FOUND
,
3587 _("Subscription #%d does not exist."), sub_id
);
3595 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
3597 con
, sub
->owner
)) != HTTP_OK
)
3599 send_http_error(con
, status
, sub
->dest
);
3604 * Cancel the subscription...
3607 cupsdDeleteSubscription(sub
, 1);
3609 con
->response
->request
.status
.status_code
= IPP_OK
;
3614 * 'check_rss_recipient()' - Check that we do not have a duplicate RSS feed URI.
3617 static int /* O - 1 if OK, 0 if not */
3618 check_rss_recipient(
3619 const char *recipient
) /* I - Recipient URI */
3621 cupsd_subscription_t
*sub
; /* Current subscription */
3624 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
);
3626 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
3630 * Compare the URIs up to the first ?...
3633 const char *r1
, *r2
;
3635 for (r1
= recipient
, r2
= sub
->recipient
;
3636 *r1
== *r2
&& *r1
&& *r1
!= '?' && *r2
&& *r2
!= '?';
3648 * 'check_quotas()' - Check quotas for a printer and user.
3651 static int /* O - 1 if OK, 0 if forbidden,
3652 -1 if limit reached */
3653 check_quotas(cupsd_client_t
*con
, /* I - Client connection */
3654 cupsd_printer_t
*p
) /* I - Printer or class */
3656 char username
[33], /* Username */
3657 *name
; /* Current user name */
3658 cupsd_quota_t
*q
; /* Quota data */
3659 #ifdef HAVE_MBR_UID_TO_UUID
3661 * Use Apple membership APIs which require that all names represent
3662 * valid user account or group records accessible by the server.
3665 uuid_t usr_uuid
; /* UUID for job requesting user */
3666 uuid_t usr2_uuid
; /* UUID for ACL user name entry */
3667 uuid_t grp_uuid
; /* UUID for ACL group name entry */
3668 int mbr_err
; /* Error from membership function */
3669 int is_member
; /* Is this user a member? */
3672 * Use standard POSIX APIs for checking users and groups...
3675 struct passwd
*pw
; /* User password data */
3676 #endif /* HAVE_MBR_UID_TO_UUID */
3679 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "check_quotas(%p[%d], %p[%s])",
3680 con
, con
->number
, p
, p
->name
);
3683 * Figure out who is printing...
3686 strlcpy(username
, get_username(con
), sizeof(username
));
3688 if ((name
= strchr(username
, '@')) != NULL
)
3689 *name
= '\0'; /* Strip @REALM */
3692 * Check global active job limits for printers and users...
3695 if (MaxJobsPerPrinter
)
3698 * Check if there are too many pending jobs on this printer...
3701 if (cupsdGetPrinterJobCount(p
->name
) >= MaxJobsPerPrinter
)
3703 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for printer \"%s\"...",
3712 * Check if there are too many pending jobs for this user...
3715 if (cupsdGetUserJobCount(username
) >= MaxJobsPerUser
)
3717 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for user \"%s\"...",
3724 * Check against users...
3727 if (cupsArrayCount(p
->users
) == 0 && p
->k_limit
== 0 && p
->page_limit
== 0)
3730 if (cupsArrayCount(p
->users
))
3732 #ifdef HAVE_MBR_UID_TO_UUID
3734 * Get UUID for job requesting user...
3737 if (mbr_user_name_to_uuid((char *)username
, usr_uuid
))
3743 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3744 "check_quotas: UUID lookup failed for user \"%s\"",
3746 cupsdLogMessage(CUPSD_LOG_INFO
,
3747 "Denying user \"%s\" access to printer \"%s\" "
3748 "(unknown user)...",
3754 * Get UID and GID of requesting user...
3757 pw
= getpwnam(username
);
3759 #endif /* HAVE_MBR_UID_TO_UUID */
3761 for (name
= (char *)cupsArrayFirst(p
->users
);
3763 name
= (char *)cupsArrayNext(p
->users
))
3767 * Check group membership...
3770 #ifdef HAVE_MBR_UID_TO_UUID
3773 if (uuid_parse(name
+ 2, grp_uuid
))
3774 uuid_clear(grp_uuid
);
3776 else if ((mbr_err
= mbr_group_name_to_uuid(name
+ 1, grp_uuid
)) != 0)
3779 * Invalid ACL entries are ignored for matching; just record a
3780 * warning in the log...
3783 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3784 "check_quotas: UUID lookup failed for ACL entry "
3785 "\"%s\" (err=%d)", name
, mbr_err
);
3786 cupsdLogMessage(CUPSD_LOG_WARN
,
3787 "Access control entry \"%s\" not a valid group name; "
3788 "entry ignored", name
);
3791 if ((mbr_err
= mbr_check_membership(usr_uuid
, grp_uuid
,
3795 * At this point, there should be no errors, but check anyways...
3798 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3799 "check_quotas: group \"%s\" membership check "
3800 "failed (err=%d)", name
+ 1, mbr_err
);
3805 * Stop if we found a match...
3812 if (cupsdCheckGroup(username
, pw
, name
+ 1))
3814 #endif /* HAVE_MBR_UID_TO_UUID */
3816 #ifdef HAVE_MBR_UID_TO_UUID
3821 if (uuid_parse(name
+ 1, usr2_uuid
))
3822 uuid_clear(usr2_uuid
);
3824 else if ((mbr_err
= mbr_user_name_to_uuid(name
, usr2_uuid
)) != 0)
3827 * Invalid ACL entries are ignored for matching; just record a
3828 * warning in the log...
3831 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3832 "check_quotas: UUID lookup failed for ACL entry "
3833 "\"%s\" (err=%d)", name
, mbr_err
);
3834 cupsdLogMessage(CUPSD_LOG_WARN
,
3835 "Access control entry \"%s\" not a valid user name; "
3836 "entry ignored", name
);
3839 if (!uuid_compare(usr_uuid
, usr2_uuid
))
3843 else if (!_cups_strcasecmp(username
, name
))
3845 #endif /* HAVE_MBR_UID_TO_UUID */
3847 if ((name
!= NULL
) == p
->deny_users
)
3849 cupsdLogMessage(CUPSD_LOG_INFO
,
3850 "Denying user \"%s\" access to printer \"%s\"...",
3860 if (p
->k_limit
|| p
->page_limit
)
3862 if ((q
= cupsdUpdateQuota(p
, username
, 0, 0)) == NULL
)
3864 cupsdLogMessage(CUPSD_LOG_ERROR
,
3865 "Unable to allocate quota data for user \"%s\"",
3870 if ((q
->k_count
>= p
->k_limit
&& p
->k_limit
) ||
3871 (q
->page_count
>= p
->page_limit
&& p
->page_limit
))
3873 cupsdLogMessage(CUPSD_LOG_INFO
, "User \"%s\" is over the quota limit...",
3880 * If we have gotten this far, we're done!
3888 * 'close_job()' - Close a multi-file job.
3892 close_job(cupsd_client_t
*con
, /* I - Client connection */
3893 ipp_attribute_t
*uri
) /* I - Printer URI */
3895 cupsd_job_t
*job
; /* Job */
3896 ipp_attribute_t
*attr
; /* Attribute */
3897 char job_uri
[HTTP_MAX_URI
],
3899 username
[256]; /* User name */
3902 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "close_job(%p[%d], %s)", con
,
3903 con
->number
, uri
->values
[0].string
.text
);
3906 * See if we have a job URI or a printer URI...
3909 if (strcmp(uri
->name
, "printer-uri"))
3912 * job-uri is not supported by Close-Job!
3915 send_ipp_status(con
, IPP_BAD_REQUEST
,
3916 _("Close-Job doesn't support the job-uri attribute."));
3921 * Got a printer URI; see if we also have a job-id attribute...
3924 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3925 IPP_TAG_INTEGER
)) == NULL
)
3927 send_ipp_status(con
, IPP_BAD_REQUEST
,
3928 _("Got a printer-uri attribute but no job-id."));
3932 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
3935 * Nope - return a "not found" error...
3938 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3939 attr
->values
[0].integer
);
3944 * See if the job is owned by the requesting user...
3947 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3949 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3950 cupsdFindDest(job
->dest
));
3955 * Add any ending sheet...
3958 if (cupsdTimeoutJob(job
))
3961 if (job
->state_value
== IPP_JOB_STOPPED
)
3963 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
3964 job
->state_value
= IPP_JOB_PENDING
;
3966 else if (job
->state_value
== IPP_JOB_HELD
)
3968 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
3969 IPP_TAG_KEYWORD
)) == NULL
)
3970 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
3972 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
3974 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
3975 job
->state_value
= IPP_JOB_PENDING
;
3980 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
3983 * Fill in the response info...
3986 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
3987 con
->clientname
, con
->clientport
, "/jobs/%d", job
->id
);
3988 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
3991 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
3993 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
3996 con
->response
->request
.status
.status_code
= IPP_OK
;
3999 * Start the job if necessary...
4007 * 'copy_attrs()' - Copy attributes from one request to another.
4011 copy_attrs(ipp_t
*to
, /* I - Destination request */
4012 ipp_t
*from
, /* I - Source request */
4013 cups_array_t
*ra
, /* I - Requested attributes */
4014 ipp_tag_t group
, /* I - Group to copy */
4015 int quickcopy
, /* I - Do a quick copy? */
4016 cups_array_t
*exclude
) /* I - Attributes to exclude? */
4018 ipp_attribute_t
*fromattr
; /* Source attribute */
4021 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4022 "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)",
4023 to
, from
, ra
, group
, quickcopy
);
4028 for (fromattr
= from
->attrs
; fromattr
; fromattr
= fromattr
->next
)
4031 * Filter attributes as needed...
4034 if ((group
!= IPP_TAG_ZERO
&& fromattr
->group_tag
!= group
&&
4035 fromattr
->group_tag
!= IPP_TAG_ZERO
) || !fromattr
->name
)
4038 if (!strcmp(fromattr
->name
, "document-password") ||
4039 !strcmp(fromattr
->name
, "job-authorization-uri") ||
4040 !strcmp(fromattr
->name
, "job-password") ||
4041 !strcmp(fromattr
->name
, "job-password-encryption") ||
4042 !strcmp(fromattr
->name
, "job-printer-uri"))
4046 (cupsArrayFind(exclude
, fromattr
->name
) ||
4047 cupsArrayFind(exclude
, "all")))
4050 * We need to exclude this attribute for security reasons; we require the
4051 * job-id attribute regardless of the security settings for IPP
4054 * The job-printer-uri attribute is handled by copy_job_attrs().
4056 * Subscription attribute security is handled by copy_subscription_attrs().
4059 if (strcmp(fromattr
->name
, "job-id"))
4063 if (!ra
|| cupsArrayFind(ra
, fromattr
->name
))
4066 * Don't send collection attributes by default to IPP/1.x clients
4067 * since many do not support collections. Also don't send
4068 * media-col-database unless specifically requested by the client.
4071 if (fromattr
->value_tag
== IPP_TAG_BEGIN_COLLECTION
&&
4073 (to
->request
.status
.version
[0] == 1 ||
4074 !strcmp(fromattr
->name
, "media-col-database")))
4077 ippCopyAttribute(to
, fromattr
, quickcopy
);
4084 * 'copy_banner()' - Copy a banner file to the requests directory for the
4088 static int /* O - Size of banner file in kbytes */
4089 copy_banner(cupsd_client_t
*con
, /* I - Client connection */
4090 cupsd_job_t
*job
, /* I - Job information */
4091 const char *name
) /* I - Name of banner */
4093 int i
; /* Looping var */
4094 int kbytes
; /* Size of banner file in kbytes */
4095 char filename
[1024]; /* Job filename */
4096 cupsd_banner_t
*banner
; /* Pointer to banner */
4097 cups_file_t
*in
; /* Input file */
4098 cups_file_t
*out
; /* Output file */
4099 int ch
; /* Character from file */
4100 char attrname
[255], /* Name of attribute */
4101 *s
; /* Pointer into name */
4102 ipp_attribute_t
*attr
; /* Attribute */
4105 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4106 "copy_banner(con=%p[%d], job=%p[%d], name=\"%s\")",
4107 con
, con
? con
->number
: -1, job
, job
->id
,
4108 name
? name
: "(null)");
4111 * Find the banner; return if not found or "none"...
4114 if (!name
|| !strcmp(name
, "none") ||
4115 (banner
= cupsdFindBanner(name
)) == NULL
)
4119 * Open the banner and job files...
4122 if (add_file(con
, job
, banner
->filetype
, 0))
4125 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
4127 if ((out
= cupsFileOpen(filename
, "w")) == NULL
)
4129 cupsdLogMessage(CUPSD_LOG_ERROR
,
4130 "Unable to create banner job file %s - %s",
4131 filename
, strerror(errno
));
4136 fchmod(cupsFileNumber(out
), 0640);
4137 fchown(cupsFileNumber(out
), RunUser
, Group
);
4140 * Try the localized banner file under the subdirectory...
4143 strlcpy(attrname
, job
->attrs
->attrs
->next
->values
[0].string
.text
,
4145 if (strlen(attrname
) > 2 && attrname
[2] == '-')
4148 * Convert ll-cc to ll_CC...
4152 attrname
[3] = (char)toupper(attrname
[3] & 255);
4153 attrname
[4] = (char)toupper(attrname
[4] & 255);
4156 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4159 if (access(filename
, 0) && strlen(attrname
) > 2)
4162 * Wasn't able to find "ll_CC" locale file; try the non-national
4163 * localization banner directory.
4168 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4172 if (access(filename
, 0))
4175 * Use the non-localized banner file.
4178 snprintf(filename
, sizeof(filename
), "%s/banners/%s", DataDir
, name
);
4181 if ((in
= cupsFileOpen(filename
, "r")) == NULL
)
4185 cupsdLogMessage(CUPSD_LOG_ERROR
,
4186 "Unable to open banner template file %s - %s",
4187 filename
, strerror(errno
));
4193 * Parse the file to the end...
4196 while ((ch
= cupsFileGetChar(in
)) != EOF
)
4200 * Get an attribute name...
4203 for (s
= attrname
; (ch
= cupsFileGetChar(in
)) != EOF
;)
4204 if (!isalpha(ch
& 255) && ch
!= '-' && ch
!= '?')
4206 else if (s
< (attrname
+ sizeof(attrname
) - 1))
4216 * Ignore { followed by stuff that is not an attribute name...
4219 cupsFilePrintf(out
, "{%s%c", attrname
, ch
);
4224 * See if it is defined...
4227 if (attrname
[0] == '?')
4232 if (!strcmp(s
, "printer-name"))
4234 cupsFilePuts(out
, job
->dest
);
4237 else if ((attr
= ippFindAttribute(job
->attrs
, s
, IPP_TAG_ZERO
)) == NULL
)
4240 * See if we have a leading question mark...
4243 if (attrname
[0] != '?')
4246 * Nope, write to file as-is; probably a PostScript procedure...
4249 cupsFilePrintf(out
, "{%s}", attrname
);
4256 * Output value(s)...
4259 for (i
= 0; i
< attr
->num_values
; i
++)
4262 cupsFilePutChar(out
, ',');
4264 switch (attr
->value_tag
)
4266 case IPP_TAG_INTEGER
:
4268 if (!strncmp(s
, "time-at-", 8))
4270 struct timeval tv
; /* Time value */
4272 tv
.tv_sec
= attr
->values
[i
].integer
;
4275 cupsFilePuts(out
, cupsdGetDateTime(&tv
, CUPSD_TIME_STANDARD
));
4278 cupsFilePrintf(out
, "%d", attr
->values
[i
].integer
);
4281 case IPP_TAG_BOOLEAN
:
4282 cupsFilePrintf(out
, "%d", attr
->values
[i
].boolean
);
4285 case IPP_TAG_NOVALUE
:
4286 cupsFilePuts(out
, "novalue");
4289 case IPP_TAG_RANGE
:
4290 cupsFilePrintf(out
, "%d-%d", attr
->values
[i
].range
.lower
,
4291 attr
->values
[i
].range
.upper
);
4294 case IPP_TAG_RESOLUTION
:
4295 cupsFilePrintf(out
, "%dx%d%s", attr
->values
[i
].resolution
.xres
,
4296 attr
->values
[i
].resolution
.yres
,
4297 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
4302 case IPP_TAG_STRING
:
4305 case IPP_TAG_KEYWORD
:
4306 case IPP_TAG_CHARSET
:
4307 case IPP_TAG_LANGUAGE
:
4308 if (!_cups_strcasecmp(banner
->filetype
->type
, "postscript"))
4311 * Need to quote strings for PS banners...
4316 for (p
= attr
->values
[i
].string
.text
; *p
; p
++)
4318 if (*p
== '(' || *p
== ')' || *p
== '\\')
4320 cupsFilePutChar(out
, '\\');
4321 cupsFilePutChar(out
, *p
);
4323 else if (*p
< 32 || *p
> 126)
4324 cupsFilePrintf(out
, "\\%03o", *p
& 255);
4326 cupsFilePutChar(out
, *p
);
4330 cupsFilePuts(out
, attr
->values
[i
].string
.text
);
4334 break; /* anti-compiler-warning-code */
4338 else if (ch
== '\\') /* Quoted char */
4340 ch
= cupsFileGetChar(in
);
4342 if (ch
!= '{') /* Only do special handling for \{ */
4343 cupsFilePutChar(out
, '\\');
4345 cupsFilePutChar(out
, ch
);
4348 cupsFilePutChar(out
, ch
);
4352 kbytes
= (cupsFileTell(out
) + 1023) / 1024;
4354 job
->koctets
+= kbytes
;
4356 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets", IPP_TAG_INTEGER
)) != NULL
)
4357 attr
->values
[0].integer
+= kbytes
;
4366 * 'copy_file()' - Copy a PPD file or interface script...
4369 static int /* O - 0 = success, -1 = error */
4370 copy_file(const char *from
, /* I - Source file */
4371 const char *to
) /* I - Destination file */
4373 cups_file_t
*src
, /* Source file */
4374 *dst
; /* Destination file */
4375 int bytes
; /* Bytes to read/write */
4376 char buffer
[2048]; /* Copy buffer */
4379 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_file(\"%s\", \"%s\")", from
, to
);
4382 * Open the source and destination file for a copy...
4385 if ((src
= cupsFileOpen(from
, "rb")) == NULL
)
4388 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
4395 * Copy the source file to the destination...
4398 while ((bytes
= cupsFileRead(src
, buffer
, sizeof(buffer
))) > 0)
4399 if (cupsFileWrite(dst
, buffer
, (size_t)bytes
) < bytes
)
4407 * Close both files and return...
4412 return (cupsFileClose(dst
));
4417 * 'copy_model()' - Copy a PPD model file, substituting default values
4421 static int /* O - 0 = success, -1 = error */
4422 copy_model(cupsd_client_t
*con
, /* I - Client connection */
4423 const char *from
, /* I - Source file */
4424 const char *to
) /* I - Destination file */
4426 fd_set input
; /* select() input set */
4427 struct timeval timeout
; /* select() timeout */
4428 int maxfd
; /* Max file descriptor for select() */
4429 char tempfile
[1024]; /* Temporary PPD file */
4430 int tempfd
; /* Temporary PPD file descriptor */
4431 int temppid
; /* Process ID of cups-driverd */
4432 int temppipe
[2]; /* Temporary pipes */
4433 char *argv
[4], /* Command-line arguments */
4434 *envp
[MAX_ENV
]; /* Environment */
4435 cups_file_t
*src
, /* Source file */
4436 *dst
; /* Destination file */
4437 ppd_file_t
*ppd
; /* PPD file */
4438 int bytes
, /* Bytes from pipe */
4439 total
; /* Total bytes from pipe */
4440 char buffer
[2048]; /* Copy buffer */
4441 int i
; /* Looping var */
4442 char option
[PPD_MAX_NAME
], /* Option name */
4443 choice
[PPD_MAX_NAME
]; /* Choice name */
4444 ppd_size_t
*size
; /* Default size */
4445 int num_defaults
; /* Number of default options */
4446 cups_option_t
*defaults
; /* Default options */
4447 char cups_protocol
[PPD_MAX_LINE
];
4448 /* cupsProtocol attribute */
4451 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4452 "copy_model(con=%p, from=\"%s\", to=\"%s\")",
4456 * Run cups-driverd to get the PPD file...
4459 argv
[0] = "cups-driverd";
4461 argv
[2] = (char *)from
;
4464 cupsdLoadEnv(envp
, (int)(sizeof(envp
) / sizeof(envp
[0])));
4466 snprintf(buffer
, sizeof(buffer
), "%s/daemon/cups-driverd", ServerBin
);
4467 snprintf(tempfile
, sizeof(tempfile
), "%s/%d.ppd", TempDir
, con
->number
);
4468 tempfd
= open(tempfile
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
4469 if (tempfd
< 0 || cupsdOpenPipe(temppipe
))
4472 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4473 "copy_model: Running \"cups-driverd cat %s\"...", from
);
4475 if (!cupsdStartProcess(buffer
, argv
, envp
, -1, temppipe
[1], CGIPipes
[1],
4476 -1, -1, 0, DefaultProfile
, NULL
, &temppid
))
4487 * Wait up to 30 seconds for the PPD file to be copied...
4492 if (temppipe
[0] > CGIPipes
[0])
4493 maxfd
= temppipe
[0] + 1;
4495 maxfd
= CGIPipes
[0] + 1;
4500 * See if we have data ready...
4504 FD_SET(temppipe
[0], &input
);
4505 FD_SET(CGIPipes
[0], &input
);
4507 timeout
.tv_sec
= 30;
4508 timeout
.tv_usec
= 0;
4510 if ((i
= select(maxfd
, &input
, NULL
, NULL
, &timeout
)) < 0)
4520 * We have timed out...
4526 if (FD_ISSET(temppipe
[0], &input
))
4529 * Read the PPD file from the pipe, and write it to the PPD file.
4532 if ((bytes
= read(temppipe
[0], buffer
, sizeof(buffer
))) > 0)
4534 if (write(tempfd
, buffer
, (size_t)bytes
) < bytes
)
4543 if (FD_ISSET(CGIPipes
[0], &input
))
4553 * No data from cups-deviced...
4556 cupsdLogMessage(CUPSD_LOG_ERROR
, "copy_model: empty PPD file");
4562 * Open the source file for a copy...
4565 if ((src
= cupsFileOpen(tempfile
, "rb")) == NULL
)
4572 * Read the source file and see what page sizes are supported...
4575 if ((ppd
= _ppdOpen(src
, _PPD_LOCALIZATION_NONE
)) == NULL
)
4583 * Open the destination (if possible) and set the default options...
4588 cups_protocol
[0] = '\0';
4590 if ((dst
= cupsFileOpen(to
, "rb")) != NULL
)
4593 * Read all of the default lines from the old PPD...
4596 while (cupsFileGets(dst
, buffer
, sizeof(buffer
)))
4597 if (!strncmp(buffer
, "*Default", 8))
4600 * Add the default option...
4603 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
4604 choice
, sizeof(choice
)))
4606 ppd_option_t
*ppdo
; /* PPD option */
4610 * Only add the default if the default hasn't already been
4611 * set and the choice exists in the new PPD...
4614 if (!cupsGetOption(option
, num_defaults
, defaults
) &&
4615 (ppdo
= ppdFindOption(ppd
, option
)) != NULL
&&
4616 ppdFindChoice(ppdo
, choice
))
4617 num_defaults
= cupsAddOption(option
, choice
, num_defaults
,
4621 else if (!strncmp(buffer
, "*cupsProtocol:", 14))
4622 strlcpy(cups_protocol
, buffer
, sizeof(cups_protocol
));
4626 else if ((size
= ppdPageSize(ppd
, DefaultPaperSize
)) != NULL
)
4629 * Add the default media sizes...
4632 num_defaults
= cupsAddOption("PageSize", size
->name
,
4633 num_defaults
, &defaults
);
4634 num_defaults
= cupsAddOption("PageRegion", size
->name
,
4635 num_defaults
, &defaults
);
4636 num_defaults
= cupsAddOption("PaperDimension", size
->name
,
4637 num_defaults
, &defaults
);
4638 num_defaults
= cupsAddOption("ImageableArea", size
->name
,
4639 num_defaults
, &defaults
);
4645 * Open the destination file for a copy...
4648 if ((dst
= cupsdCreateConfFile(to
, ConfigFilePerm
)) == NULL
)
4650 cupsFreeOptions(num_defaults
, defaults
);
4657 * Copy the source file to the destination...
4660 cupsFileRewind(src
);
4662 while (cupsFileGets(src
, buffer
, sizeof(buffer
)))
4664 if (!strncmp(buffer
, "*Default", 8))
4667 * Check for an previous default option choice...
4670 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
4671 choice
, sizeof(choice
)))
4673 const char *val
; /* Default option value */
4676 if ((val
= cupsGetOption(option
, num_defaults
, defaults
)) != NULL
)
4679 * Substitute the previous choice...
4682 snprintf(buffer
, sizeof(buffer
), "*Default%s: %s", option
, val
);
4687 cupsFilePrintf(dst
, "%s\n", buffer
);
4690 if (cups_protocol
[0])
4691 cupsFilePrintf(dst
, "%s\n", cups_protocol
);
4693 cupsFreeOptions(num_defaults
, defaults
);
4696 * Close both files and return...
4703 return (cupsdCloseCreatedConfFile(dst
, to
));
4708 * 'copy_job_attrs()' - Copy job attributes.
4712 copy_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
4713 cupsd_job_t
*job
, /* I - Job */
4714 cups_array_t
*ra
, /* I - Requested attributes array */
4715 cups_array_t
*exclude
) /* I - Private attributes array */
4717 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
4721 * Send the requested attributes for each job...
4724 if (!cupsArrayFind(exclude
, "all"))
4726 if ((!exclude
|| !cupsArrayFind(exclude
, "number-of-documents")) &&
4727 (!ra
|| cupsArrayFind(ra
, "number-of-documents")))
4728 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4729 "number-of-documents", job
->num_files
);
4731 if ((!exclude
|| !cupsArrayFind(exclude
, "job-media-progress")) &&
4732 (!ra
|| cupsArrayFind(ra
, "job-media-progress")))
4733 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4734 "job-media-progress", job
->progress
);
4736 if ((!exclude
|| !cupsArrayFind(exclude
, "job-more-info")) &&
4737 (!ra
|| cupsArrayFind(ra
, "job-more-info")))
4739 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "http",
4740 NULL
, con
->clientname
, con
->clientport
, "/jobs/%d",
4742 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4743 "job-more-info", NULL
, job_uri
);
4746 if (job
->state_value
> IPP_JOB_PROCESSING
&&
4747 (!exclude
|| !cupsArrayFind(exclude
, "job-preserved")) &&
4748 (!ra
|| cupsArrayFind(ra
, "job-preserved")))
4749 ippAddBoolean(con
->response
, IPP_TAG_JOB
, "job-preserved",
4750 job
->num_files
> 0);
4752 if ((!exclude
|| !cupsArrayFind(exclude
, "job-printer-up-time")) &&
4753 (!ra
|| cupsArrayFind(ra
, "job-printer-up-time")))
4754 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4755 "job-printer-up-time", time(NULL
));
4758 if (!ra
|| cupsArrayFind(ra
, "job-printer-uri"))
4760 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
4761 con
->clientname
, con
->clientport
,
4762 (job
->dtype
& CUPS_PRINTER_CLASS
) ? "/classes/%s" :
4765 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4766 "job-printer-uri", NULL
, job_uri
);
4769 if (!ra
|| cupsArrayFind(ra
, "job-uri"))
4771 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
4772 con
->clientname
, con
->clientport
, "/jobs/%d",
4774 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4775 "job-uri", NULL
, job_uri
);
4780 copy_attrs(con
->response
, job
->attrs
, ra
, IPP_TAG_JOB
, 0, exclude
);
4785 * Generate attributes from the job structure...
4788 if (job
->completed_time
&& (!ra
|| cupsArrayFind(ra
, "date-time-at-completed")))
4789 ippAddDate(con
->response
, IPP_TAG_JOB
, "date-time-at-completed", ippTimeToDate(job
->completed_time
));
4791 if (job
->creation_time
&& (!ra
|| cupsArrayFind(ra
, "date-time-at-creation")))
4792 ippAddDate(con
->response
, IPP_TAG_JOB
, "date-time-at-creation", ippTimeToDate(job
->creation_time
));
4794 if (!ra
|| cupsArrayFind(ra
, "job-id"))
4795 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
4797 if (!ra
|| cupsArrayFind(ra
, "job-k-octets"))
4798 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-k-octets", job
->koctets
);
4800 if (job
->name
&& (!ra
|| cupsArrayFind(ra
, "job-name")))
4801 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_CONST_TAG(IPP_TAG_NAME
), "job-name", NULL
, job
->name
);
4803 if (job
->username
&& (!ra
|| cupsArrayFind(ra
, "job-originating-user-name")))
4804 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_CONST_TAG(IPP_TAG_NAME
), "job-originating-user-name", NULL
, job
->username
);
4806 if (!ra
|| cupsArrayFind(ra
, "job-state"))
4807 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state", (int)job
->state_value
);
4809 if (!ra
|| cupsArrayFind(ra
, "job-state-reasons"))
4811 switch (job
->state_value
)
4813 default : /* Should never get here for processing, pending, held, or stopped jobs since they don't get unloaded... */
4815 case IPP_JSTATE_ABORTED
:
4816 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons", NULL
, "job-aborted-by-system");
4818 case IPP_JSTATE_CANCELED
:
4819 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons", NULL
, "job-canceled-by-user");
4821 case IPP_JSTATE_COMPLETED
:
4822 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons", NULL
, "job-completed-successfully");
4827 if (job
->completed_time
&& (!ra
|| cupsArrayFind(ra
, "time-at-completed")))
4828 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-completed", (int)job
->completed_time
);
4830 if (job
->creation_time
&& (!ra
|| cupsArrayFind(ra
, "time-at-creation")))
4831 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation", (int)job
->creation_time
);
4837 * 'copy_printer_attrs()' - Copy printer attributes.
4842 cupsd_client_t
*con
, /* I - Client connection */
4843 cupsd_printer_t
*printer
, /* I - Printer */
4844 cups_array_t
*ra
) /* I - Requested attributes array */
4846 char printer_uri
[HTTP_MAX_URI
];
4848 char printer_icons
[HTTP_MAX_URI
];
4850 time_t curtime
; /* Current time */
4851 int i
; /* Looping var */
4855 * Copy the printer attributes to the response using requested-attributes
4856 * and document-format attributes that may be provided by the client.
4859 curtime
= time(NULL
);
4861 if (!ra
|| cupsArrayFind(ra
, "marker-change-time"))
4862 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4863 "marker-change-time", printer
->marker_time
);
4865 if (printer
->num_printers
> 0 &&
4866 (!ra
|| cupsArrayFind(ra
, "member-uris")))
4868 ipp_attribute_t
*member_uris
; /* member-uris attribute */
4869 cupsd_printer_t
*p2
; /* Printer in class */
4870 ipp_attribute_t
*p2_uri
; /* printer-uri-supported for class printer */
4873 if ((member_uris
= ippAddStrings(con
->response
, IPP_TAG_PRINTER
,
4874 IPP_TAG_URI
, "member-uris",
4875 printer
->num_printers
, NULL
,
4878 for (i
= 0; i
< printer
->num_printers
; i
++)
4880 p2
= printer
->printers
[i
];
4882 if ((p2_uri
= ippFindAttribute(p2
->attrs
, "printer-uri-supported",
4883 IPP_TAG_URI
)) != NULL
)
4884 member_uris
->values
[i
].string
.text
=
4885 _cupsStrRetain(p2_uri
->values
[0].string
.text
);
4888 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
,
4889 sizeof(printer_uri
), "ipp", NULL
, con
->clientname
,
4891 (p2
->type
& CUPS_PRINTER_CLASS
) ?
4892 "/classes/%s" : "/printers/%s", p2
->name
);
4893 member_uris
->values
[i
].string
.text
= _cupsStrAlloc(printer_uri
);
4899 if (printer
->alert
&& (!ra
|| cupsArrayFind(ra
, "printer-alert")))
4900 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_STRING
,
4901 "printer-alert", NULL
, printer
->alert
);
4903 if (printer
->alert_description
&&
4904 (!ra
|| cupsArrayFind(ra
, "printer-alert-description")))
4905 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4906 "printer-alert-description", NULL
,
4907 printer
->alert_description
);
4909 if (!ra
|| cupsArrayFind(ra
, "printer-config-change-date-time"))
4910 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-config-change-date-time", ippTimeToDate(printer
->config_time
));
4912 if (!ra
|| cupsArrayFind(ra
, "printer-config-change-time"))
4913 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4914 "printer-config-change-time", printer
->config_time
);
4916 if (!ra
|| cupsArrayFind(ra
, "printer-current-time"))
4917 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-current-time",
4918 ippTimeToDate(curtime
));
4920 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
4921 if (!ra
|| cupsArrayFind(ra
, "printer-dns-sd-name"))
4923 if (printer
->reg_name
)
4924 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4925 "printer-dns-sd-name", NULL
, printer
->reg_name
);
4927 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
4928 "printer-dns-sd-name", 0);
4930 #endif /* HAVE_DNSSD || HAVE_AVAHI */
4932 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy"))
4933 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4934 "printer-error-policy", NULL
, printer
->error_policy
);
4936 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy-supported"))
4938 static const char * const errors
[] =/* printer-error-policy-supported values */
4941 "retry-current-job",
4946 if (printer
->type
& CUPS_PRINTER_CLASS
)
4947 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
4948 "printer-error-policy-supported", NULL
, "retry-current-job");
4950 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
4951 "printer-error-policy-supported",
4952 sizeof(errors
) / sizeof(errors
[0]), NULL
, errors
);
4955 if (!ra
|| cupsArrayFind(ra
, "printer-icons"))
4957 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_icons
, sizeof(printer_icons
),
4958 "http", NULL
, con
->clientname
, con
->clientport
,
4959 "/icons/%s.png", printer
->name
);
4960 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-icons",
4961 NULL
, printer_icons
);
4962 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-icons=\"%s\"", printer_icons
);
4965 if (!ra
|| cupsArrayFind(ra
, "printer-is-accepting-jobs"))
4966 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs", (char)printer
->accepting
);
4968 if (!ra
|| cupsArrayFind(ra
, "printer-is-shared"))
4969 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-shared", (char)printer
->shared
);
4971 if (!ra
|| cupsArrayFind(ra
, "printer-more-info"))
4973 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
4974 "http", NULL
, con
->clientname
, con
->clientport
,
4975 (printer
->type
& CUPS_PRINTER_CLASS
) ?
4976 "/classes/%s" : "/printers/%s", printer
->name
);
4977 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
4978 "printer-more-info", NULL
, printer_uri
);
4981 if (!ra
|| cupsArrayFind(ra
, "printer-op-policy"))
4982 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4983 "printer-op-policy", NULL
, printer
->op_policy
);
4985 if (!ra
|| cupsArrayFind(ra
, "printer-state"))
4986 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
4989 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-date-time"))
4990 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-state-change-date-time", ippTimeToDate(printer
->state_time
));
4992 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-time"))
4993 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4994 "printer-state-change-time", printer
->state_time
);
4996 if (!ra
|| cupsArrayFind(ra
, "printer-state-message"))
4997 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4998 "printer-state-message", NULL
, printer
->state_message
);
5000 if (!ra
|| cupsArrayFind(ra
, "printer-state-reasons"))
5001 add_printer_state_reasons(con
, printer
);
5003 if (!ra
|| cupsArrayFind(ra
, "printer-type"))
5005 cups_ptype_t type
; /* printer-type value */
5008 * Add the CUPS-specific printer-type attribute...
5011 type
= printer
->type
;
5013 if (printer
== DefaultPrinter
)
5014 type
|= CUPS_PRINTER_DEFAULT
;
5016 if (!printer
->accepting
)
5017 type
|= CUPS_PRINTER_REJECTING
;
5019 if (!printer
->shared
)
5020 type
|= CUPS_PRINTER_NOT_SHARED
;
5022 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-type", (int)type
);
5025 if (!ra
|| cupsArrayFind(ra
, "printer-up-time"))
5026 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5027 "printer-up-time", curtime
);
5029 if (!ra
|| cupsArrayFind(ra
, "printer-uri-supported"))
5031 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5032 "ipp", NULL
, con
->clientname
, con
->clientport
,
5033 (printer
->type
& CUPS_PRINTER_CLASS
) ?
5034 "/classes/%s" : "/printers/%s", printer
->name
);
5035 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5036 "printer-uri-supported", NULL
, printer_uri
);
5037 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-uri-supported=\"%s\"",
5041 if (!ra
|| cupsArrayFind(ra
, "queued-job-count"))
5042 add_queued_job_count(con
, printer
);
5044 copy_attrs(con
->response
, printer
->attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
5045 if (printer
->ppd_attrs
)
5046 copy_attrs(con
->response
, printer
->ppd_attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
5047 copy_attrs(con
->response
, CommonData
, ra
, IPP_TAG_ZERO
, IPP_TAG_COPY
, NULL
);
5052 * 'copy_subscription_attrs()' - Copy subscription attributes.
5056 copy_subscription_attrs(
5057 cupsd_client_t
*con
, /* I - Client connection */
5058 cupsd_subscription_t
*sub
, /* I - Subscription */
5059 cups_array_t
*ra
, /* I - Requested attributes array */
5060 cups_array_t
*exclude
) /* I - Private attributes array */
5062 ipp_attribute_t
*attr
; /* Current attribute */
5063 char printer_uri
[HTTP_MAX_URI
];
5065 int count
; /* Number of events */
5066 unsigned mask
; /* Current event mask */
5067 const char *name
; /* Current event name */
5070 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5071 "copy_subscription_attrs(con=%p, sub=%p, ra=%p, exclude=%p)",
5072 con
, sub
, ra
, exclude
);
5075 * Copy the subscription attributes to the response using the
5076 * requested-attributes attribute that may be provided by the client.
5079 if (!exclude
|| !cupsArrayFind(exclude
, "all"))
5081 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-events")) &&
5082 (!ra
|| cupsArrayFind(ra
, "notify-events")))
5084 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_subscription_attrs: notify-events");
5086 if ((name
= cupsdEventName((cupsd_eventmask_t
)sub
->mask
)) != NULL
)
5089 * Simple event list...
5092 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
,
5093 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5094 "notify-events", NULL
, name
);
5099 * Complex event list...
5102 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5103 if (sub
->mask
& mask
)
5106 attr
= ippAddStrings(con
->response
, IPP_TAG_SUBSCRIPTION
,
5107 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5108 "notify-events", count
, NULL
, NULL
);
5110 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5111 if (sub
->mask
& mask
)
5113 attr
->values
[count
].string
.text
=
5114 (char *)cupsdEventName((cupsd_eventmask_t
)mask
);
5121 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-lease-duration")) &&
5122 (!sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-lease-duration"))))
5123 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5124 "notify-lease-duration", sub
->lease
);
5126 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-recipient-uri")) &&
5127 (sub
->recipient
&& (!ra
|| cupsArrayFind(ra
, "notify-recipient-uri"))))
5128 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5129 "notify-recipient-uri", NULL
, sub
->recipient
);
5130 else if ((!exclude
|| !cupsArrayFind(exclude
, "notify-pull-method")) &&
5131 (!ra
|| cupsArrayFind(ra
, "notify-pull-method")))
5132 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_KEYWORD
,
5133 "notify-pull-method", NULL
, "ippget");
5135 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-subscriber-user-name")) &&
5136 (!ra
|| cupsArrayFind(ra
, "notify-subscriber-user-name")))
5137 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_NAME
,
5138 "notify-subscriber-user-name", NULL
, sub
->owner
);
5140 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-time-interval")) &&
5141 (!ra
|| cupsArrayFind(ra
, "notify-time-interval")))
5142 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5143 "notify-time-interval", sub
->interval
);
5145 if (sub
->user_data_len
> 0 &&
5146 (!exclude
|| !cupsArrayFind(exclude
, "notify-user-data")) &&
5147 (!ra
|| cupsArrayFind(ra
, "notify-user-data")))
5148 ippAddOctetString(con
->response
, IPP_TAG_SUBSCRIPTION
, "notify-user-data",
5149 sub
->user_data
, sub
->user_data_len
);
5152 if (sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-job-id")))
5153 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5154 "notify-job-id", sub
->job
->id
);
5156 if (sub
->dest
&& (!ra
|| cupsArrayFind(ra
, "notify-printer-uri")))
5158 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5159 "ipp", NULL
, con
->clientname
, con
->clientport
,
5160 "/printers/%s", sub
->dest
->name
);
5161 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5162 "notify-printer-uri", NULL
, printer_uri
);
5165 if (!ra
|| cupsArrayFind(ra
, "notify-subscription-id"))
5166 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5167 "notify-subscription-id", sub
->id
);
5172 * 'create_job()' - Print a file to a printer or class.
5176 create_job(cupsd_client_t
*con
, /* I - Client connection */
5177 ipp_attribute_t
*uri
) /* I - Printer URI */
5179 int i
; /* Looping var */
5180 cupsd_printer_t
*printer
; /* Printer */
5181 cupsd_job_t
*job
; /* New job */
5182 static const char * const forbidden_attrs
[] =
5183 { /* List of forbidden attributes */
5187 "document-natural-language"
5191 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "create_job(%p[%d], %s)", con
,
5192 con
->number
, uri
->values
[0].string
.text
);
5195 * Is the destination valid?
5198 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
5204 send_ipp_status(con
, IPP_NOT_FOUND
,
5205 _("The printer or class does not exist."));
5210 * Check for invalid Create-Job attributes and log a warning or error depending
5211 * on whether cupsd is running in "strict conformance" mode...
5215 i
< (int)(sizeof(forbidden_attrs
) / sizeof(forbidden_attrs
[0]));
5217 if (ippFindAttribute(con
->request
, forbidden_attrs
[i
], IPP_TAG_ZERO
))
5219 if (StrictConformance
)
5221 send_ipp_status(con
, IPP_BAD_REQUEST
,
5222 _("The '%s' operation attribute cannot be supplied in a "
5223 "Create-Job request."), forbidden_attrs
[i
]);
5227 cupsdLogMessage(CUPSD_LOG_WARN
,
5228 "Unexpected '%s' operation attribute in a Create-Job "
5229 "request.", forbidden_attrs
[i
]);
5233 * Create the job object...
5236 if ((job
= add_job(con
, printer
, NULL
)) == NULL
)
5239 job
->pending_timeout
= 1;
5242 * Save and log the job...
5245 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
5246 job
->dest
, job
->username
);
5251 * 'create_requested_array()' - Create an array for the requested-attributes.
5254 static cups_array_t
* /* O - Array of attributes or NULL */
5255 create_requested_array(ipp_t
*request
) /* I - IPP request */
5257 cups_array_t
*ra
; /* Requested attributes array */
5261 * Create the array for standard attributes...
5264 ra
= ippCreateRequestedArray(request
);
5267 * Add CUPS defaults as needed...
5270 if (cupsArrayFind(ra
, "printer-defaults"))
5273 * Include user-set defaults...
5276 char *name
; /* Option name */
5278 cupsArrayRemove(ra
, "printer-defaults");
5280 for (name
= (char *)cupsArrayFirst(CommonDefaults
);
5282 name
= (char *)cupsArrayNext(CommonDefaults
))
5283 if (!cupsArrayFind(ra
, name
))
5284 cupsArrayAdd(ra
, name
);
5292 * 'create_subscriptions()' - Create one or more notification subscriptions.
5296 create_subscriptions(
5297 cupsd_client_t
*con
, /* I - Client connection */
5298 ipp_attribute_t
*uri
) /* I - Printer URI */
5300 http_status_t status
; /* Policy status */
5301 int i
; /* Looping var */
5302 ipp_attribute_t
*attr
; /* Current attribute */
5303 cups_ptype_t dtype
; /* Destination type (printer/class) */
5304 char scheme
[HTTP_MAX_URI
],
5305 /* Scheme portion of URI */
5306 userpass
[HTTP_MAX_URI
],
5307 /* Username portion of URI */
5309 /* Host portion of URI */
5310 resource
[HTTP_MAX_URI
];
5311 /* Resource portion of URI */
5312 int port
; /* Port portion of URI */
5313 cupsd_printer_t
*printer
; /* Printer/class */
5314 cupsd_job_t
*job
; /* Job */
5315 int jobid
; /* Job ID */
5316 cupsd_subscription_t
*sub
; /* Subscription object */
5317 const char *username
, /* requesting-user-name or
5318 authenticated username */
5319 *recipient
, /* notify-recipient-uri */
5320 *pullmethod
; /* notify-pull-method */
5321 ipp_attribute_t
*user_data
; /* notify-user-data */
5322 int interval
, /* notify-time-interval */
5323 lease
; /* notify-lease-duration */
5324 unsigned mask
; /* notify-events */
5325 ipp_attribute_t
*notify_events
,/* notify-events(-default) */
5326 *notify_lease
; /* notify-lease-duration(-default) */
5330 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
5332 if (attr
->group_tag
!= IPP_TAG_ZERO
)
5333 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "g%04x v%04x %s", attr
->group_tag
,
5334 attr
->value_tag
, attr
->name
);
5336 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "----SEP----");
5341 * Is the destination valid?
5344 cupsdLogMessage(CUPSD_LOG_DEBUG
, "create_subscriptions(con=%p(%d), uri=\"%s\")", con
, con
->number
, uri
->values
[0].string
.text
);
5346 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
5347 sizeof(scheme
), userpass
, sizeof(userpass
), host
,
5348 sizeof(host
), &port
, resource
, sizeof(resource
));
5350 if (!strcmp(resource
, "/"))
5352 dtype
= (cups_ptype_t
)0;
5355 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
5357 dtype
= (cups_ptype_t
)0;
5360 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
5362 dtype
= CUPS_PRINTER_CLASS
;
5365 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
5371 send_ipp_status(con
, IPP_NOT_FOUND
,
5372 _("The printer or class does not exist."));
5382 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
5385 send_http_error(con
, status
, printer
);
5389 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5391 send_http_error(con
, status
, NULL
);
5396 * Get the user that is requesting the subscription...
5399 username
= get_username(con
);
5402 * Find the first subscription group attribute; return if we have
5406 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
5407 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
5412 send_ipp_status(con
, IPP_BAD_REQUEST
,
5413 _("No subscription attributes in request."));
5418 * Process the subscription attributes in the request...
5421 con
->response
->request
.status
.status_code
= IPP_BAD_REQUEST
;
5429 lease
= DefaultLeaseDuration
;
5431 mask
= CUPSD_EVENT_NONE
;
5435 notify_events
= ippFindAttribute(printer
->attrs
, "notify-events-default",
5437 notify_lease
= ippFindAttribute(printer
->attrs
,
5438 "notify-lease-duration-default",
5442 lease
= notify_lease
->values
[0].integer
;
5446 notify_events
= NULL
;
5447 notify_lease
= NULL
;
5450 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
5452 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
5453 attr
->value_tag
== IPP_TAG_URI
)
5456 * Validate the recipient scheme against the ServerBin/notifier
5460 char notifier
[1024]; /* Notifier filename */
5463 recipient
= attr
->values
[0].string
.text
;
5465 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
5466 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
5467 host
, sizeof(host
), &port
,
5468 resource
, sizeof(resource
)) < HTTP_URI_OK
)
5470 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5471 _("Bad notify-recipient-uri \"%s\"."), recipient
);
5472 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5473 "notify-status-code", IPP_URI_SCHEME
);
5477 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
5479 if (access(notifier
, X_OK
))
5481 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5482 _("notify-recipient-uri URI \"%s\" uses unknown "
5483 "scheme."), recipient
);
5484 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5485 "notify-status-code", IPP_URI_SCHEME
);
5489 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
5491 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5492 _("notify-recipient-uri URI \"%s\" is already used."),
5494 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5495 "notify-status-code", IPP_ATTRIBUTES
);
5499 else if (!strcmp(attr
->name
, "notify-pull-method") &&
5500 attr
->value_tag
== IPP_TAG_KEYWORD
)
5502 pullmethod
= attr
->values
[0].string
.text
;
5504 if (strcmp(pullmethod
, "ippget"))
5506 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5507 _("Bad notify-pull-method \"%s\"."), pullmethod
);
5508 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5509 "notify-status-code", IPP_ATTRIBUTES
);
5513 else if (!strcmp(attr
->name
, "notify-charset") &&
5514 attr
->value_tag
== IPP_TAG_CHARSET
&&
5515 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
5516 strcmp(attr
->values
[0].string
.text
, "utf-8"))
5518 send_ipp_status(con
, IPP_CHARSET
,
5519 _("Character set \"%s\" not supported."),
5520 attr
->values
[0].string
.text
);
5523 else if (!strcmp(attr
->name
, "notify-natural-language") &&
5524 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
5525 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
5527 send_ipp_status(con
, IPP_CHARSET
,
5528 _("Language \"%s\" not supported."),
5529 attr
->values
[0].string
.text
);
5532 else if (!strcmp(attr
->name
, "notify-user-data") &&
5533 attr
->value_tag
== IPP_TAG_STRING
)
5535 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
5537 send_ipp_status(con
, IPP_REQUEST_VALUE
,
5538 _("The notify-user-data value is too large "
5539 "(%d > 63 octets)."),
5540 attr
->values
[0].unknown
.length
);
5546 else if (!strcmp(attr
->name
, "notify-events") &&
5547 attr
->value_tag
== IPP_TAG_KEYWORD
)
5548 notify_events
= attr
;
5549 else if (!strcmp(attr
->name
, "notify-lease-duration") &&
5550 attr
->value_tag
== IPP_TAG_INTEGER
)
5551 lease
= attr
->values
[0].integer
;
5552 else if (!strcmp(attr
->name
, "notify-time-interval") &&
5553 attr
->value_tag
== IPP_TAG_INTEGER
)
5554 interval
= attr
->values
[0].integer
;
5555 else if (!strcmp(attr
->name
, "notify-job-id") &&
5556 attr
->value_tag
== IPP_TAG_INTEGER
)
5557 jobid
= attr
->values
[0].integer
;
5564 for (i
= 0; i
< notify_events
->num_values
; i
++)
5565 mask
|= cupsdEventValue(notify_events
->values
[i
].string
.text
);
5569 cupsdLogMessage(CUPSD_LOG_DEBUG
, "recipient=\"%s\"", recipient
);
5571 cupsdLogMessage(CUPSD_LOG_DEBUG
, "pullmethod=\"%s\"", pullmethod
);
5572 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-lease-duration=%d", lease
);
5573 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-time-interval=%d", interval
);
5575 if (!recipient
&& !pullmethod
)
5578 if (mask
== CUPSD_EVENT_NONE
)
5581 mask
= CUPSD_EVENT_JOB_COMPLETED
;
5583 mask
= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
5586 send_ipp_status(con
, IPP_BAD_REQUEST
,
5587 _("notify-events not specified."));
5592 if (MaxLeaseDuration
&& (lease
== 0 || lease
> MaxLeaseDuration
))
5594 cupsdLogMessage(CUPSD_LOG_INFO
,
5595 "create_subscriptions: Limiting notify-lease-duration to "
5598 lease
= MaxLeaseDuration
;
5603 if ((job
= cupsdFindJob(jobid
)) == NULL
)
5605 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
5613 if ((sub
= cupsdAddSubscription(mask
, printer
, job
, recipient
, 0)) == NULL
)
5615 send_ipp_status(con
, IPP_TOO_MANY_SUBSCRIPTIONS
,
5616 _("There are too many subscriptions."));
5621 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription #%d for job %d.",
5624 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5625 "Added subscription #%d for printer \"%s\".",
5626 sub
->id
, printer
->name
);
5628 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription #%d for server.",
5631 sub
->interval
= interval
;
5633 sub
->expire
= lease
? time(NULL
) + lease
: 0;
5635 cupsdSetString(&sub
->owner
, username
);
5639 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
5640 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
5641 (size_t)sub
->user_data_len
);
5644 ippAddSeparator(con
->response
);
5645 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5646 "notify-subscription-id", sub
->id
);
5648 con
->response
->request
.status
.status_code
= IPP_OK
;
5654 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
5659 * 'delete_printer()' - Remove a printer or class from the system.
5663 delete_printer(cupsd_client_t
*con
, /* I - Client connection */
5664 ipp_attribute_t
*uri
) /* I - URI of printer or class */
5666 http_status_t status
; /* Policy status */
5667 cups_ptype_t dtype
; /* Destination type (printer/class) */
5668 cupsd_printer_t
*printer
; /* Printer/class */
5669 char filename
[1024]; /* Script/PPD filename */
5672 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "delete_printer(%p[%d], %s)", con
,
5673 con
->number
, uri
->values
[0].string
.text
);
5676 * Do we have a valid URI?
5679 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
5685 send_ipp_status(con
, IPP_NOT_FOUND
,
5686 _("The printer or class does not exist."));
5694 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5696 send_http_error(con
, status
, NULL
);
5701 * Remove old jobs...
5704 cupsdCancelJobs(printer
->name
, NULL
, 1);
5707 * Remove old subscriptions and send a "deleted printer" event...
5710 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED
, printer
, NULL
,
5711 "%s \"%s\" deleted by \"%s\".",
5712 (dtype
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
5713 printer
->name
, get_username(con
));
5715 cupsdExpireSubscriptions(printer
, NULL
);
5718 * Remove any old PPD or script files...
5721 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
,
5724 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s.O", ServerRoot
,
5728 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
5731 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd.O", ServerRoot
,
5735 snprintf(filename
, sizeof(filename
), "%s/%s.png", CacheDir
, printer
->name
);
5738 snprintf(filename
, sizeof(filename
), "%s/%s.data", CacheDir
, printer
->name
);
5742 * Unregister color profiles...
5745 cupsdUnregisterColor(printer
);
5747 if (dtype
& CUPS_PRINTER_CLASS
)
5749 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" deleted by \"%s\".",
5750 printer
->name
, get_username(con
));
5752 cupsdDeletePrinter(printer
, 0);
5753 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
5757 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" deleted by \"%s\".",
5758 printer
->name
, get_username(con
));
5760 if (cupsdDeletePrinter(printer
, 0))
5761 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
5763 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
5766 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
5769 * Return with no errors...
5772 con
->response
->request
.status
.status_code
= IPP_OK
;
5777 * 'get_default()' - Get the default destination.
5781 get_default(cupsd_client_t
*con
) /* I - Client connection */
5783 http_status_t status
; /* Policy status */
5784 cups_array_t
*ra
; /* Requested attributes array */
5787 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_default(%p[%d])", con
, con
->number
);
5793 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5795 send_http_error(con
, status
, NULL
);
5801 ra
= create_requested_array(con
->request
);
5803 copy_printer_attrs(con
, DefaultPrinter
, ra
);
5805 cupsArrayDelete(ra
);
5807 con
->response
->request
.status
.status_code
= IPP_OK
;
5810 send_ipp_status(con
, IPP_NOT_FOUND
, _("No default printer."));
5815 * 'get_devices()' - Get the list of available devices on the local system.
5819 get_devices(cupsd_client_t
*con
) /* I - Client connection */
5821 http_status_t status
; /* Policy status */
5822 ipp_attribute_t
*limit
, /* limit attribute */
5823 *timeout
, /* timeout attribute */
5824 *requested
, /* requested-attributes attribute */
5825 *exclude
, /* exclude-schemes attribute */
5826 *include
; /* include-schemes attribute */
5827 char command
[1024], /* cups-deviced command */
5828 options
[2048], /* Options to pass to command */
5830 /* String for requested attributes */
5832 /* String for excluded schemes */
5834 /* String for included schemes */
5837 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_devices(%p[%d])", con
, con
->number
);
5843 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5845 send_http_error(con
, status
, NULL
);
5850 * Run cups-deviced command with the given options...
5853 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
5854 timeout
= ippFindAttribute(con
->request
, "timeout", IPP_TAG_INTEGER
);
5855 requested
= ippFindAttribute(con
->request
, "requested-attributes",
5857 exclude
= ippFindAttribute(con
->request
, "exclude-schemes", IPP_TAG_NAME
);
5858 include
= ippFindAttribute(con
->request
, "include-schemes", IPP_TAG_NAME
);
5861 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
5863 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
5866 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
5868 exclude_str
[0] = '\0';
5871 url_encode_attr(include
, include_str
, sizeof(include_str
));
5873 include_str
[0] = '\0';
5875 snprintf(command
, sizeof(command
), "%s/daemon/cups-deviced", ServerBin
);
5876 snprintf(options
, sizeof(options
),
5877 "%d+%d+%d+%d+%s%s%s%s%s",
5878 con
->request
->request
.op
.request_id
,
5879 limit
? limit
->values
[0].integer
: 0,
5880 timeout
? timeout
->values
[0].integer
: 15,
5883 exclude_str
[0] ? "%20" : "", exclude_str
,
5884 include_str
[0] ? "%20" : "", include_str
);
5886 if (cupsdSendCommand(con
, command
, options
, 1))
5889 * Command started successfully, don't send an IPP response here...
5892 ippDelete(con
->response
);
5893 con
->response
= NULL
;
5898 * Command failed, return "internal error" so the user knows something
5902 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
5903 _("cups-deviced failed to execute."));
5909 * 'get_document()' - Get a copy of a job file.
5913 get_document(cupsd_client_t
*con
, /* I - Client connection */
5914 ipp_attribute_t
*uri
) /* I - Job URI */
5916 http_status_t status
; /* Policy status */
5917 ipp_attribute_t
*attr
; /* Current attribute */
5918 int jobid
; /* Job ID */
5919 int docnum
; /* Document number */
5920 cupsd_job_t
*job
; /* Current job */
5921 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
5922 username
[HTTP_MAX_URI
], /* Username portion of URI */
5923 host
[HTTP_MAX_URI
], /* Host portion of URI */
5924 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
5925 int port
; /* Port portion of URI */
5926 char filename
[1024], /* Filename for document */
5927 format
[1024]; /* Format for document */
5930 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_document(%p[%d], %s)", con
,
5931 con
->number
, uri
->values
[0].string
.text
);
5934 * See if we have a job URI or a printer URI...
5937 if (!strcmp(uri
->name
, "printer-uri"))
5940 * Got a printer URI; see if we also have a job-id attribute...
5943 if ((attr
= ippFindAttribute(con
->request
, "job-id",
5944 IPP_TAG_INTEGER
)) == NULL
)
5946 send_ipp_status(con
, IPP_BAD_REQUEST
,
5947 _("Got a printer-uri attribute but no job-id."));
5951 jobid
= attr
->values
[0].integer
;
5956 * Got a job URI; parse it to get the job ID...
5959 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
5960 sizeof(scheme
), username
, sizeof(username
), host
,
5961 sizeof(host
), &port
, resource
, sizeof(resource
));
5963 if (strncmp(resource
, "/jobs/", 6))
5969 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
5970 uri
->values
[0].string
.text
);
5974 jobid
= atoi(resource
+ 6);
5978 * See if the job exists...
5981 if ((job
= cupsdFindJob(jobid
)) == NULL
)
5984 * Nope - return a "not found" error...
5987 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
5995 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
,
5996 job
->username
)) != HTTP_OK
)
5998 send_http_error(con
, status
, NULL
);
6003 * Get the document number...
6006 if ((attr
= ippFindAttribute(con
->request
, "document-number",
6007 IPP_TAG_INTEGER
)) == NULL
)
6009 send_ipp_status(con
, IPP_BAD_REQUEST
,
6010 _("Missing document-number attribute."));
6014 if ((docnum
= attr
->values
[0].integer
) < 1 || docnum
> job
->num_files
||
6015 attr
->num_values
> 1)
6017 send_ipp_status(con
, IPP_NOT_FOUND
,
6018 _("Document #%d does not exist in job #%d."), docnum
,
6023 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, jobid
,
6025 if ((con
->file
= open(filename
, O_RDONLY
)) == -1)
6027 cupsdLogMessage(CUPSD_LOG_ERROR
,
6028 "Unable to open document %d in job %d - %s", docnum
, jobid
,
6030 send_ipp_status(con
, IPP_NOT_FOUND
,
6031 _("Unable to open document #%d in job #%d."), docnum
,
6036 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
6040 snprintf(format
, sizeof(format
), "%s/%s", job
->filetypes
[docnum
- 1]->super
,
6041 job
->filetypes
[docnum
- 1]->type
);
6043 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format",
6045 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "document-number",
6047 if ((attr
= ippFindAttribute(job
->attrs
, "document-name",
6048 IPP_TAG_NAME
)) != NULL
)
6049 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name",
6050 NULL
, attr
->values
[0].string
.text
);
6055 * 'get_job_attrs()' - Get job attributes.
6059 get_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
6060 ipp_attribute_t
*uri
) /* I - Job URI */
6062 http_status_t status
; /* Policy status */
6063 ipp_attribute_t
*attr
; /* Current attribute */
6064 int jobid
; /* Job ID */
6065 cupsd_job_t
*job
; /* Current job */
6066 cupsd_printer_t
*printer
; /* Current printer */
6067 cupsd_policy_t
*policy
; /* Current security policy */
6068 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6069 username
[HTTP_MAX_URI
], /* Username portion of URI */
6070 host
[HTTP_MAX_URI
], /* Host portion of URI */
6071 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6072 int port
; /* Port portion of URI */
6073 cups_array_t
*ra
, /* Requested attributes array */
6074 *exclude
; /* Private attributes array */
6077 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_job_attrs(%p[%d], %s)", con
,
6078 con
->number
, uri
->values
[0].string
.text
);
6081 * See if we have a job URI or a printer URI...
6084 if (!strcmp(uri
->name
, "printer-uri"))
6087 * Got a printer URI; see if we also have a job-id attribute...
6090 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6091 IPP_TAG_INTEGER
)) == NULL
)
6093 send_ipp_status(con
, IPP_BAD_REQUEST
,
6094 _("Got a printer-uri attribute but no job-id."));
6098 jobid
= attr
->values
[0].integer
;
6103 * Got a job URI; parse it to get the job ID...
6106 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6107 sizeof(scheme
), username
, sizeof(username
), host
,
6108 sizeof(host
), &port
, resource
, sizeof(resource
));
6110 if (strncmp(resource
, "/jobs/", 6))
6116 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
6117 uri
->values
[0].string
.text
);
6121 jobid
= atoi(resource
+ 6);
6125 * See if the job exists...
6128 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6131 * Nope - return a "not found" error...
6134 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
6142 if ((printer
= job
->printer
) == NULL
)
6143 printer
= cupsdFindDest(job
->dest
);
6146 policy
= printer
->op_policy_ptr
;
6148 policy
= DefaultPolicyPtr
;
6150 if ((status
= cupsdCheckPolicy(policy
, con
, job
->username
)) != HTTP_OK
)
6152 send_http_error(con
, status
, NULL
);
6156 exclude
= cupsdGetPrivateAttrs(policy
, con
, printer
, job
->username
);
6159 * Copy attributes...
6164 ra
= create_requested_array(con
->request
);
6165 copy_job_attrs(con
, job
, ra
, exclude
);
6166 cupsArrayDelete(ra
);
6168 con
->response
->request
.status
.status_code
= IPP_OK
;
6173 * 'get_jobs()' - Get a list of jobs for the specified printer.
6177 get_jobs(cupsd_client_t
*con
, /* I - Client connection */
6178 ipp_attribute_t
*uri
) /* I - Printer URI */
6180 http_status_t status
; /* Policy status */
6181 ipp_attribute_t
*attr
; /* Current attribute */
6182 const char *dest
; /* Destination */
6183 cups_ptype_t dtype
; /* Destination type (printer/class) */
6184 cups_ptype_t dmask
; /* Destination type mask */
6185 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6186 username
[HTTP_MAX_URI
], /* Username portion of URI */
6187 host
[HTTP_MAX_URI
], /* Host portion of URI */
6188 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6189 int port
; /* Port portion of URI */
6190 int job_comparison
; /* Job comparison */
6191 ipp_jstate_t job_state
; /* job-state value */
6192 int first_job_id
= 1, /* First job ID */
6193 first_index
= 1, /* First index */
6194 current_index
= 0; /* Current index */
6195 int limit
= 0; /* Maximum number of jobs to return */
6196 int count
; /* Number of jobs that match */
6197 int need_load_job
= 0; /* Do we need to load the job? */
6198 const char *job_attr
; /* Job attribute requested */
6199 ipp_attribute_t
*job_ids
; /* job-ids attribute */
6200 cupsd_job_t
*job
; /* Current job pointer */
6201 cupsd_printer_t
*printer
; /* Printer */
6202 cups_array_t
*list
; /* Which job list... */
6203 int delete_list
= 0; /* Delete the list afterwards? */
6204 cups_array_t
*ra
, /* Requested attributes array */
6205 *exclude
; /* Private attributes array */
6206 cupsd_policy_t
*policy
; /* Current policy */
6209 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs(%p[%d], %s)", con
, con
->number
,
6210 uri
->values
[0].string
.text
);
6213 * Is the destination valid?
6216 if (strcmp(uri
->name
, "printer-uri"))
6218 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No printer-uri in request."));
6222 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6223 sizeof(scheme
), username
, sizeof(username
), host
,
6224 sizeof(host
), &port
, resource
, sizeof(resource
));
6226 if (!strcmp(resource
, "/") || !strcmp(resource
, "/jobs"))
6229 dtype
= (cups_ptype_t
)0;
6230 dmask
= (cups_ptype_t
)0;
6233 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6236 dtype
= (cups_ptype_t
)0;
6237 dmask
= CUPS_PRINTER_CLASS
;
6240 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6243 dtype
= CUPS_PRINTER_CLASS
;
6244 dmask
= CUPS_PRINTER_CLASS
;
6247 else if ((dest
= cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
,
6254 send_ipp_status(con
, IPP_NOT_FOUND
,
6255 _("The printer or class does not exist."));
6260 dtype
&= CUPS_PRINTER_CLASS
;
6261 dmask
= CUPS_PRINTER_CLASS
;
6269 policy
= printer
->op_policy_ptr
;
6271 policy
= DefaultPolicyPtr
;
6273 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
6275 send_http_error(con
, status
, NULL
);
6279 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
6282 * See if the "which-jobs" attribute have been specified...
6285 if ((attr
= ippFindAttribute(con
->request
, "which-jobs",
6286 IPP_TAG_KEYWORD
)) != NULL
&& job_ids
)
6288 send_ipp_status(con
, IPP_CONFLICT
,
6289 _("The %s attribute cannot be provided with job-ids."),
6293 else if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "not-completed"))
6295 job_comparison
= -1;
6296 job_state
= IPP_JOB_STOPPED
;
6299 else if (!strcmp(attr
->values
[0].string
.text
, "completed"))
6302 job_state
= IPP_JOB_CANCELED
;
6303 list
= cupsdGetCompletedJobs(printer
);
6306 else if (!strcmp(attr
->values
[0].string
.text
, "aborted"))
6309 job_state
= IPP_JOB_ABORTED
;
6310 list
= cupsdGetCompletedJobs(printer
);
6313 else if (!strcmp(attr
->values
[0].string
.text
, "all"))
6316 job_state
= IPP_JOB_PENDING
;
6319 else if (!strcmp(attr
->values
[0].string
.text
, "canceled"))
6322 job_state
= IPP_JOB_CANCELED
;
6323 list
= cupsdGetCompletedJobs(printer
);
6326 else if (!strcmp(attr
->values
[0].string
.text
, "pending"))
6329 job_state
= IPP_JOB_PENDING
;
6332 else if (!strcmp(attr
->values
[0].string
.text
, "pending-held"))
6335 job_state
= IPP_JOB_HELD
;
6338 else if (!strcmp(attr
->values
[0].string
.text
, "processing"))
6341 job_state
= IPP_JOB_PROCESSING
;
6342 list
= PrintingJobs
;
6344 else if (!strcmp(attr
->values
[0].string
.text
, "processing-stopped"))
6347 job_state
= IPP_JOB_STOPPED
;
6352 send_ipp_status(con
, IPP_ATTRIBUTES
,
6353 _("The which-jobs value \"%s\" is not supported."),
6354 attr
->values
[0].string
.text
);
6355 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
6356 "which-jobs", NULL
, attr
->values
[0].string
.text
);
6361 * See if they want to limit the number of jobs reported...
6364 if ((attr
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
)) != NULL
)
6368 send_ipp_status(con
, IPP_CONFLICT
,
6369 _("The %s attribute cannot be provided with job-ids."),
6374 limit
= attr
->values
[0].integer
;
6377 if ((attr
= ippFindAttribute(con
->request
, "first-index", IPP_TAG_INTEGER
)) != NULL
)
6381 send_ipp_status(con
, IPP_CONFLICT
,
6382 _("The %s attribute cannot be provided with job-ids."),
6387 first_index
= attr
->values
[0].integer
;
6389 else if ((attr
= ippFindAttribute(con
->request
, "first-job-id", IPP_TAG_INTEGER
)) != NULL
)
6393 send_ipp_status(con
, IPP_CONFLICT
,
6394 _("The %s attribute cannot be provided with job-ids."),
6399 first_job_id
= attr
->values
[0].integer
;
6403 * See if we only want to see jobs for a specific user...
6406 if ((attr
= ippFindAttribute(con
->request
, "my-jobs", IPP_TAG_BOOLEAN
)) != NULL
&& job_ids
)
6408 send_ipp_status(con
, IPP_CONFLICT
,
6409 _("The %s attribute cannot be provided with job-ids."),
6413 else if (attr
&& attr
->values
[0].boolean
)
6414 strlcpy(username
, get_username(con
), sizeof(username
));
6418 ra
= create_requested_array(con
->request
);
6419 for (job_attr
= (char *)cupsArrayFirst(ra
); job_attr
; job_attr
= (char *)cupsArrayNext(ra
))
6420 if (strcmp(job_attr
, "job-id") &&
6421 strcmp(job_attr
, "job-k-octets") &&
6422 strcmp(job_attr
, "job-media-progress") &&
6423 strcmp(job_attr
, "job-more-info") &&
6424 strcmp(job_attr
, "job-name") &&
6425 strcmp(job_attr
, "job-originating-user-name") &&
6426 strcmp(job_attr
, "job-preserved") &&
6427 strcmp(job_attr
, "job-printer-up-time") &&
6428 strcmp(job_attr
, "job-printer-uri") &&
6429 strcmp(job_attr
, "job-state") &&
6430 strcmp(job_attr
, "job-state-reasons") &&
6431 strcmp(job_attr
, "job-uri") &&
6432 strcmp(job_attr
, "time-at-completed") &&
6433 strcmp(job_attr
, "time-at-creation") &&
6434 strcmp(job_attr
, "number-of-documents"))
6440 if (need_load_job
&& (limit
== 0 || limit
> 500) && (list
== Jobs
|| delete_list
))
6443 * Limit expensive Get-Jobs for job history to 500 jobs...
6446 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
, "limit", 500);
6449 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
, "limit", limit
);
6453 cupsdLogClient(con
, CUPSD_LOG_INFO
, "Limiting Get-Jobs response to %d jobs.", limit
);
6457 * OK, build a list of jobs for this printer...
6462 int i
; /* Looping var */
6464 for (i
= 0; i
< job_ids
->num_values
; i
++)
6466 if (!cupsdFindJob(job_ids
->values
[i
].integer
))
6470 if (i
< job_ids
->num_values
)
6472 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
6473 job_ids
->values
[i
].integer
);
6477 for (i
= 0; i
< job_ids
->num_values
; i
++)
6479 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
6481 if (need_load_job
&& !job
->attrs
)
6487 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d", job
->id
);
6493 ippAddSeparator(con
->response
);
6495 exclude
= cupsdGetPrivateAttrs(job
->printer
?
6496 job
->printer
->op_policy_ptr
:
6497 policy
, con
, job
->printer
,
6500 copy_job_attrs(con
, job
, ra
, exclude
);
6505 for (count
= 0, job
= (cupsd_job_t
*)cupsArrayFirst(list
);
6506 (limit
<= 0 || count
< limit
) && job
;
6507 job
= (cupsd_job_t
*)cupsArrayNext(list
))
6510 * Filter out jobs that don't match...
6513 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
6514 "get_jobs: job->id=%d, dest=\"%s\", username=\"%s\", "
6515 "state_value=%d, attrs=%p", job
->id
, job
->dest
,
6516 job
->username
, job
->state_value
, job
->attrs
);
6518 if (!job
->dest
|| !job
->username
)
6521 if (!job
->dest
|| !job
->username
)
6524 if ((dest
&& strcmp(job
->dest
, dest
)) &&
6525 (!job
->printer
|| !dest
|| strcmp(job
->printer
->name
, dest
)))
6527 if ((job
->dtype
& dmask
) != dtype
&&
6528 (!job
->printer
|| (job
->printer
->type
& dmask
) != dtype
))
6531 if ((job_comparison
< 0 && job
->state_value
> job_state
) ||
6532 (job_comparison
== 0 && job
->state_value
!= job_state
) ||
6533 (job_comparison
> 0 && job
->state_value
< job_state
))
6536 if (job
->id
< first_job_id
)
6540 if (current_index
< first_index
)
6543 if (need_load_job
&& !job
->attrs
)
6549 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d", job
->id
);
6554 if (username
[0] && _cups_strcasecmp(username
, job
->username
))
6558 ippAddSeparator(con
->response
);
6562 exclude
= cupsdGetPrivateAttrs(job
->printer
?
6563 job
->printer
->op_policy_ptr
:
6564 policy
, con
, job
->printer
,
6567 copy_job_attrs(con
, job
, ra
, exclude
);
6570 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: count=%d", count
);
6573 cupsArrayDelete(ra
);
6576 cupsArrayDelete(list
);
6578 con
->response
->request
.status
.status_code
= IPP_OK
;
6583 * 'get_notifications()' - Get events for a subscription.
6587 get_notifications(cupsd_client_t
*con
) /* I - Client connection */
6589 int i
, j
; /* Looping vars */
6590 http_status_t status
; /* Policy status */
6591 cupsd_subscription_t
*sub
; /* Subscription */
6592 ipp_attribute_t
*ids
, /* notify-subscription-ids */
6593 *sequences
; /* notify-sequence-numbers */
6594 int min_seq
; /* Minimum sequence number */
6595 int interval
; /* Poll interval */
6598 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_notifications(con=%p[%d])",
6602 * Get subscription attributes...
6605 ids
= ippFindAttribute(con
->request
, "notify-subscription-ids",
6607 sequences
= ippFindAttribute(con
->request
, "notify-sequence-numbers",
6612 send_ipp_status(con
, IPP_BAD_REQUEST
,
6613 _("Missing notify-subscription-ids attribute."));
6618 * Are the subscription IDs valid?
6621 for (i
= 0, interval
= 60; i
< ids
->num_values
; i
++)
6623 if ((sub
= cupsdFindSubscription(ids
->values
[i
].integer
)) == NULL
)
6626 * Bad subscription ID...
6629 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
6630 ids
->values
[i
].integer
);
6638 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
6640 con
, sub
->owner
)) != HTTP_OK
)
6642 send_http_error(con
, status
, sub
->dest
);
6647 * Check the subscription type and update the interval accordingly.
6650 if (sub
->job
&& sub
->job
->state_value
== IPP_JOB_PROCESSING
&&
6653 else if (sub
->job
&& sub
->job
->state_value
>= IPP_JOB_STOPPED
)
6655 else if (sub
->dest
&& sub
->dest
->state
== IPP_PRINTER_PROCESSING
&&
6661 * Tell the client to poll again in N seconds...
6665 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
6666 "notify-get-interval", interval
);
6668 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
6669 "printer-up-time", time(NULL
));
6672 * Copy the subscription event attributes to the response.
6675 con
->response
->request
.status
.status_code
=
6676 interval
? IPP_OK
: IPP_OK_EVENTS_COMPLETE
;
6678 for (i
= 0; i
< ids
->num_values
; i
++)
6681 * Get the subscription and sequence number...
6684 sub
= cupsdFindSubscription(ids
->values
[i
].integer
);
6686 if (sequences
&& i
< sequences
->num_values
)
6687 min_seq
= sequences
->values
[i
].integer
;
6692 * If we don't have any new events, nothing to do here...
6695 if (min_seq
> (sub
->first_event_id
+ cupsArrayCount(sub
->events
)))
6699 * Otherwise copy all of the new events...
6702 if (sub
->first_event_id
> min_seq
)
6705 j
= min_seq
- sub
->first_event_id
;
6707 for (; j
< cupsArrayCount(sub
->events
); j
++)
6709 ippAddSeparator(con
->response
);
6711 copy_attrs(con
->response
,
6712 ((cupsd_event_t
*)cupsArrayIndex(sub
->events
, j
))->attrs
, NULL
,
6713 IPP_TAG_EVENT_NOTIFICATION
, 0, NULL
);
6720 * 'get_ppd()' - Get a named PPD from the local system.
6724 get_ppd(cupsd_client_t
*con
, /* I - Client connection */
6725 ipp_attribute_t
*uri
) /* I - Printer URI or PPD name */
6727 http_status_t status
; /* Policy status */
6728 cupsd_printer_t
*dest
; /* Destination */
6729 cups_ptype_t dtype
; /* Destination type */
6732 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppd(%p[%d], %p[%s=%s])", con
,
6733 con
->number
, uri
, uri
->name
, uri
->values
[0].string
.text
);
6735 if (!strcmp(uri
->name
, "ppd-name"))
6738 * Return a PPD file from cups-driverd...
6741 char command
[1024], /* cups-driverd command */
6742 options
[1024], /* Options to pass to command */
6743 ppd_name
[1024]; /* ppd-name */
6750 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6752 send_http_error(con
, status
, NULL
);
6757 * Run cups-driverd command with the given options...
6760 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
6761 url_encode_string(uri
->values
[0].string
.text
, ppd_name
, sizeof(ppd_name
));
6762 snprintf(options
, sizeof(options
), "get+%d+%s",
6763 con
->request
->request
.op
.request_id
, ppd_name
);
6765 if (cupsdSendCommand(con
, command
, options
, 0))
6768 * Command started successfully, don't send an IPP response here...
6771 ippDelete(con
->response
);
6772 con
->response
= NULL
;
6777 * Command failed, return "internal error" so the user knows something
6781 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
6782 _("cups-driverd failed to execute."));
6785 else if (!strcmp(uri
->name
, "printer-uri") &&
6786 cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &dest
))
6788 int i
; /* Looping var */
6789 char filename
[1024]; /* PPD filename */
6796 if ((status
= cupsdCheckPolicy(dest
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
6798 send_http_error(con
, status
, dest
);
6803 * See if we need the PPD for a class or remote printer...
6806 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
6809 if ((dtype
& CUPS_PRINTER_REMOTE
) && access(filename
, 0))
6811 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
6812 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
6813 "printer-uri", NULL
, dest
->uri
);
6816 else if (dtype
& CUPS_PRINTER_CLASS
)
6818 for (i
= 0; i
< dest
->num_printers
; i
++)
6819 if (!(dest
->printers
[i
]->type
& CUPS_PRINTER_CLASS
))
6821 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
6822 dest
->printers
[i
]->name
);
6824 if (!access(filename
, 0))
6828 if (i
< dest
->num_printers
)
6829 dest
= dest
->printers
[i
];
6832 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
6833 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
6834 "printer-uri", NULL
, dest
->printers
[0]->uri
);
6840 * Found the printer with the PPD file, now see if there is one...
6843 if ((con
->file
= open(filename
, O_RDONLY
)) < 0)
6845 send_ipp_status(con
, IPP_NOT_FOUND
,
6846 _("The PPD file \"%s\" could not be opened: %s"),
6847 uri
->values
[0].string
.text
, strerror(errno
));
6851 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
6855 con
->response
->request
.status
.status_code
= IPP_OK
;
6858 send_ipp_status(con
, IPP_NOT_FOUND
,
6859 _("The PPD file \"%s\" could not be found."),
6860 uri
->values
[0].string
.text
);
6865 * 'get_ppds()' - Get the list of PPD files on the local system.
6869 get_ppds(cupsd_client_t
*con
) /* I - Client connection */
6871 http_status_t status
; /* Policy status */
6872 ipp_attribute_t
*limit
, /* Limit attribute */
6873 *device
, /* ppd-device-id attribute */
6874 *language
, /* ppd-natural-language attribute */
6875 *make
, /* ppd-make attribute */
6876 *model
, /* ppd-make-and-model attribute */
6877 *model_number
, /* ppd-model-number attribute */
6878 *product
, /* ppd-product attribute */
6879 *psversion
, /* ppd-psverion attribute */
6880 *type
, /* ppd-type attribute */
6881 *requested
, /* requested-attributes attribute */
6882 *exclude
, /* exclude-schemes attribute */
6883 *include
; /* include-schemes attribute */
6884 char command
[1024], /* cups-driverd command */
6885 options
[4096], /* Options to pass to command */
6886 device_str
[256],/* Escaped ppd-device-id string */
6888 /* Escaped ppd-natural-language */
6889 make_str
[256], /* Escaped ppd-make string */
6890 model_str
[256], /* Escaped ppd-make-and-model string */
6891 model_number_str
[256],
6892 /* ppd-model-number string */
6894 /* Escaped ppd-product string */
6896 /* Escaped ppd-psversion string */
6897 type_str
[256], /* Escaped ppd-type string */
6899 /* String for requested attributes */
6901 /* String for excluded schemes */
6903 /* String for included schemes */
6906 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppds(%p[%d])", con
, con
->number
);
6912 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6914 send_http_error(con
, status
, NULL
);
6919 * Run cups-driverd command with the given options...
6922 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
6923 device
= ippFindAttribute(con
->request
, "ppd-device-id", IPP_TAG_TEXT
);
6924 language
= ippFindAttribute(con
->request
, "ppd-natural-language",
6926 make
= ippFindAttribute(con
->request
, "ppd-make", IPP_TAG_TEXT
);
6927 model
= ippFindAttribute(con
->request
, "ppd-make-and-model",
6929 model_number
= ippFindAttribute(con
->request
, "ppd-model-number",
6931 product
= ippFindAttribute(con
->request
, "ppd-product", IPP_TAG_TEXT
);
6932 psversion
= ippFindAttribute(con
->request
, "ppd-psversion", IPP_TAG_TEXT
);
6933 type
= ippFindAttribute(con
->request
, "ppd-type", IPP_TAG_KEYWORD
);
6934 requested
= ippFindAttribute(con
->request
, "requested-attributes",
6936 exclude
= ippFindAttribute(con
->request
, "exclude-schemes",
6938 include
= ippFindAttribute(con
->request
, "include-schemes",
6942 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
6944 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
6947 url_encode_attr(device
, device_str
, sizeof(device_str
));
6949 device_str
[0] = '\0';
6952 url_encode_attr(language
, language_str
, sizeof(language_str
));
6954 language_str
[0] = '\0';
6957 url_encode_attr(make
, make_str
, sizeof(make_str
));
6962 url_encode_attr(model
, model_str
, sizeof(model_str
));
6964 model_str
[0] = '\0';
6967 snprintf(model_number_str
, sizeof(model_number_str
), "ppd-model-number=%d",
6968 model_number
->values
[0].integer
);
6970 model_number_str
[0] = '\0';
6973 url_encode_attr(product
, product_str
, sizeof(product_str
));
6975 product_str
[0] = '\0';
6978 url_encode_attr(psversion
, psversion_str
, sizeof(psversion_str
));
6980 psversion_str
[0] = '\0';
6983 url_encode_attr(type
, type_str
, sizeof(type_str
));
6988 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
6990 exclude_str
[0] = '\0';
6993 url_encode_attr(include
, include_str
, sizeof(include_str
));
6995 include_str
[0] = '\0';
6997 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
6998 snprintf(options
, sizeof(options
),
6999 "list+%d+%d+%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
7000 con
->request
->request
.op
.request_id
,
7001 limit
? limit
->values
[0].integer
: 0,
7003 device
? "%20" : "", device_str
,
7004 language
? "%20" : "", language_str
,
7005 make
? "%20" : "", make_str
,
7006 model
? "%20" : "", model_str
,
7007 model_number
? "%20" : "", model_number_str
,
7008 product
? "%20" : "", product_str
,
7009 psversion
? "%20" : "", psversion_str
,
7010 type
? "%20" : "", type_str
,
7011 exclude_str
[0] ? "%20" : "", exclude_str
,
7012 include_str
[0] ? "%20" : "", include_str
);
7014 if (cupsdSendCommand(con
, command
, options
, 0))
7017 * Command started successfully, don't send an IPP response here...
7020 ippDelete(con
->response
);
7021 con
->response
= NULL
;
7026 * Command failed, return "internal error" so the user knows something
7030 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7031 _("cups-driverd failed to execute."));
7037 * 'get_printer_attrs()' - Get printer attributes.
7041 get_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
7042 ipp_attribute_t
*uri
) /* I - Printer URI */
7044 http_status_t status
; /* Policy status */
7045 cups_ptype_t dtype
; /* Destination type (printer/class) */
7046 cupsd_printer_t
*printer
; /* Printer/class */
7047 cups_array_t
*ra
; /* Requested attributes array */
7050 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_attrs(%p[%d], %s)", con
,
7051 con
->number
, uri
->values
[0].string
.text
);
7054 * Is the destination valid?
7057 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7063 send_ipp_status(con
, IPP_NOT_FOUND
,
7064 _("The printer or class does not exist."));
7072 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7074 send_http_error(con
, status
, printer
);
7079 * Send the attributes...
7082 ra
= create_requested_array(con
->request
);
7084 copy_printer_attrs(con
, printer
, ra
);
7086 cupsArrayDelete(ra
);
7088 con
->response
->request
.status
.status_code
= IPP_OK
;
7093 * 'get_printer_supported()' - Get printer supported values.
7097 get_printer_supported(
7098 cupsd_client_t
*con
, /* I - Client connection */
7099 ipp_attribute_t
*uri
) /* I - Printer URI */
7101 http_status_t status
; /* Policy status */
7102 cups_ptype_t dtype
; /* Destination type (printer/class) */
7103 cupsd_printer_t
*printer
; /* Printer/class */
7106 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_supported(%p[%d], %s)", con
,
7107 con
->number
, uri
->values
[0].string
.text
);
7110 * Is the destination valid?
7113 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7119 send_ipp_status(con
, IPP_NOT_FOUND
,
7120 _("The printer or class does not exist."));
7128 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7130 send_http_error(con
, status
, printer
);
7135 * Return a list of attributes that can be set via Set-Printer-Attributes.
7138 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7139 "printer-geo-location", 0);
7140 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7142 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7143 "printer-location", 0);
7144 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7145 "printer-organization", 0);
7146 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7147 "printer-organizational-unit", 0);
7149 con
->response
->request
.status
.status_code
= IPP_OK
;
7154 * 'get_printers()' - Get a list of printers or classes.
7158 get_printers(cupsd_client_t
*con
, /* I - Client connection */
7159 int type
) /* I - 0 or CUPS_PRINTER_CLASS */
7161 http_status_t status
; /* Policy status */
7162 ipp_attribute_t
*attr
; /* Current attribute */
7163 int limit
; /* Max number of printers to return */
7164 int count
; /* Number of printers that match */
7165 cupsd_printer_t
*printer
; /* Current printer pointer */
7166 cups_ptype_t printer_type
, /* printer-type attribute */
7167 printer_mask
; /* printer-type-mask attribute */
7168 char *location
; /* Location string */
7169 const char *username
; /* Current user */
7170 char *first_printer_name
; /* first-printer-name attribute */
7171 cups_array_t
*ra
; /* Requested attributes array */
7172 int local
; /* Local connection? */
7175 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printers(%p[%d], %x)", con
,
7182 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7184 send_http_error(con
, status
, NULL
);
7189 * Check for printers...
7192 if (!Printers
|| !cupsArrayCount(Printers
))
7194 send_ipp_status(con
, IPP_NOT_FOUND
, _("No destinations added."));
7199 * See if they want to limit the number of printers reported...
7202 if ((attr
= ippFindAttribute(con
->request
, "limit",
7203 IPP_TAG_INTEGER
)) != NULL
)
7204 limit
= attr
->values
[0].integer
;
7208 if ((attr
= ippFindAttribute(con
->request
, "first-printer-name",
7209 IPP_TAG_NAME
)) != NULL
)
7210 first_printer_name
= attr
->values
[0].string
.text
;
7212 first_printer_name
= NULL
;
7215 * Support filtering...
7218 if ((attr
= ippFindAttribute(con
->request
, "printer-type",
7219 IPP_TAG_ENUM
)) != NULL
)
7220 printer_type
= (cups_ptype_t
)attr
->values
[0].integer
;
7222 printer_type
= (cups_ptype_t
)0;
7224 if ((attr
= ippFindAttribute(con
->request
, "printer-type-mask",
7225 IPP_TAG_ENUM
)) != NULL
)
7226 printer_mask
= (cups_ptype_t
)attr
->values
[0].integer
;
7228 printer_mask
= (cups_ptype_t
)0;
7230 local
= httpAddrLocalhost(&(con
->clientaddr
));
7232 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
7233 IPP_TAG_TEXT
)) != NULL
)
7234 location
= attr
->values
[0].string
.text
;
7238 if (con
->username
[0])
7239 username
= con
->username
;
7240 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7241 IPP_TAG_NAME
)) != NULL
)
7242 username
= attr
->values
[0].string
.text
;
7246 ra
= create_requested_array(con
->request
);
7249 * OK, build a list of printers for this printer...
7252 if (first_printer_name
)
7254 if ((printer
= cupsdFindDest(first_printer_name
)) == NULL
)
7255 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7258 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7261 count
< limit
&& printer
;
7262 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
7264 if (!local
&& !printer
->shared
)
7267 if ((!type
|| (printer
->type
& CUPS_PRINTER_CLASS
) == type
) &&
7268 (printer
->type
& printer_mask
) == printer_type
&&
7270 (printer
->location
&& !_cups_strcasecmp(printer
->location
, location
))))
7273 * If a username is specified, see if it is allowed or denied
7277 if (cupsArrayCount(printer
->users
) && username
&&
7278 !user_allowed(printer
, username
))
7282 * Add the group separator as needed...
7286 ippAddSeparator(con
->response
);
7291 * Send the attributes...
7294 copy_printer_attrs(con
, printer
, ra
);
7298 cupsArrayDelete(ra
);
7300 con
->response
->request
.status
.status_code
= IPP_OK
;
7305 * 'get_subscription_attrs()' - Get subscription attributes.
7309 get_subscription_attrs(
7310 cupsd_client_t
*con
, /* I - Client connection */
7311 int sub_id
) /* I - Subscription ID */
7313 http_status_t status
; /* Policy status */
7314 cupsd_subscription_t
*sub
; /* Subscription */
7315 cupsd_policy_t
*policy
; /* Current security policy */
7316 cups_array_t
*ra
, /* Requested attributes array */
7317 *exclude
; /* Private attributes array */
7320 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7321 "get_subscription_attrs(con=%p[%d], sub_id=%d)",
7322 con
, con
->number
, sub_id
);
7325 * Is the subscription ID valid?
7328 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
7331 * Bad subscription ID...
7334 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
7344 policy
= sub
->dest
->op_policy_ptr
;
7346 policy
= DefaultPolicyPtr
;
7348 if ((status
= cupsdCheckPolicy(policy
, con
, sub
->owner
)) != HTTP_OK
)
7350 send_http_error(con
, status
, sub
->dest
);
7354 exclude
= cupsdGetPrivateAttrs(policy
, con
, sub
->dest
, sub
->owner
);
7357 * Copy the subscription attributes to the response using the
7358 * requested-attributes attribute that may be provided by the client.
7361 ra
= create_requested_array(con
->request
);
7363 copy_subscription_attrs(con
, sub
, ra
, exclude
);
7365 cupsArrayDelete(ra
);
7367 con
->response
->request
.status
.status_code
= IPP_OK
;
7372 * 'get_subscriptions()' - Get subscriptions.
7376 get_subscriptions(cupsd_client_t
*con
, /* I - Client connection */
7377 ipp_attribute_t
*uri
) /* I - Printer/job URI */
7379 http_status_t status
; /* Policy status */
7380 int count
; /* Number of subscriptions */
7381 int limit
; /* Limit */
7382 cupsd_subscription_t
*sub
; /* Subscription */
7383 cups_array_t
*ra
; /* Requested attributes array */
7384 ipp_attribute_t
*attr
; /* Attribute */
7385 cups_ptype_t dtype
; /* Destination type (printer/class) */
7386 char scheme
[HTTP_MAX_URI
],
7387 /* Scheme portion of URI */
7388 username
[HTTP_MAX_URI
],
7389 /* Username portion of URI */
7391 /* Host portion of URI */
7392 resource
[HTTP_MAX_URI
];
7393 /* Resource portion of URI */
7394 int port
; /* Port portion of URI */
7395 cupsd_job_t
*job
; /* Job pointer */
7396 cupsd_printer_t
*printer
; /* Printer */
7397 cupsd_policy_t
*policy
; /* Policy */
7398 cups_array_t
*exclude
; /* Private attributes array */
7401 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7402 "get_subscriptions(con=%p[%d], uri=%s)",
7403 con
, con
->number
, uri
->values
[0].string
.text
);
7406 * Is the destination valid?
7409 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7410 sizeof(scheme
), username
, sizeof(username
), host
,
7411 sizeof(host
), &port
, resource
, sizeof(resource
));
7413 if (!strcmp(resource
, "/") ||
7414 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6) ||
7415 (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10) ||
7416 (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9))
7421 else if (!strncmp(resource
, "/jobs/", 6) && resource
[6])
7424 job
= cupsdFindJob(atoi(resource
+ 6));
7428 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
7429 atoi(resource
+ 6));
7433 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7439 send_ipp_status(con
, IPP_NOT_FOUND
,
7440 _("The printer or class does not exist."));
7443 else if ((attr
= ippFindAttribute(con
->request
, "notify-job-id",
7444 IPP_TAG_INTEGER
)) != NULL
)
7446 job
= cupsdFindJob(attr
->values
[0].integer
);
7450 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
7451 attr
->values
[0].integer
);
7463 policy
= printer
->op_policy_ptr
;
7465 policy
= DefaultPolicyPtr
;
7467 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
7469 send_http_error(con
, status
, printer
);
7474 * Copy the subscription attributes to the response using the
7475 * requested-attributes attribute that may be provided by the client.
7478 ra
= create_requested_array(con
->request
);
7480 if ((attr
= ippFindAttribute(con
->request
, "limit",
7481 IPP_TAG_INTEGER
)) != NULL
)
7482 limit
= attr
->values
[0].integer
;
7487 * See if we only want to see subscriptions for a specific user...
7490 if ((attr
= ippFindAttribute(con
->request
, "my-subscriptions",
7491 IPP_TAG_BOOLEAN
)) != NULL
&&
7492 attr
->values
[0].boolean
)
7493 strlcpy(username
, get_username(con
), sizeof(username
));
7497 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
), count
= 0;
7499 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
7500 if ((!printer
|| sub
->dest
== printer
) && (!job
|| sub
->job
== job
) &&
7501 (!username
[0] || !_cups_strcasecmp(username
, sub
->owner
)))
7503 ippAddSeparator(con
->response
);
7505 exclude
= cupsdGetPrivateAttrs(sub
->dest
? sub
->dest
->op_policy_ptr
:
7506 policy
, con
, sub
->dest
,
7509 copy_subscription_attrs(con
, sub
, ra
, exclude
);
7512 if (limit
&& count
>= limit
)
7516 cupsArrayDelete(ra
);
7519 con
->response
->request
.status
.status_code
= IPP_OK
;
7521 send_ipp_status(con
, IPP_NOT_FOUND
, _("No subscriptions found."));
7526 * 'get_username()' - Get the username associated with a request.
7529 static const char * /* O - Username */
7530 get_username(cupsd_client_t
*con
) /* I - Connection */
7532 ipp_attribute_t
*attr
; /* Attribute */
7535 if (con
->username
[0])
7536 return (con
->username
);
7537 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7538 IPP_TAG_NAME
)) != NULL
)
7539 return (attr
->values
[0].string
.text
);
7541 return ("anonymous");
7546 * 'hold_job()' - Hold a print job.
7550 hold_job(cupsd_client_t
*con
, /* I - Client connection */
7551 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
7553 ipp_attribute_t
*attr
; /* Current job-hold-until */
7554 const char *when
; /* New value */
7555 int jobid
; /* Job ID */
7556 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
7557 username
[HTTP_MAX_URI
], /* Username portion of URI */
7558 host
[HTTP_MAX_URI
], /* Host portion of URI */
7559 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7560 int port
; /* Port portion of URI */
7561 cupsd_job_t
*job
; /* Job information */
7564 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_job(%p[%d], %s)", con
, con
->number
,
7565 uri
->values
[0].string
.text
);
7568 * See if we have a job URI or a printer URI...
7571 if (!strcmp(uri
->name
, "printer-uri"))
7574 * Got a printer URI; see if we also have a job-id attribute...
7577 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7578 IPP_TAG_INTEGER
)) == NULL
)
7580 send_ipp_status(con
, IPP_BAD_REQUEST
,
7581 _("Got a printer-uri attribute but no job-id."));
7585 jobid
= attr
->values
[0].integer
;
7590 * Got a job URI; parse it to get the job ID...
7593 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7594 sizeof(scheme
), username
, sizeof(username
), host
,
7595 sizeof(host
), &port
, resource
, sizeof(resource
));
7597 if (strncmp(resource
, "/jobs/", 6))
7603 send_ipp_status(con
, IPP_BAD_REQUEST
,
7604 _("Bad job-uri \"%s\"."),
7605 uri
->values
[0].string
.text
);
7609 jobid
= atoi(resource
+ 6);
7613 * See if the job exists...
7616 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7619 * Nope - return a "not found" error...
7622 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
7627 * See if the job is owned by the requesting user...
7630 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7632 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
7633 cupsdFindDest(job
->dest
));
7638 * See if the job is in a state that allows holding...
7641 if (job
->state_value
> IPP_JOB_STOPPED
)
7644 * Return a "not-possible" error...
7647 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
7648 _("Job #%d is finished and cannot be altered."),
7654 * Hold the job and return...
7657 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
7658 IPP_TAG_KEYWORD
)) == NULL
)
7659 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
7663 when
= attr
->values
[0].string
.text
;
7665 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
7666 "Job job-hold-until value changed by user.");
7669 when
= "indefinite";
7671 cupsdSetJobHoldUntil(job
, when
, 1);
7672 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
, "Job held by \"%s\".",
7675 con
->response
->request
.status
.status_code
= IPP_OK
;
7680 * 'hold_new_jobs()' - Hold pending/new jobs on a printer or class.
7684 hold_new_jobs(cupsd_client_t
*con
, /* I - Connection */
7685 ipp_attribute_t
*uri
) /* I - Printer URI */
7687 http_status_t status
; /* Policy status */
7688 cups_ptype_t dtype
; /* Destination type (printer/class) */
7689 cupsd_printer_t
*printer
; /* Printer data */
7692 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_new_jobs(%p[%d], %s)", con
,
7693 con
->number
, uri
->values
[0].string
.text
);
7696 * Is the destination valid?
7699 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7705 send_ipp_status(con
, IPP_NOT_FOUND
,
7706 _("The printer or class does not exist."));
7714 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7716 send_http_error(con
, status
, printer
);
7721 * Hold pending/new jobs sent to the printer...
7724 printer
->holding_new_jobs
= 1;
7726 cupsdSetPrinterReasons(printer
, "+hold-new-jobs");
7728 if (dtype
& CUPS_PRINTER_CLASS
)
7729 cupsdLogMessage(CUPSD_LOG_INFO
,
7730 "Class \"%s\" now holding pending/new jobs (\"%s\").",
7731 printer
->name
, get_username(con
));
7733 cupsdLogMessage(CUPSD_LOG_INFO
,
7734 "Printer \"%s\" now holding pending/new jobs (\"%s\").",
7735 printer
->name
, get_username(con
));
7738 * Everything was ok, so return OK status...
7741 con
->response
->request
.status
.status_code
= IPP_OK
;
7746 * 'move_job()' - Move a job to a new destination.
7750 move_job(cupsd_client_t
*con
, /* I - Client connection */
7751 ipp_attribute_t
*uri
) /* I - Job URI */
7753 http_status_t status
; /* Policy status */
7754 ipp_attribute_t
*attr
; /* Current attribute */
7755 int jobid
; /* Job ID */
7756 cupsd_job_t
*job
; /* Current job */
7757 const char *src
; /* Source printer/class */
7758 cups_ptype_t stype
, /* Source type (printer or class) */
7759 dtype
; /* Destination type (printer/class) */
7760 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
7761 username
[HTTP_MAX_URI
], /* Username portion of URI */
7762 host
[HTTP_MAX_URI
], /* Host portion of URI */
7763 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7764 int port
; /* Port portion of URI */
7765 cupsd_printer_t
*sprinter
, /* Source printer */
7766 *dprinter
; /* Destination printer */
7769 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "move_job(%p[%d], %s)", con
, con
->number
,
7770 uri
->values
[0].string
.text
);
7773 * Get the new printer or class...
7776 if ((attr
= ippFindAttribute(con
->request
, "job-printer-uri",
7777 IPP_TAG_URI
)) == NULL
)
7780 * Need job-printer-uri...
7783 send_ipp_status(con
, IPP_BAD_REQUEST
,
7784 _("job-printer-uri attribute missing."));
7788 if (!cupsdValidateDest(attr
->values
[0].string
.text
, &dtype
, &dprinter
))
7794 send_ipp_status(con
, IPP_NOT_FOUND
,
7795 _("The printer or class does not exist."));
7800 * See if we have a job URI or a printer URI...
7803 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7804 sizeof(scheme
), username
, sizeof(username
), host
,
7805 sizeof(host
), &port
, resource
, sizeof(resource
));
7807 if (!strcmp(uri
->name
, "printer-uri"))
7810 * Got a printer URI; see if we also have a job-id attribute...
7813 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7814 IPP_TAG_INTEGER
)) == NULL
)
7820 if ((src
= cupsdValidateDest(uri
->values
[0].string
.text
, &stype
,
7821 &sprinter
)) == NULL
)
7827 send_ipp_status(con
, IPP_NOT_FOUND
,
7828 _("The printer or class does not exist."));
7837 * Otherwise, just move a single job...
7840 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
7843 * Nope - return a "not found" error...
7846 send_ipp_status(con
, IPP_NOT_FOUND
,
7847 _("Job #%d does not exist."), attr
->values
[0].integer
);
7853 * Job found, initialize source pointers...
7864 * Got a job URI; parse it to get the job ID...
7867 if (strncmp(resource
, "/jobs/", 6))
7873 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
7874 uri
->values
[0].string
.text
);
7879 * See if the job exists...
7882 jobid
= atoi(resource
+ 6);
7884 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7887 * Nope - return a "not found" error...
7890 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
7896 * Job found, initialize source pointers...
7905 * Check the policy of the destination printer...
7908 if ((status
= cupsdCheckPolicy(dprinter
->op_policy_ptr
, con
,
7909 job
? job
->username
: NULL
)) != HTTP_OK
)
7911 send_http_error(con
, status
, dprinter
);
7916 * Now move the job or jobs...
7922 * See if the job has been completed...
7925 if (job
->state_value
> IPP_JOB_STOPPED
)
7928 * Return a "not-possible" error...
7931 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
7932 _("Job #%d is finished and cannot be altered."),
7938 * See if the job is owned by the requesting user...
7941 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7943 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
7944 cupsdFindDest(job
->dest
));
7949 * Move the job to a different printer or class...
7952 cupsdMoveJob(job
, dprinter
);
7957 * Got the source printer, now look through the jobs...
7960 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
7962 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
7965 * See if the job is pointing at the source printer or has not been
7969 if (_cups_strcasecmp(job
->dest
, src
) ||
7970 job
->state_value
> IPP_JOB_STOPPED
)
7974 * See if the job can be moved by the requesting user...
7977 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7981 * Move the job to a different printer or class...
7984 cupsdMoveJob(job
, dprinter
);
7989 * Start jobs if possible...
7995 * Return with "everything is OK" status...
7998 con
->response
->request
.status
.status_code
= IPP_OK
;
8003 * 'ppd_parse_line()' - Parse a PPD default line.
8006 static int /* O - 0 on success, -1 on failure */
8007 ppd_parse_line(const char *line
, /* I - Line */
8008 char *option
, /* O - Option name */
8009 int olen
, /* I - Size of option name */
8010 char *choice
, /* O - Choice name */
8011 int clen
) /* I - Size of choice name */
8014 * Verify this is a default option line...
8017 if (strncmp(line
, "*Default", 8))
8021 * Read the option name...
8024 for (line
+= 8, olen
--;
8025 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
8036 * Skip everything else up to the colon (:)...
8039 while (*line
&& *line
!= ':')
8048 * Now grab the option choice, skipping leading whitespace...
8051 while (isspace(*line
& 255))
8055 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
8066 * Return with no errors...
8074 * 'print_job()' - Print a file to a printer or class.
8078 print_job(cupsd_client_t
*con
, /* I - Client connection */
8079 ipp_attribute_t
*uri
) /* I - Printer URI */
8081 ipp_attribute_t
*attr
; /* Current attribute */
8082 ipp_attribute_t
*format
; /* Document-format attribute */
8083 const char *default_format
; /* document-format-default value */
8084 cupsd_job_t
*job
; /* New job */
8085 char filename
[1024]; /* Job filename */
8086 mime_type_t
*filetype
; /* Type of file */
8087 char super
[MIME_MAX_SUPER
], /* Supertype of file */
8088 type
[MIME_MAX_TYPE
], /* Subtype of file */
8089 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
8090 /* Textual name of mime type */
8091 cupsd_printer_t
*printer
; /* Printer data */
8092 struct stat fileinfo
; /* File information */
8093 int kbytes
; /* Size of file */
8094 int compression
; /* Document compression */
8097 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "print_job(%p[%d], %s)", con
, con
->number
,
8098 uri
->values
[0].string
.text
);
8101 * Validate print file attributes, for now just document-format and
8102 * compression (CUPS only supports "none" and "gzip")...
8105 compression
= CUPS_FILE_NONE
;
8107 if ((attr
= ippFindAttribute(con
->request
, "compression",
8108 IPP_TAG_KEYWORD
)) != NULL
)
8110 if (strcmp(attr
->values
[0].string
.text
, "none")
8112 && strcmp(attr
->values
[0].string
.text
, "gzip")
8113 #endif /* HAVE_LIBZ */
8116 send_ipp_status(con
, IPP_ATTRIBUTES
,
8117 _("Unsupported compression \"%s\"."),
8118 attr
->values
[0].string
.text
);
8119 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
8120 "compression", NULL
, attr
->values
[0].string
.text
);
8125 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
8126 compression
= CUPS_FILE_GZIP
;
8127 #endif /* HAVE_LIBZ */
8131 * Do we have a file to print?
8136 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file in print request."));
8141 * Is the destination valid?
8144 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
8150 send_ipp_status(con
, IPP_NOT_FOUND
,
8151 _("The printer or class does not exist."));
8156 * Is it a format we support?
8159 if ((format
= ippFindAttribute(con
->request
, "document-format",
8160 IPP_TAG_MIMETYPE
)) != NULL
)
8163 * Grab format from client...
8166 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%255[^;]", super
,
8169 send_ipp_status(con
, IPP_BAD_REQUEST
,
8170 _("Bad document-format \"%s\"."),
8171 format
->values
[0].string
.text
);
8175 else if ((default_format
= cupsGetOption("document-format",
8176 printer
->num_options
,
8177 printer
->options
)) != NULL
)
8180 * Use default document format...
8183 if (sscanf(default_format
, "%15[^/]/%255[^;]", super
, type
) != 2)
8185 send_ipp_status(con
, IPP_BAD_REQUEST
,
8186 _("Bad document-format \"%s\"."),
8197 strlcpy(super
, "application", sizeof(super
));
8198 strlcpy(type
, "octet-stream", sizeof(type
));
8201 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
8204 * Auto-type the file...
8207 ipp_attribute_t
*doc_name
; /* document-name attribute */
8210 cupsdLogMessage(CUPSD_LOG_DEBUG
, "[Job ???] Auto-typing file...");
8212 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
8213 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
8214 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
8218 filetype
= mimeType(MimeDatabase
, super
, type
);
8220 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job ???] Request file type is %s/%s.",
8221 filetype
->super
, filetype
->type
);
8224 filetype
= mimeType(MimeDatabase
, super
, type
);
8228 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
8231 * Replace the document-format attribute value with the auto-typed or
8235 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
8240 _cupsStrFree(format
->values
[0].string
.text
);
8242 format
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
8245 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
8246 "document-format", NULL
, mimetype
);
8250 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
8251 _("Unsupported document-format \"%s\"."),
8252 format
? format
->values
[0].string
.text
:
8253 "application/octet-stream");
8254 cupsdLogMessage(CUPSD_LOG_INFO
,
8255 "Hint: Do you have the raw file printing rules enabled?");
8258 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
8259 "document-format", NULL
, format
->values
[0].string
.text
);
8265 * Read any embedded job ticket info from PS files...
8268 if (!_cups_strcasecmp(filetype
->super
, "application") &&
8269 (!_cups_strcasecmp(filetype
->type
, "postscript") ||
8270 !_cups_strcasecmp(filetype
->type
, "pdf")))
8271 read_job_ticket(con
);
8274 * Create the job object...
8277 if ((job
= add_job(con
, printer
, filetype
)) == NULL
)
8281 * Update quota data...
8284 if (stat(con
->filename
, &fileinfo
))
8287 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
8289 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
8291 job
->koctets
+= kbytes
;
8293 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets", IPP_TAG_INTEGER
)) != NULL
)
8294 attr
->values
[0].integer
+= kbytes
;
8297 * Add the job file...
8300 if (add_file(con
, job
, filetype
, compression
))
8303 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
, job
->num_files
);
8304 if (rename(con
->filename
, filename
))
8306 cupsdLogJob(job
, CUPSD_LOG_ERROR
, "Unable to rename job document file \"%s\": %s", filename
, strerror(errno
));
8308 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to rename job document file."));
8312 cupsdClearString(&con
->filename
);
8315 * See if we need to add the ending sheet...
8318 if (cupsdTimeoutJob(job
))
8322 * Log and save the job...
8325 cupsdLogJob(job
, CUPSD_LOG_INFO
,
8326 "File of type %s/%s queued by \"%s\".",
8327 filetype
->super
, filetype
->type
, job
->username
);
8328 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "hold_until=%d", (int)job
->hold_until
);
8329 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
8330 job
->dest
, job
->username
);
8333 * Start the job if possible...
8341 * 'read_job_ticket()' - Read a job ticket embedded in a print file.
8343 * This function only gets called when printing a single PDF or PostScript
8344 * file using the Print-Job operation. It doesn't work for Create-Job +
8345 * Send-File, since the job attributes need to be set at job creation
8346 * time for banners to work. The embedded job ticket stuff is here
8347 * primarily to allow the Windows printer driver for CUPS to pass in JCL
8348 * options and IPP attributes which otherwise would be lost.
8350 * The format of a job ticket is simple:
8352 * %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
8354 * %cupsJobTicket: attr1=value1
8355 * %cupsJobTicket: attr2=value2
8357 * %cupsJobTicket: attrN=valueN
8359 * Job ticket lines must appear immediately after the first line that
8360 * specifies PostScript (%!PS-Adobe-3.0) or PDF (%PDF) format, and CUPS
8361 * stops looking for job ticket info when it finds a line that does not begin
8362 * with "%cupsJobTicket:".
8364 * The maximum length of a job ticket line, including the prefix, is
8365 * 255 characters to conform with the Adobe DSC.
8367 * Read-only attributes are rejected with a notice to the error log in
8368 * case a malicious user tries anything. Since the job ticket is read
8369 * prior to attribute validation in print_job(), job ticket attributes
8370 * will go through the same validation as IPP attributes...
8374 read_job_ticket(cupsd_client_t
*con
) /* I - Client connection */
8376 cups_file_t
*fp
; /* File to read from */
8377 char line
[256]; /* Line data */
8378 int num_options
; /* Number of options */
8379 cups_option_t
*options
; /* Options */
8380 ipp_t
*ticket
; /* New attributes */
8381 ipp_attribute_t
*attr
, /* Current attribute */
8382 *attr2
, /* Job attribute */
8383 *prev2
; /* Previous job attribute */
8387 * First open the print file...
8390 if ((fp
= cupsFileOpen(con
->filename
, "rb")) == NULL
)
8392 cupsdLogMessage(CUPSD_LOG_ERROR
,
8393 "Unable to open print file for job ticket - %s",
8399 * Skip the first line...
8402 if (cupsFileGets(fp
, line
, sizeof(line
)) == NULL
)
8404 cupsdLogMessage(CUPSD_LOG_ERROR
,
8405 "Unable to read from print file for job ticket - %s",
8411 if (strncmp(line
, "%!PS-Adobe-", 11) && strncmp(line
, "%PDF-", 5))
8414 * Not a DSC-compliant file, so no job ticket info will be available...
8422 * Read job ticket info from the file...
8428 while (cupsFileGets(fp
, line
, sizeof(line
)))
8431 * Stop at the first non-ticket line...
8434 if (strncmp(line
, "%cupsJobTicket:", 15))
8438 * Add the options to the option array...
8441 num_options
= cupsParseOptions(line
+ 15, num_options
, &options
);
8445 * Done with the file; see if we have any options...
8450 if (num_options
== 0)
8454 * OK, convert the options to an attribute list, and apply them to
8459 cupsEncodeOptions(ticket
, num_options
, options
);
8462 * See what the user wants to change.
8465 for (attr
= ticket
->attrs
; attr
; attr
= attr
->next
)
8467 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
8470 if (!strcmp(attr
->name
, "job-originating-host-name") ||
8471 !strcmp(attr
->name
, "job-originating-user-name") ||
8472 !strcmp(attr
->name
, "job-media-sheets-completed") ||
8473 !strcmp(attr
->name
, "job-k-octets") ||
8474 !strcmp(attr
->name
, "job-id") ||
8475 !strncmp(attr
->name
, "job-state", 9) ||
8476 !strncmp(attr
->name
, "time-at-", 8))
8477 continue; /* Read-only attrs */
8479 if ((attr2
= ippFindAttribute(con
->request
, attr
->name
,
8480 IPP_TAG_ZERO
)) != NULL
)
8483 * Some other value; first free the old value...
8486 if (con
->request
->attrs
== attr2
)
8488 con
->request
->attrs
= attr2
->next
;
8493 for (prev2
= con
->request
->attrs
; prev2
; prev2
= prev2
->next
)
8494 if (prev2
->next
== attr2
)
8496 prev2
->next
= attr2
->next
;
8501 if (con
->request
->last
== attr2
)
8502 con
->request
->last
= prev2
;
8504 ippDeleteAttribute(NULL
, attr2
);
8508 * Add new option by copying it...
8511 ippCopyAttribute(con
->request
, attr
, 0);
8515 * Then free the attribute list and option array...
8519 cupsFreeOptions(num_options
, options
);
8524 * 'reject_jobs()' - Reject print jobs to a printer.
8528 reject_jobs(cupsd_client_t
*con
, /* I - Client connection */
8529 ipp_attribute_t
*uri
) /* I - Printer or class URI */
8531 http_status_t status
; /* Policy status */
8532 cups_ptype_t dtype
; /* Destination type (printer/class) */
8533 cupsd_printer_t
*printer
; /* Printer data */
8534 ipp_attribute_t
*attr
; /* printer-state-message text */
8537 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "reject_jobs(%p[%d], %s)", con
,
8538 con
->number
, uri
->values
[0].string
.text
);
8541 * Is the destination valid?
8544 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8550 send_ipp_status(con
, IPP_NOT_FOUND
,
8551 _("The printer or class does not exist."));
8559 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8561 send_http_error(con
, status
, printer
);
8566 * Reject jobs sent to the printer...
8569 printer
->accepting
= 0;
8571 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
8572 IPP_TAG_TEXT
)) == NULL
)
8573 strlcpy(printer
->state_message
, "Rejecting Jobs",
8574 sizeof(printer
->state_message
));
8576 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
8577 sizeof(printer
->state_message
));
8579 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
8580 "No longer accepting jobs.");
8582 if (dtype
& CUPS_PRINTER_CLASS
)
8584 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
8586 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" rejecting jobs (\"%s\").",
8587 printer
->name
, get_username(con
));
8591 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
8593 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" rejecting jobs (\"%s\").",
8594 printer
->name
, get_username(con
));
8598 * Everything was ok, so return OK status...
8601 con
->response
->request
.status
.status_code
= IPP_OK
;
8606 * 'release_held_new_jobs()' - Release pending/new jobs on a printer or class.
8610 release_held_new_jobs(
8611 cupsd_client_t
*con
, /* I - Connection */
8612 ipp_attribute_t
*uri
) /* I - Printer URI */
8614 http_status_t status
; /* Policy status */
8615 cups_ptype_t dtype
; /* Destination type (printer/class) */
8616 cupsd_printer_t
*printer
; /* Printer data */
8619 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_held_new_jobs(%p[%d], %s)", con
,
8620 con
->number
, uri
->values
[0].string
.text
);
8623 * Is the destination valid?
8626 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8632 send_ipp_status(con
, IPP_NOT_FOUND
,
8633 _("The printer or class does not exist."));
8641 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8643 send_http_error(con
, status
, printer
);
8648 * Hold pending/new jobs sent to the printer...
8651 printer
->holding_new_jobs
= 0;
8653 cupsdSetPrinterReasons(printer
, "-hold-new-jobs");
8655 if (dtype
& CUPS_PRINTER_CLASS
)
8656 cupsdLogMessage(CUPSD_LOG_INFO
,
8657 "Class \"%s\" now printing pending/new jobs (\"%s\").",
8658 printer
->name
, get_username(con
));
8660 cupsdLogMessage(CUPSD_LOG_INFO
,
8661 "Printer \"%s\" now printing pending/new jobs (\"%s\").",
8662 printer
->name
, get_username(con
));
8665 * Everything was ok, so return OK status...
8668 con
->response
->request
.status
.status_code
= IPP_OK
;
8673 * 'release_job()' - Release a held print job.
8677 release_job(cupsd_client_t
*con
, /* I - Client connection */
8678 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
8680 ipp_attribute_t
*attr
; /* Current attribute */
8681 int jobid
; /* Job ID */
8682 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
8683 username
[HTTP_MAX_URI
], /* Username portion of URI */
8684 host
[HTTP_MAX_URI
], /* Host portion of URI */
8685 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8686 int port
; /* Port portion of URI */
8687 cupsd_job_t
*job
; /* Job information */
8690 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_job(%p[%d], %s)", con
,
8691 con
->number
, uri
->values
[0].string
.text
);
8694 * See if we have a job URI or a printer URI...
8697 if (!strcmp(uri
->name
, "printer-uri"))
8700 * Got a printer URI; see if we also have a job-id attribute...
8703 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8704 IPP_TAG_INTEGER
)) == NULL
)
8706 send_ipp_status(con
, IPP_BAD_REQUEST
,
8707 _("Got a printer-uri attribute but no job-id."));
8711 jobid
= attr
->values
[0].integer
;
8716 * Got a job URI; parse it to get the job ID...
8719 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8720 sizeof(scheme
), username
, sizeof(username
), host
,
8721 sizeof(host
), &port
, resource
, sizeof(resource
));
8723 if (strncmp(resource
, "/jobs/", 6))
8729 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
8730 uri
->values
[0].string
.text
);
8734 jobid
= atoi(resource
+ 6);
8738 * See if the job exists...
8741 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8744 * Nope - return a "not found" error...
8747 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
8752 * See if job is "held"...
8755 if (job
->state_value
!= IPP_JOB_HELD
)
8758 * Nope - return a "not possible" error...
8761 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not held."), jobid
);
8766 * See if the job is owned by the requesting user...
8769 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8771 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8772 cupsdFindDest(job
->dest
));
8777 * Reset the job-hold-until value to "no-hold"...
8780 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
8781 IPP_TAG_KEYWORD
)) == NULL
)
8782 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
8786 _cupsStrFree(attr
->values
[0].string
.text
);
8788 attr
->value_tag
= IPP_TAG_KEYWORD
;
8789 attr
->values
[0].string
.text
= _cupsStrAlloc("no-hold");
8791 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
8792 "Job job-hold-until value changed by user.");
8793 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
8797 * Release the job and return...
8800 cupsdReleaseJob(job
);
8802 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
8803 "Job released by user.");
8805 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Released by \"%s\".", username
);
8807 con
->response
->request
.status
.status_code
= IPP_OK
;
8814 * 'renew_subscription()' - Renew an existing subscription...
8819 cupsd_client_t
*con
, /* I - Client connection */
8820 int sub_id
) /* I - Subscription ID */
8822 http_status_t status
; /* Policy status */
8823 cupsd_subscription_t
*sub
; /* Subscription */
8824 ipp_attribute_t
*lease
; /* notify-lease-duration */
8827 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
8828 "renew_subscription(con=%p[%d], sub_id=%d)",
8829 con
, con
->number
, sub_id
);
8832 * Is the subscription ID valid?
8835 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
8838 * Bad subscription ID...
8841 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
8849 * Job subscriptions cannot be renewed...
8852 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8853 _("Job subscriptions cannot be renewed."));
8861 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
8863 con
, sub
->owner
)) != HTTP_OK
)
8865 send_http_error(con
, status
, sub
->dest
);
8870 * Renew the subscription...
8873 lease
= ippFindAttribute(con
->request
, "notify-lease-duration",
8876 sub
->lease
= lease
? lease
->values
[0].integer
: DefaultLeaseDuration
;
8878 if (MaxLeaseDuration
&& (sub
->lease
== 0 || sub
->lease
> MaxLeaseDuration
))
8880 cupsdLogMessage(CUPSD_LOG_INFO
,
8881 "renew_subscription: Limiting notify-lease-duration to "
8884 sub
->lease
= MaxLeaseDuration
;
8887 sub
->expire
= sub
->lease
? time(NULL
) + sub
->lease
: 0;
8889 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
8891 con
->response
->request
.status
.status_code
= IPP_OK
;
8893 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
8894 "notify-lease-duration", sub
->lease
);
8899 * 'restart_job()' - Restart an old print job.
8903 restart_job(cupsd_client_t
*con
, /* I - Client connection */
8904 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
8906 ipp_attribute_t
*attr
; /* Current attribute */
8907 int jobid
; /* Job ID */
8908 cupsd_job_t
*job
; /* Job information */
8909 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
8910 username
[HTTP_MAX_URI
], /* Username portion of URI */
8911 host
[HTTP_MAX_URI
], /* Host portion of URI */
8912 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8913 int port
; /* Port portion of URI */
8916 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "restart_job(%p[%d], %s)", con
,
8917 con
->number
, uri
->values
[0].string
.text
);
8920 * See if we have a job URI or a printer URI...
8923 if (!strcmp(uri
->name
, "printer-uri"))
8926 * Got a printer URI; see if we also have a job-id attribute...
8929 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8930 IPP_TAG_INTEGER
)) == NULL
)
8932 send_ipp_status(con
, IPP_BAD_REQUEST
,
8933 _("Got a printer-uri attribute but no job-id."));
8937 jobid
= attr
->values
[0].integer
;
8942 * Got a job URI; parse it to get the job ID...
8945 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8946 sizeof(scheme
), username
, sizeof(username
), host
,
8947 sizeof(host
), &port
, resource
, sizeof(resource
));
8949 if (strncmp(resource
, "/jobs/", 6))
8955 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
8956 uri
->values
[0].string
.text
);
8960 jobid
= atoi(resource
+ 6);
8964 * See if the job exists...
8967 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8970 * Nope - return a "not found" error...
8973 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
8978 * See if job is in any of the "completed" states...
8981 if (job
->state_value
<= IPP_JOB_PROCESSING
)
8984 * Nope - return a "not possible" error...
8987 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not complete."),
8993 * See if we have retained the job files...
8998 if (!job
->attrs
|| job
->num_files
== 0)
9001 * Nope - return a "not possible" error...
9004 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9005 _("Job #%d cannot be restarted - no files."), jobid
);
9010 * See if the job is owned by the requesting user...
9013 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9015 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9016 cupsdFindDest(job
->dest
));
9021 * See if the job-hold-until attribute is specified...
9024 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
9025 IPP_TAG_KEYWORD
)) == NULL
)
9026 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
9028 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
9031 * Return the job to a held state...
9034 cupsdLogJob(job
, CUPSD_LOG_DEBUG
,
9035 "Restarted by \"%s\" with job-hold-until=%s.",
9036 username
, attr
->values
[0].string
.text
);
9037 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
9039 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
,
9040 NULL
, job
, "Job restarted by user with job-hold-until=%s",
9041 attr
->values
[0].string
.text
);
9046 * Restart the job...
9049 cupsdRestartJob(job
);
9053 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Restarted by \"%s\".", username
);
9055 con
->response
->request
.status
.status_code
= IPP_OK
;
9060 * 'save_auth_info()' - Save authentication information for a job.
9065 cupsd_client_t
*con
, /* I - Client connection */
9066 cupsd_job_t
*job
, /* I - Job */
9067 ipp_attribute_t
*auth_info
) /* I - auth-info attribute, if any */
9069 int i
; /* Looping var */
9070 char filename
[1024]; /* Job authentication filename */
9071 cups_file_t
*fp
; /* Job authentication file */
9072 char line
[65536]; /* Line for file */
9073 cupsd_printer_t
*dest
; /* Destination printer/class */
9077 * This function saves the in-memory authentication information for
9078 * a job so that it can be used to authenticate with a remote host.
9079 * The information is stored in a file that is readable only by the
9080 * root user. The fields are Base-64 encoded, each on a separate line,
9081 * followed by random number (up to 1024) of newlines to limit the
9082 * amount of information that is exposed.
9084 * Because of the potential for exposing of authentication information,
9085 * this functionality is only enabled when running cupsd as root.
9087 * This caching only works for the Basic and BasicDigest authentication
9088 * types. Digest authentication cannot be cached this way, and in
9089 * the future Kerberos authentication may make all of this obsolete.
9091 * Authentication information is saved whenever an authenticated
9092 * Print-Job, Create-Job, or CUPS-Authenticate-Job operation is
9095 * This information is deleted after a job is completed or canceled,
9096 * so reprints may require subsequent re-authentication.
9102 if ((dest
= cupsdFindDest(job
->dest
)) == NULL
)
9106 * Create the authentication file and change permissions...
9109 snprintf(filename
, sizeof(filename
), "%s/a%05d", RequestRoot
, job
->id
);
9110 if ((fp
= cupsFileOpen(filename
, "w")) == NULL
)
9112 cupsdLogMessage(CUPSD_LOG_ERROR
,
9113 "Unable to save authentication info to \"%s\" - %s",
9114 filename
, strerror(errno
));
9118 fchown(cupsFileNumber(fp
), 0, 0);
9119 fchmod(cupsFileNumber(fp
), 0400);
9121 cupsFilePuts(fp
, "CUPSD-AUTH-V3\n");
9124 i
< (int)(sizeof(job
->auth_env
) / sizeof(job
->auth_env
[0]));
9126 cupsdClearString(job
->auth_env
+ i
);
9128 if (auth_info
&& auth_info
->num_values
== dest
->num_auth_info_required
)
9131 * Write 1 to 3 auth values...
9135 i
< auth_info
->num_values
&&
9136 i
< (int)(sizeof(job
->auth_env
) / sizeof(job
->auth_env
[0]));
9139 if (strcmp(dest
->auth_info_required
[i
], "negotiate"))
9141 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[i
].string
.text
, (int)strlen(auth_info
->values
[i
].string
.text
));
9142 cupsFilePutConf(fp
, dest
->auth_info_required
[i
], line
);
9145 cupsFilePutConf(fp
, dest
->auth_info_required
[i
],
9146 auth_info
->values
[i
].string
.text
);
9148 if (!strcmp(dest
->auth_info_required
[i
], "username"))
9149 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_USERNAME=%s",
9150 auth_info
->values
[i
].string
.text
);
9151 else if (!strcmp(dest
->auth_info_required
[i
], "domain"))
9152 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_DOMAIN=%s",
9153 auth_info
->values
[i
].string
.text
);
9154 else if (!strcmp(dest
->auth_info_required
[i
], "password"))
9155 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_PASSWORD=%s",
9156 auth_info
->values
[i
].string
.text
);
9157 else if (!strcmp(dest
->auth_info_required
[i
], "negotiate"))
9158 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_NEGOTIATE=%s",
9159 auth_info
->values
[i
].string
.text
);
9164 else if (auth_info
&& auth_info
->num_values
== 2 &&
9165 dest
->num_auth_info_required
== 1 &&
9166 !strcmp(dest
->auth_info_required
[0], "negotiate"))
9169 * Allow fallback to username+password for Kerberized queues...
9172 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[0].string
.text
, (int)strlen(auth_info
->values
[0].string
.text
));
9173 cupsFilePutConf(fp
, "username", line
);
9175 cupsdSetStringf(job
->auth_env
+ 0, "AUTH_USERNAME=%s",
9176 auth_info
->values
[0].string
.text
);
9178 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[1].string
.text
, (int)strlen(auth_info
->values
[1].string
.text
));
9179 cupsFilePutConf(fp
, "password", line
);
9181 cupsdSetStringf(job
->auth_env
+ 1, "AUTH_PASSWORD=%s",
9182 auth_info
->values
[1].string
.text
);
9184 else if (con
->username
[0])
9187 * Write the authenticated username...
9190 httpEncode64_2(line
, sizeof(line
), con
->username
, (int)strlen(con
->username
));
9191 cupsFilePutConf(fp
, "username", line
);
9193 cupsdSetStringf(job
->auth_env
+ 0, "AUTH_USERNAME=%s", con
->username
);
9196 * Write the authenticated password...
9199 httpEncode64_2(line
, sizeof(line
), con
->password
, (int)strlen(con
->password
));
9200 cupsFilePutConf(fp
, "password", line
);
9202 cupsdSetStringf(job
->auth_env
+ 1, "AUTH_PASSWORD=%s", con
->password
);
9206 if (con
->gss_uid
> 0)
9208 cupsFilePrintf(fp
, "uid %d\n", (int)con
->gss_uid
);
9209 cupsdSetStringf(&job
->auth_uid
, "AUTH_UID=%d", (int)con
->gss_uid
);
9211 #endif /* HAVE_GSSAPI */
9214 * Write a random number of newlines to the end of the file...
9217 for (i
= (CUPS_RAND() % 1024); i
>= 0; i
--)
9218 cupsFilePutChar(fp
, '\n');
9221 * Close the file and return...
9229 * 'send_document()' - Send a file to a printer or class.
9233 send_document(cupsd_client_t
*con
, /* I - Client connection */
9234 ipp_attribute_t
*uri
) /* I - Printer URI */
9236 ipp_attribute_t
*attr
; /* Current attribute */
9237 ipp_attribute_t
*format
; /* Request's document-format attribute */
9238 ipp_attribute_t
*jformat
; /* Job's document-format attribute */
9239 const char *default_format
;/* document-format-default value */
9240 int jobid
; /* Job ID number */
9241 cupsd_job_t
*job
; /* Current job */
9242 char job_uri
[HTTP_MAX_URI
],
9244 scheme
[HTTP_MAX_URI
],
9245 /* Method portion of URI */
9246 username
[HTTP_MAX_URI
],
9247 /* Username portion of URI */
9249 /* Host portion of URI */
9250 resource
[HTTP_MAX_URI
];
9251 /* Resource portion of URI */
9252 int port
; /* Port portion of URI */
9253 mime_type_t
*filetype
; /* Type of file */
9254 char super
[MIME_MAX_SUPER
],
9255 /* Supertype of file */
9256 type
[MIME_MAX_TYPE
],
9257 /* Subtype of file */
9258 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
9259 /* Textual name of mime type */
9260 char filename
[1024]; /* Job filename */
9261 cupsd_printer_t
*printer
; /* Current printer */
9262 struct stat fileinfo
; /* File information */
9263 int kbytes
; /* Size of file */
9264 int compression
; /* Type of compression */
9265 int start_job
; /* Start the job? */
9268 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "send_document(%p[%d], %s)", con
,
9269 con
->number
, uri
->values
[0].string
.text
);
9272 * See if we have a job URI or a printer URI...
9275 if (!strcmp(uri
->name
, "printer-uri"))
9278 * Got a printer URI; see if we also have a job-id attribute...
9281 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9282 IPP_TAG_INTEGER
)) == NULL
)
9284 send_ipp_status(con
, IPP_BAD_REQUEST
,
9285 _("Got a printer-uri attribute but no job-id."));
9289 jobid
= attr
->values
[0].integer
;
9294 * Got a job URI; parse it to get the job ID...
9297 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9298 sizeof(scheme
), username
, sizeof(username
), host
,
9299 sizeof(host
), &port
, resource
, sizeof(resource
));
9301 if (strncmp(resource
, "/jobs/", 6))
9307 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9308 uri
->values
[0].string
.text
);
9312 jobid
= atoi(resource
+ 6);
9316 * See if the job exists...
9319 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9322 * Nope - return a "not found" error...
9325 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9329 printer
= cupsdFindDest(job
->dest
);
9332 * See if the job is owned by the requesting user...
9335 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9337 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9338 cupsdFindDest(job
->dest
));
9343 * OK, see if the client is sending the document compressed - CUPS
9344 * only supports "none" and "gzip".
9347 compression
= CUPS_FILE_NONE
;
9349 if ((attr
= ippFindAttribute(con
->request
, "compression",
9350 IPP_TAG_KEYWORD
)) != NULL
)
9352 if (strcmp(attr
->values
[0].string
.text
, "none")
9354 && strcmp(attr
->values
[0].string
.text
, "gzip")
9355 #endif /* HAVE_LIBZ */
9358 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Unsupported compression \"%s\"."),
9359 attr
->values
[0].string
.text
);
9360 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
9361 "compression", NULL
, attr
->values
[0].string
.text
);
9366 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
9367 compression
= CUPS_FILE_GZIP
;
9368 #endif /* HAVE_LIBZ */
9372 * Do we have a file to print?
9375 if ((attr
= ippFindAttribute(con
->request
, "last-document",
9376 IPP_TAG_BOOLEAN
)) == NULL
)
9378 send_ipp_status(con
, IPP_BAD_REQUEST
,
9379 _("Missing last-document attribute in request."));
9386 * Check for an empty request with "last-document" set to true, which is
9387 * used to close an "open" job by RFC 2911, section 3.3.2.
9390 if (job
->num_files
> 0 && attr
->values
[0].boolean
)
9393 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file in print request."));
9398 * Is it a format we support?
9401 if ((format
= ippFindAttribute(con
->request
, "document-format",
9402 IPP_TAG_MIMETYPE
)) != NULL
)
9405 * Grab format from client...
9408 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%255[^;]",
9411 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"."),
9412 format
->values
[0].string
.text
);
9416 else if ((default_format
= cupsGetOption("document-format",
9417 printer
->num_options
,
9418 printer
->options
)) != NULL
)
9421 * Use default document format...
9424 if (sscanf(default_format
, "%15[^/]/%255[^;]", super
, type
) != 2)
9426 send_ipp_status(con
, IPP_BAD_REQUEST
,
9427 _("Bad document-format-default \"%s\"."), default_format
);
9434 * No document format attribute? Auto-type it!
9437 strlcpy(super
, "application", sizeof(super
));
9438 strlcpy(type
, "octet-stream", sizeof(type
));
9441 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
9444 * Auto-type the file...
9447 ipp_attribute_t
*doc_name
; /* document-name attribute */
9450 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Auto-typing file...");
9452 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
9453 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
9454 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
9458 filetype
= mimeType(MimeDatabase
, super
, type
);
9461 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Request file type is %s/%s.",
9462 filetype
->super
, filetype
->type
);
9465 filetype
= mimeType(MimeDatabase
, super
, type
);
9470 * Replace the document-format attribute value with the auto-typed or
9474 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9477 if ((jformat
= ippFindAttribute(job
->attrs
, "document-format",
9478 IPP_TAG_MIMETYPE
)) != NULL
)
9480 _cupsStrFree(jformat
->values
[0].string
.text
);
9482 jformat
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
9485 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
9486 "document-format", NULL
, mimetype
);
9490 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9491 _("Unsupported document-format \"%s/%s\"."), super
, type
);
9492 cupsdLogMessage(CUPSD_LOG_INFO
,
9493 "Hint: Do you have the raw file printing rules enabled?");
9496 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9497 "document-format", NULL
, format
->values
[0].string
.text
);
9502 if (printer
->filetypes
&& !cupsArrayFind(printer
->filetypes
, filetype
))
9504 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9507 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9508 _("Unsupported document-format \"%s\"."), mimetype
);
9510 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9511 "document-format", NULL
, mimetype
);
9517 * Add the file to the job...
9522 if (add_file(con
, job
, filetype
, compression
))
9525 if (stat(con
->filename
, &fileinfo
))
9528 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
9530 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
9532 job
->koctets
+= kbytes
;
9534 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets", IPP_TAG_INTEGER
)) != NULL
)
9535 attr
->values
[0].integer
+= kbytes
;
9537 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
, job
->num_files
);
9538 if (rename(con
->filename
, filename
))
9540 cupsdLogJob(job
, CUPSD_LOG_ERROR
, "Unable to rename job document file \"%s\": %s", filename
, strerror(errno
));
9542 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to rename job document file."));
9546 cupsdClearString(&con
->filename
);
9548 cupsdLogJob(job
, CUPSD_LOG_INFO
, "File of type %s/%s queued by \"%s\".",
9549 filetype
->super
, filetype
->type
, job
->username
);
9552 * Start the job if this is the last document...
9557 if ((attr
= ippFindAttribute(con
->request
, "last-document",
9558 IPP_TAG_BOOLEAN
)) != NULL
&&
9559 attr
->values
[0].boolean
)
9562 * See if we need to add the ending sheet...
9565 if (cupsdTimeoutJob(job
))
9568 if (job
->state_value
== IPP_JOB_STOPPED
)
9570 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9571 job
->state_value
= IPP_JOB_PENDING
;
9573 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
9575 else if (job
->state_value
== IPP_JOB_HELD
)
9577 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9578 IPP_TAG_KEYWORD
)) == NULL
)
9579 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9581 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9583 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9584 job
->state_value
= IPP_JOB_PENDING
;
9586 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
9589 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-hold-until-specified");
9593 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
9599 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9600 IPP_TAG_KEYWORD
)) == NULL
)
9601 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9603 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9605 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
9606 job
->state_value
= IPP_JOB_HELD
;
9607 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
9609 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-incoming");
9612 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
9619 * Fill in the response info...
9622 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
9623 con
->clientname
, con
->clientport
, "/jobs/%d", jobid
);
9624 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
9627 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", jobid
);
9629 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
9631 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons",
9632 NULL
, job
->reasons
->values
[0].string
.text
);
9634 con
->response
->request
.status
.status_code
= IPP_OK
;
9637 * Start the job if necessary...
9646 * 'send_http_error()' - Send a HTTP error back to the IPP client.
9651 cupsd_client_t
*con
, /* I - Client connection */
9652 http_status_t status
, /* I - HTTP status code */
9653 cupsd_printer_t
*printer
) /* I - Printer, if any */
9655 ipp_attribute_t
*uri
; /* Request URI, if any */
9658 if ((uri
= ippFindAttribute(con
->request
, "printer-uri",
9659 IPP_TAG_URI
)) == NULL
)
9660 uri
= ippFindAttribute(con
->request
, "job-uri", IPP_TAG_URI
);
9662 cupsdLogMessage(status
== HTTP_FORBIDDEN
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
9663 "[Client %d] Returning HTTP %s for %s (%s) from %s",
9664 con
->number
, httpStatus(status
),
9666 ippOpString(con
->request
->request
.op
.operation_id
) :
9668 uri
? uri
->values
[0].string
.text
: "no URI",
9669 con
->http
->hostname
);
9673 int auth_type
; /* Type of authentication required */
9676 auth_type
= CUPSD_AUTH_NONE
;
9678 if (status
== HTTP_UNAUTHORIZED
&&
9679 printer
->num_auth_info_required
> 0 &&
9680 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
9682 (con
->request
->request
.op
.operation_id
== IPP_PRINT_JOB
||
9683 con
->request
->request
.op
.operation_id
== IPP_CREATE_JOB
||
9684 con
->request
->request
.op
.operation_id
== CUPS_AUTHENTICATE_JOB
))
9687 * Creating and authenticating jobs requires Kerberos...
9690 auth_type
= CUPSD_AUTH_NEGOTIATE
;
9695 * Use policy/location-defined authentication requirements...
9698 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9699 cupsd_location_t
*auth
; /* Pointer to authentication element */
9702 if (printer
->type
& CUPS_PRINTER_CLASS
)
9703 snprintf(resource
, sizeof(resource
), "/classes/%s", printer
->name
);
9705 snprintf(resource
, sizeof(resource
), "/printers/%s", printer
->name
);
9707 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
9708 auth
->type
== CUPSD_AUTH_NONE
)
9709 auth
= cupsdFindPolicyOp(printer
->op_policy_ptr
,
9711 con
->request
->request
.op
.operation_id
:
9716 if (auth
->type
== CUPSD_AUTH_DEFAULT
)
9717 auth_type
= cupsdDefaultAuthType();
9719 auth_type
= auth
->type
;
9723 cupsdSendError(con
, status
, auth_type
);
9726 cupsdSendError(con
, status
, CUPSD_AUTH_NONE
);
9728 ippDelete(con
->response
);
9729 con
->response
= NULL
;
9736 * 'send_ipp_status()' - Send a status back to the IPP client.
9740 send_ipp_status(cupsd_client_t
*con
, /* I - Client connection */
9741 ipp_status_t status
, /* I - IPP status code */
9742 const char *message
,/* I - Status message */
9743 ...) /* I - Additional args as needed */
9745 va_list ap
; /* Pointer to additional args */
9746 char formatted
[1024]; /* Formatted errror message */
9749 va_start(ap
, message
);
9750 vsnprintf(formatted
, sizeof(formatted
),
9751 _cupsLangString(con
->language
, message
), ap
);
9754 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s: %s",
9755 ippOpString(con
->request
->request
.op
.operation_id
),
9756 ippErrorString(status
), formatted
);
9758 con
->response
->request
.status
.status_code
= status
;
9760 if (ippFindAttribute(con
->response
, "attributes-charset",
9761 IPP_TAG_ZERO
) == NULL
)
9762 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
9763 "attributes-charset", NULL
, "utf-8");
9765 if (ippFindAttribute(con
->response
, "attributes-natural-language",
9766 IPP_TAG_ZERO
) == NULL
)
9767 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
9768 "attributes-natural-language", NULL
, DefaultLanguage
);
9770 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
9771 "status-message", NULL
, formatted
);
9776 * 'set_default()' - Set the default destination...
9780 set_default(cupsd_client_t
*con
, /* I - Client connection */
9781 ipp_attribute_t
*uri
) /* I - Printer URI */
9783 http_status_t status
; /* Policy status */
9784 cups_ptype_t dtype
; /* Destination type (printer/class) */
9785 cupsd_printer_t
*printer
, /* Printer */
9786 *oldprinter
; /* Old default printer */
9789 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_default(%p[%d], %s)", con
,
9790 con
->number
, uri
->values
[0].string
.text
);
9793 * Is the destination valid?
9796 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9802 send_ipp_status(con
, IPP_NOT_FOUND
,
9803 _("The printer or class does not exist."));
9811 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
9813 send_http_error(con
, status
, NULL
);
9818 * Set it as the default...
9821 oldprinter
= DefaultPrinter
;
9822 DefaultPrinter
= printer
;
9825 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, oldprinter
, NULL
,
9826 "%s is no longer the default printer.", oldprinter
->name
);
9828 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
9829 "%s is now the default printer.", printer
->name
);
9831 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
| CUPSD_DIRTY_CLASSES
|
9832 CUPSD_DIRTY_PRINTCAP
);
9834 cupsdLogMessage(CUPSD_LOG_INFO
,
9835 "Default destination set to \"%s\" by \"%s\".",
9836 printer
->name
, get_username(con
));
9839 * Everything was ok, so return OK status...
9842 con
->response
->request
.status
.status_code
= IPP_OK
;
9847 * 'set_job_attrs()' - Set job attributes.
9851 set_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
9852 ipp_attribute_t
*uri
) /* I - Job URI */
9854 ipp_attribute_t
*attr
, /* Current attribute */
9855 *attr2
; /* Job attribute */
9856 int jobid
; /* Job ID */
9857 cupsd_job_t
*job
; /* Current job */
9858 char scheme
[HTTP_MAX_URI
],
9859 /* Method portion of URI */
9860 username
[HTTP_MAX_URI
],
9861 /* Username portion of URI */
9863 /* Host portion of URI */
9864 resource
[HTTP_MAX_URI
];
9865 /* Resource portion of URI */
9866 int port
; /* Port portion of URI */
9867 int event
; /* Events? */
9868 int check_jobs
; /* Check jobs? */
9871 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_job_attrs(%p[%d], %s)", con
,
9872 con
->number
, uri
->values
[0].string
.text
);
9875 * Start with "everything is OK" status...
9878 con
->response
->request
.status
.status_code
= IPP_OK
;
9881 * See if we have a job URI or a printer URI...
9884 if (!strcmp(uri
->name
, "printer-uri"))
9887 * Got a printer URI; see if we also have a job-id attribute...
9890 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9891 IPP_TAG_INTEGER
)) == NULL
)
9893 send_ipp_status(con
, IPP_BAD_REQUEST
,
9894 _("Got a printer-uri attribute but no job-id."));
9898 jobid
= attr
->values
[0].integer
;
9903 * Got a job URI; parse it to get the job ID...
9906 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9907 sizeof(scheme
), username
, sizeof(username
), host
,
9908 sizeof(host
), &port
, resource
, sizeof(resource
));
9910 if (strncmp(resource
, "/jobs/", 6))
9916 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9917 uri
->values
[0].string
.text
);
9921 jobid
= atoi(resource
+ 6);
9925 * See if the job exists...
9928 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9931 * Nope - return a "not found" error...
9934 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9939 * See if the job has been completed...
9942 if (job
->state_value
> IPP_JOB_STOPPED
)
9945 * Return a "not-possible" error...
9948 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9949 _("Job #%d is finished and cannot be altered."), jobid
);
9954 * See if the job is owned by the requesting user...
9957 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9959 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9960 cupsdFindDest(job
->dest
));
9965 * See what the user wants to change.
9973 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
9975 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
9978 if (!strcmp(attr
->name
, "attributes-charset") ||
9979 !strcmp(attr
->name
, "attributes-natural-language") ||
9980 !strcmp(attr
->name
, "document-compression") ||
9981 !strcmp(attr
->name
, "document-format") ||
9982 !strcmp(attr
->name
, "job-detailed-status-messages") ||
9983 !strcmp(attr
->name
, "job-document-access-errors") ||
9984 !strcmp(attr
->name
, "job-id") ||
9985 !strcmp(attr
->name
, "job-impressions-completed") ||
9986 !strcmp(attr
->name
, "job-k-octets") ||
9987 !strcmp(attr
->name
, "job-originating-host-name") ||
9988 !strcmp(attr
->name
, "job-originating-user-name") ||
9989 !strcmp(attr
->name
, "job-printer-up-time") ||
9990 !strcmp(attr
->name
, "job-printer-uri") ||
9991 !strcmp(attr
->name
, "job-sheets") ||
9992 !strcmp(attr
->name
, "job-state-message") ||
9993 !strcmp(attr
->name
, "job-state-reasons") ||
9994 !strcmp(attr
->name
, "job-uri") ||
9995 !strcmp(attr
->name
, "number-of-documents") ||
9996 !strcmp(attr
->name
, "number-of-intervening-jobs") ||
9997 !strcmp(attr
->name
, "output-device-assigned") ||
9998 !strncmp(attr
->name
, "date-time-at-", 13) ||
9999 !strncmp(attr
->name
, "job-k-octets", 12) ||
10000 !strncmp(attr
->name
, "job-media-sheets", 16) ||
10001 !strncmp(attr
->name
, "time-at-", 8))
10007 send_ipp_status(con
, IPP_ATTRIBUTES_NOT_SETTABLE
,
10008 _("%s cannot be changed."), attr
->name
);
10010 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
10011 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
10015 if (!strcmp(attr
->name
, "job-priority"))
10018 * Change the job priority...
10021 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10023 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-priority value."));
10025 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
10026 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
10028 else if (job
->state_value
>= IPP_JOB_PROCESSING
)
10030 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10031 _("Job is completed and cannot be changed."));
10034 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10036 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-priority to %d",
10037 attr
->values
[0].integer
);
10038 cupsdSetJobPriority(job
, attr
->values
[0].integer
);
10041 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
|
10042 CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
;
10045 else if (!strcmp(attr
->name
, "job-state"))
10048 * Change the job state...
10051 if (attr
->value_tag
!= IPP_TAG_ENUM
)
10053 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-state value."));
10055 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
10056 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
10060 switch (attr
->values
[0].integer
)
10062 case IPP_JOB_PENDING
:
10063 case IPP_JOB_HELD
:
10064 if (job
->state_value
> IPP_JOB_HELD
)
10066 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10067 _("Job state cannot be changed."));
10070 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10072 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10073 attr
->values
[0].integer
);
10074 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
, CUPSD_JOB_DEFAULT
, "Job state changed by \"%s\"", username
);
10079 case IPP_JOB_PROCESSING
:
10080 case IPP_JOB_STOPPED
:
10081 if (job
->state_value
!= attr
->values
[0].integer
)
10083 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10084 _("Job state cannot be changed."));
10089 case IPP_JOB_CANCELED
:
10090 case IPP_JOB_ABORTED
:
10091 case IPP_JOB_COMPLETED
:
10092 if (job
->state_value
> IPP_JOB_PROCESSING
)
10094 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10095 _("Job state cannot be changed."));
10098 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10100 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10101 attr
->values
[0].integer
);
10102 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
,
10104 "Job state changed by \"%s\"", username
);
10111 else if (con
->response
->request
.status
.status_code
!= IPP_OK
)
10113 else if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10114 IPP_TAG_ZERO
)) != NULL
)
10117 * Some other value; first free the old value...
10120 if (job
->attrs
->prev
)
10121 job
->attrs
->prev
->next
= attr2
->next
;
10123 job
->attrs
->attrs
= attr2
->next
;
10125 if (job
->attrs
->last
== attr2
)
10126 job
->attrs
->last
= job
->attrs
->prev
;
10128 ippDeleteAttribute(NULL
, attr2
);
10131 * Then copy the attribute...
10134 ippCopyAttribute(job
->attrs
, attr
, 0);
10137 * See if the job-name or job-hold-until is being changed.
10140 if (!strcmp(attr
->name
, "job-hold-until"))
10142 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-hold-until to %s",
10143 attr
->values
[0].string
.text
);
10144 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
10146 if (!strcmp(attr
->values
[0].string
.text
, "no-hold"))
10148 cupsdReleaseJob(job
);
10152 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
,
10153 "Job held by \"%s\".", username
);
10155 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
;
10158 else if (attr
->value_tag
== IPP_TAG_DELETEATTR
)
10161 * Delete the attribute...
10164 if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10165 IPP_TAG_ZERO
)) != NULL
)
10167 if (job
->attrs
->prev
)
10168 job
->attrs
->prev
->next
= attr2
->next
;
10170 job
->attrs
->attrs
= attr2
->next
;
10172 if (attr2
== job
->attrs
->last
)
10173 job
->attrs
->last
= job
->attrs
->prev
;
10175 ippDeleteAttribute(NULL
, attr2
);
10177 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10183 * Add new option by copying it...
10186 ippCopyAttribute(job
->attrs
, attr
, 0);
10188 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10197 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10200 * Send events as needed...
10203 if (event
& CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
)
10204 cupsdAddEvent(CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
,
10205 cupsdFindDest(job
->dest
), job
,
10206 "Job priority changed by user.");
10208 if (event
& CUPSD_EVENT_JOB_STATE
)
10209 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
10210 job
->state_value
== IPP_JOB_HELD
?
10211 "Job held by user." : "Job restarted by user.");
10213 if (event
& CUPSD_EVENT_JOB_CONFIG_CHANGED
)
10214 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
10215 "Job options changed by user.");
10218 * Start jobs if possible...
10227 * 'set_printer_attrs()' - Set printer attributes.
10231 set_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
10232 ipp_attribute_t
*uri
) /* I - Printer */
10234 http_status_t status
; /* Policy status */
10235 cups_ptype_t dtype
; /* Destination type (printer/class) */
10236 cupsd_printer_t
*printer
; /* Printer/class */
10237 ipp_attribute_t
*attr
; /* Printer attribute */
10238 int changed
= 0; /* Was anything changed? */
10241 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_attrs(%p[%d], %s)", con
,
10242 con
->number
, uri
->values
[0].string
.text
);
10245 * Is the destination valid?
10248 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10254 send_ipp_status(con
, IPP_NOT_FOUND
,
10255 _("The printer or class does not exist."));
10263 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10265 send_http_error(con
, status
, printer
);
10270 * Return a list of attributes that can be set via Set-Printer-Attributes.
10273 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
10274 IPP_TAG_TEXT
)) != NULL
)
10276 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
10280 if ((attr
= ippFindAttribute(con
->request
, "printer-geo-location", IPP_TAG_URI
)) != NULL
&& !strncmp(attr
->values
[0].string
.text
, "geo:", 4))
10282 cupsdSetString(&printer
->geo_location
, attr
->values
[0].string
.text
);
10286 if ((attr
= ippFindAttribute(con
->request
, "printer-organization", IPP_TAG_TEXT
)) != NULL
)
10288 cupsdSetString(&printer
->organization
, attr
->values
[0].string
.text
);
10292 if ((attr
= ippFindAttribute(con
->request
, "printer-organizational-unit", IPP_TAG_TEXT
)) != NULL
)
10294 cupsdSetString(&printer
->organizational_unit
, attr
->values
[0].string
.text
);
10298 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
10299 IPP_TAG_TEXT
)) != NULL
)
10301 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
10306 * Update the printer attributes and return...
10311 printer
->config_time
= time(NULL
);
10313 cupsdSetPrinterAttrs(printer
);
10314 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
10316 cupsdAddEvent(CUPSD_EVENT_PRINTER_CONFIG
, printer
, NULL
,
10317 "Printer \"%s\" description or location changed by \"%s\".",
10318 printer
->name
, get_username(con
));
10320 cupsdLogMessage(CUPSD_LOG_INFO
,
10321 "Printer \"%s\" description or location changed by \"%s\".",
10322 printer
->name
, get_username(con
));
10325 con
->response
->request
.status
.status_code
= IPP_OK
;
10330 * 'set_printer_defaults()' - Set printer default options from a request.
10334 set_printer_defaults(
10335 cupsd_client_t
*con
, /* I - Client connection */
10336 cupsd_printer_t
*printer
) /* I - Printer */
10338 int i
; /* Looping var */
10339 ipp_attribute_t
*attr
; /* Current attribute */
10340 size_t namelen
; /* Length of attribute name */
10341 char name
[256], /* New attribute name */
10342 value
[256]; /* String version of integer attrs */
10345 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10348 * Skip non-printer attributes...
10351 if (attr
->group_tag
!= IPP_TAG_PRINTER
|| !attr
->name
)
10354 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_defaults: %s", attr
->name
);
10356 if (!strcmp(attr
->name
, "job-sheets-default"))
10359 * Only allow keywords and names...
10362 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10366 * Only allow job-sheets-default to be set when running without a
10367 * system high classification level...
10370 if (Classification
)
10373 cupsdSetString(&printer
->job_sheets
[0], attr
->values
[0].string
.text
);
10375 if (attr
->num_values
> 1)
10376 cupsdSetString(&printer
->job_sheets
[1], attr
->values
[1].string
.text
);
10378 cupsdSetString(&printer
->job_sheets
[1], "none");
10380 else if (!strcmp(attr
->name
, "requesting-user-name-allowed"))
10382 cupsdFreeStrings(&(printer
->users
));
10384 printer
->deny_users
= 0;
10386 if (attr
->value_tag
== IPP_TAG_NAME
&&
10387 (attr
->num_values
> 1 ||
10388 strcmp(attr
->values
[0].string
.text
, "all")))
10390 for (i
= 0; i
< attr
->num_values
; i
++)
10391 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
10394 else if (!strcmp(attr
->name
, "requesting-user-name-denied"))
10396 cupsdFreeStrings(&(printer
->users
));
10398 printer
->deny_users
= 1;
10400 if (attr
->value_tag
== IPP_TAG_NAME
&&
10401 (attr
->num_values
> 1 ||
10402 strcmp(attr
->values
[0].string
.text
, "none")))
10404 for (i
= 0; i
< attr
->num_values
; i
++)
10405 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
10408 else if (!strcmp(attr
->name
, "job-quota-period"))
10410 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10413 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-quota-period to %d...",
10414 attr
->values
[0].integer
);
10415 cupsdFreeQuotas(printer
);
10417 printer
->quota_period
= attr
->values
[0].integer
;
10419 else if (!strcmp(attr
->name
, "job-k-limit"))
10421 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10424 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-k-limit to %d...",
10425 attr
->values
[0].integer
);
10426 cupsdFreeQuotas(printer
);
10428 printer
->k_limit
= attr
->values
[0].integer
;
10430 else if (!strcmp(attr
->name
, "job-page-limit"))
10432 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10435 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-page-limit to %d...",
10436 attr
->values
[0].integer
);
10437 cupsdFreeQuotas(printer
);
10439 printer
->page_limit
= attr
->values
[0].integer
;
10441 else if (!strcmp(attr
->name
, "printer-op-policy"))
10443 cupsd_policy_t
*p
; /* Policy */
10446 if (attr
->value_tag
!= IPP_TAG_NAME
)
10449 if ((p
= cupsdFindPolicy(attr
->values
[0].string
.text
)) != NULL
)
10451 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10452 "Setting printer-op-policy to \"%s\"...",
10453 attr
->values
[0].string
.text
);
10454 cupsdSetString(&printer
->op_policy
, attr
->values
[0].string
.text
);
10455 printer
->op_policy_ptr
= p
;
10459 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10460 _("Unknown printer-op-policy \"%s\"."),
10461 attr
->values
[0].string
.text
);
10465 else if (!strcmp(attr
->name
, "printer-error-policy"))
10467 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10470 if (strcmp(attr
->values
[0].string
.text
, "retry-current-job") &&
10471 ((printer
->type
& CUPS_PRINTER_CLASS
) ||
10472 (strcmp(attr
->values
[0].string
.text
, "abort-job") &&
10473 strcmp(attr
->values
[0].string
.text
, "retry-job") &&
10474 strcmp(attr
->values
[0].string
.text
, "stop-printer"))))
10476 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10477 _("Unknown printer-error-policy \"%s\"."),
10478 attr
->values
[0].string
.text
);
10482 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10483 "Setting printer-error-policy to \"%s\"...",
10484 attr
->values
[0].string
.text
);
10485 cupsdSetString(&printer
->error_policy
, attr
->values
[0].string
.text
);
10489 * Skip any other non-default attributes...
10492 namelen
= strlen(attr
->name
);
10493 if (namelen
< 9 || strcmp(attr
->name
+ namelen
- 8, "-default") ||
10494 namelen
> (sizeof(name
) - 1) || attr
->num_values
!= 1)
10498 * OK, anything else must be a user-defined default...
10501 strlcpy(name
, attr
->name
, sizeof(name
));
10502 name
[namelen
- 8] = '\0'; /* Strip "-default" */
10504 switch (attr
->value_tag
)
10506 case IPP_TAG_DELETEATTR
:
10507 printer
->num_options
= cupsRemoveOption(name
,
10508 printer
->num_options
,
10509 &(printer
->options
));
10510 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10511 "Deleting %s", attr
->name
);
10514 case IPP_TAG_NAME
:
10515 case IPP_TAG_TEXT
:
10516 case IPP_TAG_KEYWORD
:
10518 printer
->num_options
= cupsAddOption(name
,
10519 attr
->values
[0].string
.text
,
10520 printer
->num_options
,
10521 &(printer
->options
));
10522 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10523 "Setting %s to \"%s\"...", attr
->name
,
10524 attr
->values
[0].string
.text
);
10527 case IPP_TAG_BOOLEAN
:
10528 printer
->num_options
= cupsAddOption(name
,
10529 attr
->values
[0].boolean
?
10531 printer
->num_options
,
10532 &(printer
->options
));
10533 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10534 "Setting %s to %s...", attr
->name
,
10535 attr
->values
[0].boolean
? "true" : "false");
10538 case IPP_TAG_INTEGER
:
10539 case IPP_TAG_ENUM
:
10540 sprintf(value
, "%d", attr
->values
[0].integer
);
10541 printer
->num_options
= cupsAddOption(name
, value
,
10542 printer
->num_options
,
10543 &(printer
->options
));
10544 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10545 "Setting %s to %s...", attr
->name
, value
);
10548 case IPP_TAG_RANGE
:
10549 sprintf(value
, "%d-%d", attr
->values
[0].range
.lower
,
10550 attr
->values
[0].range
.upper
);
10551 printer
->num_options
= cupsAddOption(name
, value
,
10552 printer
->num_options
,
10553 &(printer
->options
));
10554 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10555 "Setting %s to %s...", attr
->name
, value
);
10558 case IPP_TAG_RESOLUTION
:
10559 sprintf(value
, "%dx%d%s", attr
->values
[0].resolution
.xres
,
10560 attr
->values
[0].resolution
.yres
,
10561 attr
->values
[0].resolution
.units
== IPP_RES_PER_INCH
?
10563 printer
->num_options
= cupsAddOption(name
, value
,
10564 printer
->num_options
,
10565 &(printer
->options
));
10566 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10567 "Setting %s to %s...", attr
->name
, value
);
10571 /* Do nothing for other values */
10579 * 'start_printer()' - Start a printer.
10583 start_printer(cupsd_client_t
*con
, /* I - Client connection */
10584 ipp_attribute_t
*uri
) /* I - Printer URI */
10586 int i
; /* Temporary variable */
10587 http_status_t status
; /* Policy status */
10588 cups_ptype_t dtype
; /* Destination type (printer/class) */
10589 cupsd_printer_t
*printer
; /* Printer data */
10592 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_printer(%p[%d], %s)", con
,
10593 con
->number
, uri
->values
[0].string
.text
);
10596 * Is the destination valid?
10599 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10605 send_ipp_status(con
, IPP_NOT_FOUND
,
10606 _("The printer or class does not exist."));
10614 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10616 send_http_error(con
, status
, printer
);
10621 * Start the printer...
10624 printer
->state_message
[0] = '\0';
10626 cupsdStartPrinter(printer
, 1);
10628 if (dtype
& CUPS_PRINTER_CLASS
)
10629 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" started by \"%s\".",
10630 printer
->name
, get_username(con
));
10632 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" started by \"%s\".",
10633 printer
->name
, get_username(con
));
10641 if ((i
= check_quotas(con
, printer
)) < 0)
10643 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
10648 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
10653 * Everything was ok, so return OK status...
10656 con
->response
->request
.status
.status_code
= IPP_OK
;
10661 * 'stop_printer()' - Stop a printer.
10665 stop_printer(cupsd_client_t
*con
, /* I - Client connection */
10666 ipp_attribute_t
*uri
) /* I - Printer URI */
10668 http_status_t status
; /* Policy status */
10669 cups_ptype_t dtype
; /* Destination type (printer/class) */
10670 cupsd_printer_t
*printer
; /* Printer data */
10671 ipp_attribute_t
*attr
; /* printer-state-message attribute */
10674 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "stop_printer(%p[%d], %s)", con
,
10675 con
->number
, uri
->values
[0].string
.text
);
10678 * Is the destination valid?
10681 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10687 send_ipp_status(con
, IPP_NOT_FOUND
,
10688 _("The printer or class does not exist."));
10696 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10698 send_http_error(con
, status
, printer
);
10703 * Stop the printer...
10706 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
10707 IPP_TAG_TEXT
)) == NULL
)
10708 strlcpy(printer
->state_message
, "Paused", sizeof(printer
->state_message
));
10711 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
10712 sizeof(printer
->state_message
));
10715 cupsdStopPrinter(printer
, 1);
10717 if (dtype
& CUPS_PRINTER_CLASS
)
10718 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" stopped by \"%s\".",
10719 printer
->name
, get_username(con
));
10721 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" stopped by \"%s\".",
10722 printer
->name
, get_username(con
));
10725 * Everything was ok, so return OK status...
10728 con
->response
->request
.status
.status_code
= IPP_OK
;
10733 * 'url_encode_attr()' - URL-encode a string attribute.
10737 url_encode_attr(ipp_attribute_t
*attr
, /* I - Attribute */
10738 char *buffer
,/* I - String buffer */
10739 size_t bufsize
)/* I - Size of buffer */
10741 int i
; /* Looping var */
10742 char *bufptr
, /* Pointer into buffer */
10743 *bufend
; /* End of buffer */
10746 strlcpy(buffer
, attr
->name
, bufsize
);
10747 bufptr
= buffer
+ strlen(buffer
);
10748 bufend
= buffer
+ bufsize
- 1;
10750 for (i
= 0; i
< attr
->num_values
; i
++)
10752 if (bufptr
>= bufend
)
10760 if (bufptr
>= bufend
)
10765 bufptr
= url_encode_string(attr
->values
[i
].string
.text
, bufptr
, (size_t)(bufend
- bufptr
+ 1));
10767 if (bufptr
>= bufend
)
10778 * 'url_encode_string()' - URL-encode a string.
10781 static char * /* O - End of string */
10782 url_encode_string(const char *s
, /* I - String */
10783 char *buffer
, /* I - String buffer */
10784 size_t bufsize
) /* I - Size of buffer */
10786 char *bufptr
, /* Pointer into buffer */
10787 *bufend
; /* End of buffer */
10788 static const char *hex
= "0123456789ABCDEF";
10793 bufend
= buffer
+ bufsize
- 1;
10795 while (*s
&& bufptr
< bufend
)
10797 if (*s
== ' ' || *s
== '%' || *s
== '+')
10799 if (bufptr
>= (bufend
- 2))
10803 *bufptr
++ = hex
[(*s
>> 4) & 15];
10804 *bufptr
++ = hex
[*s
& 15];
10808 else if (*s
== '\'' || *s
== '\\')
10810 if (bufptr
>= (bufend
- 1))
10827 * 'user_allowed()' - See if a user is allowed to print to a queue.
10830 static int /* O - 0 if not allowed, 1 if allowed */
10831 user_allowed(cupsd_printer_t
*p
, /* I - Printer or class */
10832 const char *username
) /* I - Username */
10834 struct passwd
*pw
; /* User password data */
10835 char baseuser
[256], /* Base username */
10836 *baseptr
, /* Pointer to "@" in base username */
10837 *name
; /* Current user name */
10840 if (cupsArrayCount(p
->users
) == 0)
10843 if (!strcmp(username
, "root"))
10846 if (strchr(username
, '@'))
10849 * Strip @REALM for username check...
10852 strlcpy(baseuser
, username
, sizeof(baseuser
));
10854 if ((baseptr
= strchr(baseuser
, '@')) != NULL
)
10857 username
= baseuser
;
10860 pw
= getpwnam(username
);
10863 for (name
= (char *)cupsArrayFirst(p
->users
);
10865 name
= (char *)cupsArrayNext(p
->users
))
10867 if (name
[0] == '@')
10870 * Check group membership...
10873 if (cupsdCheckGroup(username
, pw
, name
+ 1))
10876 else if (name
[0] == '#')
10882 if (cupsdCheckGroup(username
, pw
, name
))
10885 else if (!_cups_strcasecmp(username
, name
))
10889 return ((name
!= NULL
) != p
->deny_users
);
10894 * 'validate_job()' - Validate printer options and destination.
10898 validate_job(cupsd_client_t
*con
, /* I - Client connection */
10899 ipp_attribute_t
*uri
) /* I - Printer URI */
10901 http_status_t status
; /* Policy status */
10902 ipp_attribute_t
*attr
; /* Current attribute */
10904 ipp_attribute_t
*auth_info
; /* auth-info attribute */
10905 #endif /* HAVE_SSL */
10906 ipp_attribute_t
*format
, /* Document-format attribute */
10907 *name
; /* Job-name attribute */
10908 cups_ptype_t dtype
; /* Destination type (printer/class) */
10909 char super
[MIME_MAX_SUPER
],
10910 /* Supertype of file */
10911 type
[MIME_MAX_TYPE
];
10912 /* Subtype of file */
10913 cupsd_printer_t
*printer
; /* Printer */
10916 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_job(%p[%d], %s)", con
,
10917 con
->number
, uri
->values
[0].string
.text
);
10920 * OK, see if the client is sending the document compressed - CUPS
10921 * doesn't support compression yet...
10924 if ((attr
= ippFindAttribute(con
->request
, "compression",
10925 IPP_TAG_KEYWORD
)) != NULL
)
10927 if (strcmp(attr
->values
[0].string
.text
, "none")
10929 && strcmp(attr
->values
[0].string
.text
, "gzip")
10930 #endif /* HAVE_LIBZ */
10933 send_ipp_status(con
, IPP_ATTRIBUTES
,
10934 _("Unsupported 'compression' value \"%s\"."),
10935 attr
->values
[0].string
.text
);
10936 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
10937 "compression", NULL
, attr
->values
[0].string
.text
);
10943 * Is it a format we support?
10946 if ((format
= ippFindAttribute(con
->request
, "document-format",
10947 IPP_TAG_MIMETYPE
)) != NULL
)
10949 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%255[^;]",
10952 send_ipp_status(con
, IPP_BAD_REQUEST
,
10953 _("Bad 'document-format' value \"%s\"."),
10954 format
->values
[0].string
.text
);
10958 if ((strcmp(super
, "application") || strcmp(type
, "octet-stream")) &&
10959 !mimeType(MimeDatabase
, super
, type
))
10961 cupsdLogMessage(CUPSD_LOG_INFO
,
10962 "Hint: Do you have the raw file printing rules enabled?");
10963 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
10964 _("Unsupported 'document-format' value \"%s\"."),
10965 format
->values
[0].string
.text
);
10966 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
10967 "document-format", NULL
, format
->values
[0].string
.text
);
10973 * Is the job-name valid?
10976 if ((name
= ippFindAttribute(con
->request
, "job-name", IPP_TAG_ZERO
)) != NULL
)
10978 int bad_name
= 0; /* Is the job-name value bad? */
10980 if ((name
->value_tag
!= IPP_TAG_NAME
&& name
->value_tag
!= IPP_TAG_NAMELANG
) ||
10981 name
->num_values
!= 1)
10988 * Validate that job-name conforms to RFC 5198 (Network Unicode) and
10989 * IPP Everywhere requirements for "name" values...
10992 const unsigned char *nameptr
; /* Pointer into "job-name" attribute */
10994 for (nameptr
= (unsigned char *)name
->values
[0].string
.text
;
10998 if (*nameptr
< ' ' && *nameptr
!= '\t')
11000 else if (*nameptr
== 0x7f)
11002 else if ((*nameptr
& 0xe0) == 0xc0)
11004 if ((nameptr
[1] & 0xc0) != 0x80)
11009 else if ((*nameptr
& 0xf0) == 0xe0)
11011 if ((nameptr
[1] & 0xc0) != 0x80 ||
11012 (nameptr
[2] & 0xc0) != 0x80)
11017 else if ((*nameptr
& 0xf8) == 0xf0)
11019 if ((nameptr
[1] & 0xc0) != 0x80 ||
11020 (nameptr
[2] & 0xc0) != 0x80 ||
11021 (nameptr
[3] & 0xc0) != 0x80)
11026 else if (*nameptr
& 0x80)
11036 if (StrictConformance
)
11038 send_ipp_status(con
, IPP_ATTRIBUTES
,
11039 _("Unsupported 'job-name' value."));
11040 ippCopyAttribute(con
->response
, name
, 0);
11045 cupsdLogMessage(CUPSD_LOG_WARN
,
11046 "Unsupported 'job-name' value, deleting from request.");
11047 ippDeleteAttribute(con
->request
, name
);
11053 * Is the destination valid?
11056 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11062 send_ipp_status(con
, IPP_NOT_FOUND
,
11063 _("The printer or class does not exist."));
11072 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
11073 #endif /* HAVE_SSL */
11075 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11077 send_http_error(con
, status
, printer
);
11080 else if (printer
->num_auth_info_required
== 1 &&
11081 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
11084 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
11088 else if (auth_info
&& !con
->http
->tls
&&
11089 !httpAddrLocalhost(con
->http
->hostaddr
))
11092 * Require encryption of auth-info over non-local connections...
11095 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
11098 #endif /* HAVE_SSL */
11101 * Everything was ok, so return OK status...
11104 con
->response
->request
.status
.status_code
= IPP_OK
;
11109 * 'validate_name()' - Make sure the printer name only contains valid chars.
11112 static int /* O - 0 if name is no good, 1 if good */
11113 validate_name(const char *name
) /* I - Name to check */
11115 const char *ptr
; /* Pointer into name */
11119 * Scan the whole name...
11122 for (ptr
= name
; *ptr
; ptr
++)
11123 if ((*ptr
> 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
11127 * All the characters are good; validate the length, too...
11130 return ((ptr
- name
) < 128);
11135 * 'validate_user()' - Validate the user for the request.
11138 static int /* O - 1 if permitted, 0 otherwise */
11139 validate_user(cupsd_job_t
*job
, /* I - Job */
11140 cupsd_client_t
*con
, /* I - Client connection */
11141 const char *owner
, /* I - Owner of job/resource */
11142 char *username
, /* O - Authenticated username */
11143 size_t userlen
) /* I - Length of username */
11145 cupsd_printer_t
*printer
; /* Printer for job */
11148 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
);
11151 * Validate input...
11154 if (!con
|| !owner
|| !username
|| userlen
<= 0)
11158 * Get the best authenticated username that is available.
11161 strlcpy(username
, get_username(con
), userlen
);
11164 * Check the username against the owner...
11167 printer
= cupsdFindDest(job
->dest
);
11169 return (cupsdCheckPolicy(printer
? printer
->op_policy_ptr
: DefaultPolicyPtr
,
11170 con
, owner
) == HTTP_OK
);