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",
950 IPP_TAG_TEXT
)) != NULL
)
951 cupsdSetString(&pclass
->location
, attr
->values
[0].string
.text
);
953 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
954 IPP_TAG_TEXT
)) != NULL
)
955 cupsdSetString(&pclass
->info
, attr
->values
[0].string
.text
);
957 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
958 IPP_TAG_BOOLEAN
)) != NULL
&&
959 attr
->values
[0].boolean
!= pclass
->accepting
)
961 cupsdLogMessage(CUPSD_LOG_INFO
,
962 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
963 pclass
->name
, attr
->values
[0].boolean
, pclass
->accepting
);
965 pclass
->accepting
= attr
->values
[0].boolean
;
967 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s accepting jobs.",
968 pclass
->accepting
? "Now" : "No longer");
971 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
972 IPP_TAG_BOOLEAN
)) != NULL
)
974 if (pclass
->shared
&& !attr
->values
[0].boolean
)
975 cupsdDeregisterPrinter(pclass
, 1);
977 cupsdLogMessage(CUPSD_LOG_INFO
,
978 "Setting %s printer-is-shared to %d (was %d.)",
979 pclass
->name
, attr
->values
[0].boolean
, pclass
->shared
);
981 pclass
->shared
= attr
->values
[0].boolean
;
984 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
985 IPP_TAG_ENUM
)) != NULL
)
987 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
988 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
990 send_ipp_status(con
, IPP_BAD_REQUEST
,
991 _("Attempt to set %s printer-state to bad value %d."),
992 pclass
->name
, attr
->values
[0].integer
);
996 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
997 pclass
->name
, attr
->values
[0].integer
, pclass
->state
);
999 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
1000 cupsdStopPrinter(pclass
, 0);
1003 cupsdSetPrinterState(pclass
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
1004 need_restart_job
= 1;
1007 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
1008 IPP_TAG_TEXT
)) != NULL
)
1010 strlcpy(pclass
->state_message
, attr
->values
[0].string
.text
,
1011 sizeof(pclass
->state_message
));
1013 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s",
1014 pclass
->state_message
);
1016 if ((attr
= ippFindAttribute(con
->request
, "member-uris",
1017 IPP_TAG_URI
)) != NULL
)
1020 * Clear the printer array as needed...
1023 need_restart_job
= 1;
1025 if (pclass
->num_printers
> 0)
1027 free(pclass
->printers
);
1028 pclass
->num_printers
= 0;
1032 * Add each printer or class that is listed...
1035 for (i
= 0; i
< attr
->num_values
; i
++)
1038 * Search for the printer or class URI...
1041 if (!cupsdValidateDest(attr
->values
[i
].string
.text
, &dtype
, &member
))
1047 send_ipp_status(con
, IPP_NOT_FOUND
,
1048 _("The printer or class does not exist."));
1051 else if (dtype
& CUPS_PRINTER_CLASS
)
1053 send_ipp_status(con
, IPP_BAD_REQUEST
,
1054 _("Nested classes are not allowed."));
1059 * Add it to the class...
1062 cupsdAddPrinterToClass(pclass
, member
);
1066 set_printer_defaults(con
, pclass
);
1068 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
1069 IPP_TAG_KEYWORD
)) != NULL
)
1070 cupsdSetAuthInfoRequired(pclass
, NULL
, attr
);
1073 * Update the printer class attributes and return...
1076 cupsdSetPrinterAttrs(pclass
);
1077 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
1079 if (need_restart_job
&& pclass
->job
)
1082 * Reset the current job to a "pending" status...
1085 cupsdSetJobState(pclass
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
1086 "Job restarted because the class was modified.");
1089 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1093 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
1094 pclass
, NULL
, "Class \"%s\" modified by \"%s\".",
1095 pclass
->name
, get_username(con
));
1097 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" modified by \"%s\".",
1098 pclass
->name
, get_username(con
));
1102 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
1103 pclass
, NULL
, "New class \"%s\" added by \"%s\".",
1104 pclass
->name
, get_username(con
));
1106 cupsdLogMessage(CUPSD_LOG_INFO
, "New class \"%s\" added by \"%s\".",
1107 pclass
->name
, get_username(con
));
1110 con
->response
->request
.status
.status_code
= IPP_OK
;
1115 * 'add_file()' - Add a file to a job.
1118 static int /* O - 0 on success, -1 on error */
1119 add_file(cupsd_client_t
*con
, /* I - Connection to client */
1120 cupsd_job_t
*job
, /* I - Job to add to */
1121 mime_type_t
*filetype
, /* I - Type of file */
1122 int compression
) /* I - Compression */
1124 mime_type_t
**filetypes
; /* New filetypes array... */
1125 int *compressions
; /* New compressions array... */
1128 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1129 "add_file(con=%p[%d], job=%d, filetype=%s/%s, "
1130 "compression=%d)", con
, con
? con
->number
: -1, job
->id
,
1131 filetype
->super
, filetype
->type
, compression
);
1134 * Add the file to the job...
1137 if (job
->num_files
== 0)
1139 compressions
= (int *)malloc(sizeof(int));
1140 filetypes
= (mime_type_t
**)malloc(sizeof(mime_type_t
*));
1144 compressions
= (int *)realloc(job
->compressions
,
1145 (size_t)(job
->num_files
+ 1) * sizeof(int));
1146 filetypes
= (mime_type_t
**)realloc(job
->filetypes
,
1147 (size_t)(job
->num_files
+ 1) *
1148 sizeof(mime_type_t
*));
1152 job
->compressions
= compressions
;
1155 job
->filetypes
= filetypes
;
1157 if (!compressions
|| !filetypes
)
1159 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1160 "Job aborted because the scheduler ran out of memory.");
1163 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1164 _("Unable to allocate memory for file types."));
1169 job
->compressions
[job
->num_files
] = compression
;
1170 job
->filetypes
[job
->num_files
] = filetype
;
1175 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1182 * 'add_job()' - Add a job to a print queue.
1185 static cupsd_job_t
* /* O - Job object */
1186 add_job(cupsd_client_t
*con
, /* I - Client connection */
1187 cupsd_printer_t
*printer
, /* I - Destination printer */
1188 mime_type_t
*filetype
) /* I - First print file type, if any */
1190 http_status_t status
; /* Policy status */
1191 ipp_attribute_t
*attr
, /* Current attribute */
1192 *auth_info
; /* auth-info attribute */
1193 const char *mandatory
; /* Current mandatory job attribute */
1194 const char *val
; /* Default option value */
1195 int priority
; /* Job priority */
1196 cupsd_job_t
*job
; /* Current job */
1197 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
1198 int kbytes
; /* Size of print file */
1199 int i
; /* Looping var */
1200 int lowerpagerange
; /* Page range bound */
1201 int exact
; /* Did we have an exact match? */
1202 ipp_attribute_t
*media_col
, /* media-col attribute */
1203 *media_margin
; /* media-*-margin attribute */
1204 ipp_t
*unsup_col
; /* media-col in unsupported response */
1205 static const char * const readonly
[] =/* List of read-only attributes */
1208 "job-k-octets-completed",
1209 "job-impressions-completed",
1210 "job-media-sheets-completed",
1212 "job-state-message",
1213 "job-state-reasons",
1214 "time-at-completed",
1216 "time-at-processing"
1220 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job(%p[%d], %p(%s), %p(%s/%s))",
1221 con
, con
->number
, printer
, printer
->name
,
1222 filetype
, filetype
? filetype
->super
: "none",
1223 filetype
? filetype
->type
: "none");
1226 * Check remote printing to non-shared printer...
1229 if (!printer
->shared
&&
1230 _cups_strcasecmp(con
->http
->hostname
, "localhost") &&
1231 _cups_strcasecmp(con
->http
->hostname
, ServerName
))
1233 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
1234 _("The printer or class is not shared."));
1242 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
1244 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
1246 send_http_error(con
, status
, printer
);
1249 else if (printer
->num_auth_info_required
== 1 &&
1250 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
1253 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
1257 else if (auth_info
&& !con
->http
->tls
&&
1258 !httpAddrLocalhost(con
->http
->hostaddr
))
1261 * Require encryption of auth-info over non-local connections...
1264 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
1267 #endif /* HAVE_SSL */
1270 * See if the printer is accepting jobs...
1273 if (!printer
->accepting
)
1275 send_ipp_status(con
, IPP_NOT_ACCEPTING
,
1276 _("Destination \"%s\" is not accepting jobs."),
1282 * Validate job template attributes; for now just document-format,
1283 * copies, job-sheets, number-up, page-ranges, mandatory attributes, and
1287 for (i
= 0; i
< (int)(sizeof(readonly
) / sizeof(readonly
[0])); i
++)
1289 if ((attr
= ippFindAttribute(con
->request
, readonly
[i
],
1290 IPP_TAG_ZERO
)) != NULL
)
1292 ippDeleteAttribute(con
->request
, attr
);
1294 if (StrictConformance
)
1296 send_ipp_status(con
, IPP_BAD_REQUEST
,
1297 _("The '%s' Job Description attribute cannot be "
1298 "supplied in a job creation request."), readonly
[i
]);
1302 cupsdLogMessage(CUPSD_LOG_INFO
,
1303 "Unexpected '%s' Job Description attribute in a job "
1304 "creation request.", readonly
[i
]);
1310 for (mandatory
= (char *)cupsArrayFirst(printer
->pc
->mandatory
);
1312 mandatory
= (char *)cupsArrayNext(printer
->pc
->mandatory
))
1314 if (!ippFindAttribute(con
->request
, mandatory
, IPP_TAG_ZERO
))
1317 * Missing a required attribute...
1320 send_ipp_status(con
, IPP_CONFLICT
,
1321 _("The \"%s\" attribute is required for print jobs."),
1328 if (filetype
&& printer
->filetypes
&&
1329 !cupsArrayFind(printer
->filetypes
, filetype
))
1331 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
1332 /* MIME media type string */
1335 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
1338 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
1339 _("Unsupported format \"%s\"."), mimetype
);
1341 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
1342 "document-format", NULL
, mimetype
);
1347 if ((attr
= ippFindAttribute(con
->request
, "copies",
1348 IPP_TAG_INTEGER
)) != NULL
)
1350 if (attr
->values
[0].integer
< 1 || attr
->values
[0].integer
> MaxCopies
)
1352 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad copies value %d."),
1353 attr
->values
[0].integer
);
1354 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1355 "copies", attr
->values
[0].integer
);
1360 if ((attr
= ippFindAttribute(con
->request
, "job-sheets",
1361 IPP_TAG_ZERO
)) != NULL
)
1363 if (attr
->value_tag
!= IPP_TAG_KEYWORD
&&
1364 attr
->value_tag
!= IPP_TAG_NAME
)
1366 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value type."));
1370 if (attr
->num_values
> 2)
1372 send_ipp_status(con
, IPP_BAD_REQUEST
,
1373 _("Too many job-sheets values (%d > 2)."),
1378 for (i
= 0; i
< attr
->num_values
; i
++)
1379 if (strcmp(attr
->values
[i
].string
.text
, "none") &&
1380 !cupsdFindBanner(attr
->values
[i
].string
.text
))
1382 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value \"%s\"."),
1383 attr
->values
[i
].string
.text
);
1388 if ((attr
= ippFindAttribute(con
->request
, "number-up",
1389 IPP_TAG_INTEGER
)) != NULL
)
1391 if (attr
->values
[0].integer
!= 1 &&
1392 attr
->values
[0].integer
!= 2 &&
1393 attr
->values
[0].integer
!= 4 &&
1394 attr
->values
[0].integer
!= 6 &&
1395 attr
->values
[0].integer
!= 9 &&
1396 attr
->values
[0].integer
!= 16)
1398 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad number-up value %d."),
1399 attr
->values
[0].integer
);
1400 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1401 "number-up", attr
->values
[0].integer
);
1406 if ((attr
= ippFindAttribute(con
->request
, "page-ranges",
1407 IPP_TAG_RANGE
)) != NULL
)
1409 for (i
= 0, lowerpagerange
= 1; i
< attr
->num_values
; i
++)
1411 if (attr
->values
[i
].range
.lower
< lowerpagerange
||
1412 attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
1414 send_ipp_status(con
, IPP_BAD_REQUEST
,
1415 _("Bad page-ranges values %d-%d."),
1416 attr
->values
[i
].range
.lower
,
1417 attr
->values
[i
].range
.upper
);
1421 lowerpagerange
= attr
->values
[i
].range
.upper
+ 1;
1426 * Do media selection as needed...
1429 if (!ippFindAttribute(con
->request
, "PageRegion", IPP_TAG_ZERO
) &&
1430 !ippFindAttribute(con
->request
, "PageSize", IPP_TAG_ZERO
) &&
1431 _ppdCacheGetPageSize(printer
->pc
, con
->request
, NULL
, &exact
))
1434 (media_col
= ippFindAttribute(con
->request
, "media-col",
1435 IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
1437 send_ipp_status(con
, IPP_OK_SUBST
, _("Unsupported margins."));
1439 unsup_col
= ippNew();
1440 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1441 "media-bottom-margin",
1442 IPP_TAG_INTEGER
)) != NULL
)
1443 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1444 "media-bottom-margin", media_margin
->values
[0].integer
);
1446 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1447 "media-left-margin",
1448 IPP_TAG_INTEGER
)) != NULL
)
1449 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1450 "media-left-margin", media_margin
->values
[0].integer
);
1452 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1453 "media-right-margin",
1454 IPP_TAG_INTEGER
)) != NULL
)
1455 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1456 "media-right-margin", media_margin
->values
[0].integer
);
1458 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1460 IPP_TAG_INTEGER
)) != NULL
)
1461 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1462 "media-top-margin", media_margin
->values
[0].integer
);
1464 ippAddCollection(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, "media-col",
1466 ippDelete(unsup_col
);
1471 * Make sure we aren't over our limit...
1474 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1477 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1479 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Too many active jobs."));
1483 if ((i
= check_quotas(con
, printer
)) < 0)
1485 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
1490 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
1495 * Create the job and set things up...
1498 if ((attr
= ippFindAttribute(con
->request
, "job-priority",
1499 IPP_TAG_INTEGER
)) != NULL
)
1500 priority
= attr
->values
[0].integer
;
1503 if ((val
= cupsGetOption("job-priority", printer
->num_options
,
1504 printer
->options
)) != NULL
)
1505 priority
= atoi(val
);
1509 ippAddInteger(con
->request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-priority",
1513 if ((attr
= ippFindAttribute(con
->request
, "job-name", IPP_TAG_ZERO
)) == NULL
)
1514 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
,
1516 else if ((attr
->value_tag
!= IPP_TAG_NAME
&&
1517 attr
->value_tag
!= IPP_TAG_NAMELANG
) ||
1518 attr
->num_values
!= 1)
1520 send_ipp_status(con
, IPP_ATTRIBUTES
,
1521 _("Bad job-name value: Wrong type or count."));
1522 if ((attr
= ippCopyAttribute(con
->response
, attr
, 0)) != NULL
)
1523 attr
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
1526 else if (!ippValidateAttribute(attr
))
1528 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad job-name value: %s"),
1529 cupsLastErrorString());
1530 if ((attr
= ippCopyAttribute(con
->response
, attr
, 0)) != NULL
)
1531 attr
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
1535 if ((job
= cupsdAddJob(priority
, printer
->name
)) == NULL
)
1537 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1538 _("Unable to add job for destination \"%s\"."),
1543 job
->dtype
= printer
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
1544 job
->attrs
= con
->request
;
1546 con
->request
= ippNewRequest(job
->attrs
->request
.op
.operation_id
);
1548 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1551 apply_printer_defaults(printer
, job
);
1553 attr
= ippFindAttribute(job
->attrs
, "requesting-user-name", IPP_TAG_NAME
);
1555 if (con
->username
[0])
1557 cupsdSetString(&job
->username
, con
->username
);
1560 cupsdSetString(&attr
->values
[0].string
.text
, con
->username
);
1564 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1565 "add_job: requesting-user-name=\"%s\"",
1566 attr
->values
[0].string
.text
);
1568 cupsdSetString(&job
->username
, attr
->values
[0].string
.text
);
1571 cupsdSetString(&job
->username
, "anonymous");
1574 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1575 "job-originating-user-name", NULL
, job
->username
);
1578 attr
->group_tag
= IPP_TAG_JOB
;
1579 _cupsStrFree(attr
->name
);
1580 attr
->name
= _cupsStrAlloc("job-originating-user-name");
1583 if (con
->username
[0] || auth_info
)
1585 save_auth_info(con
, job
, auth_info
);
1588 * Remove the auth-info attribute from the attribute data...
1592 ippDeleteAttribute(job
->attrs
, auth_info
);
1595 if ((attr
= ippFindAttribute(job
->attrs
, "job-originating-host-name",
1596 IPP_TAG_ZERO
)) != NULL
)
1599 * Request contains a job-originating-host-name attribute; validate it...
1602 if (attr
->value_tag
!= IPP_TAG_NAME
||
1603 attr
->num_values
!= 1 ||
1604 strcmp(con
->http
->hostname
, "localhost"))
1607 * Can't override the value if we aren't connected via localhost.
1608 * Also, we can only have 1 value and it must be a name value.
1611 switch (attr
->value_tag
)
1613 case IPP_TAG_STRING
:
1614 case IPP_TAG_TEXTLANG
:
1615 case IPP_TAG_NAMELANG
:
1618 case IPP_TAG_KEYWORD
:
1620 case IPP_TAG_URISCHEME
:
1621 case IPP_TAG_CHARSET
:
1622 case IPP_TAG_LANGUAGE
:
1623 case IPP_TAG_MIMETYPE
:
1625 * Free old strings...
1628 for (i
= 0; i
< attr
->num_values
; i
++)
1630 _cupsStrFree(attr
->values
[i
].string
.text
);
1631 attr
->values
[i
].string
.text
= NULL
;
1632 if (attr
->values
[i
].string
.language
)
1634 _cupsStrFree(attr
->values
[i
].string
.language
);
1635 attr
->values
[i
].string
.language
= NULL
;
1644 * Use the default connection hostname instead...
1647 attr
->value_tag
= IPP_TAG_NAME
;
1648 attr
->num_values
= 1;
1649 attr
->values
[0].string
.text
= _cupsStrAlloc(con
->http
->hostname
);
1652 attr
->group_tag
= IPP_TAG_JOB
;
1657 * No job-originating-host-name attribute, so use the hostname from
1661 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1662 "job-originating-host-name", NULL
, con
->http
->hostname
);
1665 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation",
1667 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1668 "time-at-processing", 0);
1669 attr
->value_tag
= IPP_TAG_NOVALUE
;
1670 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1671 "time-at-completed", 0);
1672 attr
->value_tag
= IPP_TAG_NOVALUE
;
1675 * Add remaining job attributes...
1678 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1679 job
->state
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_ENUM
,
1680 "job-state", IPP_JOB_STOPPED
);
1681 job
->state_value
= (ipp_jstate_t
)job
->state
->values
[0].integer
;
1682 job
->reasons
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1683 "job-state-reasons", NULL
, "job-incoming");
1684 job
->sheets
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1685 "job-media-sheets-completed", 0);
1686 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-printer-uri", NULL
,
1689 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
1690 IPP_TAG_INTEGER
)) != NULL
)
1691 attr
->values
[0].integer
= 0;
1693 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-k-octets", 0);
1695 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
1696 IPP_TAG_KEYWORD
)) == NULL
)
1697 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
1700 if ((val
= cupsGetOption("job-hold-until", printer
->num_options
,
1701 printer
->options
)) == NULL
)
1704 attr
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1705 "job-hold-until", NULL
, val
);
1707 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
1710 * Hold job until specified time...
1713 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
1715 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1716 job
->state_value
= IPP_JOB_HELD
;
1718 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-hold-until-specified");
1720 else if (job
->attrs
->request
.op
.operation_id
== IPP_CREATE_JOB
)
1722 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
1723 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1724 job
->state_value
= IPP_JOB_HELD
;
1728 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1729 job
->state_value
= IPP_JOB_PENDING
;
1731 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
1734 if (!(printer
->type
& CUPS_PRINTER_REMOTE
) || Classification
)
1737 * Add job sheets options...
1740 if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1741 IPP_TAG_ZERO
)) == NULL
)
1743 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1744 "Adding default job-sheets values \"%s,%s\"...",
1745 printer
->job_sheets
[0], printer
->job_sheets
[1]);
1747 attr
= ippAddStrings(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-sheets",
1749 attr
->values
[0].string
.text
= _cupsStrRetain(printer
->job_sheets
[0]);
1750 attr
->values
[1].string
.text
= _cupsStrRetain(printer
->job_sheets
[1]);
1753 job
->job_sheets
= attr
;
1756 * Enforce classification level if set...
1761 cupsdLogMessage(CUPSD_LOG_INFO
,
1762 "Classification=\"%s\", ClassifyOverride=%d",
1763 Classification
? Classification
: "(null)",
1766 if (ClassifyOverride
)
1768 if (!strcmp(attr
->values
[0].string
.text
, "none") &&
1769 (attr
->num_values
== 1 ||
1770 !strcmp(attr
->values
[1].string
.text
, "none")))
1773 * Force the leading banner to have the classification on it...
1776 cupsdSetString(&attr
->values
[0].string
.text
, Classification
);
1778 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1779 "job-sheets=\"%s,none\", "
1780 "job-originating-user-name=\"%s\"",
1781 Classification
, job
->username
);
1783 else if (attr
->num_values
== 2 &&
1784 strcmp(attr
->values
[0].string
.text
,
1785 attr
->values
[1].string
.text
) &&
1786 strcmp(attr
->values
[0].string
.text
, "none") &&
1787 strcmp(attr
->values
[1].string
.text
, "none"))
1790 * Can't put two different security markings on the same document!
1793 cupsdSetString(&attr
->values
[1].string
.text
, attr
->values
[0].string
.text
);
1795 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1796 "job-sheets=\"%s,%s\", "
1797 "job-originating-user-name=\"%s\"",
1798 attr
->values
[0].string
.text
,
1799 attr
->values
[1].string
.text
, job
->username
);
1801 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1802 strcmp(attr
->values
[0].string
.text
, "none") &&
1803 (attr
->num_values
== 1 ||
1804 (strcmp(attr
->values
[1].string
.text
, Classification
) &&
1805 strcmp(attr
->values
[1].string
.text
, "none"))))
1807 if (attr
->num_values
== 1)
1808 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1809 "CLASSIFICATION OVERRIDDEN "
1810 "job-sheets=\"%s\", "
1811 "job-originating-user-name=\"%s\"",
1812 attr
->values
[0].string
.text
, job
->username
);
1814 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1815 "CLASSIFICATION OVERRIDDEN "
1816 "job-sheets=\"%s,%s\",fffff "
1817 "job-originating-user-name=\"%s\"",
1818 attr
->values
[0].string
.text
,
1819 attr
->values
[1].string
.text
, job
->username
);
1822 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1823 (attr
->num_values
== 1 ||
1824 strcmp(attr
->values
[1].string
.text
, Classification
)))
1827 * Force the banner to have the classification on it...
1830 if (attr
->num_values
> 1 &&
1831 !strcmp(attr
->values
[0].string
.text
, attr
->values
[1].string
.text
))
1833 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1834 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1838 if (attr
->num_values
== 1 ||
1839 strcmp(attr
->values
[0].string
.text
, "none"))
1840 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1842 if (attr
->num_values
> 1 &&
1843 strcmp(attr
->values
[1].string
.text
, "none"))
1844 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1847 if (attr
->num_values
> 1)
1848 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1849 "CLASSIFICATION FORCED "
1850 "job-sheets=\"%s,%s\", "
1851 "job-originating-user-name=\"%s\"",
1852 attr
->values
[0].string
.text
,
1853 attr
->values
[1].string
.text
, job
->username
);
1855 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1856 "CLASSIFICATION FORCED "
1857 "job-sheets=\"%s\", "
1858 "job-originating-user-name=\"%s\"",
1859 Classification
, job
->username
);
1864 * See if we need to add the starting sheet...
1867 if (!(printer
->type
& CUPS_PRINTER_REMOTE
))
1869 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding start banner page \"%s\".",
1870 attr
->values
[0].string
.text
);
1872 if ((kbytes
= copy_banner(con
, job
, attr
->values
[0].string
.text
)) < 0)
1874 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1875 "Aborting job because the start banner could not be "
1880 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
1883 else if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1884 IPP_TAG_ZERO
)) != NULL
)
1885 job
->job_sheets
= attr
;
1888 * Fill in the response info...
1891 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
1892 con
->clientname
, con
->clientport
, "/jobs/%d", job
->id
);
1893 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
1896 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1898 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
1900 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons",
1901 NULL
, job
->reasons
->values
[0].string
.text
);
1903 con
->response
->request
.status
.status_code
= IPP_OK
;
1906 * Add any job subscriptions...
1909 add_job_subscriptions(con
, job
);
1912 * Set all but the first two attributes to the job attributes group...
1915 for (attr
= job
->attrs
->attrs
->next
->next
; attr
; attr
= attr
->next
)
1916 attr
->group_tag
= IPP_TAG_JOB
;
1919 * Fire the "job created" event...
1922 cupsdAddEvent(CUPSD_EVENT_JOB_CREATED
, printer
, job
, "Job created.");
1925 * Return the new job...
1933 * 'add_job_subscriptions()' - Add any subscriptions for a job.
1937 add_job_subscriptions(
1938 cupsd_client_t
*con
, /* I - Client connection */
1939 cupsd_job_t
*job
) /* I - Newly created job */
1941 int i
; /* Looping var */
1942 ipp_attribute_t
*prev
, /* Previous attribute */
1943 *next
, /* Next attribute */
1944 *attr
; /* Current attribute */
1945 cupsd_subscription_t
*sub
; /* Subscription object */
1946 const char *recipient
, /* notify-recipient-uri */
1947 *pullmethod
; /* notify-pull-method */
1948 ipp_attribute_t
*user_data
; /* notify-user-data */
1949 int interval
; /* notify-time-interval */
1950 unsigned mask
; /* notify-events */
1954 * Find the first subscription group attribute; return if we have
1958 for (attr
= job
->attrs
->attrs
; attr
; attr
= attr
->next
)
1959 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
1966 * Process the subscription attributes in the request...
1975 mask
= CUPSD_EVENT_NONE
;
1977 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
1979 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
1980 attr
->value_tag
== IPP_TAG_URI
)
1983 * Validate the recipient scheme against the ServerBin/notifier
1987 char notifier
[1024], /* Notifier filename */
1988 scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
1989 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
1990 host
[HTTP_MAX_URI
], /* Host portion of URI */
1991 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
1992 int port
; /* Port portion of URI */
1995 recipient
= attr
->values
[0].string
.text
;
1997 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
1998 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
1999 host
, sizeof(host
), &port
,
2000 resource
, sizeof(resource
)) < HTTP_URI_OK
)
2002 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2003 _("Bad notify-recipient-uri \"%s\"."), recipient
);
2004 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2005 "notify-status-code", IPP_URI_SCHEME
);
2009 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
2011 if (access(notifier
, X_OK
))
2013 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2014 _("notify-recipient-uri URI \"%s\" uses unknown "
2015 "scheme."), recipient
);
2016 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2017 "notify-status-code", IPP_URI_SCHEME
);
2021 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
2023 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2024 _("notify-recipient-uri URI \"%s\" is already used."),
2026 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2027 "notify-status-code", IPP_ATTRIBUTES
);
2031 else if (!strcmp(attr
->name
, "notify-pull-method") &&
2032 attr
->value_tag
== IPP_TAG_KEYWORD
)
2034 pullmethod
= attr
->values
[0].string
.text
;
2036 if (strcmp(pullmethod
, "ippget"))
2038 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2039 _("Bad notify-pull-method \"%s\"."), pullmethod
);
2040 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2041 "notify-status-code", IPP_ATTRIBUTES
);
2045 else if (!strcmp(attr
->name
, "notify-charset") &&
2046 attr
->value_tag
== IPP_TAG_CHARSET
&&
2047 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
2048 strcmp(attr
->values
[0].string
.text
, "utf-8"))
2050 send_ipp_status(con
, IPP_CHARSET
,
2051 _("Character set \"%s\" not supported."),
2052 attr
->values
[0].string
.text
);
2055 else if (!strcmp(attr
->name
, "notify-natural-language") &&
2056 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
2057 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
2059 send_ipp_status(con
, IPP_CHARSET
,
2060 _("Language \"%s\" not supported."),
2061 attr
->values
[0].string
.text
);
2064 else if (!strcmp(attr
->name
, "notify-user-data") &&
2065 attr
->value_tag
== IPP_TAG_STRING
)
2067 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
2069 send_ipp_status(con
, IPP_REQUEST_VALUE
,
2070 _("The notify-user-data value is too large "
2071 "(%d > 63 octets)."),
2072 attr
->values
[0].unknown
.length
);
2078 else if (!strcmp(attr
->name
, "notify-events") &&
2079 attr
->value_tag
== IPP_TAG_KEYWORD
)
2081 for (i
= 0; i
< attr
->num_values
; i
++)
2082 mask
|= cupsdEventValue(attr
->values
[i
].string
.text
);
2084 else if (!strcmp(attr
->name
, "notify-lease-duration"))
2086 send_ipp_status(con
, IPP_BAD_REQUEST
,
2087 _("The notify-lease-duration attribute cannot be "
2088 "used with job subscriptions."));
2091 else if (!strcmp(attr
->name
, "notify-time-interval") &&
2092 attr
->value_tag
== IPP_TAG_INTEGER
)
2093 interval
= attr
->values
[0].integer
;
2098 if (!recipient
&& !pullmethod
)
2101 if (mask
== CUPSD_EVENT_NONE
)
2102 mask
= CUPSD_EVENT_JOB_COMPLETED
;
2104 if ((sub
= cupsdAddSubscription(mask
, cupsdFindDest(job
->dest
), job
,
2105 recipient
, 0)) != NULL
)
2107 sub
->interval
= interval
;
2109 cupsdSetString(&sub
->owner
, job
->username
);
2113 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
2114 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
2115 (size_t)sub
->user_data_len
);
2118 ippAddSeparator(con
->response
);
2119 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
2120 "notify-subscription-id", sub
->id
);
2122 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
2130 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
2133 * Remove all of the subscription attributes from the job request...
2135 * TODO: Optimize this since subscription groups have to come at the
2136 * end of the request...
2139 for (attr
= job
->attrs
->attrs
, prev
= NULL
; attr
; attr
= next
)
2143 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
||
2144 attr
->group_tag
== IPP_TAG_ZERO
)
2147 * Free and remove this attribute...
2150 ippDeleteAttribute(NULL
, attr
);
2155 job
->attrs
->attrs
= next
;
2161 job
->attrs
->last
= prev
;
2162 job
->attrs
->current
= prev
;
2167 * 'add_job_uuid()' - Add job-uuid attribute to a job.
2169 * See RFC 4122 for the definition of UUIDs and the format.
2173 add_job_uuid(cupsd_job_t
*job
) /* I - Job */
2175 char uuid
[64]; /* job-uuid string */
2179 * Add a job-uuid attribute if none exists...
2182 if (!ippFindAttribute(job
->attrs
, "job-uuid", IPP_TAG_URI
))
2183 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uuid", NULL
,
2184 httpAssembleUUID(ServerName
, RemotePort
, job
->dest
, job
->id
,
2185 uuid
, sizeof(uuid
)));
2190 * 'add_printer()' - Add a printer to the system.
2194 add_printer(cupsd_client_t
*con
, /* I - Client connection */
2195 ipp_attribute_t
*uri
) /* I - URI of printer */
2197 http_status_t status
; /* Policy status */
2198 int i
; /* Looping var */
2199 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
2200 username
[HTTP_MAX_URI
], /* Username portion of URI */
2201 host
[HTTP_MAX_URI
], /* Host portion of URI */
2202 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2203 int port
; /* Port portion of URI */
2204 cupsd_printer_t
*printer
; /* Printer/class */
2205 ipp_attribute_t
*attr
; /* Printer attribute */
2206 cups_file_t
*fp
; /* Script/PPD file */
2207 char line
[1024]; /* Line from file... */
2208 char srcfile
[1024], /* Source Script/PPD file */
2209 dstfile
[1024]; /* Destination Script/PPD file */
2210 int modify
; /* Non-zero if we are modifying */
2211 int changed_driver
, /* Changed the PPD/interface script? */
2212 need_restart_job
, /* Need to restart job? */
2213 set_device_uri
, /* Did we set the device URI? */
2214 set_port_monitor
; /* Did we set the port monitor? */
2217 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer(%p[%d], %s)", con
,
2218 con
->number
, uri
->values
[0].string
.text
);
2221 * Do we have a valid URI?
2224 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
2225 sizeof(scheme
), username
, sizeof(username
), host
,
2226 sizeof(host
), &port
, resource
, sizeof(resource
));
2228 if (strncmp(resource
, "/printers/", 10) || strlen(resource
) == 10)
2231 * No, return an error...
2234 send_ipp_status(con
, IPP_BAD_REQUEST
,
2235 _("The printer-uri must be of the form "
2236 "\"ipp://HOSTNAME/printers/PRINTERNAME\"."));
2241 * Do we have a valid printer name?
2244 if (!validate_name(resource
+ 10))
2247 * No, return an error...
2250 send_ipp_status(con
, IPP_BAD_REQUEST
,
2251 _("The printer-uri \"%s\" contains invalid characters."),
2252 uri
->values
[0].string
.text
);
2257 * See if the printer already exists; if not, create a new printer...
2260 if ((printer
= cupsdFindPrinter(resource
+ 10)) == NULL
)
2263 * Printer doesn't exist; see if we have a class of the same name...
2266 if ((printer
= cupsdFindClass(resource
+ 10)) != NULL
)
2269 * Yes, return an error...
2272 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2273 _("A class named \"%s\" already exists."),
2279 * No, check the default policy then add the printer...
2282 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2284 send_http_error(con
, status
, NULL
);
2288 printer
= cupsdAddPrinter(resource
+ 10);
2291 else if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
2294 send_http_error(con
, status
, printer
);
2301 * Look for attributes and copy them over as needed...
2305 need_restart_job
= 0;
2307 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
2308 IPP_TAG_TEXT
)) != NULL
)
2309 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
2311 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
2312 IPP_TAG_TEXT
)) != NULL
)
2313 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
2317 if ((attr
= ippFindAttribute(con
->request
, "device-uri",
2318 IPP_TAG_URI
)) != NULL
)
2321 * Do we have a valid device URI?
2324 http_uri_status_t uri_status
; /* URI separation status */
2325 char old_device_uri
[1024];
2326 /* Old device URI */
2327 static const char * const uri_status_strings
[] =
2330 "Bad arguments to function.",
2331 "Bad resource path.",
2333 "Bad hostname/address.",
2334 "Bad username/password.",
2338 "Missing URI scheme.",
2339 "Unknown URI scheme",
2340 "Missing resource path."
2344 need_restart_job
= 1;
2346 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
,
2347 attr
->values
[0].string
.text
,
2348 scheme
, sizeof(scheme
),
2349 username
, sizeof(username
),
2350 host
, sizeof(host
), &port
,
2351 resource
, sizeof(resource
));
2353 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2354 "%s device-uri: %s", printer
->name
,
2355 uri_status_strings
[uri_status
- HTTP_URI_STATUS_OVERFLOW
]);
2357 if (uri_status
< HTTP_URI_OK
)
2359 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri \"%s\"."),
2360 attr
->values
[0].string
.text
);
2364 if (!strcmp(scheme
, "file"))
2367 * See if the administrator has enabled file devices...
2370 if (!FileDevice
&& strcmp(resource
, "/dev/null"))
2373 * File devices are disabled and the URL is not file:/dev/null...
2376 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2377 _("File device URIs have been disabled. "
2378 "To enable, see the FileDevice directive in "
2379 "\"%s/cups-files.conf\"."),
2387 * See if the backend exists and is executable...
2390 snprintf(srcfile
, sizeof(srcfile
), "%s/backend/%s", ServerBin
, scheme
);
2391 if (access(srcfile
, X_OK
))
2394 * Could not find device in list!
2397 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2398 _("Bad device-uri scheme \"%s\"."), scheme
);
2403 if (printer
->sanitized_device_uri
)
2404 strlcpy(old_device_uri
, printer
->sanitized_device_uri
,
2405 sizeof(old_device_uri
));
2407 old_device_uri
[0] = '\0';
2409 cupsdSetDeviceURI(printer
, attr
->values
[0].string
.text
);
2411 cupsdLogMessage(CUPSD_LOG_INFO
,
2412 "Setting %s device-uri to \"%s\" (was \"%s\".)",
2413 printer
->name
, printer
->sanitized_device_uri
,
2419 set_port_monitor
= 0;
2421 if ((attr
= ippFindAttribute(con
->request
, "port-monitor",
2422 IPP_TAG_NAME
)) != NULL
)
2424 ipp_attribute_t
*supported
; /* port-monitor-supported attribute */
2427 need_restart_job
= 1;
2429 supported
= ippFindAttribute(printer
->ppd_attrs
, "port-monitor-supported",
2433 for (i
= 0; i
< supported
->num_values
; i
++)
2434 if (!strcmp(supported
->values
[i
].string
.text
,
2435 attr
->values
[0].string
.text
))
2439 if (!supported
|| i
>= supported
->num_values
)
2441 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad port-monitor \"%s\"."),
2442 attr
->values
[0].string
.text
);
2446 cupsdLogMessage(CUPSD_LOG_INFO
,
2447 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2448 printer
->name
, attr
->values
[0].string
.text
,
2449 printer
->port_monitor
? printer
->port_monitor
: "none");
2451 if (strcmp(attr
->values
[0].string
.text
, "none"))
2452 cupsdSetString(&printer
->port_monitor
, attr
->values
[0].string
.text
);
2454 cupsdClearString(&printer
->port_monitor
);
2456 set_port_monitor
= 1;
2459 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
2460 IPP_TAG_BOOLEAN
)) != NULL
&&
2461 attr
->values
[0].boolean
!= printer
->accepting
)
2463 cupsdLogMessage(CUPSD_LOG_INFO
,
2464 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
2465 printer
->name
, attr
->values
[0].boolean
, printer
->accepting
);
2467 printer
->accepting
= attr
->values
[0].boolean
;
2469 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2470 "%s accepting jobs.",
2471 printer
->accepting
? "Now" : "No longer");
2474 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
2475 IPP_TAG_BOOLEAN
)) != NULL
)
2477 if (attr
->values
[0].boolean
&&
2478 printer
->num_auth_info_required
== 1 &&
2479 !strcmp(printer
->auth_info_required
[0], "negotiate"))
2481 send_ipp_status(con
, IPP_BAD_REQUEST
,
2482 _("Cannot share a remote Kerberized printer."));
2486 if (printer
->shared
&& !attr
->values
[0].boolean
)
2487 cupsdDeregisterPrinter(printer
, 1);
2489 cupsdLogMessage(CUPSD_LOG_INFO
,
2490 "Setting %s printer-is-shared to %d (was %d.)",
2491 printer
->name
, attr
->values
[0].boolean
, printer
->shared
);
2493 printer
->shared
= attr
->values
[0].boolean
;
2496 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
2497 IPP_TAG_ENUM
)) != NULL
)
2499 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
2500 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
2502 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad printer-state value %d."),
2503 attr
->values
[0].integer
);
2507 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
2508 printer
->name
, attr
->values
[0].integer
, printer
->state
);
2510 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
2511 cupsdStopPrinter(printer
, 0);
2514 need_restart_job
= 1;
2515 cupsdSetPrinterState(printer
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
2519 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
2520 IPP_TAG_TEXT
)) != NULL
)
2522 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
2523 sizeof(printer
->state_message
));
2525 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
, "%s",
2526 printer
->state_message
);
2529 if ((attr
= ippFindAttribute(con
->request
, "printer-state-reasons",
2530 IPP_TAG_KEYWORD
)) != NULL
)
2532 if (attr
->num_values
>
2533 (int)(sizeof(printer
->reasons
) / sizeof(printer
->reasons
[0])))
2535 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2536 _("Too many printer-state-reasons values (%d > %d)."),
2538 (int)(sizeof(printer
->reasons
) /
2539 sizeof(printer
->reasons
[0])));
2543 for (i
= 0; i
< printer
->num_reasons
; i
++)
2544 _cupsStrFree(printer
->reasons
[i
]);
2546 printer
->num_reasons
= 0;
2547 for (i
= 0; i
< attr
->num_values
; i
++)
2549 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
2552 printer
->reasons
[printer
->num_reasons
] =
2553 _cupsStrRetain(attr
->values
[i
].string
.text
);
2554 printer
->num_reasons
++;
2556 if (!strcmp(attr
->values
[i
].string
.text
, "paused") &&
2557 printer
->state
!= IPP_PRINTER_STOPPED
)
2559 cupsdLogMessage(CUPSD_LOG_INFO
,
2560 "Setting %s printer-state to %d (was %d.)",
2561 printer
->name
, IPP_PRINTER_STOPPED
, printer
->state
);
2562 cupsdStopPrinter(printer
, 0);
2566 if (PrintcapFormat
== PRINTCAP_PLIST
)
2567 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2569 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2570 "Printer \"%s\" state changed.", printer
->name
);
2573 set_printer_defaults(con
, printer
);
2575 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
2576 IPP_TAG_KEYWORD
)) != NULL
)
2577 cupsdSetAuthInfoRequired(printer
, NULL
, attr
);
2580 * See if we have all required attributes...
2583 if (!printer
->device_uri
)
2584 cupsdSetString(&printer
->device_uri
, "file:///dev/null");
2587 * See if we have an interface script or PPD file attached to the request...
2592 need_restart_job
= 1;
2595 strlcpy(srcfile
, con
->filename
, sizeof(srcfile
));
2597 if ((fp
= cupsFileOpen(srcfile
, "rb")))
2600 * Yes; get the first line from it...
2604 cupsFileGets(fp
, line
, sizeof(line
));
2608 * Then see what kind of file it is...
2611 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2614 if (!strncmp(line
, "*PPD-Adobe", 10))
2617 * The new file is a PPD file, so remove any old interface script
2618 * that might be lying around...
2626 * This must be an interface script, so move the file over to the
2627 * interfaces directory and make it executable...
2630 if (copy_file(srcfile
, dstfile
))
2632 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2633 _("Unable to copy interface script - %s"),
2638 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2639 "Copied interface script successfully");
2640 chmod(dstfile
, 0755);
2643 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2646 if (!strncmp(line
, "*PPD-Adobe", 10))
2649 * The new file is a PPD file, so move the file over to the
2650 * ppd directory and make it readable by all...
2653 if (copy_file(srcfile
, dstfile
))
2655 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2656 _("Unable to copy PPD file - %s"),
2661 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2662 "Copied PPD file successfully");
2663 chmod(dstfile
, 0644);
2668 * This must be an interface script, so remove any old PPD file that
2669 * may be lying around...
2676 else if ((attr
= ippFindAttribute(con
->request
, "ppd-name",
2677 IPP_TAG_NAME
)) != NULL
)
2679 need_restart_job
= 1;
2682 if (!strcmp(attr
->values
[0].string
.text
, "raw"))
2685 * Raw driver, remove any existing PPD or interface script files.
2688 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2692 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2702 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2706 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2709 if (copy_model(con
, attr
->values
[0].string
.text
, dstfile
))
2711 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file."));
2715 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2716 "Copied PPD file successfully");
2717 chmod(dstfile
, 0644);
2724 * If we changed the PPD/interface script, then remove the printer's cache
2725 * file and clear the printer-state-reasons...
2728 char cache_name
[1024]; /* Cache filename for printer attrs */
2730 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.data", CacheDir
,
2734 cupsdSetPrinterReasons(printer
, "none");
2737 * (Re)register color profiles...
2740 cupsdRegisterColor(printer
);
2744 * If we set the device URI but not the port monitor, check which port
2745 * monitor to use by default...
2748 if (set_device_uri
&& !set_port_monitor
)
2750 ppd_file_t
*ppd
; /* PPD file */
2751 ppd_attr_t
*ppdattr
; /* cupsPortMonitor attribute */
2754 httpSeparateURI(HTTP_URI_CODING_ALL
, printer
->device_uri
, scheme
,
2755 sizeof(scheme
), username
, sizeof(username
), host
,
2756 sizeof(host
), &port
, resource
, sizeof(resource
));
2758 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
,
2760 if ((ppd
= _ppdOpenFile(srcfile
, _PPD_LOCALIZATION_NONE
)) != NULL
)
2762 for (ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2764 ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
2765 if (!strcmp(scheme
, ppdattr
->spec
))
2767 cupsdLogMessage(CUPSD_LOG_INFO
,
2768 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2769 printer
->name
, ppdattr
->value
,
2770 printer
->port_monitor
? printer
->port_monitor
2773 if (strcmp(ppdattr
->value
, "none"))
2774 cupsdSetString(&printer
->port_monitor
, ppdattr
->value
);
2776 cupsdClearString(&printer
->port_monitor
);
2786 * Update the printer attributes and return...
2789 cupsdSetPrinterAttrs(printer
);
2790 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2792 if (need_restart_job
&& printer
->job
)
2795 * Restart the current job...
2798 cupsdSetJobState(printer
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
2799 "Job restarted because the printer was modified.");
2802 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2806 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
2807 printer
, NULL
, "Printer \"%s\" modified by \"%s\".",
2808 printer
->name
, get_username(con
));
2810 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" modified by \"%s\".",
2811 printer
->name
, get_username(con
));
2815 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
2816 printer
, NULL
, "New printer \"%s\" added by \"%s\".",
2817 printer
->name
, get_username(con
));
2819 cupsdLogMessage(CUPSD_LOG_INFO
, "New printer \"%s\" added by \"%s\".",
2820 printer
->name
, get_username(con
));
2823 con
->response
->request
.status
.status_code
= IPP_OK
;
2828 * 'add_printer_state_reasons()' - Add the "printer-state-reasons" attribute
2829 * based upon the printer state...
2833 add_printer_state_reasons(
2834 cupsd_client_t
*con
, /* I - Client connection */
2835 cupsd_printer_t
*p
) /* I - Printer info */
2837 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2838 "add_printer_state_reasons(%p[%d], %p[%s])",
2839 con
, con
->number
, p
, p
->name
);
2841 if (p
->num_reasons
== 0)
2842 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2843 "printer-state-reasons", NULL
, "none");
2845 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2846 "printer-state-reasons", p
->num_reasons
, NULL
,
2847 (const char * const *)p
->reasons
);
2852 * 'add_queued_job_count()' - Add the "queued-job-count" attribute for
2853 * the specified printer or class.
2857 add_queued_job_count(
2858 cupsd_client_t
*con
, /* I - Client connection */
2859 cupsd_printer_t
*p
) /* I - Printer or class */
2861 int count
; /* Number of jobs on destination */
2864 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_queued_job_count(%p[%d], %p[%s])",
2865 con
, con
->number
, p
, p
->name
);
2867 count
= cupsdGetPrinterJobCount(p
->name
);
2869 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2870 "queued-job-count", count
);
2875 * 'apply_printer_defaults()' - Apply printer default options to a job.
2879 apply_printer_defaults(
2880 cupsd_printer_t
*printer
, /* I - Printer */
2881 cupsd_job_t
*job
) /* I - Job */
2883 int i
, /* Looping var */
2884 num_options
; /* Number of default options */
2885 cups_option_t
*options
, /* Default options */
2886 *option
; /* Current option */
2890 * Collect all of the default options and add the missing ones to the
2894 for (i
= printer
->num_options
, num_options
= 0, options
= NULL
,
2895 option
= printer
->options
;
2898 if (!ippFindAttribute(job
->attrs
, option
->name
, IPP_TAG_ZERO
))
2900 num_options
= cupsAddOption(option
->name
, option
->value
, num_options
,
2905 * Encode these options as attributes in the job object...
2908 cupsEncodeOptions2(job
->attrs
, num_options
, options
, IPP_TAG_JOB
);
2909 cupsFreeOptions(num_options
, options
);
2914 * 'authenticate_job()' - Set job authentication info.
2918 authenticate_job(cupsd_client_t
*con
, /* I - Client connection */
2919 ipp_attribute_t
*uri
) /* I - Job URI */
2921 ipp_attribute_t
*attr
, /* job-id attribute */
2922 *auth_info
; /* auth-info attribute */
2923 int jobid
; /* Job ID */
2924 cupsd_job_t
*job
; /* Current job */
2925 char scheme
[HTTP_MAX_URI
],
2926 /* Method portion of URI */
2927 username
[HTTP_MAX_URI
],
2928 /* Username portion of URI */
2930 /* Host portion of URI */
2931 resource
[HTTP_MAX_URI
];
2932 /* Resource portion of URI */
2933 int port
; /* Port portion of URI */
2936 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "authenticate_job(%p[%d], %s)",
2937 con
, con
->number
, uri
->values
[0].string
.text
);
2940 * Start with "everything is OK" status...
2943 con
->response
->request
.status
.status_code
= IPP_OK
;
2946 * See if we have a job URI or a printer URI...
2949 if (!strcmp(uri
->name
, "printer-uri"))
2952 * Got a printer URI; see if we also have a job-id attribute...
2955 if ((attr
= ippFindAttribute(con
->request
, "job-id",
2956 IPP_TAG_INTEGER
)) == NULL
)
2958 send_ipp_status(con
, IPP_BAD_REQUEST
,
2959 _("Got a printer-uri attribute but no job-id."));
2963 jobid
= attr
->values
[0].integer
;
2968 * Got a job URI; parse it to get the job ID...
2971 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
2972 sizeof(scheme
), username
, sizeof(username
), host
,
2973 sizeof(host
), &port
, resource
, sizeof(resource
));
2975 if (strncmp(resource
, "/jobs/", 6))
2981 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
2982 uri
->values
[0].string
.text
);
2986 jobid
= atoi(resource
+ 6);
2990 * See if the job exists...
2993 if ((job
= cupsdFindJob(jobid
)) == NULL
)
2996 * Nope - return a "not found" error...
2999 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
3004 * See if the job has been completed...
3007 if (job
->state_value
!= IPP_JOB_HELD
)
3010 * Return a "not-possible" error...
3013 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3014 _("Job #%d is not held for authentication."),
3020 * See if we have already authenticated...
3023 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
3025 if (!con
->username
[0] && !auth_info
)
3027 cupsd_printer_t
*printer
; /* Job destination */
3030 * No auth data. If we need to authenticate via Kerberos, send a
3031 * HTTP auth challenge, otherwise just return an IPP error...
3034 printer
= cupsdFindDest(job
->dest
);
3036 if (printer
&& printer
->num_auth_info_required
> 0 &&
3037 !strcmp(printer
->auth_info_required
[0], "negotiate"))
3038 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
3040 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
3041 _("No authentication information provided."));
3046 * See if the job is owned by the requesting user...
3049 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3051 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3052 cupsdFindDest(job
->dest
));
3057 * Save the authentication information for this job...
3060 save_auth_info(con
, job
, auth_info
);
3063 * Reset the job-hold-until value to "no-hold"...
3066 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
3067 IPP_TAG_KEYWORD
)) == NULL
)
3068 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
3072 attr
->value_tag
= IPP_TAG_KEYWORD
;
3073 cupsdSetString(&(attr
->values
[0].string
.text
), "no-hold");
3077 * Release the job and return...
3080 cupsdReleaseJob(job
);
3082 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, NULL
, job
, "Job authenticated by user");
3084 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Authenticated by \"%s\".", con
->username
);
3091 * 'cancel_all_jobs()' - Cancel all or selected print jobs.
3095 cancel_all_jobs(cupsd_client_t
*con
, /* I - Client connection */
3096 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3098 int i
; /* Looping var */
3099 http_status_t status
; /* Policy status */
3100 cups_ptype_t dtype
; /* Destination type */
3101 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3102 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
3103 hostname
[HTTP_MAX_URI
], /* Host portion of URI */
3104 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3105 int port
; /* Port portion of URI */
3106 ipp_attribute_t
*attr
; /* Attribute in request */
3107 const char *username
= NULL
; /* Username */
3108 cupsd_jobaction_t purge
= CUPSD_JOB_DEFAULT
;
3110 cupsd_printer_t
*printer
; /* Printer */
3111 ipp_attribute_t
*job_ids
; /* job-ids attribute */
3112 cupsd_job_t
*job
; /* Job */
3115 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_all_jobs(%p[%d], %s)", con
,
3116 con
->number
, uri
->values
[0].string
.text
);
3119 * Get the jobs to cancel/purge...
3122 switch (con
->request
->request
.op
.operation_id
)
3124 case IPP_PURGE_JOBS
:
3126 * Get the username (if any) for the jobs we want to cancel (only if
3127 * "my-jobs" is specified...
3130 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
3131 IPP_TAG_BOOLEAN
)) != NULL
&&
3132 attr
->values
[0].boolean
)
3134 if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3135 IPP_TAG_NAME
)) != NULL
)
3136 username
= attr
->values
[0].string
.text
;
3139 send_ipp_status(con
, IPP_BAD_REQUEST
,
3140 _("Missing requesting-user-name attribute."));
3146 * Look for the "purge-jobs" attribute...
3149 if ((attr
= ippFindAttribute(con
->request
, "purge-jobs",
3150 IPP_TAG_BOOLEAN
)) != NULL
)
3151 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
3153 purge
= CUPSD_JOB_PURGE
;
3156 case IPP_CANCEL_MY_JOBS
:
3157 if (con
->username
[0])
3158 username
= con
->username
;
3159 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3160 IPP_TAG_NAME
)) != NULL
)
3161 username
= attr
->values
[0].string
.text
;
3164 send_ipp_status(con
, IPP_BAD_REQUEST
,
3165 _("Missing requesting-user-name attribute."));
3173 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
3176 * See if we have a printer URI...
3179 if (strcmp(uri
->name
, "printer-uri"))
3181 send_ipp_status(con
, IPP_BAD_REQUEST
,
3182 _("The printer-uri attribute is required."));
3187 * And if the destination is valid...
3190 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3196 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
,
3197 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
3198 hostname
, sizeof(hostname
), &port
,
3199 resource
, sizeof(resource
));
3201 if ((!strncmp(resource
, "/printers/", 10) && resource
[10]) ||
3202 (!strncmp(resource
, "/classes/", 9) && resource
[9]))
3204 send_ipp_status(con
, IPP_NOT_FOUND
,
3205 _("The printer or class does not exist."));
3213 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
3215 send_http_error(con
, status
, NULL
);
3221 for (i
= 0; i
< job_ids
->num_values
; i
++)
3223 if ((job
= cupsdFindJob(job_ids
->values
[i
].integer
)) == NULL
)
3226 if (con
->request
->request
.op
.operation_id
== IPP_CANCEL_MY_JOBS
&&
3227 _cups_strcasecmp(job
->username
, username
))
3231 if (i
< job_ids
->num_values
)
3233 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3234 job_ids
->values
[i
].integer
);
3238 for (i
= 0; i
< job_ids
->num_values
; i
++)
3240 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
3242 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3243 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
3244 "Job canceled by user.");
3247 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
3248 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3254 * Cancel all jobs on all printers...
3257 cupsdCancelJobs(NULL
, username
, purge
);
3259 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs were %s by \"%s\".",
3260 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3270 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
3273 send_http_error(con
, status
, printer
);
3279 for (i
= 0; i
< job_ids
->num_values
; i
++)
3281 if ((job
= cupsdFindJob(job_ids
->values
[i
].integer
)) == NULL
||
3282 _cups_strcasecmp(job
->dest
, printer
->name
))
3285 if (con
->request
->request
.op
.operation_id
== IPP_CANCEL_MY_JOBS
&&
3286 _cups_strcasecmp(job
->username
, username
))
3290 if (i
< job_ids
->num_values
)
3292 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3293 job_ids
->values
[i
].integer
);
3297 for (i
= 0; i
< job_ids
->num_values
; i
++)
3299 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
3301 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3302 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
3303 "Job canceled by user.");
3306 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
3307 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3313 * Cancel all of the jobs on the named printer...
3316 cupsdCancelJobs(printer
->name
, username
, purge
);
3318 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs on \"%s\" were %s by \"%s\".",
3320 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3325 con
->response
->request
.status
.status_code
= IPP_OK
;
3330 * 'cancel_job()' - Cancel a print job.
3334 cancel_job(cupsd_client_t
*con
, /* I - Client connection */
3335 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3337 ipp_attribute_t
*attr
; /* Current attribute */
3338 int jobid
; /* Job ID */
3339 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3340 username
[HTTP_MAX_URI
], /* Username portion of URI */
3341 host
[HTTP_MAX_URI
], /* Host portion of URI */
3342 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3343 int port
; /* Port portion of URI */
3344 cupsd_job_t
*job
; /* Job information */
3345 cups_ptype_t dtype
; /* Destination type (printer/class) */
3346 cupsd_printer_t
*printer
; /* Printer data */
3347 cupsd_jobaction_t purge
; /* Purge the job? */
3350 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_job(%p[%d], %s)", con
,
3351 con
->number
, uri
->values
[0].string
.text
);
3354 * See if we have a job URI or a printer URI...
3357 if (!strcmp(uri
->name
, "printer-uri"))
3360 * Got a printer URI; see if we also have a job-id attribute...
3363 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3364 IPP_TAG_INTEGER
)) == NULL
)
3366 send_ipp_status(con
, IPP_BAD_REQUEST
,
3367 _("Got a printer-uri attribute but no job-id."));
3371 if ((jobid
= attr
->values
[0].integer
) == 0)
3374 * Find the current job on the specified printer...
3377 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3383 send_ipp_status(con
, IPP_NOT_FOUND
,
3384 _("The printer or class does not exist."));
3389 * See if there are any pending jobs...
3392 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3394 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3395 if (job
->state_value
<= IPP_JOB_PROCESSING
&&
3396 !_cups_strcasecmp(job
->dest
, printer
->name
))
3404 * No, try stopped jobs...
3407 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3409 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3410 if (job
->state_value
== IPP_JOB_STOPPED
&&
3411 !_cups_strcasecmp(job
->dest
, printer
->name
))
3418 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("No active jobs on %s."),
3428 * Got a job URI; parse it to get the job ID...
3431 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
3432 sizeof(scheme
), username
, sizeof(username
), host
,
3433 sizeof(host
), &port
, resource
, sizeof(resource
));
3435 if (strncmp(resource
, "/jobs/", 6))
3441 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
3442 uri
->values
[0].string
.text
);
3446 jobid
= atoi(resource
+ 6);
3450 * Look for the "purge-job" attribute...
3453 if ((attr
= ippFindAttribute(con
->request
, "purge-job",
3454 IPP_TAG_BOOLEAN
)) != NULL
)
3455 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
3457 purge
= CUPSD_JOB_DEFAULT
;
3460 * See if the job exists...
3463 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3466 * Nope - return a "not found" error...
3469 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
3474 * See if the job is owned by the requesting user...
3477 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3479 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3480 cupsdFindDest(job
->dest
));
3485 * See if the job is already completed, canceled, or aborted; if so,
3486 * we can't cancel...
3489 if (job
->state_value
>= IPP_JOB_CANCELED
&& purge
!= CUPSD_JOB_PURGE
)
3491 switch (job
->state_value
)
3493 case IPP_JOB_CANCELED
:
3494 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3495 _("Job #%d is already canceled - can\'t cancel."),
3499 case IPP_JOB_ABORTED
:
3500 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3501 _("Job #%d is already aborted - can\'t cancel."),
3506 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3507 _("Job #%d is already completed - can\'t cancel."),
3516 * Cancel the job and return...
3519 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3520 purge
== CUPSD_JOB_PURGE
? "Job purged by \"%s\"" :
3521 "Job canceled by \"%s\"",
3525 if (purge
== CUPSD_JOB_PURGE
)
3526 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Purged by \"%s\".", jobid
,
3529 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Canceled by \"%s\".", jobid
,
3532 con
->response
->request
.status
.status_code
= IPP_OK
;
3537 * 'cancel_subscription()' - Cancel a subscription.
3541 cancel_subscription(
3542 cupsd_client_t
*con
, /* I - Client connection */
3543 int sub_id
) /* I - Subscription ID */
3545 http_status_t status
; /* Policy status */
3546 cupsd_subscription_t
*sub
; /* Subscription */
3549 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3550 "cancel_subscription(con=%p[%d], sub_id=%d)",
3551 con
, con
->number
, sub_id
);
3554 * Is the subscription ID valid?
3557 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
3560 * Bad subscription ID...
3563 send_ipp_status(con
, IPP_NOT_FOUND
,
3564 _("Subscription #%d does not exist."), sub_id
);
3572 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
3574 con
, sub
->owner
)) != HTTP_OK
)
3576 send_http_error(con
, status
, sub
->dest
);
3581 * Cancel the subscription...
3584 cupsdDeleteSubscription(sub
, 1);
3586 con
->response
->request
.status
.status_code
= IPP_OK
;
3591 * 'check_rss_recipient()' - Check that we do not have a duplicate RSS feed URI.
3594 static int /* O - 1 if OK, 0 if not */
3595 check_rss_recipient(
3596 const char *recipient
) /* I - Recipient URI */
3598 cupsd_subscription_t
*sub
; /* Current subscription */
3601 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
);
3603 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
3607 * Compare the URIs up to the first ?...
3610 const char *r1
, *r2
;
3612 for (r1
= recipient
, r2
= sub
->recipient
;
3613 *r1
== *r2
&& *r1
&& *r1
!= '?' && *r2
&& *r2
!= '?';
3625 * 'check_quotas()' - Check quotas for a printer and user.
3628 static int /* O - 1 if OK, 0 if forbidden,
3629 -1 if limit reached */
3630 check_quotas(cupsd_client_t
*con
, /* I - Client connection */
3631 cupsd_printer_t
*p
) /* I - Printer or class */
3633 char username
[33], /* Username */
3634 *name
; /* Current user name */
3635 cupsd_quota_t
*q
; /* Quota data */
3636 #ifdef HAVE_MBR_UID_TO_UUID
3638 * Use Apple membership APIs which require that all names represent
3639 * valid user account or group records accessible by the server.
3642 uuid_t usr_uuid
; /* UUID for job requesting user */
3643 uuid_t usr2_uuid
; /* UUID for ACL user name entry */
3644 uuid_t grp_uuid
; /* UUID for ACL group name entry */
3645 int mbr_err
; /* Error from membership function */
3646 int is_member
; /* Is this user a member? */
3649 * Use standard POSIX APIs for checking users and groups...
3652 struct passwd
*pw
; /* User password data */
3653 #endif /* HAVE_MBR_UID_TO_UUID */
3656 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "check_quotas(%p[%d], %p[%s])",
3657 con
, con
->number
, p
, p
->name
);
3660 * Figure out who is printing...
3663 strlcpy(username
, get_username(con
), sizeof(username
));
3665 if ((name
= strchr(username
, '@')) != NULL
)
3666 *name
= '\0'; /* Strip @REALM */
3669 * Check global active job limits for printers and users...
3672 if (MaxJobsPerPrinter
)
3675 * Check if there are too many pending jobs on this printer...
3678 if (cupsdGetPrinterJobCount(p
->name
) >= MaxJobsPerPrinter
)
3680 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for printer \"%s\"...",
3689 * Check if there are too many pending jobs for this user...
3692 if (cupsdGetUserJobCount(username
) >= MaxJobsPerUser
)
3694 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for user \"%s\"...",
3701 * Check against users...
3704 if (cupsArrayCount(p
->users
) == 0 && p
->k_limit
== 0 && p
->page_limit
== 0)
3707 if (cupsArrayCount(p
->users
))
3709 #ifdef HAVE_MBR_UID_TO_UUID
3711 * Get UUID for job requesting user...
3714 if (mbr_user_name_to_uuid((char *)username
, usr_uuid
))
3720 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3721 "check_quotas: UUID lookup failed for user \"%s\"",
3723 cupsdLogMessage(CUPSD_LOG_INFO
,
3724 "Denying user \"%s\" access to printer \"%s\" "
3725 "(unknown user)...",
3731 * Get UID and GID of requesting user...
3734 pw
= getpwnam(username
);
3736 #endif /* HAVE_MBR_UID_TO_UUID */
3738 for (name
= (char *)cupsArrayFirst(p
->users
);
3740 name
= (char *)cupsArrayNext(p
->users
))
3744 * Check group membership...
3747 #ifdef HAVE_MBR_UID_TO_UUID
3750 if (uuid_parse(name
+ 2, grp_uuid
))
3751 uuid_clear(grp_uuid
);
3753 else if ((mbr_err
= mbr_group_name_to_uuid(name
+ 1, grp_uuid
)) != 0)
3756 * Invalid ACL entries are ignored for matching; just record a
3757 * warning in the log...
3760 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3761 "check_quotas: UUID lookup failed for ACL entry "
3762 "\"%s\" (err=%d)", name
, mbr_err
);
3763 cupsdLogMessage(CUPSD_LOG_WARN
,
3764 "Access control entry \"%s\" not a valid group name; "
3765 "entry ignored", name
);
3768 if ((mbr_err
= mbr_check_membership(usr_uuid
, grp_uuid
,
3772 * At this point, there should be no errors, but check anyways...
3775 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3776 "check_quotas: group \"%s\" membership check "
3777 "failed (err=%d)", name
+ 1, mbr_err
);
3782 * Stop if we found a match...
3789 if (cupsdCheckGroup(username
, pw
, name
+ 1))
3791 #endif /* HAVE_MBR_UID_TO_UUID */
3793 #ifdef HAVE_MBR_UID_TO_UUID
3798 if (uuid_parse(name
+ 1, usr2_uuid
))
3799 uuid_clear(usr2_uuid
);
3801 else if ((mbr_err
= mbr_user_name_to_uuid(name
, usr2_uuid
)) != 0)
3804 * Invalid ACL entries are ignored for matching; just record a
3805 * warning in the log...
3808 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3809 "check_quotas: UUID lookup failed for ACL entry "
3810 "\"%s\" (err=%d)", name
, mbr_err
);
3811 cupsdLogMessage(CUPSD_LOG_WARN
,
3812 "Access control entry \"%s\" not a valid user name; "
3813 "entry ignored", name
);
3816 if (!uuid_compare(usr_uuid
, usr2_uuid
))
3820 else if (!_cups_strcasecmp(username
, name
))
3822 #endif /* HAVE_MBR_UID_TO_UUID */
3824 if ((name
!= NULL
) == p
->deny_users
)
3826 cupsdLogMessage(CUPSD_LOG_INFO
,
3827 "Denying user \"%s\" access to printer \"%s\"...",
3837 if (p
->k_limit
|| p
->page_limit
)
3839 if ((q
= cupsdUpdateQuota(p
, username
, 0, 0)) == NULL
)
3841 cupsdLogMessage(CUPSD_LOG_ERROR
,
3842 "Unable to allocate quota data for user \"%s\"",
3847 if ((q
->k_count
>= p
->k_limit
&& p
->k_limit
) ||
3848 (q
->page_count
>= p
->page_limit
&& p
->page_limit
))
3850 cupsdLogMessage(CUPSD_LOG_INFO
, "User \"%s\" is over the quota limit...",
3857 * If we have gotten this far, we're done!
3865 * 'close_job()' - Close a multi-file job.
3869 close_job(cupsd_client_t
*con
, /* I - Client connection */
3870 ipp_attribute_t
*uri
) /* I - Printer URI */
3872 cupsd_job_t
*job
; /* Job */
3873 ipp_attribute_t
*attr
; /* Attribute */
3874 char job_uri
[HTTP_MAX_URI
],
3876 username
[256]; /* User name */
3879 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "close_job(%p[%d], %s)", con
,
3880 con
->number
, uri
->values
[0].string
.text
);
3883 * See if we have a job URI or a printer URI...
3886 if (strcmp(uri
->name
, "printer-uri"))
3889 * job-uri is not supported by Close-Job!
3892 send_ipp_status(con
, IPP_BAD_REQUEST
,
3893 _("Close-Job doesn't support the job-uri attribute."));
3898 * Got a printer URI; see if we also have a job-id attribute...
3901 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3902 IPP_TAG_INTEGER
)) == NULL
)
3904 send_ipp_status(con
, IPP_BAD_REQUEST
,
3905 _("Got a printer-uri attribute but no job-id."));
3909 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
3912 * Nope - return a "not found" error...
3915 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3916 attr
->values
[0].integer
);
3921 * See if the job is owned by the requesting user...
3924 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3926 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3927 cupsdFindDest(job
->dest
));
3932 * Add any ending sheet...
3935 if (cupsdTimeoutJob(job
))
3938 if (job
->state_value
== IPP_JOB_STOPPED
)
3940 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
3941 job
->state_value
= IPP_JOB_PENDING
;
3943 else if (job
->state_value
== IPP_JOB_HELD
)
3945 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
3946 IPP_TAG_KEYWORD
)) == NULL
)
3947 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
3949 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
3951 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
3952 job
->state_value
= IPP_JOB_PENDING
;
3957 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
3960 * Fill in the response info...
3963 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
3964 con
->clientname
, con
->clientport
, "/jobs/%d", job
->id
);
3965 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
3968 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
3970 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
3973 con
->response
->request
.status
.status_code
= IPP_OK
;
3976 * Start the job if necessary...
3984 * 'copy_attrs()' - Copy attributes from one request to another.
3988 copy_attrs(ipp_t
*to
, /* I - Destination request */
3989 ipp_t
*from
, /* I - Source request */
3990 cups_array_t
*ra
, /* I - Requested attributes */
3991 ipp_tag_t group
, /* I - Group to copy */
3992 int quickcopy
, /* I - Do a quick copy? */
3993 cups_array_t
*exclude
) /* I - Attributes to exclude? */
3995 ipp_attribute_t
*fromattr
; /* Source attribute */
3998 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3999 "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)",
4000 to
, from
, ra
, group
, quickcopy
);
4005 for (fromattr
= from
->attrs
; fromattr
; fromattr
= fromattr
->next
)
4008 * Filter attributes as needed...
4011 if ((group
!= IPP_TAG_ZERO
&& fromattr
->group_tag
!= group
&&
4012 fromattr
->group_tag
!= IPP_TAG_ZERO
) || !fromattr
->name
)
4015 if (!strcmp(fromattr
->name
, "document-password") ||
4016 !strcmp(fromattr
->name
, "job-authorization-uri") ||
4017 !strcmp(fromattr
->name
, "job-password") ||
4018 !strcmp(fromattr
->name
, "job-password-encryption") ||
4019 !strcmp(fromattr
->name
, "job-printer-uri"))
4023 (cupsArrayFind(exclude
, fromattr
->name
) ||
4024 cupsArrayFind(exclude
, "all")))
4027 * We need to exclude this attribute for security reasons; we require the
4028 * job-id attribute regardless of the security settings for IPP
4031 * The job-printer-uri attribute is handled by copy_job_attrs().
4033 * Subscription attribute security is handled by copy_subscription_attrs().
4036 if (strcmp(fromattr
->name
, "job-id"))
4040 if (!ra
|| cupsArrayFind(ra
, fromattr
->name
))
4043 * Don't send collection attributes by default to IPP/1.x clients
4044 * since many do not support collections. Also don't send
4045 * media-col-database unless specifically requested by the client.
4048 if (fromattr
->value_tag
== IPP_TAG_BEGIN_COLLECTION
&&
4050 (to
->request
.status
.version
[0] == 1 ||
4051 !strcmp(fromattr
->name
, "media-col-database")))
4054 ippCopyAttribute(to
, fromattr
, quickcopy
);
4061 * 'copy_banner()' - Copy a banner file to the requests directory for the
4065 static int /* O - Size of banner file in kbytes */
4066 copy_banner(cupsd_client_t
*con
, /* I - Client connection */
4067 cupsd_job_t
*job
, /* I - Job information */
4068 const char *name
) /* I - Name of banner */
4070 int i
; /* Looping var */
4071 int kbytes
; /* Size of banner file in kbytes */
4072 char filename
[1024]; /* Job filename */
4073 cupsd_banner_t
*banner
; /* Pointer to banner */
4074 cups_file_t
*in
; /* Input file */
4075 cups_file_t
*out
; /* Output file */
4076 int ch
; /* Character from file */
4077 char attrname
[255], /* Name of attribute */
4078 *s
; /* Pointer into name */
4079 ipp_attribute_t
*attr
; /* Attribute */
4082 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4083 "copy_banner(con=%p[%d], job=%p[%d], name=\"%s\")",
4084 con
, con
? con
->number
: -1, job
, job
->id
,
4085 name
? name
: "(null)");
4088 * Find the banner; return if not found or "none"...
4091 if (!name
|| !strcmp(name
, "none") ||
4092 (banner
= cupsdFindBanner(name
)) == NULL
)
4096 * Open the banner and job files...
4099 if (add_file(con
, job
, banner
->filetype
, 0))
4102 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
4104 if ((out
= cupsFileOpen(filename
, "w")) == NULL
)
4106 cupsdLogMessage(CUPSD_LOG_ERROR
,
4107 "Unable to create banner job file %s - %s",
4108 filename
, strerror(errno
));
4113 fchmod(cupsFileNumber(out
), 0640);
4114 fchown(cupsFileNumber(out
), RunUser
, Group
);
4117 * Try the localized banner file under the subdirectory...
4120 strlcpy(attrname
, job
->attrs
->attrs
->next
->values
[0].string
.text
,
4122 if (strlen(attrname
) > 2 && attrname
[2] == '-')
4125 * Convert ll-cc to ll_CC...
4129 attrname
[3] = (char)toupper(attrname
[3] & 255);
4130 attrname
[4] = (char)toupper(attrname
[4] & 255);
4133 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4136 if (access(filename
, 0) && strlen(attrname
) > 2)
4139 * Wasn't able to find "ll_CC" locale file; try the non-national
4140 * localization banner directory.
4145 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4149 if (access(filename
, 0))
4152 * Use the non-localized banner file.
4155 snprintf(filename
, sizeof(filename
), "%s/banners/%s", DataDir
, name
);
4158 if ((in
= cupsFileOpen(filename
, "r")) == NULL
)
4162 cupsdLogMessage(CUPSD_LOG_ERROR
,
4163 "Unable to open banner template file %s - %s",
4164 filename
, strerror(errno
));
4170 * Parse the file to the end...
4173 while ((ch
= cupsFileGetChar(in
)) != EOF
)
4177 * Get an attribute name...
4180 for (s
= attrname
; (ch
= cupsFileGetChar(in
)) != EOF
;)
4181 if (!isalpha(ch
& 255) && ch
!= '-' && ch
!= '?')
4183 else if (s
< (attrname
+ sizeof(attrname
) - 1))
4193 * Ignore { followed by stuff that is not an attribute name...
4196 cupsFilePrintf(out
, "{%s%c", attrname
, ch
);
4201 * See if it is defined...
4204 if (attrname
[0] == '?')
4209 if (!strcmp(s
, "printer-name"))
4211 cupsFilePuts(out
, job
->dest
);
4214 else if ((attr
= ippFindAttribute(job
->attrs
, s
, IPP_TAG_ZERO
)) == NULL
)
4217 * See if we have a leading question mark...
4220 if (attrname
[0] != '?')
4223 * Nope, write to file as-is; probably a PostScript procedure...
4226 cupsFilePrintf(out
, "{%s}", attrname
);
4233 * Output value(s)...
4236 for (i
= 0; i
< attr
->num_values
; i
++)
4239 cupsFilePutChar(out
, ',');
4241 switch (attr
->value_tag
)
4243 case IPP_TAG_INTEGER
:
4245 if (!strncmp(s
, "time-at-", 8))
4247 struct timeval tv
; /* Time value */
4249 tv
.tv_sec
= attr
->values
[i
].integer
;
4252 cupsFilePuts(out
, cupsdGetDateTime(&tv
, CUPSD_TIME_STANDARD
));
4255 cupsFilePrintf(out
, "%d", attr
->values
[i
].integer
);
4258 case IPP_TAG_BOOLEAN
:
4259 cupsFilePrintf(out
, "%d", attr
->values
[i
].boolean
);
4262 case IPP_TAG_NOVALUE
:
4263 cupsFilePuts(out
, "novalue");
4266 case IPP_TAG_RANGE
:
4267 cupsFilePrintf(out
, "%d-%d", attr
->values
[i
].range
.lower
,
4268 attr
->values
[i
].range
.upper
);
4271 case IPP_TAG_RESOLUTION
:
4272 cupsFilePrintf(out
, "%dx%d%s", attr
->values
[i
].resolution
.xres
,
4273 attr
->values
[i
].resolution
.yres
,
4274 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
4279 case IPP_TAG_STRING
:
4282 case IPP_TAG_KEYWORD
:
4283 case IPP_TAG_CHARSET
:
4284 case IPP_TAG_LANGUAGE
:
4285 if (!_cups_strcasecmp(banner
->filetype
->type
, "postscript"))
4288 * Need to quote strings for PS banners...
4293 for (p
= attr
->values
[i
].string
.text
; *p
; p
++)
4295 if (*p
== '(' || *p
== ')' || *p
== '\\')
4297 cupsFilePutChar(out
, '\\');
4298 cupsFilePutChar(out
, *p
);
4300 else if (*p
< 32 || *p
> 126)
4301 cupsFilePrintf(out
, "\\%03o", *p
& 255);
4303 cupsFilePutChar(out
, *p
);
4307 cupsFilePuts(out
, attr
->values
[i
].string
.text
);
4311 break; /* anti-compiler-warning-code */
4315 else if (ch
== '\\') /* Quoted char */
4317 ch
= cupsFileGetChar(in
);
4319 if (ch
!= '{') /* Only do special handling for \{ */
4320 cupsFilePutChar(out
, '\\');
4322 cupsFilePutChar(out
, ch
);
4325 cupsFilePutChar(out
, ch
);
4329 kbytes
= (cupsFileTell(out
) + 1023) / 1024;
4331 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
4332 IPP_TAG_INTEGER
)) != NULL
)
4333 attr
->values
[0].integer
+= kbytes
;
4342 * 'copy_file()' - Copy a PPD file or interface script...
4345 static int /* O - 0 = success, -1 = error */
4346 copy_file(const char *from
, /* I - Source file */
4347 const char *to
) /* I - Destination file */
4349 cups_file_t
*src
, /* Source file */
4350 *dst
; /* Destination file */
4351 int bytes
; /* Bytes to read/write */
4352 char buffer
[2048]; /* Copy buffer */
4355 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_file(\"%s\", \"%s\")", from
, to
);
4358 * Open the source and destination file for a copy...
4361 if ((src
= cupsFileOpen(from
, "rb")) == NULL
)
4364 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
4371 * Copy the source file to the destination...
4374 while ((bytes
= cupsFileRead(src
, buffer
, sizeof(buffer
))) > 0)
4375 if (cupsFileWrite(dst
, buffer
, (size_t)bytes
) < bytes
)
4383 * Close both files and return...
4388 return (cupsFileClose(dst
));
4393 * 'copy_model()' - Copy a PPD model file, substituting default values
4397 static int /* O - 0 = success, -1 = error */
4398 copy_model(cupsd_client_t
*con
, /* I - Client connection */
4399 const char *from
, /* I - Source file */
4400 const char *to
) /* I - Destination file */
4402 fd_set input
; /* select() input set */
4403 struct timeval timeout
; /* select() timeout */
4404 int maxfd
; /* Max file descriptor for select() */
4405 char tempfile
[1024]; /* Temporary PPD file */
4406 int tempfd
; /* Temporary PPD file descriptor */
4407 int temppid
; /* Process ID of cups-driverd */
4408 int temppipe
[2]; /* Temporary pipes */
4409 char *argv
[4], /* Command-line arguments */
4410 *envp
[MAX_ENV
]; /* Environment */
4411 cups_file_t
*src
, /* Source file */
4412 *dst
; /* Destination file */
4413 ppd_file_t
*ppd
; /* PPD file */
4414 int bytes
, /* Bytes from pipe */
4415 total
; /* Total bytes from pipe */
4416 char buffer
[2048]; /* Copy buffer */
4417 int i
; /* Looping var */
4418 char option
[PPD_MAX_NAME
], /* Option name */
4419 choice
[PPD_MAX_NAME
]; /* Choice name */
4420 ppd_size_t
*size
; /* Default size */
4421 int num_defaults
; /* Number of default options */
4422 cups_option_t
*defaults
; /* Default options */
4423 char cups_protocol
[PPD_MAX_LINE
];
4424 /* cupsProtocol attribute */
4427 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4428 "copy_model(con=%p, from=\"%s\", to=\"%s\")",
4432 * Run cups-driverd to get the PPD file...
4435 argv
[0] = "cups-driverd";
4437 argv
[2] = (char *)from
;
4440 cupsdLoadEnv(envp
, (int)(sizeof(envp
) / sizeof(envp
[0])));
4442 snprintf(buffer
, sizeof(buffer
), "%s/daemon/cups-driverd", ServerBin
);
4443 snprintf(tempfile
, sizeof(tempfile
), "%s/%d.ppd", TempDir
, con
->number
);
4444 tempfd
= open(tempfile
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
4445 if (tempfd
< 0 || cupsdOpenPipe(temppipe
))
4448 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4449 "copy_model: Running \"cups-driverd cat %s\"...", from
);
4451 if (!cupsdStartProcess(buffer
, argv
, envp
, -1, temppipe
[1], CGIPipes
[1],
4452 -1, -1, 0, DefaultProfile
, NULL
, &temppid
))
4463 * Wait up to 30 seconds for the PPD file to be copied...
4468 if (temppipe
[0] > CGIPipes
[0])
4469 maxfd
= temppipe
[0] + 1;
4471 maxfd
= CGIPipes
[0] + 1;
4476 * See if we have data ready...
4480 FD_SET(temppipe
[0], &input
);
4481 FD_SET(CGIPipes
[0], &input
);
4483 timeout
.tv_sec
= 30;
4484 timeout
.tv_usec
= 0;
4486 if ((i
= select(maxfd
, &input
, NULL
, NULL
, &timeout
)) < 0)
4496 * We have timed out...
4502 if (FD_ISSET(temppipe
[0], &input
))
4505 * Read the PPD file from the pipe, and write it to the PPD file.
4508 if ((bytes
= read(temppipe
[0], buffer
, sizeof(buffer
))) > 0)
4510 if (write(tempfd
, buffer
, (size_t)bytes
) < bytes
)
4519 if (FD_ISSET(CGIPipes
[0], &input
))
4529 * No data from cups-deviced...
4532 cupsdLogMessage(CUPSD_LOG_ERROR
, "copy_model: empty PPD file");
4538 * Open the source file for a copy...
4541 if ((src
= cupsFileOpen(tempfile
, "rb")) == NULL
)
4548 * Read the source file and see what page sizes are supported...
4551 if ((ppd
= _ppdOpen(src
, _PPD_LOCALIZATION_NONE
)) == NULL
)
4559 * Open the destination (if possible) and set the default options...
4564 cups_protocol
[0] = '\0';
4566 if ((dst
= cupsFileOpen(to
, "rb")) != NULL
)
4569 * Read all of the default lines from the old PPD...
4572 while (cupsFileGets(dst
, buffer
, sizeof(buffer
)))
4573 if (!strncmp(buffer
, "*Default", 8))
4576 * Add the default option...
4579 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
4580 choice
, sizeof(choice
)))
4582 ppd_option_t
*ppdo
; /* PPD option */
4586 * Only add the default if the default hasn't already been
4587 * set and the choice exists in the new PPD...
4590 if (!cupsGetOption(option
, num_defaults
, defaults
) &&
4591 (ppdo
= ppdFindOption(ppd
, option
)) != NULL
&&
4592 ppdFindChoice(ppdo
, choice
))
4593 num_defaults
= cupsAddOption(option
, choice
, num_defaults
,
4597 else if (!strncmp(buffer
, "*cupsProtocol:", 14))
4598 strlcpy(cups_protocol
, buffer
, sizeof(cups_protocol
));
4602 else if ((size
= ppdPageSize(ppd
, DefaultPaperSize
)) != NULL
)
4605 * Add the default media sizes...
4608 num_defaults
= cupsAddOption("PageSize", size
->name
,
4609 num_defaults
, &defaults
);
4610 num_defaults
= cupsAddOption("PageRegion", size
->name
,
4611 num_defaults
, &defaults
);
4612 num_defaults
= cupsAddOption("PaperDimension", size
->name
,
4613 num_defaults
, &defaults
);
4614 num_defaults
= cupsAddOption("ImageableArea", size
->name
,
4615 num_defaults
, &defaults
);
4621 * Open the destination file for a copy...
4624 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
4626 cupsFreeOptions(num_defaults
, defaults
);
4633 * Copy the source file to the destination...
4636 cupsFileRewind(src
);
4638 while (cupsFileGets(src
, buffer
, sizeof(buffer
)))
4640 if (!strncmp(buffer
, "*Default", 8))
4643 * Check for an previous default option choice...
4646 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
4647 choice
, sizeof(choice
)))
4649 const char *val
; /* Default option value */
4652 if ((val
= cupsGetOption(option
, num_defaults
, defaults
)) != NULL
)
4655 * Substitute the previous choice...
4658 snprintf(buffer
, sizeof(buffer
), "*Default%s: %s", option
, val
);
4663 cupsFilePrintf(dst
, "%s\n", buffer
);
4666 if (cups_protocol
[0])
4667 cupsFilePrintf(dst
, "%s\n", cups_protocol
);
4669 cupsFreeOptions(num_defaults
, defaults
);
4672 * Close both files and return...
4679 return (cupsFileClose(dst
));
4684 * 'copy_job_attrs()' - Copy job attributes.
4688 copy_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
4689 cupsd_job_t
*job
, /* I - Job */
4690 cups_array_t
*ra
, /* I - Requested attributes array */
4691 cups_array_t
*exclude
) /* I - Private attributes array */
4693 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
4697 * Send the requested attributes for each job...
4700 if (!cupsArrayFind(exclude
, "all"))
4702 if ((!exclude
|| !cupsArrayFind(exclude
, "number-of-documents")) &&
4703 (!ra
|| cupsArrayFind(ra
, "number-of-documents")))
4704 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4705 "number-of-documents", job
->num_files
);
4707 if ((!exclude
|| !cupsArrayFind(exclude
, "job-media-progress")) &&
4708 (!ra
|| cupsArrayFind(ra
, "job-media-progress")))
4709 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4710 "job-media-progress", job
->progress
);
4712 if ((!exclude
|| !cupsArrayFind(exclude
, "job-more-info")) &&
4713 (!ra
|| cupsArrayFind(ra
, "job-more-info")))
4715 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "http",
4716 NULL
, con
->clientname
, con
->clientport
, "/jobs/%d",
4718 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4719 "job-more-info", NULL
, job_uri
);
4722 if (job
->state_value
> IPP_JOB_PROCESSING
&&
4723 (!exclude
|| !cupsArrayFind(exclude
, "job-preserved")) &&
4724 (!ra
|| cupsArrayFind(ra
, "job-preserved")))
4725 ippAddBoolean(con
->response
, IPP_TAG_JOB
, "job-preserved",
4726 job
->num_files
> 0);
4728 if ((!exclude
|| !cupsArrayFind(exclude
, "job-printer-up-time")) &&
4729 (!ra
|| cupsArrayFind(ra
, "job-printer-up-time")))
4730 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4731 "job-printer-up-time", time(NULL
));
4734 if (!ra
|| cupsArrayFind(ra
, "job-printer-uri"))
4736 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
4737 con
->clientname
, con
->clientport
,
4738 (job
->dtype
& CUPS_PRINTER_CLASS
) ? "/classes/%s" :
4741 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4742 "job-printer-uri", NULL
, job_uri
);
4745 if (!ra
|| cupsArrayFind(ra
, "job-uri"))
4747 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
4748 con
->clientname
, con
->clientport
, "/jobs/%d",
4750 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4751 "job-uri", NULL
, job_uri
);
4754 copy_attrs(con
->response
, job
->attrs
, ra
, IPP_TAG_JOB
, 0, exclude
);
4759 * 'copy_printer_attrs()' - Copy printer attributes.
4764 cupsd_client_t
*con
, /* I - Client connection */
4765 cupsd_printer_t
*printer
, /* I - Printer */
4766 cups_array_t
*ra
) /* I - Requested attributes array */
4768 char printer_uri
[HTTP_MAX_URI
];
4770 char printer_icons
[HTTP_MAX_URI
];
4772 time_t curtime
; /* Current time */
4773 int i
; /* Looping var */
4777 * Copy the printer attributes to the response using requested-attributes
4778 * and document-format attributes that may be provided by the client.
4781 curtime
= time(NULL
);
4783 if (!ra
|| cupsArrayFind(ra
, "marker-change-time"))
4784 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4785 "marker-change-time", printer
->marker_time
);
4787 if (printer
->num_printers
> 0 &&
4788 (!ra
|| cupsArrayFind(ra
, "member-uris")))
4790 ipp_attribute_t
*member_uris
; /* member-uris attribute */
4791 cupsd_printer_t
*p2
; /* Printer in class */
4792 ipp_attribute_t
*p2_uri
; /* printer-uri-supported for class printer */
4795 if ((member_uris
= ippAddStrings(con
->response
, IPP_TAG_PRINTER
,
4796 IPP_TAG_URI
, "member-uris",
4797 printer
->num_printers
, NULL
,
4800 for (i
= 0; i
< printer
->num_printers
; i
++)
4802 p2
= printer
->printers
[i
];
4804 if ((p2_uri
= ippFindAttribute(p2
->attrs
, "printer-uri-supported",
4805 IPP_TAG_URI
)) != NULL
)
4806 member_uris
->values
[i
].string
.text
=
4807 _cupsStrRetain(p2_uri
->values
[0].string
.text
);
4810 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
,
4811 sizeof(printer_uri
), "ipp", NULL
, con
->clientname
,
4813 (p2
->type
& CUPS_PRINTER_CLASS
) ?
4814 "/classes/%s" : "/printers/%s", p2
->name
);
4815 member_uris
->values
[i
].string
.text
= _cupsStrAlloc(printer_uri
);
4821 if (printer
->alert
&& (!ra
|| cupsArrayFind(ra
, "printer-alert")))
4822 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_STRING
,
4823 "printer-alert", NULL
, printer
->alert
);
4825 if (printer
->alert_description
&&
4826 (!ra
|| cupsArrayFind(ra
, "printer-alert-description")))
4827 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4828 "printer-alert-description", NULL
,
4829 printer
->alert_description
);
4831 if (!ra
|| cupsArrayFind(ra
, "printer-current-time"))
4832 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-current-time",
4833 ippTimeToDate(curtime
));
4835 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
4836 if (!ra
|| cupsArrayFind(ra
, "printer-dns-sd-name"))
4838 if (printer
->reg_name
)
4839 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4840 "printer-dns-sd-name", NULL
, printer
->reg_name
);
4842 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
4843 "printer-dns-sd-name", 0);
4845 #endif /* HAVE_DNSSD || HAVE_AVAHI */
4847 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy"))
4848 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4849 "printer-error-policy", NULL
, printer
->error_policy
);
4851 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy-supported"))
4853 static const char * const errors
[] =/* printer-error-policy-supported values */
4856 "retry-current-job",
4861 if (printer
->type
& CUPS_PRINTER_CLASS
)
4862 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
4863 "printer-error-policy-supported", NULL
, "retry-current-job");
4865 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
4866 "printer-error-policy-supported",
4867 sizeof(errors
) / sizeof(errors
[0]), NULL
, errors
);
4870 if (!ra
|| cupsArrayFind(ra
, "printer-icons"))
4872 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_icons
, sizeof(printer_icons
),
4873 "http", NULL
, con
->clientname
, con
->clientport
,
4874 "/icons/%s.png", printer
->name
);
4875 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-icons",
4876 NULL
, printer_icons
);
4877 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-icons=\"%s\"", printer_icons
);
4880 if (!ra
|| cupsArrayFind(ra
, "printer-is-accepting-jobs"))
4881 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs", (char)printer
->accepting
);
4883 if (!ra
|| cupsArrayFind(ra
, "printer-is-shared"))
4884 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-shared", (char)printer
->shared
);
4886 if (!ra
|| cupsArrayFind(ra
, "printer-more-info"))
4888 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
4889 "http", NULL
, con
->clientname
, con
->clientport
,
4890 (printer
->type
& CUPS_PRINTER_CLASS
) ?
4891 "/classes/%s" : "/printers/%s", printer
->name
);
4892 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
4893 "printer-more-info", NULL
, printer_uri
);
4896 if (!ra
|| cupsArrayFind(ra
, "printer-op-policy"))
4897 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4898 "printer-op-policy", NULL
, printer
->op_policy
);
4900 if (!ra
|| cupsArrayFind(ra
, "printer-state"))
4901 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
4904 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-time"))
4905 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4906 "printer-state-change-time", printer
->state_time
);
4908 if (!ra
|| cupsArrayFind(ra
, "printer-state-message"))
4909 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4910 "printer-state-message", NULL
, printer
->state_message
);
4912 if (!ra
|| cupsArrayFind(ra
, "printer-state-reasons"))
4913 add_printer_state_reasons(con
, printer
);
4915 if (!ra
|| cupsArrayFind(ra
, "printer-type"))
4917 cups_ptype_t type
; /* printer-type value */
4920 * Add the CUPS-specific printer-type attribute...
4923 type
= printer
->type
;
4925 if (printer
== DefaultPrinter
)
4926 type
|= CUPS_PRINTER_DEFAULT
;
4928 if (!printer
->accepting
)
4929 type
|= CUPS_PRINTER_REJECTING
;
4931 if (!printer
->shared
)
4932 type
|= CUPS_PRINTER_NOT_SHARED
;
4934 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-type", (int)type
);
4937 if (!ra
|| cupsArrayFind(ra
, "printer-up-time"))
4938 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4939 "printer-up-time", curtime
);
4941 if (!ra
|| cupsArrayFind(ra
, "printer-uri-supported"))
4943 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
4944 "ipp", NULL
, con
->clientname
, con
->clientport
,
4945 (printer
->type
& CUPS_PRINTER_CLASS
) ?
4946 "/classes/%s" : "/printers/%s", printer
->name
);
4947 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
4948 "printer-uri-supported", NULL
, printer_uri
);
4949 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-uri-supported=\"%s\"",
4953 if (!ra
|| cupsArrayFind(ra
, "queued-job-count"))
4954 add_queued_job_count(con
, printer
);
4956 copy_attrs(con
->response
, printer
->attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
4957 if (printer
->ppd_attrs
)
4958 copy_attrs(con
->response
, printer
->ppd_attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
4959 copy_attrs(con
->response
, CommonData
, ra
, IPP_TAG_ZERO
, IPP_TAG_COPY
, NULL
);
4964 * 'copy_subscription_attrs()' - Copy subscription attributes.
4968 copy_subscription_attrs(
4969 cupsd_client_t
*con
, /* I - Client connection */
4970 cupsd_subscription_t
*sub
, /* I - Subscription */
4971 cups_array_t
*ra
, /* I - Requested attributes array */
4972 cups_array_t
*exclude
) /* I - Private attributes array */
4974 ipp_attribute_t
*attr
; /* Current attribute */
4975 char printer_uri
[HTTP_MAX_URI
];
4977 int count
; /* Number of events */
4978 unsigned mask
; /* Current event mask */
4979 const char *name
; /* Current event name */
4982 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4983 "copy_subscription_attrs(con=%p, sub=%p, ra=%p, exclude=%p)",
4984 con
, sub
, ra
, exclude
);
4987 * Copy the subscription attributes to the response using the
4988 * requested-attributes attribute that may be provided by the client.
4991 if (!exclude
|| !cupsArrayFind(exclude
, "all"))
4993 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-events")) &&
4994 (!ra
|| cupsArrayFind(ra
, "notify-events")))
4996 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_subscription_attrs: notify-events");
4998 if ((name
= cupsdEventName((cupsd_eventmask_t
)sub
->mask
)) != NULL
)
5001 * Simple event list...
5004 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
,
5005 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5006 "notify-events", NULL
, name
);
5011 * Complex event list...
5014 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5015 if (sub
->mask
& mask
)
5018 attr
= ippAddStrings(con
->response
, IPP_TAG_SUBSCRIPTION
,
5019 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5020 "notify-events", count
, NULL
, NULL
);
5022 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5023 if (sub
->mask
& mask
)
5025 attr
->values
[count
].string
.text
=
5026 (char *)cupsdEventName((cupsd_eventmask_t
)mask
);
5033 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-lease-duration")) &&
5034 (!sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-lease-duration"))))
5035 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5036 "notify-lease-duration", sub
->lease
);
5038 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-recipient-uri")) &&
5039 (sub
->recipient
&& (!ra
|| cupsArrayFind(ra
, "notify-recipient-uri"))))
5040 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5041 "notify-recipient-uri", NULL
, sub
->recipient
);
5042 else if ((!exclude
|| !cupsArrayFind(exclude
, "notify-pull-method")) &&
5043 (!ra
|| cupsArrayFind(ra
, "notify-pull-method")))
5044 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_KEYWORD
,
5045 "notify-pull-method", NULL
, "ippget");
5047 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-subscriber-user-name")) &&
5048 (!ra
|| cupsArrayFind(ra
, "notify-subscriber-user-name")))
5049 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_NAME
,
5050 "notify-subscriber-user-name", NULL
, sub
->owner
);
5052 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-time-interval")) &&
5053 (!ra
|| cupsArrayFind(ra
, "notify-time-interval")))
5054 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5055 "notify-time-interval", sub
->interval
);
5057 if (sub
->user_data_len
> 0 &&
5058 (!exclude
|| !cupsArrayFind(exclude
, "notify-user-data")) &&
5059 (!ra
|| cupsArrayFind(ra
, "notify-user-data")))
5060 ippAddOctetString(con
->response
, IPP_TAG_SUBSCRIPTION
, "notify-user-data",
5061 sub
->user_data
, sub
->user_data_len
);
5064 if (sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-job-id")))
5065 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5066 "notify-job-id", sub
->job
->id
);
5068 if (sub
->dest
&& (!ra
|| cupsArrayFind(ra
, "notify-printer-uri")))
5070 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5071 "ipp", NULL
, con
->clientname
, con
->clientport
,
5072 "/printers/%s", sub
->dest
->name
);
5073 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5074 "notify-printer-uri", NULL
, printer_uri
);
5077 if (!ra
|| cupsArrayFind(ra
, "notify-subscription-id"))
5078 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5079 "notify-subscription-id", sub
->id
);
5084 * 'create_job()' - Print a file to a printer or class.
5088 create_job(cupsd_client_t
*con
, /* I - Client connection */
5089 ipp_attribute_t
*uri
) /* I - Printer URI */
5091 int i
; /* Looping var */
5092 cupsd_printer_t
*printer
; /* Printer */
5093 cupsd_job_t
*job
; /* New job */
5094 static const char * const forbidden_attrs
[] =
5095 { /* List of forbidden attributes */
5099 "document-natural-language"
5103 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "create_job(%p[%d], %s)", con
,
5104 con
->number
, uri
->values
[0].string
.text
);
5107 * Is the destination valid?
5110 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
5116 send_ipp_status(con
, IPP_NOT_FOUND
,
5117 _("The printer or class does not exist."));
5122 * Check for invalid Create-Job attributes and log a warning or error depending
5123 * on whether cupsd is running in "strict conformance" mode...
5127 i
< (int)(sizeof(forbidden_attrs
) / sizeof(forbidden_attrs
[0]));
5129 if (ippFindAttribute(con
->request
, forbidden_attrs
[i
], IPP_TAG_ZERO
))
5131 if (StrictConformance
)
5133 send_ipp_status(con
, IPP_BAD_REQUEST
,
5134 _("The '%s' operation attribute cannot be supplied in a "
5135 "Create-Job request."), forbidden_attrs
[i
]);
5139 cupsdLogMessage(CUPSD_LOG_WARN
,
5140 "Unexpected '%s' operation attribute in a Create-Job "
5141 "request.", forbidden_attrs
[i
]);
5145 * Create the job object...
5148 if ((job
= add_job(con
, printer
, NULL
)) == NULL
)
5151 job
->pending_timeout
= 1;
5154 * Save and log the job...
5157 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
5158 job
->dest
, job
->username
);
5163 * 'create_requested_array()' - Create an array for the requested-attributes.
5166 static cups_array_t
* /* O - Array of attributes or NULL */
5167 create_requested_array(ipp_t
*request
) /* I - IPP request */
5169 cups_array_t
*ra
; /* Requested attributes array */
5173 * Create the array for standard attributes...
5176 ra
= ippCreateRequestedArray(request
);
5179 * Add CUPS defaults as needed...
5182 if (cupsArrayFind(ra
, "printer-defaults"))
5185 * Include user-set defaults...
5188 char *name
; /* Option name */
5190 cupsArrayRemove(ra
, "printer-defaults");
5192 for (name
= (char *)cupsArrayFirst(CommonDefaults
);
5194 name
= (char *)cupsArrayNext(CommonDefaults
))
5195 if (!cupsArrayFind(ra
, name
))
5196 cupsArrayAdd(ra
, name
);
5204 * 'create_subscriptions()' - Create one or more notification subscriptions.
5208 create_subscriptions(
5209 cupsd_client_t
*con
, /* I - Client connection */
5210 ipp_attribute_t
*uri
) /* I - Printer URI */
5212 http_status_t status
; /* Policy status */
5213 int i
; /* Looping var */
5214 ipp_attribute_t
*attr
; /* Current attribute */
5215 cups_ptype_t dtype
; /* Destination type (printer/class) */
5216 char scheme
[HTTP_MAX_URI
],
5217 /* Scheme portion of URI */
5218 userpass
[HTTP_MAX_URI
],
5219 /* Username portion of URI */
5221 /* Host portion of URI */
5222 resource
[HTTP_MAX_URI
];
5223 /* Resource portion of URI */
5224 int port
; /* Port portion of URI */
5225 cupsd_printer_t
*printer
; /* Printer/class */
5226 cupsd_job_t
*job
; /* Job */
5227 int jobid
; /* Job ID */
5228 cupsd_subscription_t
*sub
; /* Subscription object */
5229 const char *username
, /* requesting-user-name or
5230 authenticated username */
5231 *recipient
, /* notify-recipient-uri */
5232 *pullmethod
; /* notify-pull-method */
5233 ipp_attribute_t
*user_data
; /* notify-user-data */
5234 int interval
, /* notify-time-interval */
5235 lease
; /* notify-lease-duration */
5236 unsigned mask
; /* notify-events */
5237 ipp_attribute_t
*notify_events
,/* notify-events(-default) */
5238 *notify_lease
; /* notify-lease-duration(-default) */
5242 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
5244 if (attr
->group_tag
!= IPP_TAG_ZERO
)
5245 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "g%04x v%04x %s", attr
->group_tag
,
5246 attr
->value_tag
, attr
->name
);
5248 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "----SEP----");
5253 * Is the destination valid?
5256 cupsdLogMessage(CUPSD_LOG_DEBUG
, "create_subscriptions(con=%p(%d), uri=\"%s\")", con
, con
->number
, uri
->values
[0].string
.text
);
5258 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
5259 sizeof(scheme
), userpass
, sizeof(userpass
), host
,
5260 sizeof(host
), &port
, resource
, sizeof(resource
));
5262 if (!strcmp(resource
, "/"))
5264 dtype
= (cups_ptype_t
)0;
5267 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
5269 dtype
= (cups_ptype_t
)0;
5272 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
5274 dtype
= CUPS_PRINTER_CLASS
;
5277 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
5283 send_ipp_status(con
, IPP_NOT_FOUND
,
5284 _("The printer or class does not exist."));
5294 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
5297 send_http_error(con
, status
, printer
);
5301 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5303 send_http_error(con
, status
, NULL
);
5308 * Get the user that is requesting the subscription...
5311 username
= get_username(con
);
5314 * Find the first subscription group attribute; return if we have
5318 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
5319 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
5324 send_ipp_status(con
, IPP_BAD_REQUEST
,
5325 _("No subscription attributes in request."));
5330 * Process the subscription attributes in the request...
5333 con
->response
->request
.status
.status_code
= IPP_BAD_REQUEST
;
5341 lease
= DefaultLeaseDuration
;
5343 mask
= CUPSD_EVENT_NONE
;
5347 notify_events
= ippFindAttribute(printer
->attrs
, "notify-events-default",
5349 notify_lease
= ippFindAttribute(printer
->attrs
,
5350 "notify-lease-duration-default",
5354 lease
= notify_lease
->values
[0].integer
;
5358 notify_events
= NULL
;
5359 notify_lease
= NULL
;
5362 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
5364 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
5365 attr
->value_tag
== IPP_TAG_URI
)
5368 * Validate the recipient scheme against the ServerBin/notifier
5372 char notifier
[1024]; /* Notifier filename */
5375 recipient
= attr
->values
[0].string
.text
;
5377 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
5378 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
5379 host
, sizeof(host
), &port
,
5380 resource
, sizeof(resource
)) < HTTP_URI_OK
)
5382 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5383 _("Bad notify-recipient-uri \"%s\"."), recipient
);
5384 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5385 "notify-status-code", IPP_URI_SCHEME
);
5389 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
5391 if (access(notifier
, X_OK
))
5393 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5394 _("notify-recipient-uri URI \"%s\" uses unknown "
5395 "scheme."), recipient
);
5396 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5397 "notify-status-code", IPP_URI_SCHEME
);
5401 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
5403 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5404 _("notify-recipient-uri URI \"%s\" is already used."),
5406 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5407 "notify-status-code", IPP_ATTRIBUTES
);
5411 else if (!strcmp(attr
->name
, "notify-pull-method") &&
5412 attr
->value_tag
== IPP_TAG_KEYWORD
)
5414 pullmethod
= attr
->values
[0].string
.text
;
5416 if (strcmp(pullmethod
, "ippget"))
5418 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5419 _("Bad notify-pull-method \"%s\"."), pullmethod
);
5420 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5421 "notify-status-code", IPP_ATTRIBUTES
);
5425 else if (!strcmp(attr
->name
, "notify-charset") &&
5426 attr
->value_tag
== IPP_TAG_CHARSET
&&
5427 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
5428 strcmp(attr
->values
[0].string
.text
, "utf-8"))
5430 send_ipp_status(con
, IPP_CHARSET
,
5431 _("Character set \"%s\" not supported."),
5432 attr
->values
[0].string
.text
);
5435 else if (!strcmp(attr
->name
, "notify-natural-language") &&
5436 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
5437 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
5439 send_ipp_status(con
, IPP_CHARSET
,
5440 _("Language \"%s\" not supported."),
5441 attr
->values
[0].string
.text
);
5444 else if (!strcmp(attr
->name
, "notify-user-data") &&
5445 attr
->value_tag
== IPP_TAG_STRING
)
5447 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
5449 send_ipp_status(con
, IPP_REQUEST_VALUE
,
5450 _("The notify-user-data value is too large "
5451 "(%d > 63 octets)."),
5452 attr
->values
[0].unknown
.length
);
5458 else if (!strcmp(attr
->name
, "notify-events") &&
5459 attr
->value_tag
== IPP_TAG_KEYWORD
)
5460 notify_events
= attr
;
5461 else if (!strcmp(attr
->name
, "notify-lease-duration") &&
5462 attr
->value_tag
== IPP_TAG_INTEGER
)
5463 lease
= attr
->values
[0].integer
;
5464 else if (!strcmp(attr
->name
, "notify-time-interval") &&
5465 attr
->value_tag
== IPP_TAG_INTEGER
)
5466 interval
= attr
->values
[0].integer
;
5467 else if (!strcmp(attr
->name
, "notify-job-id") &&
5468 attr
->value_tag
== IPP_TAG_INTEGER
)
5469 jobid
= attr
->values
[0].integer
;
5476 for (i
= 0; i
< notify_events
->num_values
; i
++)
5477 mask
|= cupsdEventValue(notify_events
->values
[i
].string
.text
);
5481 cupsdLogMessage(CUPSD_LOG_DEBUG
, "recipient=\"%s\"", recipient
);
5483 cupsdLogMessage(CUPSD_LOG_DEBUG
, "pullmethod=\"%s\"", pullmethod
);
5484 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-lease-duration=%d", lease
);
5485 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-time-interval=%d", interval
);
5487 if (!recipient
&& !pullmethod
)
5490 if (mask
== CUPSD_EVENT_NONE
)
5493 mask
= CUPSD_EVENT_JOB_COMPLETED
;
5495 mask
= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
5498 send_ipp_status(con
, IPP_BAD_REQUEST
,
5499 _("notify-events not specified."));
5504 if (MaxLeaseDuration
&& (lease
== 0 || lease
> MaxLeaseDuration
))
5506 cupsdLogMessage(CUPSD_LOG_INFO
,
5507 "create_subscriptions: Limiting notify-lease-duration to "
5510 lease
= MaxLeaseDuration
;
5515 if ((job
= cupsdFindJob(jobid
)) == NULL
)
5517 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
5525 if ((sub
= cupsdAddSubscription(mask
, printer
, job
, recipient
, 0)) == NULL
)
5527 send_ipp_status(con
, IPP_TOO_MANY_SUBSCRIPTIONS
,
5528 _("There are too many subscriptions."));
5533 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription #%d for job %d.",
5536 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5537 "Added subscription #%d for printer \"%s\".",
5538 sub
->id
, printer
->name
);
5540 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription #%d for server.",
5543 sub
->interval
= interval
;
5545 sub
->expire
= lease
? time(NULL
) + lease
: 0;
5547 cupsdSetString(&sub
->owner
, username
);
5551 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
5552 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
5553 (size_t)sub
->user_data_len
);
5556 ippAddSeparator(con
->response
);
5557 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5558 "notify-subscription-id", sub
->id
);
5560 con
->response
->request
.status
.status_code
= IPP_OK
;
5566 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
5571 * 'delete_printer()' - Remove a printer or class from the system.
5575 delete_printer(cupsd_client_t
*con
, /* I - Client connection */
5576 ipp_attribute_t
*uri
) /* I - URI of printer or class */
5578 http_status_t status
; /* Policy status */
5579 cups_ptype_t dtype
; /* Destination type (printer/class) */
5580 cupsd_printer_t
*printer
; /* Printer/class */
5581 char filename
[1024]; /* Script/PPD filename */
5584 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "delete_printer(%p[%d], %s)", con
,
5585 con
->number
, uri
->values
[0].string
.text
);
5588 * Do we have a valid URI?
5591 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
5597 send_ipp_status(con
, IPP_NOT_FOUND
,
5598 _("The printer or class does not exist."));
5606 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5608 send_http_error(con
, status
, NULL
);
5613 * Remove old jobs...
5616 cupsdCancelJobs(printer
->name
, NULL
, 1);
5619 * Remove old subscriptions and send a "deleted printer" event...
5622 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED
, printer
, NULL
,
5623 "%s \"%s\" deleted by \"%s\".",
5624 (dtype
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
5625 printer
->name
, get_username(con
));
5627 cupsdExpireSubscriptions(printer
, NULL
);
5630 * Remove any old PPD or script files...
5633 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
,
5636 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s.O", ServerRoot
,
5640 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
5643 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd.O", ServerRoot
,
5647 snprintf(filename
, sizeof(filename
), "%s/%s.png", CacheDir
, printer
->name
);
5650 snprintf(filename
, sizeof(filename
), "%s/%s.data", CacheDir
, printer
->name
);
5654 * Unregister color profiles...
5657 cupsdUnregisterColor(printer
);
5659 if (dtype
& CUPS_PRINTER_CLASS
)
5661 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" deleted by \"%s\".",
5662 printer
->name
, get_username(con
));
5664 cupsdDeletePrinter(printer
, 0);
5665 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
5669 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" deleted by \"%s\".",
5670 printer
->name
, get_username(con
));
5672 if (cupsdDeletePrinter(printer
, 0))
5673 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
5675 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
5678 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
5681 * Return with no errors...
5684 con
->response
->request
.status
.status_code
= IPP_OK
;
5689 * 'get_default()' - Get the default destination.
5693 get_default(cupsd_client_t
*con
) /* I - Client connection */
5695 http_status_t status
; /* Policy status */
5696 cups_array_t
*ra
; /* Requested attributes array */
5699 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_default(%p[%d])", con
, con
->number
);
5705 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5707 send_http_error(con
, status
, NULL
);
5713 ra
= create_requested_array(con
->request
);
5715 copy_printer_attrs(con
, DefaultPrinter
, ra
);
5717 cupsArrayDelete(ra
);
5719 con
->response
->request
.status
.status_code
= IPP_OK
;
5722 send_ipp_status(con
, IPP_NOT_FOUND
, _("No default printer."));
5727 * 'get_devices()' - Get the list of available devices on the local system.
5731 get_devices(cupsd_client_t
*con
) /* I - Client connection */
5733 http_status_t status
; /* Policy status */
5734 ipp_attribute_t
*limit
, /* limit attribute */
5735 *timeout
, /* timeout attribute */
5736 *requested
, /* requested-attributes attribute */
5737 *exclude
, /* exclude-schemes attribute */
5738 *include
; /* include-schemes attribute */
5739 char command
[1024], /* cups-deviced command */
5740 options
[2048], /* Options to pass to command */
5742 /* String for requested attributes */
5744 /* String for excluded schemes */
5746 /* String for included schemes */
5749 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_devices(%p[%d])", con
, con
->number
);
5755 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5757 send_http_error(con
, status
, NULL
);
5762 * Run cups-deviced command with the given options...
5765 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
5766 timeout
= ippFindAttribute(con
->request
, "timeout", IPP_TAG_INTEGER
);
5767 requested
= ippFindAttribute(con
->request
, "requested-attributes",
5769 exclude
= ippFindAttribute(con
->request
, "exclude-schemes", IPP_TAG_NAME
);
5770 include
= ippFindAttribute(con
->request
, "include-schemes", IPP_TAG_NAME
);
5773 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
5775 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
5778 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
5780 exclude_str
[0] = '\0';
5783 url_encode_attr(include
, include_str
, sizeof(include_str
));
5785 include_str
[0] = '\0';
5787 snprintf(command
, sizeof(command
), "%s/daemon/cups-deviced", ServerBin
);
5788 snprintf(options
, sizeof(options
),
5789 "%d+%d+%d+%d+%s%s%s%s%s",
5790 con
->request
->request
.op
.request_id
,
5791 limit
? limit
->values
[0].integer
: 0,
5792 timeout
? timeout
->values
[0].integer
: 15,
5795 exclude_str
[0] ? "%20" : "", exclude_str
,
5796 include_str
[0] ? "%20" : "", include_str
);
5798 if (cupsdSendCommand(con
, command
, options
, 1))
5801 * Command started successfully, don't send an IPP response here...
5804 ippDelete(con
->response
);
5805 con
->response
= NULL
;
5810 * Command failed, return "internal error" so the user knows something
5814 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
5815 _("cups-deviced failed to execute."));
5821 * 'get_document()' - Get a copy of a job file.
5825 get_document(cupsd_client_t
*con
, /* I - Client connection */
5826 ipp_attribute_t
*uri
) /* I - Job URI */
5828 http_status_t status
; /* Policy status */
5829 ipp_attribute_t
*attr
; /* Current attribute */
5830 int jobid
; /* Job ID */
5831 int docnum
; /* Document number */
5832 cupsd_job_t
*job
; /* Current job */
5833 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
5834 username
[HTTP_MAX_URI
], /* Username portion of URI */
5835 host
[HTTP_MAX_URI
], /* Host portion of URI */
5836 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
5837 int port
; /* Port portion of URI */
5838 char filename
[1024], /* Filename for document */
5839 format
[1024]; /* Format for document */
5842 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_document(%p[%d], %s)", con
,
5843 con
->number
, uri
->values
[0].string
.text
);
5846 * See if we have a job URI or a printer URI...
5849 if (!strcmp(uri
->name
, "printer-uri"))
5852 * Got a printer URI; see if we also have a job-id attribute...
5855 if ((attr
= ippFindAttribute(con
->request
, "job-id",
5856 IPP_TAG_INTEGER
)) == NULL
)
5858 send_ipp_status(con
, IPP_BAD_REQUEST
,
5859 _("Got a printer-uri attribute but no job-id."));
5863 jobid
= attr
->values
[0].integer
;
5868 * Got a job URI; parse it to get the job ID...
5871 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
5872 sizeof(scheme
), username
, sizeof(username
), host
,
5873 sizeof(host
), &port
, resource
, sizeof(resource
));
5875 if (strncmp(resource
, "/jobs/", 6))
5881 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
5882 uri
->values
[0].string
.text
);
5886 jobid
= atoi(resource
+ 6);
5890 * See if the job exists...
5893 if ((job
= cupsdFindJob(jobid
)) == NULL
)
5896 * Nope - return a "not found" error...
5899 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
5907 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
,
5908 job
->username
)) != HTTP_OK
)
5910 send_http_error(con
, status
, NULL
);
5915 * Get the document number...
5918 if ((attr
= ippFindAttribute(con
->request
, "document-number",
5919 IPP_TAG_INTEGER
)) == NULL
)
5921 send_ipp_status(con
, IPP_BAD_REQUEST
,
5922 _("Missing document-number attribute."));
5926 if ((docnum
= attr
->values
[0].integer
) < 1 || docnum
> job
->num_files
||
5927 attr
->num_values
> 1)
5929 send_ipp_status(con
, IPP_NOT_FOUND
,
5930 _("Document #%d does not exist in job #%d."), docnum
,
5935 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, jobid
,
5937 if ((con
->file
= open(filename
, O_RDONLY
)) == -1)
5939 cupsdLogMessage(CUPSD_LOG_ERROR
,
5940 "Unable to open document %d in job %d - %s", docnum
, jobid
,
5942 send_ipp_status(con
, IPP_NOT_FOUND
,
5943 _("Unable to open document #%d in job #%d."), docnum
,
5948 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
5952 snprintf(format
, sizeof(format
), "%s/%s", job
->filetypes
[docnum
- 1]->super
,
5953 job
->filetypes
[docnum
- 1]->type
);
5955 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format",
5957 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "document-number",
5959 if ((attr
= ippFindAttribute(job
->attrs
, "document-name",
5960 IPP_TAG_NAME
)) != NULL
)
5961 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name",
5962 NULL
, attr
->values
[0].string
.text
);
5967 * 'get_job_attrs()' - Get job attributes.
5971 get_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
5972 ipp_attribute_t
*uri
) /* I - Job URI */
5974 http_status_t status
; /* Policy status */
5975 ipp_attribute_t
*attr
; /* Current attribute */
5976 int jobid
; /* Job ID */
5977 cupsd_job_t
*job
; /* Current job */
5978 cupsd_printer_t
*printer
; /* Current printer */
5979 cupsd_policy_t
*policy
; /* Current security policy */
5980 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
5981 username
[HTTP_MAX_URI
], /* Username portion of URI */
5982 host
[HTTP_MAX_URI
], /* Host portion of URI */
5983 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
5984 int port
; /* Port portion of URI */
5985 cups_array_t
*ra
, /* Requested attributes array */
5986 *exclude
; /* Private attributes array */
5989 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_job_attrs(%p[%d], %s)", con
,
5990 con
->number
, uri
->values
[0].string
.text
);
5993 * See if we have a job URI or a printer URI...
5996 if (!strcmp(uri
->name
, "printer-uri"))
5999 * Got a printer URI; see if we also have a job-id attribute...
6002 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6003 IPP_TAG_INTEGER
)) == NULL
)
6005 send_ipp_status(con
, IPP_BAD_REQUEST
,
6006 _("Got a printer-uri attribute but no job-id."));
6010 jobid
= attr
->values
[0].integer
;
6015 * Got a job URI; parse it to get the job ID...
6018 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6019 sizeof(scheme
), username
, sizeof(username
), host
,
6020 sizeof(host
), &port
, resource
, sizeof(resource
));
6022 if (strncmp(resource
, "/jobs/", 6))
6028 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
6029 uri
->values
[0].string
.text
);
6033 jobid
= atoi(resource
+ 6);
6037 * See if the job exists...
6040 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6043 * Nope - return a "not found" error...
6046 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
6054 if ((printer
= job
->printer
) == NULL
)
6055 printer
= cupsdFindDest(job
->dest
);
6058 policy
= printer
->op_policy_ptr
;
6060 policy
= DefaultPolicyPtr
;
6062 if ((status
= cupsdCheckPolicy(policy
, con
, job
->username
)) != HTTP_OK
)
6064 send_http_error(con
, status
, NULL
);
6068 exclude
= cupsdGetPrivateAttrs(policy
, con
, printer
, job
->username
);
6071 * Copy attributes...
6076 ra
= create_requested_array(con
->request
);
6077 copy_job_attrs(con
, job
, ra
, exclude
);
6078 cupsArrayDelete(ra
);
6080 con
->response
->request
.status
.status_code
= IPP_OK
;
6085 * 'get_jobs()' - Get a list of jobs for the specified printer.
6089 get_jobs(cupsd_client_t
*con
, /* I - Client connection */
6090 ipp_attribute_t
*uri
) /* I - Printer URI */
6092 http_status_t status
; /* Policy status */
6093 ipp_attribute_t
*attr
; /* Current attribute */
6094 const char *dest
; /* Destination */
6095 cups_ptype_t dtype
; /* Destination type (printer/class) */
6096 cups_ptype_t dmask
; /* Destination type mask */
6097 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6098 username
[HTTP_MAX_URI
], /* Username portion of URI */
6099 host
[HTTP_MAX_URI
], /* Host portion of URI */
6100 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6101 int port
; /* Port portion of URI */
6102 int job_comparison
; /* Job comparison */
6103 ipp_jstate_t job_state
; /* job-state value */
6104 int first_job_id
; /* First job ID */
6105 int limit
; /* Maximum number of jobs to return */
6106 int count
; /* Number of jobs that match */
6107 ipp_attribute_t
*job_ids
; /* job-ids attribute */
6108 cupsd_job_t
*job
; /* Current job pointer */
6109 cupsd_printer_t
*printer
; /* Printer */
6110 cups_array_t
*list
; /* Which job list... */
6111 cups_array_t
*ra
, /* Requested attributes array */
6112 *exclude
; /* Private attributes array */
6113 cupsd_policy_t
*policy
; /* Current policy */
6116 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs(%p[%d], %s)", con
, con
->number
,
6117 uri
->values
[0].string
.text
);
6120 * Is the destination valid?
6123 if (strcmp(uri
->name
, "printer-uri"))
6125 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No printer-uri in request."));
6129 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6130 sizeof(scheme
), username
, sizeof(username
), host
,
6131 sizeof(host
), &port
, resource
, sizeof(resource
));
6133 if (!strcmp(resource
, "/") || !strcmp(resource
, "/jobs"))
6136 dtype
= (cups_ptype_t
)0;
6137 dmask
= (cups_ptype_t
)0;
6140 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6143 dtype
= (cups_ptype_t
)0;
6144 dmask
= CUPS_PRINTER_CLASS
;
6147 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6150 dtype
= CUPS_PRINTER_CLASS
;
6151 dmask
= CUPS_PRINTER_CLASS
;
6154 else if ((dest
= cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
,
6161 send_ipp_status(con
, IPP_NOT_FOUND
,
6162 _("The printer or class does not exist."));
6167 dtype
&= CUPS_PRINTER_CLASS
;
6168 dmask
= CUPS_PRINTER_CLASS
;
6176 policy
= printer
->op_policy_ptr
;
6178 policy
= DefaultPolicyPtr
;
6180 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
6182 send_http_error(con
, status
, NULL
);
6186 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
6189 * See if the "which-jobs" attribute have been specified...
6192 if ((attr
= ippFindAttribute(con
->request
, "which-jobs",
6193 IPP_TAG_KEYWORD
)) != NULL
&& job_ids
)
6195 send_ipp_status(con
, IPP_CONFLICT
,
6196 _("The %s attribute cannot be provided with job-ids."),
6200 else if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "not-completed"))
6202 job_comparison
= -1;
6203 job_state
= IPP_JOB_STOPPED
;
6206 else if (!strcmp(attr
->values
[0].string
.text
, "completed"))
6209 job_state
= IPP_JOB_CANCELED
;
6212 else if (!strcmp(attr
->values
[0].string
.text
, "aborted"))
6215 job_state
= IPP_JOB_ABORTED
;
6218 else if (!strcmp(attr
->values
[0].string
.text
, "all"))
6221 job_state
= IPP_JOB_PENDING
;
6224 else if (!strcmp(attr
->values
[0].string
.text
, "canceled"))
6227 job_state
= IPP_JOB_CANCELED
;
6230 else if (!strcmp(attr
->values
[0].string
.text
, "pending"))
6233 job_state
= IPP_JOB_PENDING
;
6236 else if (!strcmp(attr
->values
[0].string
.text
, "pending-held"))
6239 job_state
= IPP_JOB_HELD
;
6242 else if (!strcmp(attr
->values
[0].string
.text
, "processing"))
6245 job_state
= IPP_JOB_PROCESSING
;
6246 list
= PrintingJobs
;
6248 else if (!strcmp(attr
->values
[0].string
.text
, "processing-stopped"))
6251 job_state
= IPP_JOB_STOPPED
;
6256 send_ipp_status(con
, IPP_ATTRIBUTES
,
6257 _("The which-jobs value \"%s\" is not supported."),
6258 attr
->values
[0].string
.text
);
6259 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
6260 "which-jobs", NULL
, attr
->values
[0].string
.text
);
6265 * See if they want to limit the number of jobs reported...
6268 if ((attr
= ippFindAttribute(con
->request
, "limit",
6269 IPP_TAG_INTEGER
)) != NULL
)
6273 send_ipp_status(con
, IPP_CONFLICT
,
6274 _("The %s attribute cannot be provided with job-ids."),
6279 limit
= attr
->values
[0].integer
;
6284 if ((attr
= ippFindAttribute(con
->request
, "first-job-id",
6285 IPP_TAG_INTEGER
)) != NULL
)
6289 send_ipp_status(con
, IPP_CONFLICT
,
6290 _("The %s attribute cannot be provided with job-ids."),
6295 first_job_id
= attr
->values
[0].integer
;
6301 * See if we only want to see jobs for a specific user...
6304 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
6305 IPP_TAG_BOOLEAN
)) != NULL
&& job_ids
)
6307 send_ipp_status(con
, IPP_CONFLICT
,
6308 _("The %s attribute cannot be provided with job-ids."),
6312 else if (attr
&& attr
->values
[0].boolean
)
6313 strlcpy(username
, get_username(con
), sizeof(username
));
6317 ra
= create_requested_array(con
->request
);
6320 * OK, build a list of jobs for this printer...
6325 int i
; /* Looping var */
6327 for (i
= 0; i
< job_ids
->num_values
; i
++)
6329 if (!cupsdFindJob(job_ids
->values
[i
].integer
))
6333 if (i
< job_ids
->num_values
)
6335 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
6336 job_ids
->values
[i
].integer
);
6340 for (i
= 0; i
< job_ids
->num_values
; i
++)
6342 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
6348 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d",
6354 ippAddSeparator(con
->response
);
6356 exclude
= cupsdGetPrivateAttrs(job
->printer
?
6357 job
->printer
->op_policy_ptr
:
6358 policy
, con
, job
->printer
,
6361 copy_job_attrs(con
, job
, ra
, exclude
);
6366 for (count
= 0, job
= (cupsd_job_t
*)cupsArrayFirst(list
);
6367 (limit
<= 0 || count
< limit
) && job
;
6368 job
= (cupsd_job_t
*)cupsArrayNext(list
))
6371 * Filter out jobs that don't match...
6374 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
6375 "get_jobs: job->id=%d, dest=\"%s\", username=\"%s\", "
6376 "state_value=%d, attrs=%p", job
->id
, job
->dest
,
6377 job
->username
, job
->state_value
, job
->attrs
);
6379 if (!job
->dest
|| !job
->username
)
6382 if (!job
->dest
|| !job
->username
)
6385 if ((dest
&& strcmp(job
->dest
, dest
)) &&
6386 (!job
->printer
|| !dest
|| strcmp(job
->printer
->name
, dest
)))
6388 if ((job
->dtype
& dmask
) != dtype
&&
6389 (!job
->printer
|| (job
->printer
->type
& dmask
) != dtype
))
6392 if ((job_comparison
< 0 && job
->state_value
> job_state
) ||
6393 (job_comparison
== 0 && job
->state_value
!= job_state
) ||
6394 (job_comparison
> 0 && job
->state_value
< job_state
))
6397 if (job
->id
< first_job_id
)
6404 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d",
6409 if (username
[0] && _cups_strcasecmp(username
, job
->username
))
6413 ippAddSeparator(con
->response
);
6417 exclude
= cupsdGetPrivateAttrs(job
->printer
?
6418 job
->printer
->op_policy_ptr
:
6419 policy
, con
, job
->printer
,
6422 copy_job_attrs(con
, job
, ra
, exclude
);
6425 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: count=%d", count
);
6428 cupsArrayDelete(ra
);
6430 con
->response
->request
.status
.status_code
= IPP_OK
;
6435 * 'get_notifications()' - Get events for a subscription.
6439 get_notifications(cupsd_client_t
*con
) /* I - Client connection */
6441 int i
, j
; /* Looping vars */
6442 http_status_t status
; /* Policy status */
6443 cupsd_subscription_t
*sub
; /* Subscription */
6444 ipp_attribute_t
*ids
, /* notify-subscription-ids */
6445 *sequences
; /* notify-sequence-numbers */
6446 int min_seq
; /* Minimum sequence number */
6447 int interval
; /* Poll interval */
6450 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_notifications(con=%p[%d])",
6454 * Get subscription attributes...
6457 ids
= ippFindAttribute(con
->request
, "notify-subscription-ids",
6459 sequences
= ippFindAttribute(con
->request
, "notify-sequence-numbers",
6464 send_ipp_status(con
, IPP_BAD_REQUEST
,
6465 _("Missing notify-subscription-ids attribute."));
6470 * Are the subscription IDs valid?
6473 for (i
= 0, interval
= 60; i
< ids
->num_values
; i
++)
6475 if ((sub
= cupsdFindSubscription(ids
->values
[i
].integer
)) == NULL
)
6478 * Bad subscription ID...
6481 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
6482 ids
->values
[i
].integer
);
6490 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
6492 con
, sub
->owner
)) != HTTP_OK
)
6494 send_http_error(con
, status
, sub
->dest
);
6499 * Check the subscription type and update the interval accordingly.
6502 if (sub
->job
&& sub
->job
->state_value
== IPP_JOB_PROCESSING
&&
6505 else if (sub
->job
&& sub
->job
->state_value
>= IPP_JOB_STOPPED
)
6507 else if (sub
->dest
&& sub
->dest
->state
== IPP_PRINTER_PROCESSING
&&
6513 * Tell the client to poll again in N seconds...
6517 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
6518 "notify-get-interval", interval
);
6520 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
6521 "printer-up-time", time(NULL
));
6524 * Copy the subscription event attributes to the response.
6527 con
->response
->request
.status
.status_code
=
6528 interval
? IPP_OK
: IPP_OK_EVENTS_COMPLETE
;
6530 for (i
= 0; i
< ids
->num_values
; i
++)
6533 * Get the subscription and sequence number...
6536 sub
= cupsdFindSubscription(ids
->values
[i
].integer
);
6538 if (sequences
&& i
< sequences
->num_values
)
6539 min_seq
= sequences
->values
[i
].integer
;
6544 * If we don't have any new events, nothing to do here...
6547 if (min_seq
> (sub
->first_event_id
+ cupsArrayCount(sub
->events
)))
6551 * Otherwise copy all of the new events...
6554 if (sub
->first_event_id
> min_seq
)
6557 j
= min_seq
- sub
->first_event_id
;
6559 for (; j
< cupsArrayCount(sub
->events
); j
++)
6561 ippAddSeparator(con
->response
);
6563 copy_attrs(con
->response
,
6564 ((cupsd_event_t
*)cupsArrayIndex(sub
->events
, j
))->attrs
, NULL
,
6565 IPP_TAG_EVENT_NOTIFICATION
, 0, NULL
);
6572 * 'get_ppd()' - Get a named PPD from the local system.
6576 get_ppd(cupsd_client_t
*con
, /* I - Client connection */
6577 ipp_attribute_t
*uri
) /* I - Printer URI or PPD name */
6579 http_status_t status
; /* Policy status */
6580 cupsd_printer_t
*dest
; /* Destination */
6581 cups_ptype_t dtype
; /* Destination type */
6584 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppd(%p[%d], %p[%s=%s])", con
,
6585 con
->number
, uri
, uri
->name
, uri
->values
[0].string
.text
);
6587 if (!strcmp(uri
->name
, "ppd-name"))
6590 * Return a PPD file from cups-driverd...
6593 char command
[1024], /* cups-driverd command */
6594 options
[1024], /* Options to pass to command */
6595 ppd_name
[1024]; /* ppd-name */
6602 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6604 send_http_error(con
, status
, NULL
);
6609 * Run cups-driverd command with the given options...
6612 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
6613 url_encode_string(uri
->values
[0].string
.text
, ppd_name
, sizeof(ppd_name
));
6614 snprintf(options
, sizeof(options
), "get+%d+%s",
6615 con
->request
->request
.op
.request_id
, ppd_name
);
6617 if (cupsdSendCommand(con
, command
, options
, 0))
6620 * Command started successfully, don't send an IPP response here...
6623 ippDelete(con
->response
);
6624 con
->response
= NULL
;
6629 * Command failed, return "internal error" so the user knows something
6633 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
6634 _("cups-driverd failed to execute."));
6637 else if (!strcmp(uri
->name
, "printer-uri") &&
6638 cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &dest
))
6640 int i
; /* Looping var */
6641 char filename
[1024]; /* PPD filename */
6648 if ((status
= cupsdCheckPolicy(dest
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
6650 send_http_error(con
, status
, dest
);
6655 * See if we need the PPD for a class or remote printer...
6658 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
6661 if ((dtype
& CUPS_PRINTER_REMOTE
) && access(filename
, 0))
6663 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
6664 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
6665 "printer-uri", NULL
, dest
->uri
);
6668 else if (dtype
& CUPS_PRINTER_CLASS
)
6670 for (i
= 0; i
< dest
->num_printers
; i
++)
6671 if (!(dest
->printers
[i
]->type
& CUPS_PRINTER_CLASS
))
6673 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
6674 dest
->printers
[i
]->name
);
6676 if (!access(filename
, 0))
6680 if (i
< dest
->num_printers
)
6681 dest
= dest
->printers
[i
];
6684 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
6685 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
6686 "printer-uri", NULL
, dest
->printers
[0]->uri
);
6692 * Found the printer with the PPD file, now see if there is one...
6695 if ((con
->file
= open(filename
, O_RDONLY
)) < 0)
6697 send_ipp_status(con
, IPP_NOT_FOUND
,
6698 _("The PPD file \"%s\" could not be opened: %s"),
6699 uri
->values
[0].string
.text
, strerror(errno
));
6703 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
6707 con
->response
->request
.status
.status_code
= IPP_OK
;
6710 send_ipp_status(con
, IPP_NOT_FOUND
,
6711 _("The PPD file \"%s\" could not be found."),
6712 uri
->values
[0].string
.text
);
6717 * 'get_ppds()' - Get the list of PPD files on the local system.
6721 get_ppds(cupsd_client_t
*con
) /* I - Client connection */
6723 http_status_t status
; /* Policy status */
6724 ipp_attribute_t
*limit
, /* Limit attribute */
6725 *device
, /* ppd-device-id attribute */
6726 *language
, /* ppd-natural-language attribute */
6727 *make
, /* ppd-make attribute */
6728 *model
, /* ppd-make-and-model attribute */
6729 *model_number
, /* ppd-model-number attribute */
6730 *product
, /* ppd-product attribute */
6731 *psversion
, /* ppd-psverion attribute */
6732 *type
, /* ppd-type attribute */
6733 *requested
, /* requested-attributes attribute */
6734 *exclude
, /* exclude-schemes attribute */
6735 *include
; /* include-schemes attribute */
6736 char command
[1024], /* cups-driverd command */
6737 options
[4096], /* Options to pass to command */
6738 device_str
[256],/* Escaped ppd-device-id string */
6740 /* Escaped ppd-natural-language */
6741 make_str
[256], /* Escaped ppd-make string */
6742 model_str
[256], /* Escaped ppd-make-and-model string */
6743 model_number_str
[256],
6744 /* ppd-model-number string */
6746 /* Escaped ppd-product string */
6748 /* Escaped ppd-psversion string */
6749 type_str
[256], /* Escaped ppd-type string */
6751 /* String for requested attributes */
6753 /* String for excluded schemes */
6755 /* String for included schemes */
6758 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppds(%p[%d])", con
, con
->number
);
6764 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6766 send_http_error(con
, status
, NULL
);
6771 * Run cups-driverd command with the given options...
6774 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
6775 device
= ippFindAttribute(con
->request
, "ppd-device-id", IPP_TAG_TEXT
);
6776 language
= ippFindAttribute(con
->request
, "ppd-natural-language",
6778 make
= ippFindAttribute(con
->request
, "ppd-make", IPP_TAG_TEXT
);
6779 model
= ippFindAttribute(con
->request
, "ppd-make-and-model",
6781 model_number
= ippFindAttribute(con
->request
, "ppd-model-number",
6783 product
= ippFindAttribute(con
->request
, "ppd-product", IPP_TAG_TEXT
);
6784 psversion
= ippFindAttribute(con
->request
, "ppd-psversion", IPP_TAG_TEXT
);
6785 type
= ippFindAttribute(con
->request
, "ppd-type", IPP_TAG_KEYWORD
);
6786 requested
= ippFindAttribute(con
->request
, "requested-attributes",
6788 exclude
= ippFindAttribute(con
->request
, "exclude-schemes",
6790 include
= ippFindAttribute(con
->request
, "include-schemes",
6794 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
6796 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
6799 url_encode_attr(device
, device_str
, sizeof(device_str
));
6801 device_str
[0] = '\0';
6804 url_encode_attr(language
, language_str
, sizeof(language_str
));
6806 language_str
[0] = '\0';
6809 url_encode_attr(make
, make_str
, sizeof(make_str
));
6814 url_encode_attr(model
, model_str
, sizeof(model_str
));
6816 model_str
[0] = '\0';
6819 snprintf(model_number_str
, sizeof(model_number_str
), "ppd-model-number=%d",
6820 model_number
->values
[0].integer
);
6822 model_number_str
[0] = '\0';
6825 url_encode_attr(product
, product_str
, sizeof(product_str
));
6827 product_str
[0] = '\0';
6830 url_encode_attr(psversion
, psversion_str
, sizeof(psversion_str
));
6832 psversion_str
[0] = '\0';
6835 url_encode_attr(type
, type_str
, sizeof(type_str
));
6840 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
6842 exclude_str
[0] = '\0';
6845 url_encode_attr(include
, include_str
, sizeof(include_str
));
6847 include_str
[0] = '\0';
6849 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
6850 snprintf(options
, sizeof(options
),
6851 "list+%d+%d+%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
6852 con
->request
->request
.op
.request_id
,
6853 limit
? limit
->values
[0].integer
: 0,
6855 device
? "%20" : "", device_str
,
6856 language
? "%20" : "", language_str
,
6857 make
? "%20" : "", make_str
,
6858 model
? "%20" : "", model_str
,
6859 model_number
? "%20" : "", model_number_str
,
6860 product
? "%20" : "", product_str
,
6861 psversion
? "%20" : "", psversion_str
,
6862 type
? "%20" : "", type_str
,
6863 exclude_str
[0] ? "%20" : "", exclude_str
,
6864 include_str
[0] ? "%20" : "", include_str
);
6866 if (cupsdSendCommand(con
, command
, options
, 0))
6869 * Command started successfully, don't send an IPP response here...
6872 ippDelete(con
->response
);
6873 con
->response
= NULL
;
6878 * Command failed, return "internal error" so the user knows something
6882 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
6883 _("cups-driverd failed to execute."));
6889 * 'get_printer_attrs()' - Get printer attributes.
6893 get_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
6894 ipp_attribute_t
*uri
) /* I - Printer URI */
6896 http_status_t status
; /* Policy status */
6897 cups_ptype_t dtype
; /* Destination type (printer/class) */
6898 cupsd_printer_t
*printer
; /* Printer/class */
6899 cups_array_t
*ra
; /* Requested attributes array */
6902 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_attrs(%p[%d], %s)", con
,
6903 con
->number
, uri
->values
[0].string
.text
);
6906 * Is the destination valid?
6909 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6915 send_ipp_status(con
, IPP_NOT_FOUND
,
6916 _("The printer or class does not exist."));
6924 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
6926 send_http_error(con
, status
, printer
);
6931 * Send the attributes...
6934 ra
= create_requested_array(con
->request
);
6936 copy_printer_attrs(con
, printer
, ra
);
6938 cupsArrayDelete(ra
);
6940 con
->response
->request
.status
.status_code
= IPP_OK
;
6945 * 'get_printer_supported()' - Get printer supported values.
6949 get_printer_supported(
6950 cupsd_client_t
*con
, /* I - Client connection */
6951 ipp_attribute_t
*uri
) /* I - Printer URI */
6953 http_status_t status
; /* Policy status */
6954 cups_ptype_t dtype
; /* Destination type (printer/class) */
6955 cupsd_printer_t
*printer
; /* Printer/class */
6958 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_supported(%p[%d], %s)", con
,
6959 con
->number
, uri
->values
[0].string
.text
);
6962 * Is the destination valid?
6965 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6971 send_ipp_status(con
, IPP_NOT_FOUND
,
6972 _("The printer or class does not exist."));
6980 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
6982 send_http_error(con
, status
, printer
);
6987 * Return a list of attributes that can be set via Set-Printer-Attributes.
6990 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
6992 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
6993 "printer-location", 0);
6995 con
->response
->request
.status
.status_code
= IPP_OK
;
7000 * 'get_printers()' - Get a list of printers or classes.
7004 get_printers(cupsd_client_t
*con
, /* I - Client connection */
7005 int type
) /* I - 0 or CUPS_PRINTER_CLASS */
7007 http_status_t status
; /* Policy status */
7008 ipp_attribute_t
*attr
; /* Current attribute */
7009 int limit
; /* Max number of printers to return */
7010 int count
; /* Number of printers that match */
7011 cupsd_printer_t
*printer
; /* Current printer pointer */
7012 cups_ptype_t printer_type
, /* printer-type attribute */
7013 printer_mask
; /* printer-type-mask attribute */
7014 char *location
; /* Location string */
7015 const char *username
; /* Current user */
7016 char *first_printer_name
; /* first-printer-name attribute */
7017 cups_array_t
*ra
; /* Requested attributes array */
7018 int local
; /* Local connection? */
7021 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printers(%p[%d], %x)", con
,
7028 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7030 send_http_error(con
, status
, NULL
);
7035 * Check for printers...
7038 if (!Printers
|| !cupsArrayCount(Printers
))
7040 send_ipp_status(con
, IPP_NOT_FOUND
, _("No destinations added."));
7045 * See if they want to limit the number of printers reported...
7048 if ((attr
= ippFindAttribute(con
->request
, "limit",
7049 IPP_TAG_INTEGER
)) != NULL
)
7050 limit
= attr
->values
[0].integer
;
7054 if ((attr
= ippFindAttribute(con
->request
, "first-printer-name",
7055 IPP_TAG_NAME
)) != NULL
)
7056 first_printer_name
= attr
->values
[0].string
.text
;
7058 first_printer_name
= NULL
;
7061 * Support filtering...
7064 if ((attr
= ippFindAttribute(con
->request
, "printer-type",
7065 IPP_TAG_ENUM
)) != NULL
)
7066 printer_type
= (cups_ptype_t
)attr
->values
[0].integer
;
7068 printer_type
= (cups_ptype_t
)0;
7070 if ((attr
= ippFindAttribute(con
->request
, "printer-type-mask",
7071 IPP_TAG_ENUM
)) != NULL
)
7072 printer_mask
= (cups_ptype_t
)attr
->values
[0].integer
;
7074 printer_mask
= (cups_ptype_t
)0;
7076 local
= httpAddrLocalhost(&(con
->clientaddr
));
7078 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
7079 IPP_TAG_TEXT
)) != NULL
)
7080 location
= attr
->values
[0].string
.text
;
7084 if (con
->username
[0])
7085 username
= con
->username
;
7086 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7087 IPP_TAG_NAME
)) != NULL
)
7088 username
= attr
->values
[0].string
.text
;
7092 ra
= create_requested_array(con
->request
);
7095 * OK, build a list of printers for this printer...
7098 if (first_printer_name
)
7100 if ((printer
= cupsdFindDest(first_printer_name
)) == NULL
)
7101 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7104 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7107 count
< limit
&& printer
;
7108 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
7110 if (!local
&& !printer
->shared
)
7113 if ((!type
|| (printer
->type
& CUPS_PRINTER_CLASS
) == type
) &&
7114 (printer
->type
& printer_mask
) == printer_type
&&
7116 (printer
->location
&& !_cups_strcasecmp(printer
->location
, location
))))
7119 * If a username is specified, see if it is allowed or denied
7123 if (cupsArrayCount(printer
->users
) && username
&&
7124 !user_allowed(printer
, username
))
7128 * Add the group separator as needed...
7132 ippAddSeparator(con
->response
);
7137 * Send the attributes...
7140 copy_printer_attrs(con
, printer
, ra
);
7144 cupsArrayDelete(ra
);
7146 con
->response
->request
.status
.status_code
= IPP_OK
;
7151 * 'get_subscription_attrs()' - Get subscription attributes.
7155 get_subscription_attrs(
7156 cupsd_client_t
*con
, /* I - Client connection */
7157 int sub_id
) /* I - Subscription ID */
7159 http_status_t status
; /* Policy status */
7160 cupsd_subscription_t
*sub
; /* Subscription */
7161 cupsd_policy_t
*policy
; /* Current security policy */
7162 cups_array_t
*ra
, /* Requested attributes array */
7163 *exclude
; /* Private attributes array */
7166 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7167 "get_subscription_attrs(con=%p[%d], sub_id=%d)",
7168 con
, con
->number
, sub_id
);
7171 * Is the subscription ID valid?
7174 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
7177 * Bad subscription ID...
7180 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
7190 policy
= sub
->dest
->op_policy_ptr
;
7192 policy
= DefaultPolicyPtr
;
7194 if ((status
= cupsdCheckPolicy(policy
, con
, sub
->owner
)) != HTTP_OK
)
7196 send_http_error(con
, status
, sub
->dest
);
7200 exclude
= cupsdGetPrivateAttrs(policy
, con
, sub
->dest
, sub
->owner
);
7203 * Copy the subscription attributes to the response using the
7204 * requested-attributes attribute that may be provided by the client.
7207 ra
= create_requested_array(con
->request
);
7209 copy_subscription_attrs(con
, sub
, ra
, exclude
);
7211 cupsArrayDelete(ra
);
7213 con
->response
->request
.status
.status_code
= IPP_OK
;
7218 * 'get_subscriptions()' - Get subscriptions.
7222 get_subscriptions(cupsd_client_t
*con
, /* I - Client connection */
7223 ipp_attribute_t
*uri
) /* I - Printer/job URI */
7225 http_status_t status
; /* Policy status */
7226 int count
; /* Number of subscriptions */
7227 int limit
; /* Limit */
7228 cupsd_subscription_t
*sub
; /* Subscription */
7229 cups_array_t
*ra
; /* Requested attributes array */
7230 ipp_attribute_t
*attr
; /* Attribute */
7231 cups_ptype_t dtype
; /* Destination type (printer/class) */
7232 char scheme
[HTTP_MAX_URI
],
7233 /* Scheme portion of URI */
7234 username
[HTTP_MAX_URI
],
7235 /* Username portion of URI */
7237 /* Host portion of URI */
7238 resource
[HTTP_MAX_URI
];
7239 /* Resource portion of URI */
7240 int port
; /* Port portion of URI */
7241 cupsd_job_t
*job
; /* Job pointer */
7242 cupsd_printer_t
*printer
; /* Printer */
7243 cupsd_policy_t
*policy
; /* Policy */
7244 cups_array_t
*exclude
; /* Private attributes array */
7247 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7248 "get_subscriptions(con=%p[%d], uri=%s)",
7249 con
, con
->number
, uri
->values
[0].string
.text
);
7252 * Is the destination valid?
7255 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7256 sizeof(scheme
), username
, sizeof(username
), host
,
7257 sizeof(host
), &port
, resource
, sizeof(resource
));
7259 if (!strcmp(resource
, "/") ||
7260 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6) ||
7261 (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10) ||
7262 (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9))
7267 else if (!strncmp(resource
, "/jobs/", 6) && resource
[6])
7270 job
= cupsdFindJob(atoi(resource
+ 6));
7274 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
7275 atoi(resource
+ 6));
7279 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7285 send_ipp_status(con
, IPP_NOT_FOUND
,
7286 _("The printer or class does not exist."));
7289 else if ((attr
= ippFindAttribute(con
->request
, "notify-job-id",
7290 IPP_TAG_INTEGER
)) != NULL
)
7292 job
= cupsdFindJob(attr
->values
[0].integer
);
7296 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
7297 attr
->values
[0].integer
);
7309 policy
= printer
->op_policy_ptr
;
7311 policy
= DefaultPolicyPtr
;
7313 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
7315 send_http_error(con
, status
, printer
);
7320 * Copy the subscription attributes to the response using the
7321 * requested-attributes attribute that may be provided by the client.
7324 ra
= create_requested_array(con
->request
);
7326 if ((attr
= ippFindAttribute(con
->request
, "limit",
7327 IPP_TAG_INTEGER
)) != NULL
)
7328 limit
= attr
->values
[0].integer
;
7333 * See if we only want to see subscriptions for a specific user...
7336 if ((attr
= ippFindAttribute(con
->request
, "my-subscriptions",
7337 IPP_TAG_BOOLEAN
)) != NULL
&&
7338 attr
->values
[0].boolean
)
7339 strlcpy(username
, get_username(con
), sizeof(username
));
7343 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
), count
= 0;
7345 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
7346 if ((!printer
|| sub
->dest
== printer
) && (!job
|| sub
->job
== job
) &&
7347 (!username
[0] || !_cups_strcasecmp(username
, sub
->owner
)))
7349 ippAddSeparator(con
->response
);
7351 exclude
= cupsdGetPrivateAttrs(sub
->dest
? sub
->dest
->op_policy_ptr
:
7352 policy
, con
, sub
->dest
,
7355 copy_subscription_attrs(con
, sub
, ra
, exclude
);
7358 if (limit
&& count
>= limit
)
7362 cupsArrayDelete(ra
);
7365 con
->response
->request
.status
.status_code
= IPP_OK
;
7367 send_ipp_status(con
, IPP_NOT_FOUND
, _("No subscriptions found."));
7372 * 'get_username()' - Get the username associated with a request.
7375 static const char * /* O - Username */
7376 get_username(cupsd_client_t
*con
) /* I - Connection */
7378 ipp_attribute_t
*attr
; /* Attribute */
7381 if (con
->username
[0])
7382 return (con
->username
);
7383 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7384 IPP_TAG_NAME
)) != NULL
)
7385 return (attr
->values
[0].string
.text
);
7387 return ("anonymous");
7392 * 'hold_job()' - Hold a print job.
7396 hold_job(cupsd_client_t
*con
, /* I - Client connection */
7397 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
7399 ipp_attribute_t
*attr
; /* Current job-hold-until */
7400 const char *when
; /* New value */
7401 int jobid
; /* Job ID */
7402 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
7403 username
[HTTP_MAX_URI
], /* Username portion of URI */
7404 host
[HTTP_MAX_URI
], /* Host portion of URI */
7405 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7406 int port
; /* Port portion of URI */
7407 cupsd_job_t
*job
; /* Job information */
7410 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_job(%p[%d], %s)", con
, con
->number
,
7411 uri
->values
[0].string
.text
);
7414 * See if we have a job URI or a printer URI...
7417 if (!strcmp(uri
->name
, "printer-uri"))
7420 * Got a printer URI; see if we also have a job-id attribute...
7423 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7424 IPP_TAG_INTEGER
)) == NULL
)
7426 send_ipp_status(con
, IPP_BAD_REQUEST
,
7427 _("Got a printer-uri attribute but no job-id."));
7431 jobid
= attr
->values
[0].integer
;
7436 * Got a job URI; parse it to get the job ID...
7439 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7440 sizeof(scheme
), username
, sizeof(username
), host
,
7441 sizeof(host
), &port
, resource
, sizeof(resource
));
7443 if (strncmp(resource
, "/jobs/", 6))
7449 send_ipp_status(con
, IPP_BAD_REQUEST
,
7450 _("Bad job-uri \"%s\"."),
7451 uri
->values
[0].string
.text
);
7455 jobid
= atoi(resource
+ 6);
7459 * See if the job exists...
7462 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7465 * Nope - return a "not found" error...
7468 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
7473 * See if the job is owned by the requesting user...
7476 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7478 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
7479 cupsdFindDest(job
->dest
));
7484 * See if the job is in a state that allows holding...
7487 if (job
->state_value
> IPP_JOB_STOPPED
)
7490 * Return a "not-possible" error...
7493 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
7494 _("Job #%d is finished and cannot be altered."),
7500 * Hold the job and return...
7503 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
7504 IPP_TAG_KEYWORD
)) == NULL
)
7505 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
7509 when
= attr
->values
[0].string
.text
;
7511 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
7512 "Job job-hold-until value changed by user.");
7515 when
= "indefinite";
7517 cupsdSetJobHoldUntil(job
, when
, 1);
7518 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
, "Job held by \"%s\".",
7521 con
->response
->request
.status
.status_code
= IPP_OK
;
7526 * 'hold_new_jobs()' - Hold pending/new jobs on a printer or class.
7530 hold_new_jobs(cupsd_client_t
*con
, /* I - Connection */
7531 ipp_attribute_t
*uri
) /* I - Printer URI */
7533 http_status_t status
; /* Policy status */
7534 cups_ptype_t dtype
; /* Destination type (printer/class) */
7535 cupsd_printer_t
*printer
; /* Printer data */
7538 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_new_jobs(%p[%d], %s)", con
,
7539 con
->number
, uri
->values
[0].string
.text
);
7542 * Is the destination valid?
7545 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7551 send_ipp_status(con
, IPP_NOT_FOUND
,
7552 _("The printer or class does not exist."));
7560 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7562 send_http_error(con
, status
, printer
);
7567 * Hold pending/new jobs sent to the printer...
7570 printer
->holding_new_jobs
= 1;
7572 cupsdSetPrinterReasons(printer
, "+hold-new-jobs");
7574 if (dtype
& CUPS_PRINTER_CLASS
)
7575 cupsdLogMessage(CUPSD_LOG_INFO
,
7576 "Class \"%s\" now holding pending/new jobs (\"%s\").",
7577 printer
->name
, get_username(con
));
7579 cupsdLogMessage(CUPSD_LOG_INFO
,
7580 "Printer \"%s\" now holding pending/new jobs (\"%s\").",
7581 printer
->name
, get_username(con
));
7584 * Everything was ok, so return OK status...
7587 con
->response
->request
.status
.status_code
= IPP_OK
;
7592 * 'move_job()' - Move a job to a new destination.
7596 move_job(cupsd_client_t
*con
, /* I - Client connection */
7597 ipp_attribute_t
*uri
) /* I - Job URI */
7599 http_status_t status
; /* Policy status */
7600 ipp_attribute_t
*attr
; /* Current attribute */
7601 int jobid
; /* Job ID */
7602 cupsd_job_t
*job
; /* Current job */
7603 const char *src
; /* Source printer/class */
7604 cups_ptype_t stype
, /* Source type (printer or class) */
7605 dtype
; /* Destination type (printer/class) */
7606 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
7607 username
[HTTP_MAX_URI
], /* Username portion of URI */
7608 host
[HTTP_MAX_URI
], /* Host portion of URI */
7609 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7610 int port
; /* Port portion of URI */
7611 cupsd_printer_t
*sprinter
, /* Source printer */
7612 *dprinter
; /* Destination printer */
7615 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "move_job(%p[%d], %s)", con
, con
->number
,
7616 uri
->values
[0].string
.text
);
7619 * Get the new printer or class...
7622 if ((attr
= ippFindAttribute(con
->request
, "job-printer-uri",
7623 IPP_TAG_URI
)) == NULL
)
7626 * Need job-printer-uri...
7629 send_ipp_status(con
, IPP_BAD_REQUEST
,
7630 _("job-printer-uri attribute missing."));
7634 if (!cupsdValidateDest(attr
->values
[0].string
.text
, &dtype
, &dprinter
))
7640 send_ipp_status(con
, IPP_NOT_FOUND
,
7641 _("The printer or class does not exist."));
7646 * See if we have a job URI or a printer URI...
7649 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7650 sizeof(scheme
), username
, sizeof(username
), host
,
7651 sizeof(host
), &port
, resource
, sizeof(resource
));
7653 if (!strcmp(uri
->name
, "printer-uri"))
7656 * Got a printer URI; see if we also have a job-id attribute...
7659 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7660 IPP_TAG_INTEGER
)) == NULL
)
7666 if ((src
= cupsdValidateDest(uri
->values
[0].string
.text
, &stype
,
7667 &sprinter
)) == NULL
)
7673 send_ipp_status(con
, IPP_NOT_FOUND
,
7674 _("The printer or class does not exist."));
7683 * Otherwise, just move a single job...
7686 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
7689 * Nope - return a "not found" error...
7692 send_ipp_status(con
, IPP_NOT_FOUND
,
7693 _("Job #%d does not exist."), attr
->values
[0].integer
);
7699 * Job found, initialize source pointers...
7710 * Got a job URI; parse it to get the job ID...
7713 if (strncmp(resource
, "/jobs/", 6))
7719 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
7720 uri
->values
[0].string
.text
);
7725 * See if the job exists...
7728 jobid
= atoi(resource
+ 6);
7730 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7733 * Nope - return a "not found" error...
7736 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
7742 * Job found, initialize source pointers...
7751 * Check the policy of the destination printer...
7754 if ((status
= cupsdCheckPolicy(dprinter
->op_policy_ptr
, con
,
7755 job
? job
->username
: NULL
)) != HTTP_OK
)
7757 send_http_error(con
, status
, dprinter
);
7762 * Now move the job or jobs...
7768 * See if the job has been completed...
7771 if (job
->state_value
> IPP_JOB_STOPPED
)
7774 * Return a "not-possible" error...
7777 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
7778 _("Job #%d is finished and cannot be altered."),
7784 * See if the job is owned by the requesting user...
7787 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7789 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
7790 cupsdFindDest(job
->dest
));
7795 * Move the job to a different printer or class...
7798 cupsdMoveJob(job
, dprinter
);
7803 * Got the source printer, now look through the jobs...
7806 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
7808 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
7811 * See if the job is pointing at the source printer or has not been
7815 if (_cups_strcasecmp(job
->dest
, src
) ||
7816 job
->state_value
> IPP_JOB_STOPPED
)
7820 * See if the job can be moved by the requesting user...
7823 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7827 * Move the job to a different printer or class...
7830 cupsdMoveJob(job
, dprinter
);
7835 * Start jobs if possible...
7841 * Return with "everything is OK" status...
7844 con
->response
->request
.status
.status_code
= IPP_OK
;
7849 * 'ppd_parse_line()' - Parse a PPD default line.
7852 static int /* O - 0 on success, -1 on failure */
7853 ppd_parse_line(const char *line
, /* I - Line */
7854 char *option
, /* O - Option name */
7855 int olen
, /* I - Size of option name */
7856 char *choice
, /* O - Choice name */
7857 int clen
) /* I - Size of choice name */
7860 * Verify this is a default option line...
7863 if (strncmp(line
, "*Default", 8))
7867 * Read the option name...
7870 for (line
+= 8, olen
--;
7871 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
7882 * Skip everything else up to the colon (:)...
7885 while (*line
&& *line
!= ':')
7894 * Now grab the option choice, skipping leading whitespace...
7897 while (isspace(*line
& 255))
7901 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
7912 * Return with no errors...
7920 * 'print_job()' - Print a file to a printer or class.
7924 print_job(cupsd_client_t
*con
, /* I - Client connection */
7925 ipp_attribute_t
*uri
) /* I - Printer URI */
7927 ipp_attribute_t
*attr
; /* Current attribute */
7928 ipp_attribute_t
*format
; /* Document-format attribute */
7929 const char *default_format
; /* document-format-default value */
7930 cupsd_job_t
*job
; /* New job */
7931 char filename
[1024]; /* Job filename */
7932 mime_type_t
*filetype
; /* Type of file */
7933 char super
[MIME_MAX_SUPER
], /* Supertype of file */
7934 type
[MIME_MAX_TYPE
], /* Subtype of file */
7935 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
7936 /* Textual name of mime type */
7937 cupsd_printer_t
*printer
; /* Printer data */
7938 struct stat fileinfo
; /* File information */
7939 int kbytes
; /* Size of file */
7940 int compression
; /* Document compression */
7943 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "print_job(%p[%d], %s)", con
, con
->number
,
7944 uri
->values
[0].string
.text
);
7947 * Validate print file attributes, for now just document-format and
7948 * compression (CUPS only supports "none" and "gzip")...
7951 compression
= CUPS_FILE_NONE
;
7953 if ((attr
= ippFindAttribute(con
->request
, "compression",
7954 IPP_TAG_KEYWORD
)) != NULL
)
7956 if (strcmp(attr
->values
[0].string
.text
, "none")
7958 && strcmp(attr
->values
[0].string
.text
, "gzip")
7959 #endif /* HAVE_LIBZ */
7962 send_ipp_status(con
, IPP_ATTRIBUTES
,
7963 _("Unsupported compression \"%s\"."),
7964 attr
->values
[0].string
.text
);
7965 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
7966 "compression", NULL
, attr
->values
[0].string
.text
);
7971 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
7972 compression
= CUPS_FILE_GZIP
;
7973 #endif /* HAVE_LIBZ */
7977 * Do we have a file to print?
7982 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file in print request."));
7987 * Is the destination valid?
7990 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
7996 send_ipp_status(con
, IPP_NOT_FOUND
,
7997 _("The printer or class does not exist."));
8002 * Is it a format we support?
8005 if ((format
= ippFindAttribute(con
->request
, "document-format",
8006 IPP_TAG_MIMETYPE
)) != NULL
)
8009 * Grab format from client...
8012 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%255[^;]", super
,
8015 send_ipp_status(con
, IPP_BAD_REQUEST
,
8016 _("Bad document-format \"%s\"."),
8017 format
->values
[0].string
.text
);
8021 else if ((default_format
= cupsGetOption("document-format",
8022 printer
->num_options
,
8023 printer
->options
)) != NULL
)
8026 * Use default document format...
8029 if (sscanf(default_format
, "%15[^/]/%255[^;]", super
, type
) != 2)
8031 send_ipp_status(con
, IPP_BAD_REQUEST
,
8032 _("Bad document-format \"%s\"."),
8043 strlcpy(super
, "application", sizeof(super
));
8044 strlcpy(type
, "octet-stream", sizeof(type
));
8047 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
8050 * Auto-type the file...
8053 ipp_attribute_t
*doc_name
; /* document-name attribute */
8056 cupsdLogMessage(CUPSD_LOG_DEBUG
, "[Job ???] Auto-typing file...");
8058 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
8059 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
8060 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
8064 filetype
= mimeType(MimeDatabase
, super
, type
);
8066 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job ???] Request file type is %s/%s.",
8067 filetype
->super
, filetype
->type
);
8070 filetype
= mimeType(MimeDatabase
, super
, type
);
8074 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
8077 * Replace the document-format attribute value with the auto-typed or
8081 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
8086 _cupsStrFree(format
->values
[0].string
.text
);
8088 format
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
8091 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
8092 "document-format", NULL
, mimetype
);
8096 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
8097 _("Unsupported document-format \"%s\"."),
8098 format
? format
->values
[0].string
.text
:
8099 "application/octet-stream");
8100 cupsdLogMessage(CUPSD_LOG_INFO
,
8101 "Hint: Do you have the raw file printing rules enabled?");
8104 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
8105 "document-format", NULL
, format
->values
[0].string
.text
);
8111 * Read any embedded job ticket info from PS files...
8114 if (!_cups_strcasecmp(filetype
->super
, "application") &&
8115 (!_cups_strcasecmp(filetype
->type
, "postscript") ||
8116 !_cups_strcasecmp(filetype
->type
, "pdf")))
8117 read_job_ticket(con
);
8120 * Create the job object...
8123 if ((job
= add_job(con
, printer
, filetype
)) == NULL
)
8127 * Update quota data...
8130 if (stat(con
->filename
, &fileinfo
))
8133 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
8135 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
8137 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
8138 IPP_TAG_INTEGER
)) != NULL
)
8139 attr
->values
[0].integer
+= kbytes
;
8142 * Add the job file...
8145 if (add_file(con
, job
, filetype
, compression
))
8148 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
8150 rename(con
->filename
, filename
);
8151 cupsdClearString(&con
->filename
);
8154 * See if we need to add the ending sheet...
8157 if (cupsdTimeoutJob(job
))
8161 * Log and save the job...
8164 cupsdLogJob(job
, CUPSD_LOG_INFO
,
8165 "File of type %s/%s queued by \"%s\".",
8166 filetype
->super
, filetype
->type
, job
->username
);
8167 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "hold_until=%d", (int)job
->hold_until
);
8168 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
8169 job
->dest
, job
->username
);
8172 * Start the job if possible...
8180 * 'read_job_ticket()' - Read a job ticket embedded in a print file.
8182 * This function only gets called when printing a single PDF or PostScript
8183 * file using the Print-Job operation. It doesn't work for Create-Job +
8184 * Send-File, since the job attributes need to be set at job creation
8185 * time for banners to work. The embedded job ticket stuff is here
8186 * primarily to allow the Windows printer driver for CUPS to pass in JCL
8187 * options and IPP attributes which otherwise would be lost.
8189 * The format of a job ticket is simple:
8191 * %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
8193 * %cupsJobTicket: attr1=value1
8194 * %cupsJobTicket: attr2=value2
8196 * %cupsJobTicket: attrN=valueN
8198 * Job ticket lines must appear immediately after the first line that
8199 * specifies PostScript (%!PS-Adobe-3.0) or PDF (%PDF) format, and CUPS
8200 * stops looking for job ticket info when it finds a line that does not begin
8201 * with "%cupsJobTicket:".
8203 * The maximum length of a job ticket line, including the prefix, is
8204 * 255 characters to conform with the Adobe DSC.
8206 * Read-only attributes are rejected with a notice to the error log in
8207 * case a malicious user tries anything. Since the job ticket is read
8208 * prior to attribute validation in print_job(), job ticket attributes
8209 * will go through the same validation as IPP attributes...
8213 read_job_ticket(cupsd_client_t
*con
) /* I - Client connection */
8215 cups_file_t
*fp
; /* File to read from */
8216 char line
[256]; /* Line data */
8217 int num_options
; /* Number of options */
8218 cups_option_t
*options
; /* Options */
8219 ipp_t
*ticket
; /* New attributes */
8220 ipp_attribute_t
*attr
, /* Current attribute */
8221 *attr2
, /* Job attribute */
8222 *prev2
; /* Previous job attribute */
8226 * First open the print file...
8229 if ((fp
= cupsFileOpen(con
->filename
, "rb")) == NULL
)
8231 cupsdLogMessage(CUPSD_LOG_ERROR
,
8232 "Unable to open print file for job ticket - %s",
8238 * Skip the first line...
8241 if (cupsFileGets(fp
, line
, sizeof(line
)) == NULL
)
8243 cupsdLogMessage(CUPSD_LOG_ERROR
,
8244 "Unable to read from print file for job ticket - %s",
8250 if (strncmp(line
, "%!PS-Adobe-", 11) && strncmp(line
, "%PDF-", 5))
8253 * Not a DSC-compliant file, so no job ticket info will be available...
8261 * Read job ticket info from the file...
8267 while (cupsFileGets(fp
, line
, sizeof(line
)))
8270 * Stop at the first non-ticket line...
8273 if (strncmp(line
, "%cupsJobTicket:", 15))
8277 * Add the options to the option array...
8280 num_options
= cupsParseOptions(line
+ 15, num_options
, &options
);
8284 * Done with the file; see if we have any options...
8289 if (num_options
== 0)
8293 * OK, convert the options to an attribute list, and apply them to
8298 cupsEncodeOptions(ticket
, num_options
, options
);
8301 * See what the user wants to change.
8304 for (attr
= ticket
->attrs
; attr
; attr
= attr
->next
)
8306 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
8309 if (!strcmp(attr
->name
, "job-originating-host-name") ||
8310 !strcmp(attr
->name
, "job-originating-user-name") ||
8311 !strcmp(attr
->name
, "job-media-sheets-completed") ||
8312 !strcmp(attr
->name
, "job-k-octets") ||
8313 !strcmp(attr
->name
, "job-id") ||
8314 !strncmp(attr
->name
, "job-state", 9) ||
8315 !strncmp(attr
->name
, "time-at-", 8))
8316 continue; /* Read-only attrs */
8318 if ((attr2
= ippFindAttribute(con
->request
, attr
->name
,
8319 IPP_TAG_ZERO
)) != NULL
)
8322 * Some other value; first free the old value...
8325 if (con
->request
->attrs
== attr2
)
8327 con
->request
->attrs
= attr2
->next
;
8332 for (prev2
= con
->request
->attrs
; prev2
; prev2
= prev2
->next
)
8333 if (prev2
->next
== attr2
)
8335 prev2
->next
= attr2
->next
;
8340 if (con
->request
->last
== attr2
)
8341 con
->request
->last
= prev2
;
8343 ippDeleteAttribute(NULL
, attr2
);
8347 * Add new option by copying it...
8350 ippCopyAttribute(con
->request
, attr
, 0);
8354 * Then free the attribute list and option array...
8358 cupsFreeOptions(num_options
, options
);
8363 * 'reject_jobs()' - Reject print jobs to a printer.
8367 reject_jobs(cupsd_client_t
*con
, /* I - Client connection */
8368 ipp_attribute_t
*uri
) /* I - Printer or class URI */
8370 http_status_t status
; /* Policy status */
8371 cups_ptype_t dtype
; /* Destination type (printer/class) */
8372 cupsd_printer_t
*printer
; /* Printer data */
8373 ipp_attribute_t
*attr
; /* printer-state-message text */
8376 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "reject_jobs(%p[%d], %s)", con
,
8377 con
->number
, uri
->values
[0].string
.text
);
8380 * Is the destination valid?
8383 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8389 send_ipp_status(con
, IPP_NOT_FOUND
,
8390 _("The printer or class does not exist."));
8398 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8400 send_http_error(con
, status
, printer
);
8405 * Reject jobs sent to the printer...
8408 printer
->accepting
= 0;
8410 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
8411 IPP_TAG_TEXT
)) == NULL
)
8412 strlcpy(printer
->state_message
, "Rejecting Jobs",
8413 sizeof(printer
->state_message
));
8415 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
8416 sizeof(printer
->state_message
));
8418 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
8419 "No longer accepting jobs.");
8421 if (dtype
& CUPS_PRINTER_CLASS
)
8423 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
8425 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" rejecting jobs (\"%s\").",
8426 printer
->name
, get_username(con
));
8430 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
8432 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" rejecting jobs (\"%s\").",
8433 printer
->name
, get_username(con
));
8437 * Everything was ok, so return OK status...
8440 con
->response
->request
.status
.status_code
= IPP_OK
;
8445 * 'release_held_new_jobs()' - Release pending/new jobs on a printer or class.
8449 release_held_new_jobs(
8450 cupsd_client_t
*con
, /* I - Connection */
8451 ipp_attribute_t
*uri
) /* I - Printer URI */
8453 http_status_t status
; /* Policy status */
8454 cups_ptype_t dtype
; /* Destination type (printer/class) */
8455 cupsd_printer_t
*printer
; /* Printer data */
8458 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_held_new_jobs(%p[%d], %s)", con
,
8459 con
->number
, uri
->values
[0].string
.text
);
8462 * Is the destination valid?
8465 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8471 send_ipp_status(con
, IPP_NOT_FOUND
,
8472 _("The printer or class does not exist."));
8480 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8482 send_http_error(con
, status
, printer
);
8487 * Hold pending/new jobs sent to the printer...
8490 printer
->holding_new_jobs
= 0;
8492 cupsdSetPrinterReasons(printer
, "-hold-new-jobs");
8494 if (dtype
& CUPS_PRINTER_CLASS
)
8495 cupsdLogMessage(CUPSD_LOG_INFO
,
8496 "Class \"%s\" now printing pending/new jobs (\"%s\").",
8497 printer
->name
, get_username(con
));
8499 cupsdLogMessage(CUPSD_LOG_INFO
,
8500 "Printer \"%s\" now printing pending/new jobs (\"%s\").",
8501 printer
->name
, get_username(con
));
8504 * Everything was ok, so return OK status...
8507 con
->response
->request
.status
.status_code
= IPP_OK
;
8512 * 'release_job()' - Release a held print job.
8516 release_job(cupsd_client_t
*con
, /* I - Client connection */
8517 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
8519 ipp_attribute_t
*attr
; /* Current attribute */
8520 int jobid
; /* Job ID */
8521 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
8522 username
[HTTP_MAX_URI
], /* Username portion of URI */
8523 host
[HTTP_MAX_URI
], /* Host portion of URI */
8524 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8525 int port
; /* Port portion of URI */
8526 cupsd_job_t
*job
; /* Job information */
8529 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_job(%p[%d], %s)", con
,
8530 con
->number
, uri
->values
[0].string
.text
);
8533 * See if we have a job URI or a printer URI...
8536 if (!strcmp(uri
->name
, "printer-uri"))
8539 * Got a printer URI; see if we also have a job-id attribute...
8542 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8543 IPP_TAG_INTEGER
)) == NULL
)
8545 send_ipp_status(con
, IPP_BAD_REQUEST
,
8546 _("Got a printer-uri attribute but no job-id."));
8550 jobid
= attr
->values
[0].integer
;
8555 * Got a job URI; parse it to get the job ID...
8558 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8559 sizeof(scheme
), username
, sizeof(username
), host
,
8560 sizeof(host
), &port
, resource
, sizeof(resource
));
8562 if (strncmp(resource
, "/jobs/", 6))
8568 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
8569 uri
->values
[0].string
.text
);
8573 jobid
= atoi(resource
+ 6);
8577 * See if the job exists...
8580 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8583 * Nope - return a "not found" error...
8586 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
8591 * See if job is "held"...
8594 if (job
->state_value
!= IPP_JOB_HELD
)
8597 * Nope - return a "not possible" error...
8600 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not held."), jobid
);
8605 * See if the job is owned by the requesting user...
8608 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8610 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8611 cupsdFindDest(job
->dest
));
8616 * Reset the job-hold-until value to "no-hold"...
8619 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
8620 IPP_TAG_KEYWORD
)) == NULL
)
8621 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
8625 _cupsStrFree(attr
->values
[0].string
.text
);
8627 attr
->value_tag
= IPP_TAG_KEYWORD
;
8628 attr
->values
[0].string
.text
= _cupsStrAlloc("no-hold");
8630 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
8631 "Job job-hold-until value changed by user.");
8632 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
8636 * Release the job and return...
8639 cupsdReleaseJob(job
);
8641 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
8642 "Job released by user.");
8644 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Released by \"%s\".", username
);
8646 con
->response
->request
.status
.status_code
= IPP_OK
;
8653 * 'renew_subscription()' - Renew an existing subscription...
8658 cupsd_client_t
*con
, /* I - Client connection */
8659 int sub_id
) /* I - Subscription ID */
8661 http_status_t status
; /* Policy status */
8662 cupsd_subscription_t
*sub
; /* Subscription */
8663 ipp_attribute_t
*lease
; /* notify-lease-duration */
8666 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
8667 "renew_subscription(con=%p[%d], sub_id=%d)",
8668 con
, con
->number
, sub_id
);
8671 * Is the subscription ID valid?
8674 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
8677 * Bad subscription ID...
8680 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
8688 * Job subscriptions cannot be renewed...
8691 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8692 _("Job subscriptions cannot be renewed."));
8700 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
8702 con
, sub
->owner
)) != HTTP_OK
)
8704 send_http_error(con
, status
, sub
->dest
);
8709 * Renew the subscription...
8712 lease
= ippFindAttribute(con
->request
, "notify-lease-duration",
8715 sub
->lease
= lease
? lease
->values
[0].integer
: DefaultLeaseDuration
;
8717 if (MaxLeaseDuration
&& (sub
->lease
== 0 || sub
->lease
> MaxLeaseDuration
))
8719 cupsdLogMessage(CUPSD_LOG_INFO
,
8720 "renew_subscription: Limiting notify-lease-duration to "
8723 sub
->lease
= MaxLeaseDuration
;
8726 sub
->expire
= sub
->lease
? time(NULL
) + sub
->lease
: 0;
8728 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
8730 con
->response
->request
.status
.status_code
= IPP_OK
;
8732 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
8733 "notify-lease-duration", sub
->lease
);
8738 * 'restart_job()' - Restart an old print job.
8742 restart_job(cupsd_client_t
*con
, /* I - Client connection */
8743 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
8745 ipp_attribute_t
*attr
; /* Current attribute */
8746 int jobid
; /* Job ID */
8747 cupsd_job_t
*job
; /* Job information */
8748 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
8749 username
[HTTP_MAX_URI
], /* Username portion of URI */
8750 host
[HTTP_MAX_URI
], /* Host portion of URI */
8751 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8752 int port
; /* Port portion of URI */
8755 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "restart_job(%p[%d], %s)", con
,
8756 con
->number
, uri
->values
[0].string
.text
);
8759 * See if we have a job URI or a printer URI...
8762 if (!strcmp(uri
->name
, "printer-uri"))
8765 * Got a printer URI; see if we also have a job-id attribute...
8768 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8769 IPP_TAG_INTEGER
)) == NULL
)
8771 send_ipp_status(con
, IPP_BAD_REQUEST
,
8772 _("Got a printer-uri attribute but no job-id."));
8776 jobid
= attr
->values
[0].integer
;
8781 * Got a job URI; parse it to get the job ID...
8784 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8785 sizeof(scheme
), username
, sizeof(username
), host
,
8786 sizeof(host
), &port
, resource
, sizeof(resource
));
8788 if (strncmp(resource
, "/jobs/", 6))
8794 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
8795 uri
->values
[0].string
.text
);
8799 jobid
= atoi(resource
+ 6);
8803 * See if the job exists...
8806 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8809 * Nope - return a "not found" error...
8812 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
8817 * See if job is in any of the "completed" states...
8820 if (job
->state_value
<= IPP_JOB_PROCESSING
)
8823 * Nope - return a "not possible" error...
8826 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not complete."),
8832 * See if we have retained the job files...
8837 if (!job
->attrs
|| job
->num_files
== 0)
8840 * Nope - return a "not possible" error...
8843 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8844 _("Job #%d cannot be restarted - no files."), jobid
);
8849 * See if the job is owned by the requesting user...
8852 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8854 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8855 cupsdFindDest(job
->dest
));
8860 * See if the job-hold-until attribute is specified...
8863 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
8864 IPP_TAG_KEYWORD
)) == NULL
)
8865 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
8867 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
8870 * Return the job to a held state...
8873 cupsdLogJob(job
, CUPSD_LOG_DEBUG
,
8874 "Restarted by \"%s\" with job-hold-until=%s.",
8875 username
, attr
->values
[0].string
.text
);
8876 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
8878 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
,
8879 NULL
, job
, "Job restarted by user with job-hold-until=%s",
8880 attr
->values
[0].string
.text
);
8885 * Restart the job...
8888 cupsdRestartJob(job
);
8892 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Restarted by \"%s\".", username
);
8894 con
->response
->request
.status
.status_code
= IPP_OK
;
8899 * 'save_auth_info()' - Save authentication information for a job.
8904 cupsd_client_t
*con
, /* I - Client connection */
8905 cupsd_job_t
*job
, /* I - Job */
8906 ipp_attribute_t
*auth_info
) /* I - auth-info attribute, if any */
8908 int i
; /* Looping var */
8909 char filename
[1024]; /* Job authentication filename */
8910 cups_file_t
*fp
; /* Job authentication file */
8911 char line
[65536]; /* Line for file */
8912 cupsd_printer_t
*dest
; /* Destination printer/class */
8916 * This function saves the in-memory authentication information for
8917 * a job so that it can be used to authenticate with a remote host.
8918 * The information is stored in a file that is readable only by the
8919 * root user. The fields are Base-64 encoded, each on a separate line,
8920 * followed by random number (up to 1024) of newlines to limit the
8921 * amount of information that is exposed.
8923 * Because of the potential for exposing of authentication information,
8924 * this functionality is only enabled when running cupsd as root.
8926 * This caching only works for the Basic and BasicDigest authentication
8927 * types. Digest authentication cannot be cached this way, and in
8928 * the future Kerberos authentication may make all of this obsolete.
8930 * Authentication information is saved whenever an authenticated
8931 * Print-Job, Create-Job, or CUPS-Authenticate-Job operation is
8934 * This information is deleted after a job is completed or canceled,
8935 * so reprints may require subsequent re-authentication.
8941 if ((dest
= cupsdFindDest(job
->dest
)) == NULL
)
8945 * Create the authentication file and change permissions...
8948 snprintf(filename
, sizeof(filename
), "%s/a%05d", RequestRoot
, job
->id
);
8949 if ((fp
= cupsFileOpen(filename
, "w")) == NULL
)
8951 cupsdLogMessage(CUPSD_LOG_ERROR
,
8952 "Unable to save authentication info to \"%s\" - %s",
8953 filename
, strerror(errno
));
8957 fchown(cupsFileNumber(fp
), 0, 0);
8958 fchmod(cupsFileNumber(fp
), 0400);
8960 cupsFilePuts(fp
, "CUPSD-AUTH-V3\n");
8963 i
< (int)(sizeof(job
->auth_env
) / sizeof(job
->auth_env
[0]));
8965 cupsdClearString(job
->auth_env
+ i
);
8967 if (auth_info
&& auth_info
->num_values
== dest
->num_auth_info_required
)
8970 * Write 1 to 3 auth values...
8974 i
< auth_info
->num_values
&&
8975 i
< (int)(sizeof(job
->auth_env
) / sizeof(job
->auth_env
[0]));
8978 if (strcmp(dest
->auth_info_required
[i
], "negotiate"))
8980 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[i
].string
.text
, (int)strlen(auth_info
->values
[i
].string
.text
));
8981 cupsFilePutConf(fp
, dest
->auth_info_required
[i
], line
);
8984 cupsFilePutConf(fp
, dest
->auth_info_required
[i
],
8985 auth_info
->values
[i
].string
.text
);
8987 if (!strcmp(dest
->auth_info_required
[i
], "username"))
8988 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_USERNAME=%s",
8989 auth_info
->values
[i
].string
.text
);
8990 else if (!strcmp(dest
->auth_info_required
[i
], "domain"))
8991 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_DOMAIN=%s",
8992 auth_info
->values
[i
].string
.text
);
8993 else if (!strcmp(dest
->auth_info_required
[i
], "password"))
8994 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_PASSWORD=%s",
8995 auth_info
->values
[i
].string
.text
);
8996 else if (!strcmp(dest
->auth_info_required
[i
], "negotiate"))
8997 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_NEGOTIATE=%s",
8998 auth_info
->values
[i
].string
.text
);
9003 else if (auth_info
&& auth_info
->num_values
== 2 &&
9004 dest
->num_auth_info_required
== 1 &&
9005 !strcmp(dest
->auth_info_required
[0], "negotiate"))
9008 * Allow fallback to username+password for Kerberized queues...
9011 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[0].string
.text
, (int)strlen(auth_info
->values
[0].string
.text
));
9012 cupsFilePutConf(fp
, "username", line
);
9014 cupsdSetStringf(job
->auth_env
+ 0, "AUTH_USERNAME=%s",
9015 auth_info
->values
[0].string
.text
);
9017 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[1].string
.text
, (int)strlen(auth_info
->values
[1].string
.text
));
9018 cupsFilePutConf(fp
, "password", line
);
9020 cupsdSetStringf(job
->auth_env
+ 1, "AUTH_PASSWORD=%s",
9021 auth_info
->values
[1].string
.text
);
9023 else if (con
->username
[0])
9026 * Write the authenticated username...
9029 httpEncode64_2(line
, sizeof(line
), con
->username
, (int)strlen(con
->username
));
9030 cupsFilePutConf(fp
, "username", line
);
9032 cupsdSetStringf(job
->auth_env
+ 0, "AUTH_USERNAME=%s", con
->username
);
9035 * Write the authenticated password...
9038 httpEncode64_2(line
, sizeof(line
), con
->password
, (int)strlen(con
->password
));
9039 cupsFilePutConf(fp
, "password", line
);
9041 cupsdSetStringf(job
->auth_env
+ 1, "AUTH_PASSWORD=%s", con
->password
);
9045 if (con
->gss_uid
> 0)
9047 cupsFilePrintf(fp
, "uid %d\n", (int)con
->gss_uid
);
9048 cupsdSetStringf(&job
->auth_uid
, "AUTH_UID=%d", (int)con
->gss_uid
);
9050 #endif /* HAVE_GSSAPI */
9053 * Write a random number of newlines to the end of the file...
9056 for (i
= (CUPS_RAND() % 1024); i
>= 0; i
--)
9057 cupsFilePutChar(fp
, '\n');
9060 * Close the file and return...
9068 * 'send_document()' - Send a file to a printer or class.
9072 send_document(cupsd_client_t
*con
, /* I - Client connection */
9073 ipp_attribute_t
*uri
) /* I - Printer URI */
9075 ipp_attribute_t
*attr
; /* Current attribute */
9076 ipp_attribute_t
*format
; /* Request's document-format attribute */
9077 ipp_attribute_t
*jformat
; /* Job's document-format attribute */
9078 const char *default_format
;/* document-format-default value */
9079 int jobid
; /* Job ID number */
9080 cupsd_job_t
*job
; /* Current job */
9081 char job_uri
[HTTP_MAX_URI
],
9083 scheme
[HTTP_MAX_URI
],
9084 /* Method portion of URI */
9085 username
[HTTP_MAX_URI
],
9086 /* Username portion of URI */
9088 /* Host portion of URI */
9089 resource
[HTTP_MAX_URI
];
9090 /* Resource portion of URI */
9091 int port
; /* Port portion of URI */
9092 mime_type_t
*filetype
; /* Type of file */
9093 char super
[MIME_MAX_SUPER
],
9094 /* Supertype of file */
9095 type
[MIME_MAX_TYPE
],
9096 /* Subtype of file */
9097 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
9098 /* Textual name of mime type */
9099 char filename
[1024]; /* Job filename */
9100 cupsd_printer_t
*printer
; /* Current printer */
9101 struct stat fileinfo
; /* File information */
9102 int kbytes
; /* Size of file */
9103 int compression
; /* Type of compression */
9104 int start_job
; /* Start the job? */
9107 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "send_document(%p[%d], %s)", con
,
9108 con
->number
, uri
->values
[0].string
.text
);
9111 * See if we have a job URI or a printer URI...
9114 if (!strcmp(uri
->name
, "printer-uri"))
9117 * Got a printer URI; see if we also have a job-id attribute...
9120 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9121 IPP_TAG_INTEGER
)) == NULL
)
9123 send_ipp_status(con
, IPP_BAD_REQUEST
,
9124 _("Got a printer-uri attribute but no job-id."));
9128 jobid
= attr
->values
[0].integer
;
9133 * Got a job URI; parse it to get the job ID...
9136 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9137 sizeof(scheme
), username
, sizeof(username
), host
,
9138 sizeof(host
), &port
, resource
, sizeof(resource
));
9140 if (strncmp(resource
, "/jobs/", 6))
9146 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9147 uri
->values
[0].string
.text
);
9151 jobid
= atoi(resource
+ 6);
9155 * See if the job exists...
9158 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9161 * Nope - return a "not found" error...
9164 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9168 printer
= cupsdFindDest(job
->dest
);
9171 * See if the job is owned by the requesting user...
9174 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9176 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9177 cupsdFindDest(job
->dest
));
9182 * OK, see if the client is sending the document compressed - CUPS
9183 * only supports "none" and "gzip".
9186 compression
= CUPS_FILE_NONE
;
9188 if ((attr
= ippFindAttribute(con
->request
, "compression",
9189 IPP_TAG_KEYWORD
)) != NULL
)
9191 if (strcmp(attr
->values
[0].string
.text
, "none")
9193 && strcmp(attr
->values
[0].string
.text
, "gzip")
9194 #endif /* HAVE_LIBZ */
9197 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Unsupported compression \"%s\"."),
9198 attr
->values
[0].string
.text
);
9199 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
9200 "compression", NULL
, attr
->values
[0].string
.text
);
9205 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
9206 compression
= CUPS_FILE_GZIP
;
9207 #endif /* HAVE_LIBZ */
9211 * Do we have a file to print?
9214 if ((attr
= ippFindAttribute(con
->request
, "last-document",
9215 IPP_TAG_BOOLEAN
)) == NULL
)
9217 send_ipp_status(con
, IPP_BAD_REQUEST
,
9218 _("Missing last-document attribute in request."));
9225 * Check for an empty request with "last-document" set to true, which is
9226 * used to close an "open" job by RFC 2911, section 3.3.2.
9229 if (job
->num_files
> 0 && attr
->values
[0].boolean
)
9232 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file in print request."));
9237 * Is it a format we support?
9240 if ((format
= ippFindAttribute(con
->request
, "document-format",
9241 IPP_TAG_MIMETYPE
)) != NULL
)
9244 * Grab format from client...
9247 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%255[^;]",
9250 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"."),
9251 format
->values
[0].string
.text
);
9255 else if ((default_format
= cupsGetOption("document-format",
9256 printer
->num_options
,
9257 printer
->options
)) != NULL
)
9260 * Use default document format...
9263 if (sscanf(default_format
, "%15[^/]/%255[^;]", super
, type
) != 2)
9265 send_ipp_status(con
, IPP_BAD_REQUEST
,
9266 _("Bad document-format-default \"%s\"."), default_format
);
9273 * No document format attribute? Auto-type it!
9276 strlcpy(super
, "application", sizeof(super
));
9277 strlcpy(type
, "octet-stream", sizeof(type
));
9280 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
9283 * Auto-type the file...
9286 ipp_attribute_t
*doc_name
; /* document-name attribute */
9289 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Auto-typing file...");
9291 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
9292 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
9293 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
9297 filetype
= mimeType(MimeDatabase
, super
, type
);
9300 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Request file type is %s/%s.",
9301 filetype
->super
, filetype
->type
);
9304 filetype
= mimeType(MimeDatabase
, super
, type
);
9309 * Replace the document-format attribute value with the auto-typed or
9313 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9316 if ((jformat
= ippFindAttribute(job
->attrs
, "document-format",
9317 IPP_TAG_MIMETYPE
)) != NULL
)
9319 _cupsStrFree(jformat
->values
[0].string
.text
);
9321 jformat
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
9324 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
9325 "document-format", NULL
, mimetype
);
9329 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9330 _("Unsupported document-format \"%s/%s\"."), super
, type
);
9331 cupsdLogMessage(CUPSD_LOG_INFO
,
9332 "Hint: Do you have the raw file printing rules enabled?");
9335 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9336 "document-format", NULL
, format
->values
[0].string
.text
);
9341 if (printer
->filetypes
&& !cupsArrayFind(printer
->filetypes
, filetype
))
9343 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9346 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9347 _("Unsupported document-format \"%s\"."), mimetype
);
9349 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9350 "document-format", NULL
, mimetype
);
9356 * Add the file to the job...
9361 if (add_file(con
, job
, filetype
, compression
))
9364 if (stat(con
->filename
, &fileinfo
))
9367 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
9369 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
9371 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
9372 IPP_TAG_INTEGER
)) != NULL
)
9373 attr
->values
[0].integer
+= kbytes
;
9375 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
9377 rename(con
->filename
, filename
);
9379 cupsdClearString(&con
->filename
);
9381 cupsdLogJob(job
, CUPSD_LOG_INFO
, "File of type %s/%s queued by \"%s\".",
9382 filetype
->super
, filetype
->type
, job
->username
);
9385 * Start the job if this is the last document...
9390 if ((attr
= ippFindAttribute(con
->request
, "last-document",
9391 IPP_TAG_BOOLEAN
)) != NULL
&&
9392 attr
->values
[0].boolean
)
9395 * See if we need to add the ending sheet...
9398 if (cupsdTimeoutJob(job
))
9401 if (job
->state_value
== IPP_JOB_STOPPED
)
9403 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9404 job
->state_value
= IPP_JOB_PENDING
;
9406 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
9408 else if (job
->state_value
== IPP_JOB_HELD
)
9410 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9411 IPP_TAG_KEYWORD
)) == NULL
)
9412 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9414 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9416 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9417 job
->state_value
= IPP_JOB_PENDING
;
9419 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
9422 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-hold-until-specified");
9426 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
9432 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9433 IPP_TAG_KEYWORD
)) == NULL
)
9434 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9436 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9438 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
9439 job
->state_value
= IPP_JOB_HELD
;
9440 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
9442 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-incoming");
9445 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
9452 * Fill in the response info...
9455 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
9456 con
->clientname
, con
->clientport
, "/jobs/%d", jobid
);
9457 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
9460 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", jobid
);
9462 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
9464 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons",
9465 NULL
, job
->reasons
->values
[0].string
.text
);
9467 con
->response
->request
.status
.status_code
= IPP_OK
;
9470 * Start the job if necessary...
9479 * 'send_http_error()' - Send a HTTP error back to the IPP client.
9484 cupsd_client_t
*con
, /* I - Client connection */
9485 http_status_t status
, /* I - HTTP status code */
9486 cupsd_printer_t
*printer
) /* I - Printer, if any */
9488 ipp_attribute_t
*uri
; /* Request URI, if any */
9491 if ((uri
= ippFindAttribute(con
->request
, "printer-uri",
9492 IPP_TAG_URI
)) == NULL
)
9493 uri
= ippFindAttribute(con
->request
, "job-uri", IPP_TAG_URI
);
9495 cupsdLogMessage(status
== HTTP_FORBIDDEN
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
9496 "[Client %d] Returning HTTP %s for %s (%s) from %s",
9497 con
->number
, httpStatus(status
),
9499 ippOpString(con
->request
->request
.op
.operation_id
) :
9501 uri
? uri
->values
[0].string
.text
: "no URI",
9502 con
->http
->hostname
);
9506 int auth_type
; /* Type of authentication required */
9509 auth_type
= CUPSD_AUTH_NONE
;
9511 if (status
== HTTP_UNAUTHORIZED
&&
9512 printer
->num_auth_info_required
> 0 &&
9513 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
9515 (con
->request
->request
.op
.operation_id
== IPP_PRINT_JOB
||
9516 con
->request
->request
.op
.operation_id
== IPP_CREATE_JOB
||
9517 con
->request
->request
.op
.operation_id
== CUPS_AUTHENTICATE_JOB
))
9520 * Creating and authenticating jobs requires Kerberos...
9523 auth_type
= CUPSD_AUTH_NEGOTIATE
;
9528 * Use policy/location-defined authentication requirements...
9531 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9532 cupsd_location_t
*auth
; /* Pointer to authentication element */
9535 if (printer
->type
& CUPS_PRINTER_CLASS
)
9536 snprintf(resource
, sizeof(resource
), "/classes/%s", printer
->name
);
9538 snprintf(resource
, sizeof(resource
), "/printers/%s", printer
->name
);
9540 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
9541 auth
->type
== CUPSD_AUTH_NONE
)
9542 auth
= cupsdFindPolicyOp(printer
->op_policy_ptr
,
9544 con
->request
->request
.op
.operation_id
:
9549 if (auth
->type
== CUPSD_AUTH_DEFAULT
)
9550 auth_type
= cupsdDefaultAuthType();
9552 auth_type
= auth
->type
;
9556 cupsdSendError(con
, status
, auth_type
);
9559 cupsdSendError(con
, status
, CUPSD_AUTH_NONE
);
9561 ippDelete(con
->response
);
9562 con
->response
= NULL
;
9569 * 'send_ipp_status()' - Send a status back to the IPP client.
9573 send_ipp_status(cupsd_client_t
*con
, /* I - Client connection */
9574 ipp_status_t status
, /* I - IPP status code */
9575 const char *message
,/* I - Status message */
9576 ...) /* I - Additional args as needed */
9578 va_list ap
; /* Pointer to additional args */
9579 char formatted
[1024]; /* Formatted errror message */
9582 va_start(ap
, message
);
9583 vsnprintf(formatted
, sizeof(formatted
),
9584 _cupsLangString(con
->language
, message
), ap
);
9587 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s: %s",
9588 ippOpString(con
->request
->request
.op
.operation_id
),
9589 ippErrorString(status
), formatted
);
9591 con
->response
->request
.status
.status_code
= status
;
9593 if (ippFindAttribute(con
->response
, "attributes-charset",
9594 IPP_TAG_ZERO
) == NULL
)
9595 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
9596 "attributes-charset", NULL
, "utf-8");
9598 if (ippFindAttribute(con
->response
, "attributes-natural-language",
9599 IPP_TAG_ZERO
) == NULL
)
9600 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
9601 "attributes-natural-language", NULL
, DefaultLanguage
);
9603 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
9604 "status-message", NULL
, formatted
);
9609 * 'set_default()' - Set the default destination...
9613 set_default(cupsd_client_t
*con
, /* I - Client connection */
9614 ipp_attribute_t
*uri
) /* I - Printer URI */
9616 http_status_t status
; /* Policy status */
9617 cups_ptype_t dtype
; /* Destination type (printer/class) */
9618 cupsd_printer_t
*printer
, /* Printer */
9619 *oldprinter
; /* Old default printer */
9622 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_default(%p[%d], %s)", con
,
9623 con
->number
, uri
->values
[0].string
.text
);
9626 * Is the destination valid?
9629 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9635 send_ipp_status(con
, IPP_NOT_FOUND
,
9636 _("The printer or class does not exist."));
9644 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
9646 send_http_error(con
, status
, NULL
);
9651 * Set it as the default...
9654 oldprinter
= DefaultPrinter
;
9655 DefaultPrinter
= printer
;
9658 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, oldprinter
, NULL
,
9659 "%s is no longer the default printer.", oldprinter
->name
);
9661 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
9662 "%s is now the default printer.", printer
->name
);
9664 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
| CUPSD_DIRTY_CLASSES
|
9665 CUPSD_DIRTY_PRINTCAP
);
9667 cupsdLogMessage(CUPSD_LOG_INFO
,
9668 "Default destination set to \"%s\" by \"%s\".",
9669 printer
->name
, get_username(con
));
9672 * Everything was ok, so return OK status...
9675 con
->response
->request
.status
.status_code
= IPP_OK
;
9680 * 'set_job_attrs()' - Set job attributes.
9684 set_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
9685 ipp_attribute_t
*uri
) /* I - Job URI */
9687 ipp_attribute_t
*attr
, /* Current attribute */
9688 *attr2
; /* Job attribute */
9689 int jobid
; /* Job ID */
9690 cupsd_job_t
*job
; /* Current job */
9691 char scheme
[HTTP_MAX_URI
],
9692 /* Method portion of URI */
9693 username
[HTTP_MAX_URI
],
9694 /* Username portion of URI */
9696 /* Host portion of URI */
9697 resource
[HTTP_MAX_URI
];
9698 /* Resource portion of URI */
9699 int port
; /* Port portion of URI */
9700 int event
; /* Events? */
9701 int check_jobs
; /* Check jobs? */
9704 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_job_attrs(%p[%d], %s)", con
,
9705 con
->number
, uri
->values
[0].string
.text
);
9708 * Start with "everything is OK" status...
9711 con
->response
->request
.status
.status_code
= IPP_OK
;
9714 * See if we have a job URI or a printer URI...
9717 if (!strcmp(uri
->name
, "printer-uri"))
9720 * Got a printer URI; see if we also have a job-id attribute...
9723 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9724 IPP_TAG_INTEGER
)) == NULL
)
9726 send_ipp_status(con
, IPP_BAD_REQUEST
,
9727 _("Got a printer-uri attribute but no job-id."));
9731 jobid
= attr
->values
[0].integer
;
9736 * Got a job URI; parse it to get the job ID...
9739 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9740 sizeof(scheme
), username
, sizeof(username
), host
,
9741 sizeof(host
), &port
, resource
, sizeof(resource
));
9743 if (strncmp(resource
, "/jobs/", 6))
9749 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9750 uri
->values
[0].string
.text
);
9754 jobid
= atoi(resource
+ 6);
9758 * See if the job exists...
9761 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9764 * Nope - return a "not found" error...
9767 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9772 * See if the job has been completed...
9775 if (job
->state_value
> IPP_JOB_STOPPED
)
9778 * Return a "not-possible" error...
9781 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9782 _("Job #%d is finished and cannot be altered."), jobid
);
9787 * See if the job is owned by the requesting user...
9790 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9792 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9793 cupsdFindDest(job
->dest
));
9798 * See what the user wants to change.
9806 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
9808 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
9811 if (!strcmp(attr
->name
, "attributes-charset") ||
9812 !strcmp(attr
->name
, "attributes-natural-language") ||
9813 !strcmp(attr
->name
, "document-compression") ||
9814 !strcmp(attr
->name
, "document-format") ||
9815 !strcmp(attr
->name
, "job-detailed-status-messages") ||
9816 !strcmp(attr
->name
, "job-document-access-errors") ||
9817 !strcmp(attr
->name
, "job-id") ||
9818 !strcmp(attr
->name
, "job-impressions-completed") ||
9819 !strcmp(attr
->name
, "job-k-octets") ||
9820 !strcmp(attr
->name
, "job-originating-host-name") ||
9821 !strcmp(attr
->name
, "job-originating-user-name") ||
9822 !strcmp(attr
->name
, "job-printer-up-time") ||
9823 !strcmp(attr
->name
, "job-printer-uri") ||
9824 !strcmp(attr
->name
, "job-sheets") ||
9825 !strcmp(attr
->name
, "job-state-message") ||
9826 !strcmp(attr
->name
, "job-state-reasons") ||
9827 !strcmp(attr
->name
, "job-uri") ||
9828 !strcmp(attr
->name
, "number-of-documents") ||
9829 !strcmp(attr
->name
, "number-of-intervening-jobs") ||
9830 !strcmp(attr
->name
, "output-device-assigned") ||
9831 !strncmp(attr
->name
, "date-time-at-", 13) ||
9832 !strncmp(attr
->name
, "job-k-octets", 12) ||
9833 !strncmp(attr
->name
, "job-media-sheets", 16) ||
9834 !strncmp(attr
->name
, "time-at-", 8))
9840 send_ipp_status(con
, IPP_ATTRIBUTES_NOT_SETTABLE
,
9841 _("%s cannot be changed."), attr
->name
);
9843 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
9844 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
9848 if (!strcmp(attr
->name
, "job-priority"))
9851 * Change the job priority...
9854 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
9856 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-priority value."));
9858 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
9859 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
9861 else if (job
->state_value
>= IPP_JOB_PROCESSING
)
9863 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9864 _("Job is completed and cannot be changed."));
9867 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
9869 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-priority to %d",
9870 attr
->values
[0].integer
);
9871 cupsdSetJobPriority(job
, attr
->values
[0].integer
);
9874 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
|
9875 CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
;
9878 else if (!strcmp(attr
->name
, "job-state"))
9881 * Change the job state...
9884 if (attr
->value_tag
!= IPP_TAG_ENUM
)
9886 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-state value."));
9888 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
9889 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
9893 switch (attr
->values
[0].integer
)
9895 case IPP_JOB_PENDING
:
9897 if (job
->state_value
> IPP_JOB_HELD
)
9899 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9900 _("Job state cannot be changed."));
9903 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
9905 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
9906 attr
->values
[0].integer
);
9907 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
, CUPSD_JOB_DEFAULT
, "Job state changed by \"%s\"", username
);
9912 case IPP_JOB_PROCESSING
:
9913 case IPP_JOB_STOPPED
:
9914 if (job
->state_value
!= attr
->values
[0].integer
)
9916 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9917 _("Job state cannot be changed."));
9922 case IPP_JOB_CANCELED
:
9923 case IPP_JOB_ABORTED
:
9924 case IPP_JOB_COMPLETED
:
9925 if (job
->state_value
> IPP_JOB_PROCESSING
)
9927 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9928 _("Job state cannot be changed."));
9931 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
9933 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
9934 attr
->values
[0].integer
);
9935 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
,
9937 "Job state changed by \"%s\"", username
);
9944 else if (con
->response
->request
.status
.status_code
!= IPP_OK
)
9946 else if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
9947 IPP_TAG_ZERO
)) != NULL
)
9950 * Some other value; first free the old value...
9953 if (job
->attrs
->prev
)
9954 job
->attrs
->prev
->next
= attr2
->next
;
9956 job
->attrs
->attrs
= attr2
->next
;
9958 if (job
->attrs
->last
== attr2
)
9959 job
->attrs
->last
= job
->attrs
->prev
;
9961 ippDeleteAttribute(NULL
, attr2
);
9964 * Then copy the attribute...
9967 ippCopyAttribute(job
->attrs
, attr
, 0);
9970 * See if the job-name or job-hold-until is being changed.
9973 if (!strcmp(attr
->name
, "job-hold-until"))
9975 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-hold-until to %s",
9976 attr
->values
[0].string
.text
);
9977 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
9979 if (!strcmp(attr
->values
[0].string
.text
, "no-hold"))
9981 cupsdReleaseJob(job
);
9985 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
,
9986 "Job held by \"%s\".", username
);
9988 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
;
9991 else if (attr
->value_tag
== IPP_TAG_DELETEATTR
)
9994 * Delete the attribute...
9997 if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
9998 IPP_TAG_ZERO
)) != NULL
)
10000 if (job
->attrs
->prev
)
10001 job
->attrs
->prev
->next
= attr2
->next
;
10003 job
->attrs
->attrs
= attr2
->next
;
10005 if (attr2
== job
->attrs
->last
)
10006 job
->attrs
->last
= job
->attrs
->prev
;
10008 ippDeleteAttribute(NULL
, attr2
);
10010 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10016 * Add new option by copying it...
10019 ippCopyAttribute(job
->attrs
, attr
, 0);
10021 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10030 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10033 * Send events as needed...
10036 if (event
& CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
)
10037 cupsdAddEvent(CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
,
10038 cupsdFindDest(job
->dest
), job
,
10039 "Job priority changed by user.");
10041 if (event
& CUPSD_EVENT_JOB_STATE
)
10042 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
10043 job
->state_value
== IPP_JOB_HELD
?
10044 "Job held by user." : "Job restarted by user.");
10046 if (event
& CUPSD_EVENT_JOB_CONFIG_CHANGED
)
10047 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
10048 "Job options changed by user.");
10051 * Start jobs if possible...
10060 * 'set_printer_attrs()' - Set printer attributes.
10064 set_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
10065 ipp_attribute_t
*uri
) /* I - Printer */
10067 http_status_t status
; /* Policy status */
10068 cups_ptype_t dtype
; /* Destination type (printer/class) */
10069 cupsd_printer_t
*printer
; /* Printer/class */
10070 ipp_attribute_t
*attr
; /* Printer attribute */
10071 int changed
= 0; /* Was anything changed? */
10074 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_attrs(%p[%d], %s)", con
,
10075 con
->number
, uri
->values
[0].string
.text
);
10078 * Is the destination valid?
10081 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10087 send_ipp_status(con
, IPP_NOT_FOUND
,
10088 _("The printer or class does not exist."));
10096 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10098 send_http_error(con
, status
, printer
);
10103 * Return a list of attributes that can be set via Set-Printer-Attributes.
10106 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
10107 IPP_TAG_TEXT
)) != NULL
)
10109 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
10113 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
10114 IPP_TAG_TEXT
)) != NULL
)
10116 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
10121 * Update the printer attributes and return...
10126 cupsdSetPrinterAttrs(printer
);
10127 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
10129 cupsdAddEvent(CUPSD_EVENT_PRINTER_CONFIG
, printer
, NULL
,
10130 "Printer \"%s\" description or location changed by \"%s\".",
10131 printer
->name
, get_username(con
));
10133 cupsdLogMessage(CUPSD_LOG_INFO
,
10134 "Printer \"%s\" description or location changed by \"%s\".",
10135 printer
->name
, get_username(con
));
10138 con
->response
->request
.status
.status_code
= IPP_OK
;
10143 * 'set_printer_defaults()' - Set printer default options from a request.
10147 set_printer_defaults(
10148 cupsd_client_t
*con
, /* I - Client connection */
10149 cupsd_printer_t
*printer
) /* I - Printer */
10151 int i
; /* Looping var */
10152 ipp_attribute_t
*attr
; /* Current attribute */
10153 size_t namelen
; /* Length of attribute name */
10154 char name
[256], /* New attribute name */
10155 value
[256]; /* String version of integer attrs */
10158 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10161 * Skip non-printer attributes...
10164 if (attr
->group_tag
!= IPP_TAG_PRINTER
|| !attr
->name
)
10167 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_defaults: %s", attr
->name
);
10169 if (!strcmp(attr
->name
, "job-sheets-default"))
10172 * Only allow keywords and names...
10175 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10179 * Only allow job-sheets-default to be set when running without a
10180 * system high classification level...
10183 if (Classification
)
10186 cupsdSetString(&printer
->job_sheets
[0], attr
->values
[0].string
.text
);
10188 if (attr
->num_values
> 1)
10189 cupsdSetString(&printer
->job_sheets
[1], attr
->values
[1].string
.text
);
10191 cupsdSetString(&printer
->job_sheets
[1], "none");
10193 else if (!strcmp(attr
->name
, "requesting-user-name-allowed"))
10195 cupsdFreeStrings(&(printer
->users
));
10197 printer
->deny_users
= 0;
10199 if (attr
->value_tag
== IPP_TAG_NAME
&&
10200 (attr
->num_values
> 1 ||
10201 strcmp(attr
->values
[0].string
.text
, "all")))
10203 for (i
= 0; i
< attr
->num_values
; i
++)
10204 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
10207 else if (!strcmp(attr
->name
, "requesting-user-name-denied"))
10209 cupsdFreeStrings(&(printer
->users
));
10211 printer
->deny_users
= 1;
10213 if (attr
->value_tag
== IPP_TAG_NAME
&&
10214 (attr
->num_values
> 1 ||
10215 strcmp(attr
->values
[0].string
.text
, "none")))
10217 for (i
= 0; i
< attr
->num_values
; i
++)
10218 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
10221 else if (!strcmp(attr
->name
, "job-quota-period"))
10223 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10226 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-quota-period to %d...",
10227 attr
->values
[0].integer
);
10228 cupsdFreeQuotas(printer
);
10230 printer
->quota_period
= attr
->values
[0].integer
;
10232 else if (!strcmp(attr
->name
, "job-k-limit"))
10234 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10237 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-k-limit to %d...",
10238 attr
->values
[0].integer
);
10239 cupsdFreeQuotas(printer
);
10241 printer
->k_limit
= attr
->values
[0].integer
;
10243 else if (!strcmp(attr
->name
, "job-page-limit"))
10245 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10248 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-page-limit to %d...",
10249 attr
->values
[0].integer
);
10250 cupsdFreeQuotas(printer
);
10252 printer
->page_limit
= attr
->values
[0].integer
;
10254 else if (!strcmp(attr
->name
, "printer-op-policy"))
10256 cupsd_policy_t
*p
; /* Policy */
10259 if (attr
->value_tag
!= IPP_TAG_NAME
)
10262 if ((p
= cupsdFindPolicy(attr
->values
[0].string
.text
)) != NULL
)
10264 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10265 "Setting printer-op-policy to \"%s\"...",
10266 attr
->values
[0].string
.text
);
10267 cupsdSetString(&printer
->op_policy
, attr
->values
[0].string
.text
);
10268 printer
->op_policy_ptr
= p
;
10272 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10273 _("Unknown printer-op-policy \"%s\"."),
10274 attr
->values
[0].string
.text
);
10278 else if (!strcmp(attr
->name
, "printer-error-policy"))
10280 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10283 if (strcmp(attr
->values
[0].string
.text
, "retry-current-job") &&
10284 ((printer
->type
& CUPS_PRINTER_CLASS
) ||
10285 (strcmp(attr
->values
[0].string
.text
, "abort-job") &&
10286 strcmp(attr
->values
[0].string
.text
, "retry-job") &&
10287 strcmp(attr
->values
[0].string
.text
, "stop-printer"))))
10289 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10290 _("Unknown printer-error-policy \"%s\"."),
10291 attr
->values
[0].string
.text
);
10295 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10296 "Setting printer-error-policy to \"%s\"...",
10297 attr
->values
[0].string
.text
);
10298 cupsdSetString(&printer
->error_policy
, attr
->values
[0].string
.text
);
10302 * Skip any other non-default attributes...
10305 namelen
= strlen(attr
->name
);
10306 if (namelen
< 9 || strcmp(attr
->name
+ namelen
- 8, "-default") ||
10307 namelen
> (sizeof(name
) - 1) || attr
->num_values
!= 1)
10311 * OK, anything else must be a user-defined default...
10314 strlcpy(name
, attr
->name
, sizeof(name
));
10315 name
[namelen
- 8] = '\0'; /* Strip "-default" */
10317 switch (attr
->value_tag
)
10319 case IPP_TAG_DELETEATTR
:
10320 printer
->num_options
= cupsRemoveOption(name
,
10321 printer
->num_options
,
10322 &(printer
->options
));
10323 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10324 "Deleting %s", attr
->name
);
10327 case IPP_TAG_NAME
:
10328 case IPP_TAG_TEXT
:
10329 case IPP_TAG_KEYWORD
:
10331 printer
->num_options
= cupsAddOption(name
,
10332 attr
->values
[0].string
.text
,
10333 printer
->num_options
,
10334 &(printer
->options
));
10335 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10336 "Setting %s to \"%s\"...", attr
->name
,
10337 attr
->values
[0].string
.text
);
10340 case IPP_TAG_BOOLEAN
:
10341 printer
->num_options
= cupsAddOption(name
,
10342 attr
->values
[0].boolean
?
10344 printer
->num_options
,
10345 &(printer
->options
));
10346 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10347 "Setting %s to %s...", attr
->name
,
10348 attr
->values
[0].boolean
? "true" : "false");
10351 case IPP_TAG_INTEGER
:
10352 case IPP_TAG_ENUM
:
10353 sprintf(value
, "%d", attr
->values
[0].integer
);
10354 printer
->num_options
= cupsAddOption(name
, value
,
10355 printer
->num_options
,
10356 &(printer
->options
));
10357 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10358 "Setting %s to %s...", attr
->name
, value
);
10361 case IPP_TAG_RANGE
:
10362 sprintf(value
, "%d-%d", attr
->values
[0].range
.lower
,
10363 attr
->values
[0].range
.upper
);
10364 printer
->num_options
= cupsAddOption(name
, value
,
10365 printer
->num_options
,
10366 &(printer
->options
));
10367 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10368 "Setting %s to %s...", attr
->name
, value
);
10371 case IPP_TAG_RESOLUTION
:
10372 sprintf(value
, "%dx%d%s", attr
->values
[0].resolution
.xres
,
10373 attr
->values
[0].resolution
.yres
,
10374 attr
->values
[0].resolution
.units
== IPP_RES_PER_INCH
?
10376 printer
->num_options
= cupsAddOption(name
, value
,
10377 printer
->num_options
,
10378 &(printer
->options
));
10379 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10380 "Setting %s to %s...", attr
->name
, value
);
10384 /* Do nothing for other values */
10392 * 'start_printer()' - Start a printer.
10396 start_printer(cupsd_client_t
*con
, /* I - Client connection */
10397 ipp_attribute_t
*uri
) /* I - Printer URI */
10399 int i
; /* Temporary variable */
10400 http_status_t status
; /* Policy status */
10401 cups_ptype_t dtype
; /* Destination type (printer/class) */
10402 cupsd_printer_t
*printer
; /* Printer data */
10405 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_printer(%p[%d], %s)", con
,
10406 con
->number
, uri
->values
[0].string
.text
);
10409 * Is the destination valid?
10412 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10418 send_ipp_status(con
, IPP_NOT_FOUND
,
10419 _("The printer or class does not exist."));
10427 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10429 send_http_error(con
, status
, printer
);
10434 * Start the printer...
10437 printer
->state_message
[0] = '\0';
10439 cupsdStartPrinter(printer
, 1);
10441 if (dtype
& CUPS_PRINTER_CLASS
)
10442 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" started by \"%s\".",
10443 printer
->name
, get_username(con
));
10445 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" started by \"%s\".",
10446 printer
->name
, get_username(con
));
10454 if ((i
= check_quotas(con
, printer
)) < 0)
10456 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
10461 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
10466 * Everything was ok, so return OK status...
10469 con
->response
->request
.status
.status_code
= IPP_OK
;
10474 * 'stop_printer()' - Stop a printer.
10478 stop_printer(cupsd_client_t
*con
, /* I - Client connection */
10479 ipp_attribute_t
*uri
) /* I - Printer URI */
10481 http_status_t status
; /* Policy status */
10482 cups_ptype_t dtype
; /* Destination type (printer/class) */
10483 cupsd_printer_t
*printer
; /* Printer data */
10484 ipp_attribute_t
*attr
; /* printer-state-message attribute */
10487 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "stop_printer(%p[%d], %s)", con
,
10488 con
->number
, uri
->values
[0].string
.text
);
10491 * Is the destination valid?
10494 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10500 send_ipp_status(con
, IPP_NOT_FOUND
,
10501 _("The printer or class does not exist."));
10509 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10511 send_http_error(con
, status
, printer
);
10516 * Stop the printer...
10519 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
10520 IPP_TAG_TEXT
)) == NULL
)
10521 strlcpy(printer
->state_message
, "Paused", sizeof(printer
->state_message
));
10524 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
10525 sizeof(printer
->state_message
));
10528 cupsdStopPrinter(printer
, 1);
10530 if (dtype
& CUPS_PRINTER_CLASS
)
10531 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" stopped by \"%s\".",
10532 printer
->name
, get_username(con
));
10534 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" stopped by \"%s\".",
10535 printer
->name
, get_username(con
));
10538 * Everything was ok, so return OK status...
10541 con
->response
->request
.status
.status_code
= IPP_OK
;
10546 * 'url_encode_attr()' - URL-encode a string attribute.
10550 url_encode_attr(ipp_attribute_t
*attr
, /* I - Attribute */
10551 char *buffer
,/* I - String buffer */
10552 size_t bufsize
)/* I - Size of buffer */
10554 int i
; /* Looping var */
10555 char *bufptr
, /* Pointer into buffer */
10556 *bufend
; /* End of buffer */
10559 strlcpy(buffer
, attr
->name
, bufsize
);
10560 bufptr
= buffer
+ strlen(buffer
);
10561 bufend
= buffer
+ bufsize
- 1;
10563 for (i
= 0; i
< attr
->num_values
; i
++)
10565 if (bufptr
>= bufend
)
10573 if (bufptr
>= bufend
)
10578 bufptr
= url_encode_string(attr
->values
[i
].string
.text
, bufptr
, (size_t)(bufend
- bufptr
+ 1));
10580 if (bufptr
>= bufend
)
10591 * 'url_encode_string()' - URL-encode a string.
10594 static char * /* O - End of string */
10595 url_encode_string(const char *s
, /* I - String */
10596 char *buffer
, /* I - String buffer */
10597 size_t bufsize
) /* I - Size of buffer */
10599 char *bufptr
, /* Pointer into buffer */
10600 *bufend
; /* End of buffer */
10601 static const char *hex
= "0123456789ABCDEF";
10606 bufend
= buffer
+ bufsize
- 1;
10608 while (*s
&& bufptr
< bufend
)
10610 if (*s
== ' ' || *s
== '%' || *s
== '+')
10612 if (bufptr
>= (bufend
- 2))
10616 *bufptr
++ = hex
[(*s
>> 4) & 15];
10617 *bufptr
++ = hex
[*s
& 15];
10621 else if (*s
== '\'' || *s
== '\\')
10623 if (bufptr
>= (bufend
- 1))
10640 * 'user_allowed()' - See if a user is allowed to print to a queue.
10643 static int /* O - 0 if not allowed, 1 if allowed */
10644 user_allowed(cupsd_printer_t
*p
, /* I - Printer or class */
10645 const char *username
) /* I - Username */
10647 struct passwd
*pw
; /* User password data */
10648 char baseuser
[256], /* Base username */
10649 *baseptr
, /* Pointer to "@" in base username */
10650 *name
; /* Current user name */
10653 if (cupsArrayCount(p
->users
) == 0)
10656 if (!strcmp(username
, "root"))
10659 if (strchr(username
, '@'))
10662 * Strip @REALM for username check...
10665 strlcpy(baseuser
, username
, sizeof(baseuser
));
10667 if ((baseptr
= strchr(baseuser
, '@')) != NULL
)
10670 username
= baseuser
;
10673 pw
= getpwnam(username
);
10676 for (name
= (char *)cupsArrayFirst(p
->users
);
10678 name
= (char *)cupsArrayNext(p
->users
))
10680 if (name
[0] == '@')
10683 * Check group membership...
10686 if (cupsdCheckGroup(username
, pw
, name
+ 1))
10689 else if (name
[0] == '#')
10695 if (cupsdCheckGroup(username
, pw
, name
))
10698 else if (!_cups_strcasecmp(username
, name
))
10702 return ((name
!= NULL
) != p
->deny_users
);
10707 * 'validate_job()' - Validate printer options and destination.
10711 validate_job(cupsd_client_t
*con
, /* I - Client connection */
10712 ipp_attribute_t
*uri
) /* I - Printer URI */
10714 http_status_t status
; /* Policy status */
10715 ipp_attribute_t
*attr
, /* Current attribute */
10716 *auth_info
; /* auth-info attribute */
10717 ipp_attribute_t
*format
, /* Document-format attribute */
10718 *name
; /* Job-name attribute */
10719 cups_ptype_t dtype
; /* Destination type (printer/class) */
10720 char super
[MIME_MAX_SUPER
],
10721 /* Supertype of file */
10722 type
[MIME_MAX_TYPE
];
10723 /* Subtype of file */
10724 cupsd_printer_t
*printer
; /* Printer */
10727 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_job(%p[%d], %s)", con
,
10728 con
->number
, uri
->values
[0].string
.text
);
10731 * OK, see if the client is sending the document compressed - CUPS
10732 * doesn't support compression yet...
10735 if ((attr
= ippFindAttribute(con
->request
, "compression",
10736 IPP_TAG_KEYWORD
)) != NULL
)
10738 if (strcmp(attr
->values
[0].string
.text
, "none")
10740 && strcmp(attr
->values
[0].string
.text
, "gzip")
10741 #endif /* HAVE_LIBZ */
10744 send_ipp_status(con
, IPP_ATTRIBUTES
,
10745 _("Unsupported 'compression' value \"%s\"."),
10746 attr
->values
[0].string
.text
);
10747 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
10748 "compression", NULL
, attr
->values
[0].string
.text
);
10754 * Is it a format we support?
10757 if ((format
= ippFindAttribute(con
->request
, "document-format",
10758 IPP_TAG_MIMETYPE
)) != NULL
)
10760 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%255[^;]",
10763 send_ipp_status(con
, IPP_BAD_REQUEST
,
10764 _("Bad 'document-format' value \"%s\"."),
10765 format
->values
[0].string
.text
);
10769 if ((strcmp(super
, "application") || strcmp(type
, "octet-stream")) &&
10770 !mimeType(MimeDatabase
, super
, type
))
10772 cupsdLogMessage(CUPSD_LOG_INFO
,
10773 "Hint: Do you have the raw file printing rules enabled?");
10774 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
10775 _("Unsupported 'document-format' value \"%s\"."),
10776 format
->values
[0].string
.text
);
10777 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
10778 "document-format", NULL
, format
->values
[0].string
.text
);
10784 * Is the job-name valid?
10787 if ((name
= ippFindAttribute(con
->request
, "job-name", IPP_TAG_ZERO
)) != NULL
)
10789 int bad_name
= 0; /* Is the job-name value bad? */
10791 if ((name
->value_tag
!= IPP_TAG_NAME
&& name
->value_tag
!= IPP_TAG_NAMELANG
) ||
10792 name
->num_values
!= 1)
10799 * Validate that job-name conforms to RFC 5198 (Network Unicode) and
10800 * IPP Everywhere requirements for "name" values...
10803 const unsigned char *nameptr
; /* Pointer into "job-name" attribute */
10805 for (nameptr
= (unsigned char *)name
->values
[0].string
.text
;
10809 if (*nameptr
< ' ' && *nameptr
!= '\t')
10811 else if (*nameptr
== 0x7f)
10813 else if ((*nameptr
& 0xe0) == 0xc0)
10815 if ((nameptr
[1] & 0xc0) != 0x80)
10820 else if ((*nameptr
& 0xf0) == 0xe0)
10822 if ((nameptr
[1] & 0xc0) != 0x80 ||
10823 (nameptr
[2] & 0xc0) != 0x80)
10828 else if ((*nameptr
& 0xf8) == 0xf0)
10830 if ((nameptr
[1] & 0xc0) != 0x80 ||
10831 (nameptr
[2] & 0xc0) != 0x80 ||
10832 (nameptr
[3] & 0xc0) != 0x80)
10837 else if (*nameptr
& 0x80)
10847 if (StrictConformance
)
10849 send_ipp_status(con
, IPP_ATTRIBUTES
,
10850 _("Unsupported 'job-name' value."));
10851 ippCopyAttribute(con
->response
, name
, 0);
10856 cupsdLogMessage(CUPSD_LOG_WARN
,
10857 "Unsupported 'job-name' value, deleting from request.");
10858 ippDeleteAttribute(con
->request
, name
);
10864 * Is the destination valid?
10867 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10873 send_ipp_status(con
, IPP_NOT_FOUND
,
10874 _("The printer or class does not exist."));
10882 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
10884 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10886 send_http_error(con
, status
, printer
);
10889 else if (printer
->num_auth_info_required
== 1 &&
10890 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
10893 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
10897 else if (auth_info
&& !con
->http
->tls
&&
10898 !httpAddrLocalhost(con
->http
->hostaddr
))
10901 * Require encryption of auth-info over non-local connections...
10904 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
10907 #endif /* HAVE_SSL */
10910 * Everything was ok, so return OK status...
10913 con
->response
->request
.status
.status_code
= IPP_OK
;
10918 * 'validate_name()' - Make sure the printer name only contains valid chars.
10921 static int /* O - 0 if name is no good, 1 if good */
10922 validate_name(const char *name
) /* I - Name to check */
10924 const char *ptr
; /* Pointer into name */
10928 * Scan the whole name...
10931 for (ptr
= name
; *ptr
; ptr
++)
10932 if ((*ptr
> 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
10936 * All the characters are good; validate the length, too...
10939 return ((ptr
- name
) < 128);
10944 * 'validate_user()' - Validate the user for the request.
10947 static int /* O - 1 if permitted, 0 otherwise */
10948 validate_user(cupsd_job_t
*job
, /* I - Job */
10949 cupsd_client_t
*con
, /* I - Client connection */
10950 const char *owner
, /* I - Owner of job/resource */
10951 char *username
, /* O - Authenticated username */
10952 size_t userlen
) /* I - Length of username */
10954 cupsd_printer_t
*printer
; /* Printer for job */
10957 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
);
10960 * Validate input...
10963 if (!con
|| !owner
|| !username
|| userlen
<= 0)
10967 * Get the best authenticated username that is available.
10970 strlcpy(username
, get_username(con
), userlen
);
10973 * Check the username against the owner...
10976 printer
= cupsdFindDest(job
->dest
);
10978 return (cupsdCheckPolicy(printer
? printer
->op_policy_ptr
: DefaultPolicyPtr
,
10979 con
, owner
) == HTTP_OK
);