2 * IPP routines for the CUPS scheduler.
4 * Copyright 2007-2016 by Apple Inc.
5 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
7 * This file contains Kerberos support code, copyright 2006 by
10 * Licensed under Apache License v2.0. See the file "LICENSE" for more information.
14 * Include necessary headers...
18 #include <cups/ppd-private.h>
21 /*# include <ApplicationServices/ApplicationServices.h>
22 extern CFUUIDRef ColorSyncCreateUUIDFromUInt32(unsigned id);
23 # include <CoreFoundation/CoreFoundation.h>*/
24 # ifdef HAVE_MEMBERSHIP_H
25 # include <membership.h>
26 # endif /* HAVE_MEMBERSHIP_H */
27 # ifdef HAVE_MEMBERSHIPPRIV_H
28 # include <membershipPriv.h>
30 extern int mbr_user_name_to_uuid(const char* name
, uuid_t uu
);
31 extern int mbr_group_name_to_uuid(const char* name
, uuid_t uu
);
32 extern int mbr_check_membership_by_id(uuid_t user
, gid_t group
, int* ismember
);
33 # endif /* HAVE_MEMBERSHIPPRIV_H */
34 #endif /* __APPLE__ */
41 static void accept_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
42 static void add_class(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
43 static int add_file(cupsd_client_t
*con
, cupsd_job_t
*job
,
44 mime_type_t
*filetype
, int compression
);
45 static cupsd_job_t
*add_job(cupsd_client_t
*con
, cupsd_printer_t
*printer
,
46 mime_type_t
*filetype
);
47 static void add_job_subscriptions(cupsd_client_t
*con
, cupsd_job_t
*job
);
48 static void add_job_uuid(cupsd_job_t
*job
);
49 static void add_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
50 static void add_printer_state_reasons(cupsd_client_t
*con
,
52 static void add_queued_job_count(cupsd_client_t
*con
, cupsd_printer_t
*p
);
53 static void apply_printer_defaults(cupsd_printer_t
*printer
,
55 static void authenticate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
56 static void cancel_all_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
57 static void cancel_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
58 static void cancel_subscription(cupsd_client_t
*con
, int id
);
59 static int check_rss_recipient(const char *recipient
);
60 static int check_quotas(cupsd_client_t
*con
, cupsd_printer_t
*p
);
61 static void close_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
62 static void copy_attrs(ipp_t
*to
, ipp_t
*from
, cups_array_t
*ra
,
63 ipp_tag_t group
, int quickcopy
,
64 cups_array_t
*exclude
);
65 static int copy_banner(cupsd_client_t
*con
, cupsd_job_t
*job
,
67 static int copy_file(const char *from
, const char *to
, mode_t mode
);
68 static int copy_model(cupsd_client_t
*con
, const char *from
,
70 static void copy_job_attrs(cupsd_client_t
*con
,
72 cups_array_t
*ra
, cups_array_t
*exclude
);
73 static void copy_printer_attrs(cupsd_client_t
*con
,
74 cupsd_printer_t
*printer
,
76 static void copy_subscription_attrs(cupsd_client_t
*con
,
77 cupsd_subscription_t
*sub
,
79 cups_array_t
*exclude
);
80 static void create_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
81 static void create_local_printer(cupsd_client_t
*con
);
82 static cups_array_t
*create_requested_array(ipp_t
*request
);
83 static void create_subscriptions(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
84 static void delete_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
85 static void get_default(cupsd_client_t
*con
);
86 static void get_devices(cupsd_client_t
*con
);
87 static void get_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
88 static void get_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
89 static void get_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
90 static void get_notifications(cupsd_client_t
*con
);
91 static void get_ppd(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
92 static void get_ppds(cupsd_client_t
*con
);
93 static void get_printers(cupsd_client_t
*con
, int type
);
94 static void get_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
95 static void get_printer_supported(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
96 static void get_subscription_attrs(cupsd_client_t
*con
, int sub_id
);
97 static void get_subscriptions(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
98 static const char *get_username(cupsd_client_t
*con
);
99 static void hold_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
100 static void hold_new_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
101 static void move_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
102 static int ppd_parse_line(const char *line
, char *option
, int olen
,
103 char *choice
, int clen
);
104 static void print_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
105 static void read_job_ticket(cupsd_client_t
*con
);
106 static void reject_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
107 static void release_held_new_jobs(cupsd_client_t
*con
,
108 ipp_attribute_t
*uri
);
109 static void release_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
110 static void renew_subscription(cupsd_client_t
*con
, int sub_id
);
111 static void restart_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
112 static void save_auth_info(cupsd_client_t
*con
, cupsd_job_t
*job
,
113 ipp_attribute_t
*auth_info
);
114 static void send_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
115 static void send_http_error(cupsd_client_t
*con
, http_status_t status
,
116 cupsd_printer_t
*printer
);
117 static void send_ipp_status(cupsd_client_t
*con
, ipp_status_t status
,
118 const char *message
, ...)
119 __attribute__((__format__(__printf__
, 3, 4)));
120 static void set_default(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
121 static void set_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
122 static void set_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
123 static int set_printer_defaults(cupsd_client_t
*con
, cupsd_printer_t
*printer
);
124 static void start_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
125 static void stop_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
126 static void url_encode_attr(ipp_attribute_t
*attr
, char *buffer
, size_t bufsize
);
127 static char *url_encode_string(const char *s
, char *buffer
, size_t bufsize
);
128 static int user_allowed(cupsd_printer_t
*p
, const char *username
);
129 static void validate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
130 static int validate_name(const char *name
);
131 static int validate_user(cupsd_job_t
*job
, cupsd_client_t
*con
, const char *owner
, char *username
, size_t userlen
);
135 * 'cupsdProcessIPPRequest()' - Process an incoming IPP request.
138 int /* O - 1 on success, 0 on failure */
139 cupsdProcessIPPRequest(
140 cupsd_client_t
*con
) /* I - Client connection */
142 ipp_tag_t group
; /* Current group tag */
143 ipp_attribute_t
*attr
; /* Current attribute */
144 ipp_attribute_t
*charset
; /* Character set attribute */
145 ipp_attribute_t
*language
; /* Language attribute */
146 ipp_attribute_t
*uri
= NULL
; /* Printer or job URI attribute */
147 ipp_attribute_t
*username
; /* requesting-user-name attr */
148 int sub_id
; /* Subscription ID */
151 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdProcessIPPRequest(%p[%d]): operation_id=%04x(%s)", con
, con
->number
, con
->request
->request
.op
.operation_id
, ippOpString(con
->request
->request
.op
.operation_id
));
153 if (LogLevel
>= CUPSD_LOG_DEBUG2
)
155 for (group
= IPP_TAG_ZERO
, attr
= ippFirstAttribute(con
->request
); attr
; attr
= ippNextAttribute(con
->request
))
157 const char *name
; /* Attribute name */
158 char value
[1024]; /* Attribute value */
160 if (group
!= ippGetGroupTag(attr
))
162 group
= ippGetGroupTag(attr
);
163 if (group
!= IPP_TAG_ZERO
)
164 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdProcessIPPRequest: %s", ippTagString(group
));
167 if ((name
= ippGetName(attr
)) == NULL
)
170 ippAttributeString(attr
, value
, sizeof(value
));
172 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdProcessIPPRequest: %s %s%s '%s'", name
, ippGetCount(attr
) > 1 ? "1setOf " : "", ippTagString(ippGetValueTag(attr
)), value
);
177 * First build an empty response message for this request...
180 con
->response
= ippNew();
182 con
->response
->request
.status
.version
[0] =
183 con
->request
->request
.op
.version
[0];
184 con
->response
->request
.status
.version
[1] =
185 con
->request
->request
.op
.version
[1];
186 con
->response
->request
.status
.request_id
=
187 con
->request
->request
.op
.request_id
;
190 * Then validate the request header and required attributes...
193 if (con
->request
->request
.any
.version
[0] != 1 &&
194 con
->request
->request
.any
.version
[0] != 2)
197 * Return an error, since we only support IPP 1.x and 2.x.
200 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
201 "%04X %s Bad request version number %d.%d",
202 IPP_VERSION_NOT_SUPPORTED
, con
->http
->hostname
,
203 con
->request
->request
.any
.version
[0],
204 con
->request
->request
.any
.version
[1]);
206 send_ipp_status(con
, IPP_VERSION_NOT_SUPPORTED
,
207 _("Bad request version number %d.%d."),
208 con
->request
->request
.any
.version
[0],
209 con
->request
->request
.any
.version
[1]);
211 else if (con
->request
->request
.any
.request_id
< 1)
214 * Return an error, since request IDs must be between 1 and 2^31-1
217 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
218 "%04X %s Bad request ID %d",
219 IPP_BAD_REQUEST
, con
->http
->hostname
,
220 con
->request
->request
.any
.request_id
);
222 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad request ID %d."),
223 con
->request
->request
.any
.request_id
);
225 else if (!con
->request
->attrs
)
227 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
228 "%04X %s No attributes in request",
229 IPP_BAD_REQUEST
, con
->http
->hostname
);
231 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No attributes in request."));
236 * Make sure that the attributes are provided in the correct order and
237 * don't repeat groups...
240 for (attr
= con
->request
->attrs
, group
= attr
->group_tag
;
243 if (attr
->group_tag
< group
&& attr
->group_tag
!= IPP_TAG_ZERO
)
246 * Out of order; return an error...
249 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
250 "%04X %s Attribute groups are out of order",
251 IPP_BAD_REQUEST
, con
->http
->hostname
);
253 send_ipp_status(con
, IPP_BAD_REQUEST
,
254 _("Attribute groups are out of order (%x < %x)."),
255 attr
->group_tag
, group
);
259 group
= attr
->group_tag
;
264 * Then make sure that the first three attributes are:
267 * attributes-natural-language
268 * printer-uri/job-uri
271 attr
= con
->request
->attrs
;
272 if (attr
&& attr
->name
&&
273 !strcmp(attr
->name
, "attributes-charset") &&
274 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_CHARSET
)
282 if (attr
&& attr
->name
&&
283 !strcmp(attr
->name
, "attributes-natural-language") &&
284 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_LANGUAGE
)
289 * Reset language for this request if different from Accept-Language.
292 if (!con
->language
||
293 strcmp(attr
->values
[0].string
.text
, con
->language
->language
))
295 cupsLangFree(con
->language
);
296 con
->language
= cupsLangGet(attr
->values
[0].string
.text
);
302 if ((attr
= ippFindAttribute(con
->request
, "printer-uri",
303 IPP_TAG_URI
)) != NULL
)
305 else if ((attr
= ippFindAttribute(con
->request
, "job-uri",
306 IPP_TAG_URI
)) != NULL
)
308 else if (con
->request
->request
.op
.operation_id
== CUPS_GET_PPD
)
309 uri
= ippFindAttribute(con
->request
, "ppd-name", IPP_TAG_NAME
);
314 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
315 "attributes-charset", NULL
,
316 charset
->values
[0].string
.text
);
318 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
319 "attributes-charset", NULL
, "utf-8");
322 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
323 "attributes-natural-language", NULL
,
324 language
->values
[0].string
.text
);
326 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
327 "attributes-natural-language", NULL
, DefaultLanguage
);
330 _cups_strcasecmp(charset
->values
[0].string
.text
, "us-ascii") &&
331 _cups_strcasecmp(charset
->values
[0].string
.text
, "utf-8"))
334 * Bad character set...
337 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unsupported character set \"%s\"",
338 charset
->values
[0].string
.text
);
339 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
340 "%04X %s Unsupported attributes-charset value \"%s\"",
341 IPP_CHARSET
, con
->http
->hostname
,
342 charset
->values
[0].string
.text
);
343 send_ipp_status(con
, IPP_BAD_REQUEST
,
344 _("Unsupported character set \"%s\"."),
345 charset
->values
[0].string
.text
);
347 else if (!charset
|| !language
||
349 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEFAULT
&&
350 con
->request
->request
.op
.operation_id
!= CUPS_GET_PRINTERS
&&
351 con
->request
->request
.op
.operation_id
!= CUPS_GET_CLASSES
&&
352 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEVICES
&&
353 con
->request
->request
.op
.operation_id
!= CUPS_GET_PPDS
))
356 * Return an error, since attributes-charset,
357 * attributes-natural-language, and printer-uri/job-uri are required
358 * for all operations.
363 cupsdLogMessage(CUPSD_LOG_ERROR
,
364 "Missing attributes-charset attribute");
366 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
367 "%04X %s Missing attributes-charset attribute",
368 IPP_BAD_REQUEST
, con
->http
->hostname
);
373 cupsdLogMessage(CUPSD_LOG_ERROR
,
374 "Missing attributes-natural-language attribute");
376 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
377 "%04X %s Missing attributes-natural-language attribute",
378 IPP_BAD_REQUEST
, con
->http
->hostname
);
383 cupsdLogMessage(CUPSD_LOG_ERROR
,
384 "Missing printer-uri, job-uri, or ppd-name "
387 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
388 "%04X %s Missing printer-uri, job-uri, or ppd-name "
389 "attribute", IPP_BAD_REQUEST
, con
->http
->hostname
);
392 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Request attributes follow...");
394 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
395 cupsdLogMessage(CUPSD_LOG_DEBUG
,
396 "attr \"%s\": group_tag = %x, value_tag = %x",
397 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
400 cupsdLogMessage(CUPSD_LOG_DEBUG
, "End of attributes...");
402 send_ipp_status(con
, IPP_BAD_REQUEST
,
403 _("Missing required attributes."));
408 * OK, all the checks pass so far; make sure requesting-user-name is
409 * not "root" from a remote host...
412 if ((username
= ippFindAttribute(con
->request
, "requesting-user-name",
413 IPP_TAG_NAME
)) != NULL
)
416 * Check for root user...
419 if (!strcmp(username
->values
[0].string
.text
, "root") &&
420 _cups_strcasecmp(con
->http
->hostname
, "localhost") &&
421 strcmp(con
->username
, "root"))
424 * Remote unauthenticated user masquerading as local root...
427 ippSetString(con
->request
, &username
, 0, RemoteRoot
);
431 if ((attr
= ippFindAttribute(con
->request
, "notify-subscription-id",
432 IPP_TAG_INTEGER
)) != NULL
)
433 sub_id
= attr
->values
[0].integer
;
438 * Then try processing the operation...
442 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s",
443 ippOpString(con
->request
->request
.op
.operation_id
),
444 uri
->values
[0].string
.text
);
446 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s",
447 ippOpString(con
->request
->request
.op
.operation_id
));
449 switch (con
->request
->request
.op
.operation_id
)
451 case IPP_OP_PRINT_JOB
:
455 case IPP_OP_VALIDATE_JOB
:
456 validate_job(con
, uri
);
459 case IPP_OP_CREATE_JOB
:
460 create_job(con
, uri
);
463 case IPP_OP_SEND_DOCUMENT
:
464 send_document(con
, uri
);
467 case IPP_OP_CANCEL_JOB
:
468 cancel_job(con
, uri
);
471 case IPP_OP_GET_JOB_ATTRIBUTES
:
472 get_job_attrs(con
, uri
);
475 case IPP_OP_GET_JOBS
:
479 case IPP_OP_GET_PRINTER_ATTRIBUTES
:
480 get_printer_attrs(con
, uri
);
483 case IPP_OP_GET_PRINTER_SUPPORTED_VALUES
:
484 get_printer_supported(con
, uri
);
487 case IPP_OP_HOLD_JOB
:
491 case IPP_OP_RELEASE_JOB
:
492 release_job(con
, uri
);
495 case IPP_OP_RESTART_JOB
:
496 restart_job(con
, uri
);
499 case IPP_OP_PAUSE_PRINTER
:
500 stop_printer(con
, uri
);
503 case IPP_OP_RESUME_PRINTER
:
504 start_printer(con
, uri
);
507 case IPP_OP_PURGE_JOBS
:
508 case IPP_OP_CANCEL_JOBS
:
509 case IPP_OP_CANCEL_MY_JOBS
:
510 cancel_all_jobs(con
, uri
);
513 case IPP_OP_SET_JOB_ATTRIBUTES
:
514 set_job_attrs(con
, uri
);
517 case IPP_OP_SET_PRINTER_ATTRIBUTES
:
518 set_printer_attrs(con
, uri
);
521 case IPP_OP_HOLD_NEW_JOBS
:
522 hold_new_jobs(con
, uri
);
525 case IPP_OP_RELEASE_HELD_NEW_JOBS
:
526 release_held_new_jobs(con
, uri
);
529 case IPP_OP_CLOSE_JOB
:
533 case IPP_OP_CUPS_GET_DEFAULT
:
537 case IPP_OP_CUPS_GET_PRINTERS
:
538 get_printers(con
, 0);
541 case IPP_OP_CUPS_GET_CLASSES
:
542 get_printers(con
, CUPS_PRINTER_CLASS
);
545 case IPP_OP_CUPS_ADD_MODIFY_PRINTER
:
546 add_printer(con
, uri
);
549 case IPP_OP_CUPS_DELETE_PRINTER
:
550 delete_printer(con
, uri
);
553 case IPP_OP_CUPS_ADD_MODIFY_CLASS
:
557 case IPP_OP_CUPS_DELETE_CLASS
:
558 delete_printer(con
, uri
);
561 case IPP_OP_CUPS_ACCEPT_JOBS
:
562 case IPP_OP_ENABLE_PRINTER
:
563 accept_jobs(con
, uri
);
566 case IPP_OP_CUPS_REJECT_JOBS
:
567 case IPP_OP_DISABLE_PRINTER
:
568 reject_jobs(con
, uri
);
571 case IPP_OP_CUPS_SET_DEFAULT
:
572 set_default(con
, uri
);
575 case IPP_OP_CUPS_GET_DEVICES
:
579 case IPP_OP_CUPS_GET_DOCUMENT
:
580 get_document(con
, uri
);
583 case IPP_OP_CUPS_GET_PPD
:
587 case IPP_OP_CUPS_GET_PPDS
:
591 case IPP_OP_CUPS_MOVE_JOB
:
595 case IPP_OP_CUPS_AUTHENTICATE_JOB
:
596 authenticate_job(con
, uri
);
599 case IPP_OP_CREATE_PRINTER_SUBSCRIPTIONS
:
600 case IPP_OP_CREATE_JOB_SUBSCRIPTIONS
:
601 create_subscriptions(con
, uri
);
604 case IPP_OP_GET_SUBSCRIPTION_ATTRIBUTES
:
605 get_subscription_attrs(con
, sub_id
);
608 case IPP_OP_GET_SUBSCRIPTIONS
:
609 get_subscriptions(con
, uri
);
612 case IPP_OP_RENEW_SUBSCRIPTION
:
613 renew_subscription(con
, sub_id
);
616 case IPP_OP_CANCEL_SUBSCRIPTION
:
617 cancel_subscription(con
, sub_id
);
620 case IPP_OP_GET_NOTIFICATIONS
:
621 get_notifications(con
);
624 case IPP_OP_CUPS_CREATE_LOCAL_PRINTER
:
625 create_local_printer(con
);
629 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
630 "%04X %s Operation %04X (%s) not supported",
631 IPP_OPERATION_NOT_SUPPORTED
, con
->http
->hostname
,
632 con
->request
->request
.op
.operation_id
,
633 ippOpString(con
->request
->request
.op
.operation_id
));
635 send_ipp_status(con
, IPP_OPERATION_NOT_SUPPORTED
,
636 _("%s not supported."),
638 con
->request
->request
.op
.operation_id
));
648 * Sending data from the scheduler...
651 cupsdLogMessage(con
->response
->request
.status
.status_code
652 >= IPP_BAD_REQUEST
&&
653 con
->response
->request
.status
.status_code
654 != IPP_NOT_FOUND
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
655 "[Client %d] Returning IPP %s for %s (%s) from %s",
657 ippErrorString(con
->response
->request
.status
.status_code
),
658 ippOpString(con
->request
->request
.op
.operation_id
),
659 uri
? uri
->values
[0].string
.text
: "no URI",
660 con
->http
->hostname
);
662 httpClearFields(con
->http
);
664 #ifdef CUPSD_USE_CHUNKING
666 * Because older versions of CUPS (1.1.17 and older) and some IPP
667 * clients do not implement chunking properly, we cannot use
668 * chunking by default. This may become the default in future
669 * CUPS releases, or we might add a configuration directive for
673 if (con
->http
->version
== HTTP_1_1
)
675 cupsdLogMessage(CUPSD_LOG_DEBUG
,
676 "[Client %d] Transfer-Encoding: chunked",
679 cupsdSetLength(con
->http
, 0);
682 #endif /* CUPSD_USE_CHUNKING */
684 size_t length
; /* Length of response */
687 length
= ippLength(con
->response
);
689 if (con
->file
>= 0 && !con
->pipe_pid
)
691 struct stat fileinfo
; /* File information */
693 if (!fstat(con
->file
, &fileinfo
))
694 length
+= (size_t)fileinfo
.st_size
;
697 cupsdLogMessage(CUPSD_LOG_DEBUG
,
698 "[Client %d] Content-Length: " CUPS_LLFMT
,
699 con
->number
, CUPS_LLCAST length
);
700 httpSetLength(con
->http
, length
);
703 if (cupsdSendHeader(con
, HTTP_OK
, "application/ipp", CUPSD_AUTH_NONE
))
706 * Tell the caller the response header was sent successfully...
709 cupsdAddSelect(httpGetFd(con
->http
), (cupsd_selfunc_t
)cupsdReadClient
,
710 (cupsd_selfunc_t
)cupsdWriteClient
, con
);
717 * Tell the caller the response header could not be sent...
726 * Sending data from a subprocess like cups-deviced; tell the caller
727 * everything is A-OK so far...
736 * 'cupsdTimeoutJob()' - Timeout a job waiting on job files.
739 int /* O - 0 on success, -1 on error */
740 cupsdTimeoutJob(cupsd_job_t
*job
) /* I - Job to timeout */
742 cupsd_printer_t
*printer
; /* Destination printer or class */
743 ipp_attribute_t
*attr
; /* job-sheets attribute */
744 int kbytes
; /* Kilobytes in banner */
747 job
->pending_timeout
= 0;
750 * See if we need to add the ending sheet...
753 if (!cupsdLoadJob(job
))
756 printer
= cupsdFindDest(job
->dest
);
757 attr
= ippFindAttribute(job
->attrs
, "job-sheets", IPP_TAG_NAME
);
759 if (printer
&& !(printer
->type
& CUPS_PRINTER_REMOTE
) &&
760 attr
&& attr
->num_values
> 1)
766 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding end banner page \"%s\".",
767 attr
->values
[1].string
.text
);
769 if ((kbytes
= copy_banner(NULL
, job
, attr
->values
[1].string
.text
)) < 0)
772 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
780 * 'accept_jobs()' - Accept print jobs to a printer.
784 accept_jobs(cupsd_client_t
*con
, /* I - Client connection */
785 ipp_attribute_t
*uri
) /* I - Printer or class URI */
787 http_status_t status
; /* Policy status */
788 cups_ptype_t dtype
; /* Destination type (printer/class) */
789 cupsd_printer_t
*printer
; /* Printer data */
792 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "accept_jobs(%p[%d], %s)", con
,
793 con
->number
, uri
->values
[0].string
.text
);
796 * Is the destination valid?
799 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
805 send_ipp_status(con
, IPP_NOT_FOUND
,
806 _("The printer or class does not exist."));
814 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
816 send_http_error(con
, status
, printer
);
821 * Accept jobs sent to the printer...
824 printer
->accepting
= 1;
825 printer
->state_message
[0] = '\0';
827 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
828 "Now accepting jobs.");
830 if (dtype
& CUPS_PRINTER_CLASS
)
832 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
834 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" now accepting jobs (\"%s\").",
835 printer
->name
, get_username(con
));
839 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
841 cupsdLogMessage(CUPSD_LOG_INFO
,
842 "Printer \"%s\" now accepting jobs (\"%s\").",
843 printer
->name
, get_username(con
));
847 * Everything was ok, so return OK status...
850 con
->response
->request
.status
.status_code
= IPP_OK
;
855 * 'add_class()' - Add a class to the system.
859 add_class(cupsd_client_t
*con
, /* I - Client connection */
860 ipp_attribute_t
*uri
) /* I - URI of class */
862 http_status_t status
; /* Policy status */
863 int i
; /* Looping var */
864 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
865 username
[HTTP_MAX_URI
], /* Username portion of URI */
866 host
[HTTP_MAX_URI
], /* Host portion of URI */
867 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
868 int port
; /* Port portion of URI */
869 cupsd_printer_t
*pclass
, /* Class */
870 *member
; /* Member printer/class */
871 cups_ptype_t dtype
; /* Destination type */
872 ipp_attribute_t
*attr
; /* Printer attribute */
873 int modify
; /* Non-zero if we just modified */
874 int need_restart_job
; /* Need to restart job? */
877 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_class(%p[%d], %s)", con
,
878 con
->number
, uri
->values
[0].string
.text
);
881 * Do we have a valid URI?
884 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
885 sizeof(scheme
), username
, sizeof(username
), host
,
886 sizeof(host
), &port
, resource
, sizeof(resource
));
889 if (strncmp(resource
, "/classes/", 9) || strlen(resource
) == 9)
892 * No, return an error...
895 send_ipp_status(con
, IPP_BAD_REQUEST
,
896 _("The printer-uri must be of the form "
897 "\"ipp://HOSTNAME/classes/CLASSNAME\"."));
902 * Do we have a valid printer name?
905 if (!validate_name(resource
+ 9))
908 * No, return an error...
911 send_ipp_status(con
, IPP_BAD_REQUEST
,
912 _("The printer-uri \"%s\" contains invalid characters."),
913 uri
->values
[0].string
.text
);
918 * See if the class already exists; if not, create a new class...
921 if ((pclass
= cupsdFindClass(resource
+ 9)) == NULL
)
924 * Class doesn't exist; see if we have a printer of the same name...
927 if ((pclass
= cupsdFindPrinter(resource
+ 9)) != NULL
)
930 * Yes, return an error...
933 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
934 _("A printer named \"%s\" already exists."),
940 * No, check the default policy and then add the class...
943 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
945 send_http_error(con
, status
, NULL
);
949 pclass
= cupsdAddClass(resource
+ 9);
952 pclass
->printer_id
= NextPrinterId
++;
954 else if ((status
= cupsdCheckPolicy(pclass
->op_policy_ptr
, con
,
957 send_http_error(con
, status
, pclass
);
964 * Look for attributes and copy them over as needed...
967 need_restart_job
= 0;
969 if ((attr
= ippFindAttribute(con
->request
, "printer-location", IPP_TAG_TEXT
)) != NULL
)
970 cupsdSetString(&pclass
->location
, attr
->values
[0].string
.text
);
972 if ((attr
= ippFindAttribute(con
->request
, "printer-geo-location", IPP_TAG_URI
)) != NULL
&& !strncmp(attr
->values
[0].string
.text
, "geo:", 4))
973 cupsdSetString(&pclass
->geo_location
, attr
->values
[0].string
.text
);
975 if ((attr
= ippFindAttribute(con
->request
, "printer-organization", IPP_TAG_TEXT
)) != NULL
)
976 cupsdSetString(&pclass
->organization
, attr
->values
[0].string
.text
);
978 if ((attr
= ippFindAttribute(con
->request
, "printer-organizational-unit", IPP_TAG_TEXT
)) != NULL
)
979 cupsdSetString(&pclass
->organizational_unit
, attr
->values
[0].string
.text
);
981 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
982 IPP_TAG_TEXT
)) != NULL
)
983 cupsdSetString(&pclass
->info
, attr
->values
[0].string
.text
);
985 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
986 IPP_TAG_BOOLEAN
)) != NULL
&&
987 attr
->values
[0].boolean
!= pclass
->accepting
)
989 cupsdLogMessage(CUPSD_LOG_INFO
,
990 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
991 pclass
->name
, attr
->values
[0].boolean
, pclass
->accepting
);
993 pclass
->accepting
= attr
->values
[0].boolean
;
995 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s accepting jobs.",
996 pclass
->accepting
? "Now" : "No longer");
999 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared", IPP_TAG_BOOLEAN
)) != NULL
)
1001 if (pclass
->type
& CUPS_PRINTER_REMOTE
)
1004 * Cannot re-share remote printers.
1007 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Cannot change printer-is-shared for remote queues."));
1009 cupsdDeletePrinter(pclass
, 0);
1014 if (pclass
->shared
&& !ippGetBoolean(attr
, 0))
1015 cupsdDeregisterPrinter(pclass
, 1);
1017 cupsdLogMessage(CUPSD_LOG_INFO
,
1018 "Setting %s printer-is-shared to %d (was %d.)",
1019 pclass
->name
, attr
->values
[0].boolean
, pclass
->shared
);
1021 pclass
->shared
= ippGetBoolean(attr
, 0);
1024 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
1025 IPP_TAG_ENUM
)) != NULL
)
1027 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
1028 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
1030 send_ipp_status(con
, IPP_BAD_REQUEST
,
1031 _("Attempt to set %s printer-state to bad value %d."),
1032 pclass
->name
, attr
->values
[0].integer
);
1034 cupsdDeletePrinter(pclass
, 0);
1039 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
1040 pclass
->name
, attr
->values
[0].integer
, pclass
->state
);
1042 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
1043 cupsdStopPrinter(pclass
, 0);
1046 cupsdSetPrinterState(pclass
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
1047 need_restart_job
= 1;
1050 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
1051 IPP_TAG_TEXT
)) != NULL
)
1053 strlcpy(pclass
->state_message
, attr
->values
[0].string
.text
,
1054 sizeof(pclass
->state_message
));
1056 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s",
1057 pclass
->state_message
);
1059 if ((attr
= ippFindAttribute(con
->request
, "member-uris",
1060 IPP_TAG_URI
)) != NULL
)
1063 * Clear the printer array as needed...
1066 need_restart_job
= 1;
1068 if (pclass
->num_printers
> 0)
1070 free(pclass
->printers
);
1071 pclass
->num_printers
= 0;
1075 * Add each printer or class that is listed...
1078 for (i
= 0; i
< attr
->num_values
; i
++)
1081 * Search for the printer or class URI...
1084 if (!cupsdValidateDest(attr
->values
[i
].string
.text
, &dtype
, &member
))
1090 send_ipp_status(con
, IPP_NOT_FOUND
,
1091 _("The printer or class does not exist."));
1093 cupsdDeletePrinter(pclass
, 0);
1097 else if (dtype
& CUPS_PRINTER_CLASS
)
1099 send_ipp_status(con
, IPP_BAD_REQUEST
,
1100 _("Nested classes are not allowed."));
1102 cupsdDeletePrinter(pclass
, 0);
1108 * Add it to the class...
1111 cupsdAddPrinterToClass(pclass
, member
);
1115 if (!set_printer_defaults(con
, pclass
))
1118 cupsdDeletePrinter(pclass
, 0);
1123 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
1124 IPP_TAG_KEYWORD
)) != NULL
)
1125 cupsdSetAuthInfoRequired(pclass
, NULL
, attr
);
1127 pclass
->config_time
= time(NULL
);
1130 * Update the printer class attributes and return...
1133 cupsdSetPrinterAttrs(pclass
);
1134 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
1136 if (need_restart_job
&& pclass
->job
)
1139 * Reset the current job to a "pending" status...
1142 cupsdSetJobState(pclass
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
1143 "Job restarted because the class was modified.");
1146 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1150 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
1151 pclass
, NULL
, "Class \"%s\" modified by \"%s\".",
1152 pclass
->name
, get_username(con
));
1154 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" modified by \"%s\".",
1155 pclass
->name
, get_username(con
));
1159 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
1160 pclass
, NULL
, "New class \"%s\" added by \"%s\".",
1161 pclass
->name
, get_username(con
));
1163 cupsdLogMessage(CUPSD_LOG_INFO
, "New class \"%s\" added by \"%s\".",
1164 pclass
->name
, get_username(con
));
1167 con
->response
->request
.status
.status_code
= IPP_OK
;
1172 * 'add_file()' - Add a file to a job.
1175 static int /* O - 0 on success, -1 on error */
1176 add_file(cupsd_client_t
*con
, /* I - Connection to client */
1177 cupsd_job_t
*job
, /* I - Job to add to */
1178 mime_type_t
*filetype
, /* I - Type of file */
1179 int compression
) /* I - Compression */
1181 mime_type_t
**filetypes
; /* New filetypes array... */
1182 int *compressions
; /* New compressions array... */
1185 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1186 "add_file(con=%p[%d], job=%d, filetype=%s/%s, "
1187 "compression=%d)", con
, con
? con
->number
: -1, job
->id
,
1188 filetype
->super
, filetype
->type
, compression
);
1191 * Add the file to the job...
1194 if (job
->num_files
== 0)
1196 compressions
= (int *)malloc(sizeof(int));
1197 filetypes
= (mime_type_t
**)malloc(sizeof(mime_type_t
*));
1201 compressions
= (int *)realloc(job
->compressions
,
1202 (size_t)(job
->num_files
+ 1) * sizeof(int));
1203 filetypes
= (mime_type_t
**)realloc(job
->filetypes
,
1204 (size_t)(job
->num_files
+ 1) *
1205 sizeof(mime_type_t
*));
1209 job
->compressions
= compressions
;
1212 job
->filetypes
= filetypes
;
1214 if (!compressions
|| !filetypes
)
1216 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1217 "Job aborted because the scheduler ran out of memory.");
1220 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1221 _("Unable to allocate memory for file types."));
1226 job
->compressions
[job
->num_files
] = compression
;
1227 job
->filetypes
[job
->num_files
] = filetype
;
1232 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1239 * 'add_job()' - Add a job to a print queue.
1242 static cupsd_job_t
* /* O - Job object */
1243 add_job(cupsd_client_t
*con
, /* I - Client connection */
1244 cupsd_printer_t
*printer
, /* I - Destination printer */
1245 mime_type_t
*filetype
) /* I - First print file type, if any */
1247 http_status_t status
; /* Policy status */
1248 ipp_attribute_t
*attr
, /* Current attribute */
1249 *auth_info
; /* auth-info attribute */
1250 const char *mandatory
; /* Current mandatory job attribute */
1251 const char *val
; /* Default option value */
1252 int priority
; /* Job priority */
1253 cupsd_job_t
*job
; /* Current job */
1254 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
1255 int kbytes
; /* Size of print file */
1256 int i
; /* Looping var */
1257 int lowerpagerange
; /* Page range bound */
1258 int exact
; /* Did we have an exact match? */
1259 ipp_attribute_t
*media_col
, /* media-col attribute */
1260 *media_margin
; /* media-*-margin attribute */
1261 ipp_t
*unsup_col
; /* media-col in unsupported response */
1262 static const char * const readonly
[] =/* List of read-only attributes */
1264 "date-time-at-completed",
1265 "date-time-at-creation",
1266 "date-time-at-processing",
1267 "job-detailed-status-messages",
1268 "job-document-access-errors",
1270 "job-impressions-completed",
1271 "job-k-octets-completed",
1272 "job-media-sheets-completed",
1273 "job-pages-completed",
1274 "job-printer-up-time",
1277 "job-state-message",
1278 "job-state-reasons",
1280 "number-of-documents",
1281 "number-of-intervening-jobs",
1282 "output-device-assigned",
1283 "time-at-completed",
1285 "time-at-processing"
1289 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job(%p[%d], %p(%s), %p(%s/%s))",
1290 con
, con
->number
, printer
, printer
->name
,
1291 filetype
, filetype
? filetype
->super
: "none",
1292 filetype
? filetype
->type
: "none");
1295 * Check remote printing to non-shared printer...
1298 if (!printer
->shared
&&
1299 _cups_strcasecmp(con
->http
->hostname
, "localhost") &&
1300 _cups_strcasecmp(con
->http
->hostname
, ServerName
))
1302 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
1303 _("The printer or class is not shared."));
1311 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
1313 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
1315 send_http_error(con
, status
, printer
);
1318 else if (printer
->num_auth_info_required
== 1 &&
1319 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
1322 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
1326 else if (auth_info
&& !con
->http
->tls
&&
1327 !httpAddrLocalhost(con
->http
->hostaddr
))
1330 * Require encryption of auth-info over non-local connections...
1333 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
1336 #endif /* HAVE_SSL */
1339 * See if the printer is accepting jobs...
1342 if (!printer
->accepting
)
1344 send_ipp_status(con
, IPP_NOT_ACCEPTING
,
1345 _("Destination \"%s\" is not accepting jobs."),
1351 * Validate job template attributes; for now just document-format,
1352 * copies, job-sheets, number-up, page-ranges, mandatory attributes, and
1356 for (i
= 0; i
< (int)(sizeof(readonly
) / sizeof(readonly
[0])); i
++)
1358 if ((attr
= ippFindAttribute(con
->request
, readonly
[i
], IPP_TAG_ZERO
)) != NULL
)
1360 ippDeleteAttribute(con
->request
, attr
);
1362 if (StrictConformance
)
1364 send_ipp_status(con
, IPP_BAD_REQUEST
, _("The '%s' Job Status attribute cannot be supplied in a job creation request."), readonly
[i
]);
1368 cupsdLogMessage(CUPSD_LOG_INFO
, "Unexpected '%s' Job Status attribute in a job creation request.", readonly
[i
]);
1374 for (mandatory
= (char *)cupsArrayFirst(printer
->pc
->mandatory
);
1376 mandatory
= (char *)cupsArrayNext(printer
->pc
->mandatory
))
1378 if (!ippFindAttribute(con
->request
, mandatory
, IPP_TAG_ZERO
))
1381 * Missing a required attribute...
1384 send_ipp_status(con
, IPP_CONFLICT
,
1385 _("The \"%s\" attribute is required for print jobs."),
1392 if (filetype
&& printer
->filetypes
&&
1393 !cupsArrayFind(printer
->filetypes
, filetype
))
1395 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
1396 /* MIME media type string */
1399 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
1402 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
1403 _("Unsupported format \"%s\"."), mimetype
);
1405 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
1406 "document-format", NULL
, mimetype
);
1411 if ((attr
= ippFindAttribute(con
->request
, "copies",
1412 IPP_TAG_INTEGER
)) != NULL
)
1414 if (attr
->values
[0].integer
< 1 || attr
->values
[0].integer
> MaxCopies
)
1416 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad copies value %d."),
1417 attr
->values
[0].integer
);
1418 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1419 "copies", attr
->values
[0].integer
);
1424 if ((attr
= ippFindAttribute(con
->request
, "job-sheets",
1425 IPP_TAG_ZERO
)) != NULL
)
1427 if (attr
->value_tag
!= IPP_TAG_KEYWORD
&&
1428 attr
->value_tag
!= IPP_TAG_NAME
)
1430 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value type."));
1434 if (attr
->num_values
> 2)
1436 send_ipp_status(con
, IPP_BAD_REQUEST
,
1437 _("Too many job-sheets values (%d > 2)."),
1442 for (i
= 0; i
< attr
->num_values
; i
++)
1443 if (strcmp(attr
->values
[i
].string
.text
, "none") &&
1444 !cupsdFindBanner(attr
->values
[i
].string
.text
))
1446 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value \"%s\"."),
1447 attr
->values
[i
].string
.text
);
1452 if ((attr
= ippFindAttribute(con
->request
, "number-up",
1453 IPP_TAG_INTEGER
)) != NULL
)
1455 if (attr
->values
[0].integer
!= 1 &&
1456 attr
->values
[0].integer
!= 2 &&
1457 attr
->values
[0].integer
!= 4 &&
1458 attr
->values
[0].integer
!= 6 &&
1459 attr
->values
[0].integer
!= 9 &&
1460 attr
->values
[0].integer
!= 16)
1462 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad number-up value %d."),
1463 attr
->values
[0].integer
);
1464 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1465 "number-up", attr
->values
[0].integer
);
1470 if ((attr
= ippFindAttribute(con
->request
, "page-ranges",
1471 IPP_TAG_RANGE
)) != NULL
)
1473 for (i
= 0, lowerpagerange
= 1; i
< attr
->num_values
; i
++)
1475 if (attr
->values
[i
].range
.lower
< lowerpagerange
||
1476 attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
1478 send_ipp_status(con
, IPP_BAD_REQUEST
,
1479 _("Bad page-ranges values %d-%d."),
1480 attr
->values
[i
].range
.lower
,
1481 attr
->values
[i
].range
.upper
);
1485 lowerpagerange
= attr
->values
[i
].range
.upper
+ 1;
1490 * Do media selection as needed...
1493 if (!ippFindAttribute(con
->request
, "PageRegion", IPP_TAG_ZERO
) &&
1494 !ippFindAttribute(con
->request
, "PageSize", IPP_TAG_ZERO
) &&
1495 _ppdCacheGetPageSize(printer
->pc
, con
->request
, NULL
, &exact
))
1498 (media_col
= ippFindAttribute(con
->request
, "media-col",
1499 IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
1501 send_ipp_status(con
, IPP_OK_SUBST
, _("Unsupported margins."));
1503 unsup_col
= ippNew();
1504 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1505 "media-bottom-margin",
1506 IPP_TAG_INTEGER
)) != NULL
)
1507 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1508 "media-bottom-margin", media_margin
->values
[0].integer
);
1510 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1511 "media-left-margin",
1512 IPP_TAG_INTEGER
)) != NULL
)
1513 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1514 "media-left-margin", media_margin
->values
[0].integer
);
1516 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1517 "media-right-margin",
1518 IPP_TAG_INTEGER
)) != NULL
)
1519 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1520 "media-right-margin", media_margin
->values
[0].integer
);
1522 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1524 IPP_TAG_INTEGER
)) != NULL
)
1525 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1526 "media-top-margin", media_margin
->values
[0].integer
);
1528 ippAddCollection(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, "media-col",
1530 ippDelete(unsup_col
);
1535 * Make sure we aren't over our limit...
1538 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1541 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1543 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Too many active jobs."));
1547 if ((i
= check_quotas(con
, printer
)) < 0)
1549 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
1554 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
1559 * Create the job and set things up...
1562 if ((attr
= ippFindAttribute(con
->request
, "job-priority",
1563 IPP_TAG_INTEGER
)) != NULL
)
1564 priority
= attr
->values
[0].integer
;
1567 if ((val
= cupsGetOption("job-priority", printer
->num_options
,
1568 printer
->options
)) != NULL
)
1569 priority
= atoi(val
);
1573 ippAddInteger(con
->request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-priority",
1577 if ((attr
= ippFindAttribute(con
->request
, "job-name", IPP_TAG_ZERO
)) == NULL
)
1578 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
, "Untitled");
1579 else if ((attr
->value_tag
!= IPP_TAG_NAME
&&
1580 attr
->value_tag
!= IPP_TAG_NAMELANG
) ||
1581 attr
->num_values
!= 1)
1583 send_ipp_status(con
, IPP_ATTRIBUTES
,
1584 _("Bad job-name value: Wrong type or count."));
1585 if ((attr
= ippCopyAttribute(con
->response
, attr
, 0)) != NULL
)
1586 attr
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
1589 else if (!ippValidateAttribute(attr
))
1591 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad job-name value: %s"),
1592 cupsLastErrorString());
1593 if ((attr
= ippCopyAttribute(con
->response
, attr
, 0)) != NULL
)
1594 attr
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
1598 attr
= ippFindAttribute(con
->request
, "requesting-user-name", IPP_TAG_NAME
);
1600 if (attr
&& !ippValidateAttribute(attr
))
1602 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad requesting-user-name value: %s"), cupsLastErrorString());
1603 if ((attr
= ippCopyAttribute(con
->response
, attr
, 0)) != NULL
)
1604 attr
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
1608 if ((job
= cupsdAddJob(priority
, printer
->name
)) == NULL
)
1610 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1611 _("Unable to add job for destination \"%s\"."),
1616 job
->dtype
= printer
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
1617 job
->attrs
= con
->request
;
1619 con
->request
= ippNewRequest(job
->attrs
->request
.op
.operation_id
);
1621 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1624 apply_printer_defaults(printer
, job
);
1626 if (con
->username
[0])
1628 cupsdSetString(&job
->username
, con
->username
);
1631 ippSetString(job
->attrs
, &attr
, 0, con
->username
);
1635 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1636 "add_job: requesting-user-name=\"%s\"",
1637 attr
->values
[0].string
.text
);
1639 cupsdSetString(&job
->username
, attr
->values
[0].string
.text
);
1642 cupsdSetString(&job
->username
, "anonymous");
1645 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1646 "job-originating-user-name", NULL
, job
->username
);
1649 ippSetGroupTag(job
->attrs
, &attr
, IPP_TAG_JOB
);
1650 ippSetName(job
->attrs
, &attr
, "job-originating-user-name");
1653 if (con
->username
[0] || auth_info
)
1655 save_auth_info(con
, job
, auth_info
);
1658 * Remove the auth-info attribute from the attribute data...
1662 ippDeleteAttribute(job
->attrs
, auth_info
);
1665 if ((attr
= ippFindAttribute(con
->request
, "job-name", IPP_TAG_NAME
)) != NULL
)
1666 cupsdSetString(&(job
->name
), attr
->values
[0].string
.text
);
1668 if ((attr
= ippFindAttribute(job
->attrs
, "job-originating-host-name",
1669 IPP_TAG_ZERO
)) != NULL
)
1672 * Request contains a job-originating-host-name attribute; validate it...
1675 if (attr
->value_tag
!= IPP_TAG_NAME
||
1676 attr
->num_values
!= 1 ||
1677 strcmp(con
->http
->hostname
, "localhost"))
1680 * Can't override the value if we aren't connected via localhost.
1681 * Also, we can only have 1 value and it must be a name value.
1684 ippDeleteAttribute(job
->attrs
, attr
);
1685 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-originating-host-name", NULL
, con
->http
->hostname
);
1688 ippSetGroupTag(job
->attrs
, &attr
, IPP_TAG_JOB
);
1693 * No job-originating-host-name attribute, so use the hostname from
1697 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1698 "job-originating-host-name", NULL
, con
->http
->hostname
);
1701 ippAddOutOfBand(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NOVALUE
, "date-time-at-completed");
1702 ippAddDate(job
->attrs
, IPP_TAG_JOB
, "date-time-at-creation", ippTimeToDate(time(NULL
)));
1703 ippAddOutOfBand(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NOVALUE
, "date-time-at-processing");
1704 ippAddOutOfBand(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NOVALUE
, "time-at-completed");
1705 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation", time(NULL
));
1706 ippAddOutOfBand(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NOVALUE
, "time-at-processing");
1709 * Add remaining job attributes...
1712 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1713 job
->state
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_ENUM
,
1714 "job-state", IPP_JOB_STOPPED
);
1715 job
->state_value
= (ipp_jstate_t
)job
->state
->values
[0].integer
;
1716 job
->reasons
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1717 "job-state-reasons", NULL
, "job-incoming");
1718 job
->impressions
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-impressions-completed", 0);
1719 job
->sheets
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1720 "job-media-sheets-completed", 0);
1721 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-printer-uri", NULL
,
1724 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets", IPP_TAG_INTEGER
)) != NULL
)
1725 attr
->values
[0].integer
= 0;
1727 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-k-octets", 0);
1729 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
1730 IPP_TAG_KEYWORD
)) == NULL
)
1731 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
1734 if ((val
= cupsGetOption("job-hold-until", printer
->num_options
,
1735 printer
->options
)) == NULL
)
1738 attr
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1739 "job-hold-until", NULL
, val
);
1742 if (printer
->holding_new_jobs
)
1745 * Hold all new jobs on this printer...
1748 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
1749 cupsdSetJobHoldUntil(job
, ippGetString(attr
, 0, NULL
), 0);
1751 cupsdSetJobHoldUntil(job
, "indefinite", 0);
1753 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1754 job
->state_value
= IPP_JOB_HELD
;
1756 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-held-on-create");
1758 else if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
1761 * Hold job until specified time...
1764 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
1766 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1767 job
->state_value
= IPP_JOB_HELD
;
1769 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-hold-until-specified");
1771 else if (job
->attrs
->request
.op
.operation_id
== IPP_CREATE_JOB
)
1773 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
1774 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1775 job
->state_value
= IPP_JOB_HELD
;
1779 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1780 job
->state_value
= IPP_JOB_PENDING
;
1782 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
1785 if (!(printer
->type
& CUPS_PRINTER_REMOTE
) || Classification
)
1788 * Add job sheets options...
1791 if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1792 IPP_TAG_ZERO
)) == NULL
)
1794 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1795 "Adding default job-sheets values \"%s,%s\"...",
1796 printer
->job_sheets
[0], printer
->job_sheets
[1]);
1798 attr
= ippAddStrings(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-sheets",
1800 ippSetString(job
->attrs
, &attr
, 0, printer
->job_sheets
[0]);
1801 ippSetString(job
->attrs
, &attr
, 1, printer
->job_sheets
[1]);
1804 job
->job_sheets
= attr
;
1807 * Enforce classification level if set...
1812 cupsdLogMessage(CUPSD_LOG_INFO
,
1813 "Classification=\"%s\", ClassifyOverride=%d",
1814 Classification
? Classification
: "(null)",
1817 if (ClassifyOverride
)
1819 if (!strcmp(attr
->values
[0].string
.text
, "none") &&
1820 (attr
->num_values
== 1 ||
1821 !strcmp(attr
->values
[1].string
.text
, "none")))
1824 * Force the leading banner to have the classification on it...
1827 ippSetString(job
->attrs
, &attr
, 0, Classification
);
1829 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1830 "job-sheets=\"%s,none\", "
1831 "job-originating-user-name=\"%s\"",
1832 Classification
, job
->username
);
1834 else if (attr
->num_values
== 2 &&
1835 strcmp(attr
->values
[0].string
.text
,
1836 attr
->values
[1].string
.text
) &&
1837 strcmp(attr
->values
[0].string
.text
, "none") &&
1838 strcmp(attr
->values
[1].string
.text
, "none"))
1841 * Can't put two different security markings on the same document!
1844 ippSetString(job
->attrs
, &attr
, 1, attr
->values
[0].string
.text
);
1846 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1847 "job-sheets=\"%s,%s\", "
1848 "job-originating-user-name=\"%s\"",
1849 attr
->values
[0].string
.text
,
1850 attr
->values
[1].string
.text
, job
->username
);
1852 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1853 strcmp(attr
->values
[0].string
.text
, "none") &&
1854 (attr
->num_values
== 1 ||
1855 (strcmp(attr
->values
[1].string
.text
, Classification
) &&
1856 strcmp(attr
->values
[1].string
.text
, "none"))))
1858 if (attr
->num_values
== 1)
1859 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1860 "CLASSIFICATION OVERRIDDEN "
1861 "job-sheets=\"%s\", "
1862 "job-originating-user-name=\"%s\"",
1863 attr
->values
[0].string
.text
, job
->username
);
1865 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1866 "CLASSIFICATION OVERRIDDEN "
1867 "job-sheets=\"%s,%s\",fffff "
1868 "job-originating-user-name=\"%s\"",
1869 attr
->values
[0].string
.text
,
1870 attr
->values
[1].string
.text
, job
->username
);
1873 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1874 (attr
->num_values
== 1 ||
1875 strcmp(attr
->values
[1].string
.text
, Classification
)))
1878 * Force the banner to have the classification on it...
1881 if (attr
->num_values
> 1 &&
1882 !strcmp(attr
->values
[0].string
.text
, attr
->values
[1].string
.text
))
1884 ippSetString(job
->attrs
, &attr
, 0, Classification
);
1885 ippSetString(job
->attrs
, &attr
, 1, Classification
);
1889 if (attr
->num_values
== 1 ||
1890 strcmp(attr
->values
[0].string
.text
, "none"))
1891 ippSetString(job
->attrs
, &attr
, 0, Classification
);
1893 if (attr
->num_values
> 1 &&
1894 strcmp(attr
->values
[1].string
.text
, "none"))
1895 ippSetString(job
->attrs
, &attr
, 1, Classification
);
1898 if (attr
->num_values
> 1)
1899 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1900 "CLASSIFICATION FORCED "
1901 "job-sheets=\"%s,%s\", "
1902 "job-originating-user-name=\"%s\"",
1903 attr
->values
[0].string
.text
,
1904 attr
->values
[1].string
.text
, job
->username
);
1906 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1907 "CLASSIFICATION FORCED "
1908 "job-sheets=\"%s\", "
1909 "job-originating-user-name=\"%s\"",
1910 Classification
, job
->username
);
1915 * See if we need to add the starting sheet...
1918 if (!(printer
->type
& CUPS_PRINTER_REMOTE
))
1920 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding start banner page \"%s\".",
1921 attr
->values
[0].string
.text
);
1923 if ((kbytes
= copy_banner(con
, job
, attr
->values
[0].string
.text
)) < 0)
1925 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1926 "Aborting job because the start banner could not be "
1931 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
1934 else if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1935 IPP_TAG_ZERO
)) != NULL
)
1936 job
->job_sheets
= attr
;
1939 * Fill in the response info...
1942 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
1943 con
->clientname
, con
->clientport
, "/jobs/%d", job
->id
);
1944 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
1947 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1949 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
1951 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_TEXT
, "job-state-message", NULL
, "");
1952 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons",
1953 NULL
, job
->reasons
->values
[0].string
.text
);
1955 con
->response
->request
.status
.status_code
= IPP_OK
;
1958 * Add any job subscriptions...
1961 add_job_subscriptions(con
, job
);
1964 * Set all but the first two attributes to the job attributes group...
1967 for (attr
= job
->attrs
->attrs
->next
->next
; attr
; attr
= attr
->next
)
1968 attr
->group_tag
= IPP_TAG_JOB
;
1971 * Fire the "job created" event...
1974 cupsdAddEvent(CUPSD_EVENT_JOB_CREATED
, printer
, job
, "Job created.");
1977 * Return the new job...
1985 * 'add_job_subscriptions()' - Add any subscriptions for a job.
1989 add_job_subscriptions(
1990 cupsd_client_t
*con
, /* I - Client connection */
1991 cupsd_job_t
*job
) /* I - Newly created job */
1993 int i
; /* Looping var */
1994 ipp_attribute_t
*prev
, /* Previous attribute */
1995 *next
, /* Next attribute */
1996 *attr
; /* Current attribute */
1997 cupsd_subscription_t
*sub
; /* Subscription object */
1998 const char *recipient
, /* notify-recipient-uri */
1999 *pullmethod
; /* notify-pull-method */
2000 ipp_attribute_t
*user_data
; /* notify-user-data */
2001 int interval
; /* notify-time-interval */
2002 unsigned mask
; /* notify-events */
2006 * Find the first subscription group attribute; return if we have
2010 for (attr
= job
->attrs
->attrs
; attr
; attr
= attr
->next
)
2011 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
2018 * Process the subscription attributes in the request...
2027 mask
= CUPSD_EVENT_NONE
;
2029 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
2031 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
2032 attr
->value_tag
== IPP_TAG_URI
)
2035 * Validate the recipient scheme against the ServerBin/notifier
2039 char notifier
[1024], /* Notifier filename */
2040 scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
2041 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
2042 host
[HTTP_MAX_URI
], /* Host portion of URI */
2043 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2044 int port
; /* Port portion of URI */
2047 recipient
= attr
->values
[0].string
.text
;
2049 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
2050 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
2051 host
, sizeof(host
), &port
,
2052 resource
, sizeof(resource
)) < HTTP_URI_OK
)
2054 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2055 _("Bad notify-recipient-uri \"%s\"."), recipient
);
2056 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2057 "notify-status-code", IPP_URI_SCHEME
);
2061 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
2063 if (access(notifier
, X_OK
))
2065 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2066 _("notify-recipient-uri URI \"%s\" uses unknown "
2067 "scheme."), recipient
);
2068 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2069 "notify-status-code", IPP_URI_SCHEME
);
2073 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
2075 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2076 _("notify-recipient-uri URI \"%s\" is already used."),
2078 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2079 "notify-status-code", IPP_ATTRIBUTES
);
2083 else if (!strcmp(attr
->name
, "notify-pull-method") &&
2084 attr
->value_tag
== IPP_TAG_KEYWORD
)
2086 pullmethod
= attr
->values
[0].string
.text
;
2088 if (strcmp(pullmethod
, "ippget"))
2090 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2091 _("Bad notify-pull-method \"%s\"."), pullmethod
);
2092 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2093 "notify-status-code", IPP_ATTRIBUTES
);
2097 else if (!strcmp(attr
->name
, "notify-charset") &&
2098 attr
->value_tag
== IPP_TAG_CHARSET
&&
2099 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
2100 strcmp(attr
->values
[0].string
.text
, "utf-8"))
2102 send_ipp_status(con
, IPP_CHARSET
,
2103 _("Character set \"%s\" not supported."),
2104 attr
->values
[0].string
.text
);
2107 else if (!strcmp(attr
->name
, "notify-natural-language") &&
2108 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
2109 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
2111 send_ipp_status(con
, IPP_CHARSET
,
2112 _("Language \"%s\" not supported."),
2113 attr
->values
[0].string
.text
);
2116 else if (!strcmp(attr
->name
, "notify-user-data") &&
2117 attr
->value_tag
== IPP_TAG_STRING
)
2119 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
2121 send_ipp_status(con
, IPP_REQUEST_VALUE
,
2122 _("The notify-user-data value is too large "
2123 "(%d > 63 octets)."),
2124 attr
->values
[0].unknown
.length
);
2130 else if (!strcmp(attr
->name
, "notify-events") &&
2131 attr
->value_tag
== IPP_TAG_KEYWORD
)
2133 for (i
= 0; i
< attr
->num_values
; i
++)
2134 mask
|= cupsdEventValue(attr
->values
[i
].string
.text
);
2136 else if (!strcmp(attr
->name
, "notify-lease-duration"))
2138 send_ipp_status(con
, IPP_BAD_REQUEST
,
2139 _("The notify-lease-duration attribute cannot be "
2140 "used with job subscriptions."));
2143 else if (!strcmp(attr
->name
, "notify-time-interval") &&
2144 attr
->value_tag
== IPP_TAG_INTEGER
)
2145 interval
= attr
->values
[0].integer
;
2150 if (!recipient
&& !pullmethod
)
2153 if (mask
== CUPSD_EVENT_NONE
)
2154 mask
= CUPSD_EVENT_JOB_COMPLETED
;
2156 if ((sub
= cupsdAddSubscription(mask
, cupsdFindDest(job
->dest
), job
,
2157 recipient
, 0)) != NULL
)
2159 sub
->interval
= interval
;
2161 cupsdSetString(&sub
->owner
, job
->username
);
2165 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
2166 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
2167 (size_t)sub
->user_data_len
);
2170 ippAddSeparator(con
->response
);
2171 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
2172 "notify-subscription-id", sub
->id
);
2174 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
2182 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
2185 * Remove all of the subscription attributes from the job request...
2187 * TODO: Optimize this since subscription groups have to come at the
2188 * end of the request...
2191 for (attr
= job
->attrs
->attrs
, prev
= NULL
; attr
; attr
= next
)
2195 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
||
2196 attr
->group_tag
== IPP_TAG_ZERO
)
2199 * Free and remove this attribute...
2202 ippDeleteAttribute(NULL
, attr
);
2207 job
->attrs
->attrs
= next
;
2213 job
->attrs
->last
= prev
;
2214 job
->attrs
->current
= prev
;
2219 * 'add_job_uuid()' - Add job-uuid attribute to a job.
2221 * See RFC 4122 for the definition of UUIDs and the format.
2225 add_job_uuid(cupsd_job_t
*job
) /* I - Job */
2227 char uuid
[64]; /* job-uuid string */
2231 * Add a job-uuid attribute if none exists...
2234 if (!ippFindAttribute(job
->attrs
, "job-uuid", IPP_TAG_URI
))
2235 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uuid", NULL
,
2236 httpAssembleUUID(ServerName
, RemotePort
, job
->dest
, job
->id
,
2237 uuid
, sizeof(uuid
)));
2242 * 'add_printer()' - Add a printer to the system.
2246 add_printer(cupsd_client_t
*con
, /* I - Client connection */
2247 ipp_attribute_t
*uri
) /* I - URI of printer */
2249 http_status_t status
; /* Policy status */
2250 int i
; /* Looping var */
2251 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
2252 username
[HTTP_MAX_URI
], /* Username portion of URI */
2253 host
[HTTP_MAX_URI
], /* Host portion of URI */
2254 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2255 int port
; /* Port portion of URI */
2256 cupsd_printer_t
*printer
; /* Printer/class */
2257 ipp_attribute_t
*attr
; /* Printer attribute */
2258 cups_file_t
*fp
; /* Script/PPD file */
2259 char line
[1024]; /* Line from file... */
2260 char srcfile
[1024], /* Source Script/PPD file */
2261 dstfile
[1024]; /* Destination Script/PPD file */
2262 int modify
; /* Non-zero if we are modifying */
2263 int changed_driver
, /* Changed the PPD? */
2264 need_restart_job
, /* Need to restart job? */
2265 set_device_uri
, /* Did we set the device URI? */
2266 set_port_monitor
; /* Did we set the port monitor? */
2269 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer(%p[%d], %s)", con
,
2270 con
->number
, uri
->values
[0].string
.text
);
2273 * Do we have a valid URI?
2276 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
2277 sizeof(scheme
), username
, sizeof(username
), host
,
2278 sizeof(host
), &port
, resource
, sizeof(resource
));
2280 if (strncmp(resource
, "/printers/", 10) || strlen(resource
) == 10)
2283 * No, return an error...
2286 send_ipp_status(con
, IPP_BAD_REQUEST
,
2287 _("The printer-uri must be of the form "
2288 "\"ipp://HOSTNAME/printers/PRINTERNAME\"."));
2293 * Do we have a valid printer name?
2296 if (!validate_name(resource
+ 10))
2299 * No, return an error...
2302 send_ipp_status(con
, IPP_BAD_REQUEST
,
2303 _("The printer-uri \"%s\" contains invalid characters."),
2304 uri
->values
[0].string
.text
);
2309 * See if the printer already exists; if not, create a new printer...
2312 if ((printer
= cupsdFindPrinter(resource
+ 10)) == NULL
)
2315 * Printer doesn't exist; see if we have a class of the same name...
2318 if ((printer
= cupsdFindClass(resource
+ 10)) != NULL
)
2321 * Yes, return an error...
2324 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2325 _("A class named \"%s\" already exists."),
2331 * No, check the default policy then add the printer...
2334 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2336 send_http_error(con
, status
, NULL
);
2340 printer
= cupsdAddPrinter(resource
+ 10);
2343 printer
->printer_id
= NextPrinterId
++;
2345 else if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
2348 send_http_error(con
, status
, printer
);
2355 * Look for attributes and copy them over as needed...
2359 need_restart_job
= 0;
2361 if ((attr
= ippFindAttribute(con
->request
, "printer-is-temporary", IPP_TAG_BOOLEAN
)) != NULL
)
2362 printer
->temporary
= ippGetBoolean(attr
, 0);
2364 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
2365 IPP_TAG_TEXT
)) != NULL
)
2366 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
2368 if ((attr
= ippFindAttribute(con
->request
, "printer-geo-location", IPP_TAG_URI
)) != NULL
&& !strncmp(attr
->values
[0].string
.text
, "geo:", 4))
2369 cupsdSetString(&printer
->geo_location
, attr
->values
[0].string
.text
);
2371 if ((attr
= ippFindAttribute(con
->request
, "printer-organization", IPP_TAG_TEXT
)) != NULL
)
2372 cupsdSetString(&printer
->organization
, attr
->values
[0].string
.text
);
2374 if ((attr
= ippFindAttribute(con
->request
, "printer-organizational-unit", IPP_TAG_TEXT
)) != NULL
)
2375 cupsdSetString(&printer
->organizational_unit
, attr
->values
[0].string
.text
);
2377 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
2378 IPP_TAG_TEXT
)) != NULL
)
2379 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
2383 if ((attr
= ippFindAttribute(con
->request
, "device-uri",
2384 IPP_TAG_URI
)) != NULL
)
2387 * Do we have a valid device URI?
2390 http_uri_status_t uri_status
; /* URI separation status */
2391 char old_device_uri
[1024];
2392 /* Old device URI */
2394 need_restart_job
= 1;
2396 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
,
2397 attr
->values
[0].string
.text
,
2398 scheme
, sizeof(scheme
),
2399 username
, sizeof(username
),
2400 host
, sizeof(host
), &port
,
2401 resource
, sizeof(resource
));
2403 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s device-uri: %s", printer
->name
, httpURIStatusString(uri_status
));
2405 if (uri_status
< HTTP_URI_OK
)
2407 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri \"%s\"."),
2408 attr
->values
[0].string
.text
);
2410 cupsdDeletePrinter(printer
, 0);
2415 if (!strcmp(scheme
, "file"))
2418 * See if the administrator has enabled file devices...
2421 if (!FileDevice
&& strcmp(resource
, "/dev/null"))
2424 * File devices are disabled and the URL is not file:/dev/null...
2427 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2428 _("File device URIs have been disabled. "
2429 "To enable, see the FileDevice directive in "
2430 "\"%s/cups-files.conf\"."),
2433 cupsdDeletePrinter(printer
, 0);
2441 * See if the backend exists and is executable...
2444 snprintf(srcfile
, sizeof(srcfile
), "%s/backend/%s", ServerBin
, scheme
);
2445 if (access(srcfile
, X_OK
))
2448 * Could not find device in list!
2451 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2452 _("Bad device-uri scheme \"%s\"."), scheme
);
2454 cupsdDeletePrinter(printer
, 0);
2460 if (printer
->sanitized_device_uri
)
2461 strlcpy(old_device_uri
, printer
->sanitized_device_uri
,
2462 sizeof(old_device_uri
));
2464 old_device_uri
[0] = '\0';
2466 cupsdSetDeviceURI(printer
, attr
->values
[0].string
.text
);
2468 cupsdLogMessage(CUPSD_LOG_INFO
,
2469 "Setting %s device-uri to \"%s\" (was \"%s\".)",
2470 printer
->name
, printer
->sanitized_device_uri
,
2476 set_port_monitor
= 0;
2478 if ((attr
= ippFindAttribute(con
->request
, "port-monitor",
2479 IPP_TAG_NAME
)) != NULL
)
2481 ipp_attribute_t
*supported
; /* port-monitor-supported attribute */
2484 need_restart_job
= 1;
2486 supported
= ippFindAttribute(printer
->ppd_attrs
, "port-monitor-supported",
2490 for (i
= 0; i
< supported
->num_values
; i
++)
2491 if (!strcmp(supported
->values
[i
].string
.text
,
2492 attr
->values
[0].string
.text
))
2496 if (!supported
|| i
>= supported
->num_values
)
2498 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad port-monitor \"%s\"."),
2499 attr
->values
[0].string
.text
);
2501 cupsdDeletePrinter(printer
, 0);
2506 cupsdLogMessage(CUPSD_LOG_INFO
,
2507 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2508 printer
->name
, attr
->values
[0].string
.text
,
2509 printer
->port_monitor
? printer
->port_monitor
: "none");
2511 if (strcmp(attr
->values
[0].string
.text
, "none"))
2512 cupsdSetString(&printer
->port_monitor
, attr
->values
[0].string
.text
);
2514 cupsdClearString(&printer
->port_monitor
);
2516 set_port_monitor
= 1;
2519 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
2520 IPP_TAG_BOOLEAN
)) != NULL
&&
2521 attr
->values
[0].boolean
!= printer
->accepting
)
2523 cupsdLogMessage(CUPSD_LOG_INFO
,
2524 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
2525 printer
->name
, attr
->values
[0].boolean
, printer
->accepting
);
2527 printer
->accepting
= attr
->values
[0].boolean
;
2529 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2530 "%s accepting jobs.",
2531 printer
->accepting
? "Now" : "No longer");
2534 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared", IPP_TAG_BOOLEAN
)) != NULL
)
2536 if (ippGetBoolean(attr
, 0) &&
2537 printer
->num_auth_info_required
== 1 &&
2538 !strcmp(printer
->auth_info_required
[0], "negotiate"))
2540 send_ipp_status(con
, IPP_BAD_REQUEST
,
2541 _("Cannot share a remote Kerberized printer."));
2543 cupsdDeletePrinter(printer
, 0);
2548 if (printer
->type
& CUPS_PRINTER_REMOTE
)
2551 * Cannot re-share remote printers.
2554 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Cannot change printer-is-shared for remote queues."));
2556 cupsdDeletePrinter(printer
, 0);
2561 if (printer
->shared
&& !ippGetBoolean(attr
, 0))
2562 cupsdDeregisterPrinter(printer
, 1);
2564 cupsdLogMessage(CUPSD_LOG_INFO
,
2565 "Setting %s printer-is-shared to %d (was %d.)",
2566 printer
->name
, attr
->values
[0].boolean
, printer
->shared
);
2568 printer
->shared
= ippGetBoolean(attr
, 0);
2569 if (printer
->shared
&& printer
->temporary
)
2570 printer
->temporary
= 0;
2573 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
2574 IPP_TAG_ENUM
)) != NULL
)
2576 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
2577 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
2579 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad printer-state value %d."),
2580 attr
->values
[0].integer
);
2582 cupsdDeletePrinter(printer
, 0);
2587 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
2588 printer
->name
, attr
->values
[0].integer
, printer
->state
);
2590 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
2591 cupsdStopPrinter(printer
, 0);
2594 need_restart_job
= 1;
2595 cupsdSetPrinterState(printer
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
2599 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
2600 IPP_TAG_TEXT
)) != NULL
)
2602 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
2603 sizeof(printer
->state_message
));
2605 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
, "%s",
2606 printer
->state_message
);
2609 if ((attr
= ippFindAttribute(con
->request
, "printer-state-reasons",
2610 IPP_TAG_KEYWORD
)) != NULL
)
2612 if (attr
->num_values
>
2613 (int)(sizeof(printer
->reasons
) / sizeof(printer
->reasons
[0])))
2615 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2616 _("Too many printer-state-reasons values (%d > %d)."),
2618 (int)(sizeof(printer
->reasons
) /
2619 sizeof(printer
->reasons
[0])));
2621 cupsdDeletePrinter(printer
, 0);
2626 for (i
= 0; i
< printer
->num_reasons
; i
++)
2627 _cupsStrFree(printer
->reasons
[i
]);
2629 printer
->num_reasons
= 0;
2630 for (i
= 0; i
< attr
->num_values
; i
++)
2632 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
2635 printer
->reasons
[printer
->num_reasons
] =
2636 _cupsStrRetain(attr
->values
[i
].string
.text
);
2637 printer
->num_reasons
++;
2639 if (!strcmp(attr
->values
[i
].string
.text
, "paused") &&
2640 printer
->state
!= IPP_PRINTER_STOPPED
)
2642 cupsdLogMessage(CUPSD_LOG_INFO
,
2643 "Setting %s printer-state to %d (was %d.)",
2644 printer
->name
, IPP_PRINTER_STOPPED
, printer
->state
);
2645 cupsdStopPrinter(printer
, 0);
2649 if (PrintcapFormat
== PRINTCAP_PLIST
)
2650 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2652 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2653 "Printer \"%s\" state changed.", printer
->name
);
2656 if (!set_printer_defaults(con
, printer
))
2659 cupsdDeletePrinter(printer
, 0);
2664 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
2665 IPP_TAG_KEYWORD
)) != NULL
)
2666 cupsdSetAuthInfoRequired(printer
, NULL
, attr
);
2669 * See if we have all required attributes...
2672 if (!printer
->device_uri
)
2673 cupsdSetString(&printer
->device_uri
, "file:///dev/null");
2676 * See if we have a PPD file attached to the request...
2681 need_restart_job
= 1;
2684 strlcpy(srcfile
, con
->filename
, sizeof(srcfile
));
2686 if ((fp
= cupsFileOpen(srcfile
, "rb")))
2689 * Yes; get the first line from it...
2693 cupsFileGets(fp
, line
, sizeof(line
));
2697 * Then see what kind of file it is...
2700 if (strncmp(line
, "*PPD-Adobe", 10))
2702 send_ipp_status(con
, IPP_STATUS_ERROR_DOCUMENT_FORMAT_NOT_SUPPORTED
, _("Bad PPD file."));
2704 cupsdDeletePrinter(printer
, 0);
2709 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2713 * The new file is a PPD file, so move the file over to the ppd
2717 if (copy_file(srcfile
, dstfile
, ConfigFilePerm
))
2719 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file - %s"), strerror(errno
));
2721 cupsdDeletePrinter(printer
, 0);
2726 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Copied PPD file successfully");
2729 else if ((attr
= ippFindAttribute(con
->request
, "ppd-name", IPP_TAG_NAME
)) != NULL
)
2731 const char *ppd_name
= ippGetString(attr
, 0, NULL
);
2732 /* ppd-name value */
2734 need_restart_job
= 1;
2737 if (!strcmp(ppd_name
, "raw"))
2740 * Raw driver, remove any existing PPD file.
2743 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
, printer
->name
);
2746 else if (strstr(ppd_name
, "../"))
2748 send_ipp_status(con
, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES
, _("Invalid ppd-name value."));
2750 cupsdDeletePrinter(printer
, 0);
2760 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
, printer
->name
);
2762 if (copy_model(con
, ppd_name
, dstfile
))
2764 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file."));
2766 cupsdDeletePrinter(printer
, 0);
2771 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Copied PPD file successfully");
2778 * If we changed the PPD, then remove the printer's cache file and clear the
2779 * printer-state-reasons...
2782 char cache_name
[1024]; /* Cache filename for printer attrs */
2784 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.data", CacheDir
, printer
->name
);
2787 cupsdSetPrinterReasons(printer
, "none");
2790 * (Re)register color profiles...
2793 cupsdRegisterColor(printer
);
2797 * If we set the device URI but not the port monitor, check which port
2798 * monitor to use by default...
2801 if (set_device_uri
&& !set_port_monitor
)
2803 ppd_file_t
*ppd
; /* PPD file */
2804 ppd_attr_t
*ppdattr
; /* cupsPortMonitor attribute */
2807 httpSeparateURI(HTTP_URI_CODING_ALL
, printer
->device_uri
, scheme
,
2808 sizeof(scheme
), username
, sizeof(username
), host
,
2809 sizeof(host
), &port
, resource
, sizeof(resource
));
2811 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
,
2813 if ((ppd
= _ppdOpenFile(srcfile
, _PPD_LOCALIZATION_NONE
)) != NULL
)
2815 for (ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2817 ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
2818 if (!strcmp(scheme
, ppdattr
->spec
))
2820 cupsdLogMessage(CUPSD_LOG_INFO
,
2821 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2822 printer
->name
, ppdattr
->value
,
2823 printer
->port_monitor
? printer
->port_monitor
2826 if (strcmp(ppdattr
->value
, "none"))
2827 cupsdSetString(&printer
->port_monitor
, ppdattr
->value
);
2829 cupsdClearString(&printer
->port_monitor
);
2838 printer
->config_time
= time(NULL
);
2841 * Update the printer attributes and return...
2844 if (!printer
->temporary
)
2846 if (!printer
->printer_id
)
2847 printer
->printer_id
= NextPrinterId
++;
2849 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2852 cupsdSetPrinterAttrs(printer
);
2854 if (need_restart_job
&& printer
->job
)
2857 * Restart the current job...
2860 cupsdSetJobState(printer
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
2861 "Job restarted because the printer was modified.");
2864 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2868 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
2869 printer
, NULL
, "Printer \"%s\" modified by \"%s\".",
2870 printer
->name
, get_username(con
));
2872 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" modified by \"%s\".",
2873 printer
->name
, get_username(con
));
2877 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
2878 printer
, NULL
, "New printer \"%s\" added by \"%s\".",
2879 printer
->name
, get_username(con
));
2881 cupsdLogMessage(CUPSD_LOG_INFO
, "New printer \"%s\" added by \"%s\".",
2882 printer
->name
, get_username(con
));
2885 con
->response
->request
.status
.status_code
= IPP_OK
;
2890 * 'add_printer_state_reasons()' - Add the "printer-state-reasons" attribute
2891 * based upon the printer state...
2895 add_printer_state_reasons(
2896 cupsd_client_t
*con
, /* I - Client connection */
2897 cupsd_printer_t
*p
) /* I - Printer info */
2899 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2900 "add_printer_state_reasons(%p[%d], %p[%s])",
2901 con
, con
->number
, p
, p
->name
);
2903 if (p
->num_reasons
== 0)
2904 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2905 "printer-state-reasons", NULL
, "none");
2907 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2908 "printer-state-reasons", p
->num_reasons
, NULL
,
2909 (const char * const *)p
->reasons
);
2914 * 'add_queued_job_count()' - Add the "queued-job-count" attribute for
2915 * the specified printer or class.
2919 add_queued_job_count(
2920 cupsd_client_t
*con
, /* I - Client connection */
2921 cupsd_printer_t
*p
) /* I - Printer or class */
2923 int count
; /* Number of jobs on destination */
2926 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_queued_job_count(%p[%d], %p[%s])",
2927 con
, con
->number
, p
, p
->name
);
2929 count
= cupsdGetPrinterJobCount(p
->name
);
2931 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2932 "queued-job-count", count
);
2937 * 'apply_printer_defaults()' - Apply printer default options to a job.
2941 apply_printer_defaults(
2942 cupsd_printer_t
*printer
, /* I - Printer */
2943 cupsd_job_t
*job
) /* I - Job */
2945 int i
, /* Looping var */
2946 num_options
; /* Number of default options */
2947 cups_option_t
*options
, /* Default options */
2948 *option
; /* Current option */
2951 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Applying default options...");
2954 * Collect all of the default options and add the missing ones to the
2958 for (i
= printer
->num_options
, num_options
= 0, options
= NULL
,
2959 option
= printer
->options
;
2962 if (!ippFindAttribute(job
->attrs
, option
->name
, IPP_TAG_ZERO
))
2964 if (!strcmp(option
->name
, "print-quality") && ippFindAttribute(job
->attrs
, "cupsPrintQuality", IPP_TAG_NAME
))
2965 continue; /* Don't override cupsPrintQuality */
2967 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Adding default %s=%s", option
->name
, option
->value
);
2969 num_options
= cupsAddOption(option
->name
, option
->value
, num_options
, &options
);
2973 * Encode these options as attributes in the job object...
2976 cupsEncodeOptions2(job
->attrs
, num_options
, options
, IPP_TAG_JOB
);
2977 cupsFreeOptions(num_options
, options
);
2982 * 'authenticate_job()' - Set job authentication info.
2986 authenticate_job(cupsd_client_t
*con
, /* I - Client connection */
2987 ipp_attribute_t
*uri
) /* I - Job URI */
2989 ipp_attribute_t
*attr
, /* job-id attribute */
2990 *auth_info
; /* auth-info attribute */
2991 int jobid
; /* Job ID */
2992 cupsd_job_t
*job
; /* Current job */
2993 char scheme
[HTTP_MAX_URI
],
2994 /* Method portion of URI */
2995 username
[HTTP_MAX_URI
],
2996 /* Username portion of URI */
2998 /* Host portion of URI */
2999 resource
[HTTP_MAX_URI
];
3000 /* Resource portion of URI */
3001 int port
; /* Port portion of URI */
3004 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "authenticate_job(%p[%d], %s)",
3005 con
, con
->number
, uri
->values
[0].string
.text
);
3008 * Start with "everything is OK" status...
3011 con
->response
->request
.status
.status_code
= IPP_OK
;
3014 * See if we have a job URI or a printer URI...
3017 if (!strcmp(uri
->name
, "printer-uri"))
3020 * Got a printer URI; see if we also have a job-id attribute...
3023 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3024 IPP_TAG_INTEGER
)) == NULL
)
3026 send_ipp_status(con
, IPP_BAD_REQUEST
,
3027 _("Got a printer-uri attribute but no job-id."));
3031 jobid
= attr
->values
[0].integer
;
3036 * Got a job URI; parse it to get the job ID...
3039 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
3040 sizeof(scheme
), username
, sizeof(username
), host
,
3041 sizeof(host
), &port
, resource
, sizeof(resource
));
3043 if (strncmp(resource
, "/jobs/", 6))
3049 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
3050 uri
->values
[0].string
.text
);
3054 jobid
= atoi(resource
+ 6);
3058 * See if the job exists...
3061 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3064 * Nope - return a "not found" error...
3067 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
3072 * See if the job has been completed...
3075 if (job
->state_value
!= IPP_JOB_HELD
)
3078 * Return a "not-possible" error...
3081 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3082 _("Job #%d is not held for authentication."),
3088 * See if we have already authenticated...
3091 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
3093 if (!con
->username
[0] && !auth_info
)
3095 cupsd_printer_t
*printer
; /* Job destination */
3098 * No auth data. If we need to authenticate via Kerberos, send a
3099 * HTTP auth challenge, otherwise just return an IPP error...
3102 printer
= cupsdFindDest(job
->dest
);
3104 if (printer
&& printer
->num_auth_info_required
> 0 &&
3105 !strcmp(printer
->auth_info_required
[0], "negotiate"))
3106 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
3108 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
3109 _("No authentication information provided."));
3114 * See if the job is owned by the requesting user...
3117 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3119 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3120 cupsdFindDest(job
->dest
));
3125 * Save the authentication information for this job...
3128 save_auth_info(con
, job
, auth_info
);
3131 * Reset the job-hold-until value to "no-hold"...
3134 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
3135 IPP_TAG_KEYWORD
)) == NULL
)
3136 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
3140 ippSetValueTag(job
->attrs
, &attr
, IPP_TAG_KEYWORD
);
3141 ippSetString(job
->attrs
, &attr
, 0, "no-hold");
3145 * Release the job and return...
3148 cupsdReleaseJob(job
);
3150 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, NULL
, job
, "Job authenticated by user");
3152 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Authenticated by \"%s\".", con
->username
);
3159 * 'cancel_all_jobs()' - Cancel all or selected print jobs.
3163 cancel_all_jobs(cupsd_client_t
*con
, /* I - Client connection */
3164 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3166 int i
; /* Looping var */
3167 http_status_t status
; /* Policy status */
3168 cups_ptype_t dtype
; /* Destination type */
3169 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3170 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
3171 hostname
[HTTP_MAX_URI
], /* Host portion of URI */
3172 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3173 int port
; /* Port portion of URI */
3174 ipp_attribute_t
*attr
; /* Attribute in request */
3175 const char *username
= NULL
; /* Username */
3176 cupsd_jobaction_t purge
= CUPSD_JOB_DEFAULT
;
3178 cupsd_printer_t
*printer
; /* Printer */
3179 ipp_attribute_t
*job_ids
; /* job-ids attribute */
3180 cupsd_job_t
*job
; /* Job */
3183 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_all_jobs(%p[%d], %s)", con
,
3184 con
->number
, uri
->values
[0].string
.text
);
3187 * Get the jobs to cancel/purge...
3190 switch (con
->request
->request
.op
.operation_id
)
3192 case IPP_PURGE_JOBS
:
3194 * Get the username (if any) for the jobs we want to cancel (only if
3195 * "my-jobs" is specified...
3198 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
3199 IPP_TAG_BOOLEAN
)) != NULL
&&
3200 attr
->values
[0].boolean
)
3202 if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3203 IPP_TAG_NAME
)) != NULL
)
3204 username
= attr
->values
[0].string
.text
;
3207 send_ipp_status(con
, IPP_BAD_REQUEST
,
3208 _("Missing requesting-user-name attribute."));
3214 * Look for the "purge-jobs" attribute...
3217 if ((attr
= ippFindAttribute(con
->request
, "purge-jobs",
3218 IPP_TAG_BOOLEAN
)) != NULL
)
3219 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
3221 purge
= CUPSD_JOB_PURGE
;
3224 case IPP_CANCEL_MY_JOBS
:
3225 if (con
->username
[0])
3226 username
= con
->username
;
3227 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3228 IPP_TAG_NAME
)) != NULL
)
3229 username
= attr
->values
[0].string
.text
;
3232 send_ipp_status(con
, IPP_BAD_REQUEST
,
3233 _("Missing requesting-user-name attribute."));
3241 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
3244 * See if we have a printer URI...
3247 if (strcmp(uri
->name
, "printer-uri"))
3249 send_ipp_status(con
, IPP_BAD_REQUEST
,
3250 _("The printer-uri attribute is required."));
3255 * And if the destination is valid...
3258 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3264 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
,
3265 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
3266 hostname
, sizeof(hostname
), &port
,
3267 resource
, sizeof(resource
));
3269 if ((!strncmp(resource
, "/printers/", 10) && resource
[10]) ||
3270 (!strncmp(resource
, "/classes/", 9) && resource
[9]))
3272 send_ipp_status(con
, IPP_NOT_FOUND
,
3273 _("The printer or class does not exist."));
3281 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
3283 send_http_error(con
, status
, NULL
);
3289 for (i
= 0; i
< job_ids
->num_values
; i
++)
3291 if ((job
= cupsdFindJob(job_ids
->values
[i
].integer
)) == NULL
)
3294 if (con
->request
->request
.op
.operation_id
== IPP_CANCEL_MY_JOBS
&&
3295 _cups_strcasecmp(job
->username
, username
))
3299 if (i
< job_ids
->num_values
)
3301 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3302 job_ids
->values
[i
].integer
);
3306 for (i
= 0; i
< job_ids
->num_values
; i
++)
3308 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
3310 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3311 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
3312 "Job canceled by user.");
3315 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
3316 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3322 * Cancel all jobs on all printers...
3325 cupsdCancelJobs(NULL
, username
, purge
);
3327 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs were %s by \"%s\".",
3328 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3338 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
3341 send_http_error(con
, status
, printer
);
3347 for (i
= 0; i
< job_ids
->num_values
; i
++)
3349 if ((job
= cupsdFindJob(job_ids
->values
[i
].integer
)) == NULL
||
3350 _cups_strcasecmp(job
->dest
, printer
->name
))
3353 if (con
->request
->request
.op
.operation_id
== IPP_CANCEL_MY_JOBS
&&
3354 _cups_strcasecmp(job
->username
, username
))
3358 if (i
< job_ids
->num_values
)
3360 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3361 job_ids
->values
[i
].integer
);
3365 for (i
= 0; i
< job_ids
->num_values
; i
++)
3367 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
3369 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3370 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
3371 "Job canceled by user.");
3374 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
3375 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3381 * Cancel all of the jobs on the named printer...
3384 cupsdCancelJobs(printer
->name
, username
, purge
);
3386 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs on \"%s\" were %s by \"%s\".",
3388 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3393 con
->response
->request
.status
.status_code
= IPP_OK
;
3400 * 'cancel_job()' - Cancel a print job.
3404 cancel_job(cupsd_client_t
*con
, /* I - Client connection */
3405 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3407 ipp_attribute_t
*attr
; /* Current attribute */
3408 int jobid
; /* Job ID */
3409 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3410 username
[HTTP_MAX_URI
], /* Username portion of URI */
3411 host
[HTTP_MAX_URI
], /* Host portion of URI */
3412 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3413 int port
; /* Port portion of URI */
3414 cupsd_job_t
*job
; /* Job information */
3415 cups_ptype_t dtype
; /* Destination type (printer/class) */
3416 cupsd_printer_t
*printer
; /* Printer data */
3417 cupsd_jobaction_t purge
; /* Purge the job? */
3420 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_job(%p[%d], %s)", con
,
3421 con
->number
, uri
->values
[0].string
.text
);
3424 * See if we have a job URI or a printer URI...
3427 if (!strcmp(uri
->name
, "printer-uri"))
3430 * Got a printer URI; see if we also have a job-id attribute...
3433 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3434 IPP_TAG_INTEGER
)) == NULL
)
3436 send_ipp_status(con
, IPP_BAD_REQUEST
,
3437 _("Got a printer-uri attribute but no job-id."));
3441 if ((jobid
= attr
->values
[0].integer
) == 0)
3444 * Find the current job on the specified printer...
3447 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3453 send_ipp_status(con
, IPP_NOT_FOUND
,
3454 _("The printer or class does not exist."));
3459 * See if there are any pending jobs...
3462 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3464 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3465 if (job
->state_value
<= IPP_JOB_PROCESSING
&&
3466 !_cups_strcasecmp(job
->dest
, printer
->name
))
3474 * No, try stopped jobs...
3477 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3479 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3480 if (job
->state_value
== IPP_JOB_STOPPED
&&
3481 !_cups_strcasecmp(job
->dest
, printer
->name
))
3488 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("No active jobs on %s."),
3498 * Got a job URI; parse it to get the job ID...
3501 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
3502 sizeof(scheme
), username
, sizeof(username
), host
,
3503 sizeof(host
), &port
, resource
, sizeof(resource
));
3505 if (strncmp(resource
, "/jobs/", 6))
3511 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
3512 uri
->values
[0].string
.text
);
3516 jobid
= atoi(resource
+ 6);
3520 * Look for the "purge-job" attribute...
3523 if ((attr
= ippFindAttribute(con
->request
, "purge-job",
3524 IPP_TAG_BOOLEAN
)) != NULL
)
3525 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
3527 purge
= CUPSD_JOB_DEFAULT
;
3530 * See if the job exists...
3533 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3536 * Nope - return a "not found" error...
3539 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
3544 * See if the job is owned by the requesting user...
3547 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3549 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3550 cupsdFindDest(job
->dest
));
3555 * See if the job is already completed, canceled, or aborted; if so,
3556 * we can't cancel...
3559 if (job
->state_value
>= IPP_JOB_CANCELED
&& purge
!= CUPSD_JOB_PURGE
)
3561 switch (job
->state_value
)
3563 case IPP_JOB_CANCELED
:
3564 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3565 _("Job #%d is already canceled - can\'t cancel."),
3569 case IPP_JOB_ABORTED
:
3570 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3571 _("Job #%d is already aborted - can\'t cancel."),
3576 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3577 _("Job #%d is already completed - can\'t cancel."),
3586 * Cancel the job and return...
3589 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3590 purge
== CUPSD_JOB_PURGE
? "Job purged by \"%s\"" :
3591 "Job canceled by \"%s\"",
3595 if (purge
== CUPSD_JOB_PURGE
)
3596 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Purged by \"%s\".", jobid
,
3599 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Canceled by \"%s\".", jobid
,
3602 con
->response
->request
.status
.status_code
= IPP_OK
;
3607 * 'cancel_subscription()' - Cancel a subscription.
3611 cancel_subscription(
3612 cupsd_client_t
*con
, /* I - Client connection */
3613 int sub_id
) /* I - Subscription ID */
3615 http_status_t status
; /* Policy status */
3616 cupsd_subscription_t
*sub
; /* Subscription */
3619 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3620 "cancel_subscription(con=%p[%d], sub_id=%d)",
3621 con
, con
->number
, sub_id
);
3624 * Is the subscription ID valid?
3627 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
3630 * Bad subscription ID...
3633 send_ipp_status(con
, IPP_NOT_FOUND
,
3634 _("Subscription #%d does not exist."), sub_id
);
3642 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
3644 con
, sub
->owner
)) != HTTP_OK
)
3646 send_http_error(con
, status
, sub
->dest
);
3651 * Cancel the subscription...
3654 cupsdDeleteSubscription(sub
, 1);
3656 con
->response
->request
.status
.status_code
= IPP_OK
;
3661 * 'check_rss_recipient()' - Check that we do not have a duplicate RSS feed URI.
3664 static int /* O - 1 if OK, 0 if not */
3665 check_rss_recipient(
3666 const char *recipient
) /* I - Recipient URI */
3668 cupsd_subscription_t
*sub
; /* Current subscription */
3671 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
);
3673 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
3677 * Compare the URIs up to the first ?...
3680 const char *r1
, *r2
;
3682 for (r1
= recipient
, r2
= sub
->recipient
;
3683 *r1
== *r2
&& *r1
&& *r1
!= '?' && *r2
&& *r2
!= '?';
3695 * 'check_quotas()' - Check quotas for a printer and user.
3698 static int /* O - 1 if OK, 0 if forbidden,
3699 -1 if limit reached */
3700 check_quotas(cupsd_client_t
*con
, /* I - Client connection */
3701 cupsd_printer_t
*p
) /* I - Printer or class */
3703 char username
[33], /* Username */
3704 *name
; /* Current user name */
3705 cupsd_quota_t
*q
; /* Quota data */
3706 #ifdef HAVE_MBR_UID_TO_UUID
3708 * Use Apple membership APIs which require that all names represent
3709 * valid user account or group records accessible by the server.
3712 uuid_t usr_uuid
; /* UUID for job requesting user */
3713 uuid_t usr2_uuid
; /* UUID for ACL user name entry */
3714 uuid_t grp_uuid
; /* UUID for ACL group name entry */
3715 int mbr_err
; /* Error from membership function */
3716 int is_member
; /* Is this user a member? */
3719 * Use standard POSIX APIs for checking users and groups...
3722 struct passwd
*pw
; /* User password data */
3723 #endif /* HAVE_MBR_UID_TO_UUID */
3726 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "check_quotas(%p[%d], %p[%s])",
3727 con
, con
->number
, p
, p
->name
);
3730 * Figure out who is printing...
3733 strlcpy(username
, get_username(con
), sizeof(username
));
3735 if ((name
= strchr(username
, '@')) != NULL
)
3736 *name
= '\0'; /* Strip @REALM */
3739 * Check global active job limits for printers and users...
3742 if (MaxJobsPerPrinter
)
3745 * Check if there are too many pending jobs on this printer...
3748 if (cupsdGetPrinterJobCount(p
->name
) >= MaxJobsPerPrinter
)
3750 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for printer \"%s\"...",
3759 * Check if there are too many pending jobs for this user...
3762 if (cupsdGetUserJobCount(username
) >= MaxJobsPerUser
)
3764 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for user \"%s\"...",
3771 * Check against users...
3774 if (cupsArrayCount(p
->users
) == 0 && p
->k_limit
== 0 && p
->page_limit
== 0)
3777 if (cupsArrayCount(p
->users
))
3779 #ifdef HAVE_MBR_UID_TO_UUID
3781 * Get UUID for job requesting user...
3784 if (mbr_user_name_to_uuid((char *)username
, usr_uuid
))
3790 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3791 "check_quotas: UUID lookup failed for user \"%s\"",
3793 cupsdLogMessage(CUPSD_LOG_INFO
,
3794 "Denying user \"%s\" access to printer \"%s\" "
3795 "(unknown user)...",
3801 * Get UID and GID of requesting user...
3804 pw
= getpwnam(username
);
3806 #endif /* HAVE_MBR_UID_TO_UUID */
3808 for (name
= (char *)cupsArrayFirst(p
->users
);
3810 name
= (char *)cupsArrayNext(p
->users
))
3814 * Check group membership...
3817 #ifdef HAVE_MBR_UID_TO_UUID
3820 if (uuid_parse(name
+ 2, grp_uuid
))
3821 uuid_clear(grp_uuid
);
3823 else if ((mbr_err
= mbr_group_name_to_uuid(name
+ 1, grp_uuid
)) != 0)
3826 * Invalid ACL entries are ignored for matching; just record a
3827 * warning in the log...
3830 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3831 "check_quotas: UUID lookup failed for ACL entry "
3832 "\"%s\" (err=%d)", name
, mbr_err
);
3833 cupsdLogMessage(CUPSD_LOG_WARN
,
3834 "Access control entry \"%s\" not a valid group name; "
3835 "entry ignored", name
);
3838 if ((mbr_err
= mbr_check_membership(usr_uuid
, grp_uuid
,
3842 * At this point, there should be no errors, but check anyways...
3845 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3846 "check_quotas: group \"%s\" membership check "
3847 "failed (err=%d)", name
+ 1, mbr_err
);
3852 * Stop if we found a match...
3859 if (cupsdCheckGroup(username
, pw
, name
+ 1))
3861 #endif /* HAVE_MBR_UID_TO_UUID */
3863 #ifdef HAVE_MBR_UID_TO_UUID
3868 if (uuid_parse(name
+ 1, usr2_uuid
))
3869 uuid_clear(usr2_uuid
);
3871 else if ((mbr_err
= mbr_user_name_to_uuid(name
, usr2_uuid
)) != 0)
3874 * Invalid ACL entries are ignored for matching; just record a
3875 * warning in the log...
3878 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3879 "check_quotas: UUID lookup failed for ACL entry "
3880 "\"%s\" (err=%d)", name
, mbr_err
);
3881 cupsdLogMessage(CUPSD_LOG_WARN
,
3882 "Access control entry \"%s\" not a valid user name; "
3883 "entry ignored", name
);
3886 if (!uuid_compare(usr_uuid
, usr2_uuid
))
3890 else if (!_cups_strcasecmp(username
, name
))
3892 #endif /* HAVE_MBR_UID_TO_UUID */
3894 if ((name
!= NULL
) == p
->deny_users
)
3896 cupsdLogMessage(CUPSD_LOG_INFO
,
3897 "Denying user \"%s\" access to printer \"%s\"...",
3907 if (p
->k_limit
|| p
->page_limit
)
3909 if ((q
= cupsdUpdateQuota(p
, username
, 0, 0)) == NULL
)
3911 cupsdLogMessage(CUPSD_LOG_ERROR
,
3912 "Unable to allocate quota data for user \"%s\"",
3917 if ((q
->k_count
>= p
->k_limit
&& p
->k_limit
) ||
3918 (q
->page_count
>= p
->page_limit
&& p
->page_limit
))
3920 cupsdLogMessage(CUPSD_LOG_INFO
, "User \"%s\" is over the quota limit...",
3927 * If we have gotten this far, we're done!
3935 * 'close_job()' - Close a multi-file job.
3939 close_job(cupsd_client_t
*con
, /* I - Client connection */
3940 ipp_attribute_t
*uri
) /* I - Printer URI */
3942 cupsd_job_t
*job
; /* Job */
3943 ipp_attribute_t
*attr
; /* Attribute */
3944 char job_uri
[HTTP_MAX_URI
],
3946 username
[256]; /* User name */
3949 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "close_job(%p[%d], %s)", con
,
3950 con
->number
, uri
->values
[0].string
.text
);
3953 * See if we have a job URI or a printer URI...
3956 if (strcmp(uri
->name
, "printer-uri"))
3959 * job-uri is not supported by Close-Job!
3962 send_ipp_status(con
, IPP_BAD_REQUEST
,
3963 _("Close-Job doesn't support the job-uri attribute."));
3968 * Got a printer URI; see if we also have a job-id attribute...
3971 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3972 IPP_TAG_INTEGER
)) == NULL
)
3974 send_ipp_status(con
, IPP_BAD_REQUEST
,
3975 _("Got a printer-uri attribute but no job-id."));
3979 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
3982 * Nope - return a "not found" error...
3985 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3986 attr
->values
[0].integer
);
3991 * See if the job is owned by the requesting user...
3994 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3996 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3997 cupsdFindDest(job
->dest
));
4002 * Add any ending sheet...
4005 if (cupsdTimeoutJob(job
))
4008 if (job
->state_value
== IPP_JOB_STOPPED
)
4010 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
4011 job
->state_value
= IPP_JOB_PENDING
;
4013 else if (job
->state_value
== IPP_JOB_HELD
)
4015 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
4016 IPP_TAG_KEYWORD
)) == NULL
)
4017 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
4019 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
4021 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
4022 job
->state_value
= IPP_JOB_PENDING
;
4027 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
4030 * Fill in the response info...
4033 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
4034 con
->clientname
, con
->clientport
, "/jobs/%d", job
->id
);
4035 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
4038 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
4040 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
4043 con
->response
->request
.status
.status_code
= IPP_OK
;
4046 * Start the job if necessary...
4054 * 'copy_attrs()' - Copy attributes from one request to another.
4058 copy_attrs(ipp_t
*to
, /* I - Destination request */
4059 ipp_t
*from
, /* I - Source request */
4060 cups_array_t
*ra
, /* I - Requested attributes */
4061 ipp_tag_t group
, /* I - Group to copy */
4062 int quickcopy
, /* I - Do a quick copy? */
4063 cups_array_t
*exclude
) /* I - Attributes to exclude? */
4065 ipp_attribute_t
*fromattr
; /* Source attribute */
4068 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4069 "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)",
4070 to
, from
, ra
, group
, quickcopy
);
4075 for (fromattr
= from
->attrs
; fromattr
; fromattr
= fromattr
->next
)
4078 * Filter attributes as needed...
4081 if ((group
!= IPP_TAG_ZERO
&& fromattr
->group_tag
!= group
&&
4082 fromattr
->group_tag
!= IPP_TAG_ZERO
) || !fromattr
->name
)
4085 if (!strcmp(fromattr
->name
, "document-password") ||
4086 !strcmp(fromattr
->name
, "job-authorization-uri") ||
4087 !strcmp(fromattr
->name
, "job-password") ||
4088 !strcmp(fromattr
->name
, "job-password-encryption") ||
4089 !strcmp(fromattr
->name
, "job-printer-uri"))
4093 (cupsArrayFind(exclude
, fromattr
->name
) ||
4094 cupsArrayFind(exclude
, "all")))
4097 * We need to exclude this attribute for security reasons; we require the
4098 * job-id attribute regardless of the security settings for IPP
4101 * The job-printer-uri attribute is handled by copy_job_attrs().
4103 * Subscription attribute security is handled by copy_subscription_attrs().
4106 if (strcmp(fromattr
->name
, "job-id"))
4110 if (!ra
|| cupsArrayFind(ra
, fromattr
->name
))
4113 * Don't send collection attributes by default to IPP/1.x clients
4114 * since many do not support collections. Also don't send
4115 * media-col-database unless specifically requested by the client.
4118 if (fromattr
->value_tag
== IPP_TAG_BEGIN_COLLECTION
&&
4120 (to
->request
.status
.version
[0] == 1 ||
4121 !strcmp(fromattr
->name
, "media-col-database")))
4124 ippCopyAttribute(to
, fromattr
, quickcopy
);
4131 * 'copy_banner()' - Copy a banner file to the requests directory for the
4135 static int /* O - Size of banner file in kbytes */
4136 copy_banner(cupsd_client_t
*con
, /* I - Client connection */
4137 cupsd_job_t
*job
, /* I - Job information */
4138 const char *name
) /* I - Name of banner */
4140 int i
; /* Looping var */
4141 int kbytes
; /* Size of banner file in kbytes */
4142 char filename
[1024]; /* Job filename */
4143 cupsd_banner_t
*banner
; /* Pointer to banner */
4144 cups_file_t
*in
; /* Input file */
4145 cups_file_t
*out
; /* Output file */
4146 int ch
; /* Character from file */
4147 char attrname
[255], /* Name of attribute */
4148 *s
; /* Pointer into name */
4149 ipp_attribute_t
*attr
; /* Attribute */
4152 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4153 "copy_banner(con=%p[%d], job=%p[%d], name=\"%s\")",
4154 con
, con
? con
->number
: -1, job
, job
->id
,
4155 name
? name
: "(null)");
4158 * Find the banner; return if not found or "none"...
4161 if (!name
|| !strcmp(name
, "none") ||
4162 (banner
= cupsdFindBanner(name
)) == NULL
)
4166 * Open the banner and job files...
4169 if (add_file(con
, job
, banner
->filetype
, 0))
4172 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
4174 if ((out
= cupsFileOpen(filename
, "w")) == NULL
)
4176 cupsdLogMessage(CUPSD_LOG_ERROR
,
4177 "Unable to create banner job file %s - %s",
4178 filename
, strerror(errno
));
4183 fchmod(cupsFileNumber(out
), 0640);
4184 fchown(cupsFileNumber(out
), RunUser
, Group
);
4187 * Try the localized banner file under the subdirectory...
4190 strlcpy(attrname
, job
->attrs
->attrs
->next
->values
[0].string
.text
,
4192 if (strlen(attrname
) > 2 && attrname
[2] == '-')
4195 * Convert ll-cc to ll_CC...
4199 attrname
[3] = (char)toupper(attrname
[3] & 255);
4200 attrname
[4] = (char)toupper(attrname
[4] & 255);
4203 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4206 if (access(filename
, 0) && strlen(attrname
) > 2)
4209 * Wasn't able to find "ll_CC" locale file; try the non-national
4210 * localization banner directory.
4215 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4219 if (access(filename
, 0))
4222 * Use the non-localized banner file.
4225 snprintf(filename
, sizeof(filename
), "%s/banners/%s", DataDir
, name
);
4228 if ((in
= cupsFileOpen(filename
, "r")) == NULL
)
4232 cupsdLogMessage(CUPSD_LOG_ERROR
,
4233 "Unable to open banner template file %s - %s",
4234 filename
, strerror(errno
));
4240 * Parse the file to the end...
4243 while ((ch
= cupsFileGetChar(in
)) != EOF
)
4247 * Get an attribute name...
4250 for (s
= attrname
; (ch
= cupsFileGetChar(in
)) != EOF
;)
4251 if (!isalpha(ch
& 255) && ch
!= '-' && ch
!= '?')
4253 else if (s
< (attrname
+ sizeof(attrname
) - 1))
4263 * Ignore { followed by stuff that is not an attribute name...
4266 cupsFilePrintf(out
, "{%s%c", attrname
, ch
);
4271 * See if it is defined...
4274 if (attrname
[0] == '?')
4279 if (!strcmp(s
, "printer-name"))
4281 cupsFilePuts(out
, job
->dest
);
4284 else if ((attr
= ippFindAttribute(job
->attrs
, s
, IPP_TAG_ZERO
)) == NULL
)
4287 * See if we have a leading question mark...
4290 if (attrname
[0] != '?')
4293 * Nope, write to file as-is; probably a PostScript procedure...
4296 cupsFilePrintf(out
, "{%s}", attrname
);
4303 * Output value(s)...
4306 for (i
= 0; i
< attr
->num_values
; i
++)
4309 cupsFilePutChar(out
, ',');
4311 switch (attr
->value_tag
)
4313 case IPP_TAG_INTEGER
:
4315 if (!strncmp(s
, "time-at-", 8))
4317 struct timeval tv
; /* Time value */
4319 tv
.tv_sec
= attr
->values
[i
].integer
;
4322 cupsFilePuts(out
, cupsdGetDateTime(&tv
, CUPSD_TIME_STANDARD
));
4325 cupsFilePrintf(out
, "%d", attr
->values
[i
].integer
);
4328 case IPP_TAG_BOOLEAN
:
4329 cupsFilePrintf(out
, "%d", attr
->values
[i
].boolean
);
4332 case IPP_TAG_NOVALUE
:
4333 cupsFilePuts(out
, "novalue");
4336 case IPP_TAG_RANGE
:
4337 cupsFilePrintf(out
, "%d-%d", attr
->values
[i
].range
.lower
,
4338 attr
->values
[i
].range
.upper
);
4341 case IPP_TAG_RESOLUTION
:
4342 cupsFilePrintf(out
, "%dx%d%s", attr
->values
[i
].resolution
.xres
,
4343 attr
->values
[i
].resolution
.yres
,
4344 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
4349 case IPP_TAG_STRING
:
4352 case IPP_TAG_KEYWORD
:
4353 case IPP_TAG_CHARSET
:
4354 case IPP_TAG_LANGUAGE
:
4355 if (!_cups_strcasecmp(banner
->filetype
->type
, "postscript"))
4358 * Need to quote strings for PS banners...
4363 for (p
= attr
->values
[i
].string
.text
; *p
; p
++)
4365 if (*p
== '(' || *p
== ')' || *p
== '\\')
4367 cupsFilePutChar(out
, '\\');
4368 cupsFilePutChar(out
, *p
);
4370 else if (*p
< 32 || *p
> 126)
4371 cupsFilePrintf(out
, "\\%03o", *p
& 255);
4373 cupsFilePutChar(out
, *p
);
4377 cupsFilePuts(out
, attr
->values
[i
].string
.text
);
4381 break; /* anti-compiler-warning-code */
4385 else if (ch
== '\\') /* Quoted char */
4387 ch
= cupsFileGetChar(in
);
4389 if (ch
!= '{') /* Only do special handling for \{ */
4390 cupsFilePutChar(out
, '\\');
4392 cupsFilePutChar(out
, ch
);
4395 cupsFilePutChar(out
, ch
);
4399 kbytes
= (cupsFileTell(out
) + 1023) / 1024;
4401 job
->koctets
+= kbytes
;
4403 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets", IPP_TAG_INTEGER
)) != NULL
)
4404 attr
->values
[0].integer
+= kbytes
;
4413 * 'copy_file()' - Copy a PPD file...
4416 static int /* O - 0 = success, -1 = error */
4417 copy_file(const char *from
, /* I - Source file */
4418 const char *to
, /* I - Destination file */
4419 mode_t mode
) /* I - Permissions */
4421 cups_file_t
*src
, /* Source file */
4422 *dst
; /* Destination file */
4423 int bytes
; /* Bytes to read/write */
4424 char buffer
[2048]; /* Copy buffer */
4427 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_file(\"%s\", \"%s\")", from
, to
);
4430 * Open the source and destination file for a copy...
4433 if ((src
= cupsFileOpen(from
, "rb")) == NULL
)
4436 if ((dst
= cupsdCreateConfFile(to
, mode
)) == NULL
)
4443 * Copy the source file to the destination...
4446 while ((bytes
= cupsFileRead(src
, buffer
, sizeof(buffer
))) > 0)
4447 if (cupsFileWrite(dst
, buffer
, (size_t)bytes
) < bytes
)
4455 * Close both files and return...
4460 return (cupsdCloseCreatedConfFile(dst
, to
));
4465 * 'copy_model()' - Copy a PPD model file, substituting default values
4469 static int /* O - 0 = success, -1 = error */
4470 copy_model(cupsd_client_t
*con
, /* I - Client connection */
4471 const char *from
, /* I - Source file */
4472 const char *to
) /* I - Destination file */
4474 fd_set input
; /* select() input set */
4475 struct timeval timeout
; /* select() timeout */
4476 int maxfd
; /* Max file descriptor for select() */
4477 char tempfile
[1024]; /* Temporary PPD file */
4478 int tempfd
; /* Temporary PPD file descriptor */
4479 int temppid
; /* Process ID of cups-driverd */
4480 int temppipe
[2]; /* Temporary pipes */
4481 char *argv
[4], /* Command-line arguments */
4482 *envp
[MAX_ENV
]; /* Environment */
4483 cups_file_t
*src
, /* Source file */
4484 *dst
; /* Destination file */
4485 ppd_file_t
*ppd
; /* PPD file */
4486 int bytes
, /* Bytes from pipe */
4487 total
; /* Total bytes from pipe */
4488 char buffer
[2048]; /* Copy buffer */
4489 int i
; /* Looping var */
4490 char option
[PPD_MAX_NAME
], /* Option name */
4491 choice
[PPD_MAX_NAME
]; /* Choice name */
4492 ppd_size_t
*size
; /* Default size */
4493 int num_defaults
; /* Number of default options */
4494 cups_option_t
*defaults
; /* Default options */
4495 char cups_protocol
[PPD_MAX_LINE
];
4496 /* cupsProtocol attribute */
4499 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_model(con=%p, from=\"%s\", to=\"%s\")", con
, from
, to
);
4502 * Run cups-driverd to get the PPD file...
4505 argv
[0] = "cups-driverd";
4507 argv
[2] = (char *)from
;
4510 cupsdLoadEnv(envp
, (int)(sizeof(envp
) / sizeof(envp
[0])));
4512 snprintf(buffer
, sizeof(buffer
), "%s/daemon/cups-driverd", ServerBin
);
4513 snprintf(tempfile
, sizeof(tempfile
), "%s/%d.ppd", TempDir
, con
->number
);
4514 tempfd
= open(tempfile
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
4515 if (tempfd
< 0 || cupsdOpenPipe(temppipe
))
4518 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4519 "copy_model: Running \"cups-driverd cat %s\"...", from
);
4521 if (!cupsdStartProcess(buffer
, argv
, envp
, -1, temppipe
[1], CGIPipes
[1],
4522 -1, -1, 0, DefaultProfile
, NULL
, &temppid
))
4533 * Wait up to 30 seconds for the PPD file to be copied...
4538 if (temppipe
[0] > CGIPipes
[0])
4539 maxfd
= temppipe
[0] + 1;
4541 maxfd
= CGIPipes
[0] + 1;
4546 * See if we have data ready...
4550 FD_SET(temppipe
[0], &input
);
4551 FD_SET(CGIPipes
[0], &input
);
4553 timeout
.tv_sec
= 30;
4554 timeout
.tv_usec
= 0;
4556 if ((i
= select(maxfd
, &input
, NULL
, NULL
, &timeout
)) < 0)
4566 * We have timed out...
4572 if (FD_ISSET(temppipe
[0], &input
))
4575 * Read the PPD file from the pipe, and write it to the PPD file.
4578 if ((bytes
= read(temppipe
[0], buffer
, sizeof(buffer
))) > 0)
4580 if (write(tempfd
, buffer
, (size_t)bytes
) < bytes
)
4589 if (FD_ISSET(CGIPipes
[0], &input
))
4599 * No data from cups-deviced...
4602 cupsdLogMessage(CUPSD_LOG_ERROR
, "copy_model: empty PPD file");
4608 * Open the source file for a copy...
4611 if ((src
= cupsFileOpen(tempfile
, "rb")) == NULL
)
4618 * Read the source file and see what page sizes are supported...
4621 if ((ppd
= _ppdOpen(src
, _PPD_LOCALIZATION_NONE
)) == NULL
)
4629 * Open the destination (if possible) and set the default options...
4634 cups_protocol
[0] = '\0';
4636 if ((dst
= cupsFileOpen(to
, "rb")) != NULL
)
4639 * Read all of the default lines from the old PPD...
4642 while (cupsFileGets(dst
, buffer
, sizeof(buffer
)))
4643 if (!strncmp(buffer
, "*Default", 8))
4646 * Add the default option...
4649 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
4650 choice
, sizeof(choice
)))
4652 ppd_option_t
*ppdo
; /* PPD option */
4656 * Only add the default if the default hasn't already been
4657 * set and the choice exists in the new PPD...
4660 if (!cupsGetOption(option
, num_defaults
, defaults
) &&
4661 (ppdo
= ppdFindOption(ppd
, option
)) != NULL
&&
4662 ppdFindChoice(ppdo
, choice
))
4663 num_defaults
= cupsAddOption(option
, choice
, num_defaults
,
4667 else if (!strncmp(buffer
, "*cupsProtocol:", 14))
4668 strlcpy(cups_protocol
, buffer
, sizeof(cups_protocol
));
4672 else if ((size
= ppdPageSize(ppd
, DefaultPaperSize
)) != NULL
)
4675 * Add the default media sizes...
4678 num_defaults
= cupsAddOption("PageSize", size
->name
,
4679 num_defaults
, &defaults
);
4680 num_defaults
= cupsAddOption("PageRegion", size
->name
,
4681 num_defaults
, &defaults
);
4682 num_defaults
= cupsAddOption("PaperDimension", size
->name
,
4683 num_defaults
, &defaults
);
4684 num_defaults
= cupsAddOption("ImageableArea", size
->name
,
4685 num_defaults
, &defaults
);
4691 * Open the destination file for a copy...
4694 if ((dst
= cupsdCreateConfFile(to
, ConfigFilePerm
)) == NULL
)
4696 cupsFreeOptions(num_defaults
, defaults
);
4703 * Copy the source file to the destination...
4706 cupsFileRewind(src
);
4708 while (cupsFileGets(src
, buffer
, sizeof(buffer
)))
4710 if (!strncmp(buffer
, "*Default", 8))
4713 * Check for an previous default option choice...
4716 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
4717 choice
, sizeof(choice
)))
4719 const char *val
; /* Default option value */
4722 if ((val
= cupsGetOption(option
, num_defaults
, defaults
)) != NULL
)
4725 * Substitute the previous choice...
4728 snprintf(buffer
, sizeof(buffer
), "*Default%s: %s", option
, val
);
4733 cupsFilePrintf(dst
, "%s\n", buffer
);
4736 if (cups_protocol
[0])
4737 cupsFilePrintf(dst
, "%s\n", cups_protocol
);
4739 cupsFreeOptions(num_defaults
, defaults
);
4742 * Close both files and return...
4749 return (cupsdCloseCreatedConfFile(dst
, to
));
4754 * 'copy_job_attrs()' - Copy job attributes.
4758 copy_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
4759 cupsd_job_t
*job
, /* I - Job */
4760 cups_array_t
*ra
, /* I - Requested attributes array */
4761 cups_array_t
*exclude
) /* I - Private attributes array */
4763 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
4767 * Send the requested attributes for each job...
4770 if (!cupsArrayFind(exclude
, "all"))
4772 if ((!exclude
|| !cupsArrayFind(exclude
, "number-of-documents")) &&
4773 (!ra
|| cupsArrayFind(ra
, "number-of-documents")))
4774 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4775 "number-of-documents", job
->num_files
);
4777 if ((!exclude
|| !cupsArrayFind(exclude
, "job-media-progress")) &&
4778 (!ra
|| cupsArrayFind(ra
, "job-media-progress")))
4779 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4780 "job-media-progress", job
->progress
);
4782 if ((!exclude
|| !cupsArrayFind(exclude
, "job-more-info")) &&
4783 (!ra
|| cupsArrayFind(ra
, "job-more-info")))
4785 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "http",
4786 NULL
, con
->clientname
, con
->clientport
, "/jobs/%d",
4788 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4789 "job-more-info", NULL
, job_uri
);
4792 if (job
->state_value
> IPP_JOB_PROCESSING
&&
4793 (!exclude
|| !cupsArrayFind(exclude
, "job-preserved")) &&
4794 (!ra
|| cupsArrayFind(ra
, "job-preserved")))
4795 ippAddBoolean(con
->response
, IPP_TAG_JOB
, "job-preserved",
4796 job
->num_files
> 0);
4798 if ((!exclude
|| !cupsArrayFind(exclude
, "job-printer-up-time")) &&
4799 (!ra
|| cupsArrayFind(ra
, "job-printer-up-time")))
4800 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4801 "job-printer-up-time", time(NULL
));
4804 if (!ra
|| cupsArrayFind(ra
, "job-printer-uri"))
4806 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
4807 con
->clientname
, con
->clientport
,
4808 (job
->dtype
& CUPS_PRINTER_CLASS
) ? "/classes/%s" :
4811 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4812 "job-printer-uri", NULL
, job_uri
);
4815 if (!ra
|| cupsArrayFind(ra
, "job-uri"))
4817 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
4818 con
->clientname
, con
->clientport
, "/jobs/%d",
4820 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4821 "job-uri", NULL
, job_uri
);
4826 copy_attrs(con
->response
, job
->attrs
, ra
, IPP_TAG_JOB
, 0, exclude
);
4831 * Generate attributes from the job structure...
4834 if (job
->completed_time
&& (!ra
|| cupsArrayFind(ra
, "date-time-at-completed")))
4835 ippAddDate(con
->response
, IPP_TAG_JOB
, "date-time-at-completed", ippTimeToDate(job
->completed_time
));
4837 if (job
->creation_time
&& (!ra
|| cupsArrayFind(ra
, "date-time-at-creation")))
4838 ippAddDate(con
->response
, IPP_TAG_JOB
, "date-time-at-creation", ippTimeToDate(job
->creation_time
));
4840 if (!ra
|| cupsArrayFind(ra
, "job-id"))
4841 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
4843 if (!ra
|| cupsArrayFind(ra
, "job-k-octets"))
4844 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-k-octets", job
->koctets
);
4846 if (job
->name
&& (!ra
|| cupsArrayFind(ra
, "job-name")))
4847 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_CONST_TAG(IPP_TAG_NAME
), "job-name", NULL
, job
->name
);
4849 if (job
->username
&& (!ra
|| cupsArrayFind(ra
, "job-originating-user-name")))
4850 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_CONST_TAG(IPP_TAG_NAME
), "job-originating-user-name", NULL
, job
->username
);
4852 if (!ra
|| cupsArrayFind(ra
, "job-state"))
4853 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state", (int)job
->state_value
);
4855 if (!ra
|| cupsArrayFind(ra
, "job-state-reasons"))
4857 switch (job
->state_value
)
4859 default : /* Should never get here for processing, pending, held, or stopped jobs since they don't get unloaded... */
4861 case IPP_JSTATE_ABORTED
:
4862 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons", NULL
, "job-aborted-by-system");
4864 case IPP_JSTATE_CANCELED
:
4865 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons", NULL
, "job-canceled-by-user");
4867 case IPP_JSTATE_COMPLETED
:
4868 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons", NULL
, "job-completed-successfully");
4873 if (job
->completed_time
&& (!ra
|| cupsArrayFind(ra
, "time-at-completed")))
4874 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-completed", (int)job
->completed_time
);
4876 if (job
->creation_time
&& (!ra
|| cupsArrayFind(ra
, "time-at-creation")))
4877 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation", (int)job
->creation_time
);
4883 * 'copy_printer_attrs()' - Copy printer attributes.
4888 cupsd_client_t
*con
, /* I - Client connection */
4889 cupsd_printer_t
*printer
, /* I - Printer */
4890 cups_array_t
*ra
) /* I - Requested attributes array */
4892 char printer_uri
[HTTP_MAX_URI
];
4894 char printer_icons
[HTTP_MAX_URI
];
4896 time_t curtime
; /* Current time */
4897 int i
; /* Looping var */
4901 * Copy the printer attributes to the response using requested-attributes
4902 * and document-format attributes that may be provided by the client.
4905 curtime
= time(NULL
);
4907 if (!ra
|| cupsArrayFind(ra
, "marker-change-time"))
4908 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4909 "marker-change-time", printer
->marker_time
);
4911 if (printer
->num_printers
> 0 &&
4912 (!ra
|| cupsArrayFind(ra
, "member-uris")))
4914 ipp_attribute_t
*member_uris
; /* member-uris attribute */
4915 cupsd_printer_t
*p2
; /* Printer in class */
4916 ipp_attribute_t
*p2_uri
; /* printer-uri-supported for class printer */
4919 if ((member_uris
= ippAddStrings(con
->response
, IPP_TAG_PRINTER
,
4920 IPP_TAG_URI
, "member-uris",
4921 printer
->num_printers
, NULL
,
4924 for (i
= 0; i
< printer
->num_printers
; i
++)
4926 p2
= printer
->printers
[i
];
4928 if ((p2_uri
= ippFindAttribute(p2
->attrs
, "printer-uri-supported",
4929 IPP_TAG_URI
)) != NULL
)
4930 member_uris
->values
[i
].string
.text
=
4931 _cupsStrRetain(p2_uri
->values
[0].string
.text
);
4934 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
,
4935 sizeof(printer_uri
), "ipp", NULL
, con
->clientname
,
4937 (p2
->type
& CUPS_PRINTER_CLASS
) ?
4938 "/classes/%s" : "/printers/%s", p2
->name
);
4939 member_uris
->values
[i
].string
.text
= _cupsStrAlloc(printer_uri
);
4945 if (printer
->alert
&& (!ra
|| cupsArrayFind(ra
, "printer-alert")))
4946 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_STRING
,
4947 "printer-alert", NULL
, printer
->alert
);
4949 if (printer
->alert_description
&&
4950 (!ra
|| cupsArrayFind(ra
, "printer-alert-description")))
4951 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4952 "printer-alert-description", NULL
,
4953 printer
->alert_description
);
4955 if (!ra
|| cupsArrayFind(ra
, "printer-config-change-date-time"))
4956 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-config-change-date-time", ippTimeToDate(printer
->config_time
));
4958 if (!ra
|| cupsArrayFind(ra
, "printer-config-change-time"))
4959 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4960 "printer-config-change-time", printer
->config_time
);
4962 if (!ra
|| cupsArrayFind(ra
, "printer-current-time"))
4963 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-current-time",
4964 ippTimeToDate(curtime
));
4966 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
4967 if (!ra
|| cupsArrayFind(ra
, "printer-dns-sd-name"))
4969 if (printer
->reg_name
)
4970 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4971 "printer-dns-sd-name", NULL
, printer
->reg_name
);
4973 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
4974 "printer-dns-sd-name", 0);
4976 #endif /* HAVE_DNSSD || HAVE_AVAHI */
4978 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy"))
4979 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4980 "printer-error-policy", NULL
, printer
->error_policy
);
4982 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy-supported"))
4984 static const char * const errors
[] =/* printer-error-policy-supported values */
4987 "retry-current-job",
4992 if (printer
->type
& CUPS_PRINTER_CLASS
)
4993 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
4994 "printer-error-policy-supported", NULL
, "retry-current-job");
4996 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
4997 "printer-error-policy-supported",
4998 sizeof(errors
) / sizeof(errors
[0]), NULL
, errors
);
5001 if (!ra
|| cupsArrayFind(ra
, "printer-icons"))
5003 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_icons
, sizeof(printer_icons
),
5004 "http", NULL
, con
->clientname
, con
->clientport
,
5005 "/icons/%s.png", printer
->name
);
5006 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-icons",
5007 NULL
, printer_icons
);
5008 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-icons=\"%s\"", printer_icons
);
5011 if (!ra
|| cupsArrayFind(ra
, "printer-is-accepting-jobs"))
5012 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs", (char)printer
->accepting
);
5014 if (!ra
|| cupsArrayFind(ra
, "printer-is-shared"))
5015 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-shared", (char)printer
->shared
);
5017 if (!ra
|| cupsArrayFind(ra
, "printer-is-temporary"))
5018 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-temporary", (char)printer
->temporary
);
5020 if (!ra
|| cupsArrayFind(ra
, "printer-more-info"))
5022 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5023 "http", NULL
, con
->clientname
, con
->clientport
,
5024 (printer
->type
& CUPS_PRINTER_CLASS
) ?
5025 "/classes/%s" : "/printers/%s", printer
->name
);
5026 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5027 "printer-more-info", NULL
, printer_uri
);
5030 if (!ra
|| cupsArrayFind(ra
, "printer-op-policy"))
5031 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5032 "printer-op-policy", NULL
, printer
->op_policy
);
5034 if (!ra
|| cupsArrayFind(ra
, "printer-state"))
5035 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
5038 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-date-time"))
5039 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-state-change-date-time", ippTimeToDate(printer
->state_time
));
5041 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-time"))
5042 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5043 "printer-state-change-time", printer
->state_time
);
5045 if (!ra
|| cupsArrayFind(ra
, "printer-state-message"))
5046 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5047 "printer-state-message", NULL
, printer
->state_message
);
5049 if (!ra
|| cupsArrayFind(ra
, "printer-state-reasons"))
5050 add_printer_state_reasons(con
, printer
);
5052 if (!ra
|| cupsArrayFind(ra
, "printer-type"))
5054 cups_ptype_t type
; /* printer-type value */
5057 * Add the CUPS-specific printer-type attribute...
5060 type
= printer
->type
;
5062 if (printer
== DefaultPrinter
)
5063 type
|= CUPS_PRINTER_DEFAULT
;
5065 if (!printer
->accepting
)
5066 type
|= CUPS_PRINTER_REJECTING
;
5068 if (!printer
->shared
)
5069 type
|= CUPS_PRINTER_NOT_SHARED
;
5071 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-type", (int)type
);
5074 if (!ra
|| cupsArrayFind(ra
, "printer-up-time"))
5075 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5076 "printer-up-time", curtime
);
5078 if (!ra
|| cupsArrayFind(ra
, "printer-uri-supported"))
5080 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5081 "ipp", NULL
, con
->clientname
, con
->clientport
,
5082 (printer
->type
& CUPS_PRINTER_CLASS
) ?
5083 "/classes/%s" : "/printers/%s", printer
->name
);
5084 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5085 "printer-uri-supported", NULL
, printer_uri
);
5086 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-uri-supported=\"%s\"",
5090 if (!ra
|| cupsArrayFind(ra
, "queued-job-count"))
5091 add_queued_job_count(con
, printer
);
5093 copy_attrs(con
->response
, printer
->attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
5094 if (printer
->ppd_attrs
)
5095 copy_attrs(con
->response
, printer
->ppd_attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
5096 copy_attrs(con
->response
, CommonData
, ra
, IPP_TAG_ZERO
, IPP_TAG_COPY
, NULL
);
5101 * 'copy_subscription_attrs()' - Copy subscription attributes.
5105 copy_subscription_attrs(
5106 cupsd_client_t
*con
, /* I - Client connection */
5107 cupsd_subscription_t
*sub
, /* I - Subscription */
5108 cups_array_t
*ra
, /* I - Requested attributes array */
5109 cups_array_t
*exclude
) /* I - Private attributes array */
5111 ipp_attribute_t
*attr
; /* Current attribute */
5112 char printer_uri
[HTTP_MAX_URI
];
5114 int count
; /* Number of events */
5115 unsigned mask
; /* Current event mask */
5116 const char *name
; /* Current event name */
5119 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5120 "copy_subscription_attrs(con=%p, sub=%p, ra=%p, exclude=%p)",
5121 con
, sub
, ra
, exclude
);
5124 * Copy the subscription attributes to the response using the
5125 * requested-attributes attribute that may be provided by the client.
5128 if (!exclude
|| !cupsArrayFind(exclude
, "all"))
5130 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-events")) &&
5131 (!ra
|| cupsArrayFind(ra
, "notify-events")))
5133 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_subscription_attrs: notify-events");
5135 if ((name
= cupsdEventName((cupsd_eventmask_t
)sub
->mask
)) != NULL
)
5138 * Simple event list...
5141 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
,
5142 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5143 "notify-events", NULL
, name
);
5148 * Complex event list...
5151 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5152 if (sub
->mask
& mask
)
5155 attr
= ippAddStrings(con
->response
, IPP_TAG_SUBSCRIPTION
,
5156 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5157 "notify-events", count
, NULL
, NULL
);
5159 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5160 if (sub
->mask
& mask
)
5162 attr
->values
[count
].string
.text
=
5163 (char *)cupsdEventName((cupsd_eventmask_t
)mask
);
5170 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-lease-duration")) &&
5171 (!sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-lease-duration"))))
5172 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5173 "notify-lease-duration", sub
->lease
);
5175 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-recipient-uri")) &&
5176 (sub
->recipient
&& (!ra
|| cupsArrayFind(ra
, "notify-recipient-uri"))))
5177 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5178 "notify-recipient-uri", NULL
, sub
->recipient
);
5179 else if ((!exclude
|| !cupsArrayFind(exclude
, "notify-pull-method")) &&
5180 (!ra
|| cupsArrayFind(ra
, "notify-pull-method")))
5181 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_KEYWORD
,
5182 "notify-pull-method", NULL
, "ippget");
5184 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-subscriber-user-name")) &&
5185 (!ra
|| cupsArrayFind(ra
, "notify-subscriber-user-name")))
5186 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_NAME
,
5187 "notify-subscriber-user-name", NULL
, sub
->owner
);
5189 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-time-interval")) &&
5190 (!ra
|| cupsArrayFind(ra
, "notify-time-interval")))
5191 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5192 "notify-time-interval", sub
->interval
);
5194 if (sub
->user_data_len
> 0 &&
5195 (!exclude
|| !cupsArrayFind(exclude
, "notify-user-data")) &&
5196 (!ra
|| cupsArrayFind(ra
, "notify-user-data")))
5197 ippAddOctetString(con
->response
, IPP_TAG_SUBSCRIPTION
, "notify-user-data",
5198 sub
->user_data
, sub
->user_data_len
);
5201 if (sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-job-id")))
5202 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5203 "notify-job-id", sub
->job
->id
);
5205 if (sub
->dest
&& (!ra
|| cupsArrayFind(ra
, "notify-printer-uri")))
5207 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5208 "ipp", NULL
, con
->clientname
, con
->clientport
,
5209 "/printers/%s", sub
->dest
->name
);
5210 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5211 "notify-printer-uri", NULL
, printer_uri
);
5214 if (!ra
|| cupsArrayFind(ra
, "notify-subscription-id"))
5215 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5216 "notify-subscription-id", sub
->id
);
5221 * 'create_job()' - Print a file to a printer or class.
5225 create_job(cupsd_client_t
*con
, /* I - Client connection */
5226 ipp_attribute_t
*uri
) /* I - Printer URI */
5228 int i
; /* Looping var */
5229 cupsd_printer_t
*printer
; /* Printer */
5230 cupsd_job_t
*job
; /* New job */
5231 static const char * const forbidden_attrs
[] =
5232 { /* List of forbidden attributes */
5236 "document-natural-language"
5240 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "create_job(%p[%d], %s)", con
,
5241 con
->number
, uri
->values
[0].string
.text
);
5244 * Is the destination valid?
5247 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
5253 send_ipp_status(con
, IPP_NOT_FOUND
,
5254 _("The printer or class does not exist."));
5259 * Check for invalid Create-Job attributes and log a warning or error depending
5260 * on whether cupsd is running in "strict conformance" mode...
5264 i
< (int)(sizeof(forbidden_attrs
) / sizeof(forbidden_attrs
[0]));
5266 if (ippFindAttribute(con
->request
, forbidden_attrs
[i
], IPP_TAG_ZERO
))
5268 if (StrictConformance
)
5270 send_ipp_status(con
, IPP_BAD_REQUEST
,
5271 _("The '%s' operation attribute cannot be supplied in a "
5272 "Create-Job request."), forbidden_attrs
[i
]);
5276 cupsdLogMessage(CUPSD_LOG_WARN
,
5277 "Unexpected '%s' operation attribute in a Create-Job "
5278 "request.", forbidden_attrs
[i
]);
5282 * Create the job object...
5285 if ((job
= add_job(con
, printer
, NULL
)) == NULL
)
5288 job
->pending_timeout
= 1;
5291 * Save and log the job...
5294 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
5295 job
->dest
, job
->username
);
5300 * 'create_local_bg_thread()' - Background thread for creating a local print queue.
5303 static void * /* O - Exit status */
5304 create_local_bg_thread(
5305 cupsd_printer_t
*printer
) /* I - Printer */
5307 cups_file_t
*from
, /* Source file */
5308 *to
; /* Destination file */
5309 char fromppd
[1024], /* Source PPD */
5310 toppd
[1024], /* Destination PPD */
5311 scheme
[32], /* URI scheme */
5312 userpass
[256], /* User:pass */
5313 host
[256], /* Hostname */
5314 resource
[1024], /* Resource path */
5315 line
[1024]; /* Line from PPD */
5316 int port
; /* Port number */
5317 http_encryption_t encryption
; /* Type of encryption to use */
5318 http_t
*http
; /* Connection to printer */
5319 ipp_t
*request
, /* Request to printer */
5320 *response
; /* Response from printer */
5321 ipp_attribute_t
*attr
; /* Attribute in response */
5325 * Try connecting to the printer...
5328 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s: Generating PPD file from \"%s\"...", printer
->name
, printer
->device_uri
);
5330 if (httpSeparateURI(HTTP_URI_CODING_ALL
, printer
->device_uri
, scheme
, sizeof(scheme
), userpass
, sizeof(userpass
), host
, sizeof(host
), &port
, resource
, sizeof(resource
)) < HTTP_URI_STATUS_OK
)
5332 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: Bad device URI \"%s\".", printer
->name
, printer
->device_uri
);
5336 if (!strcmp(scheme
, "ipps") || port
== 443)
5337 encryption
= HTTP_ENCRYPTION_ALWAYS
;
5339 encryption
= HTTP_ENCRYPTION_IF_REQUESTED
;
5341 if ((http
= httpConnect2(host
, port
, NULL
, AF_UNSPEC
, encryption
, 1, 30000, NULL
)) == NULL
)
5343 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: Unable to connect to %s:%d: %s", printer
->name
, host
, port
, cupsLastErrorString());
5348 * Query the printer for its capabilities...
5351 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s: Connected to %s:%d, sending Get-Printer-Attributes request...", printer
->name
, host
, port
);
5353 request
= ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES
);
5354 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
, printer
->device_uri
);
5355 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
, "requested-attributes", NULL
, "all");
5357 response
= cupsDoRequest(http
, request
, resource
);
5359 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s: Get-Printer-Attributes returned %s", printer
->name
, ippErrorString(cupsLastError()));
5361 // TODO: Grab printer icon file...
5365 * Write the PPD for the queue...
5368 if (_ppdCreateFromIPP(fromppd
, sizeof(fromppd
), response
))
5370 if ((!printer
->info
|| !*(printer
->info
)) && (attr
= ippFindAttribute(response
, "printer-info", IPP_TAG_TEXT
)) != NULL
)
5371 cupsdSetString(&printer
->info
, ippGetString(attr
, 0, NULL
));
5373 if ((!printer
->location
|| !*(printer
->location
)) && (attr
= ippFindAttribute(response
, "printer-location", IPP_TAG_TEXT
)) != NULL
)
5374 cupsdSetString(&printer
->location
, ippGetString(attr
, 0, NULL
));
5376 if ((!printer
->geo_location
|| !*(printer
->geo_location
)) && (attr
= ippFindAttribute(response
, "printer-geo-location", IPP_TAG_URI
)) != NULL
)
5377 cupsdSetString(&printer
->geo_location
, ippGetString(attr
, 0, NULL
));
5379 if ((from
= cupsFileOpen(fromppd
, "r")) == NULL
)
5381 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: Unable to read generated PPD: %s", printer
->name
, strerror(errno
));
5385 snprintf(toppd
, sizeof(toppd
), "%s/ppd/%s.ppd", ServerRoot
, printer
->name
);
5386 if ((to
= cupsdCreateConfFile(toppd
, ConfigFilePerm
)) == NULL
)
5388 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: Unable to create PPD for printer: %s", printer
->name
, strerror(errno
));
5389 cupsFileClose(from
);
5393 while (cupsFileGets(from
, line
, sizeof(line
)))
5394 cupsFilePrintf(to
, "%s\n", line
);
5396 cupsFileClose(from
);
5397 if (!cupsdCloseCreatedConfFile(to
, toppd
))
5399 printer
->config_time
= time(NULL
);
5400 printer
->state
= IPP_PSTATE_IDLE
;
5401 printer
->accepting
= 1;
5403 cupsdSetPrinterAttrs(printer
);
5405 cupsdAddEvent(CUPSD_EVENT_PRINTER_CONFIG
, printer
, NULL
, "Printer \"%s\" is now available.", printer
->name
);
5406 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" is now available.", printer
->name
);
5410 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: PPD creation failed: %s", printer
->name
, cupsLastErrorString());
5417 * 'create_local_printer()' - Create a local (temporary) print queue.
5421 create_local_printer(
5422 cupsd_client_t
*con
) /* I - Client connection */
5424 ipp_attribute_t
*device_uri
, /* device-uri attribute */
5425 *printer_geo_location
, /* printer-geo-location attribute */
5426 *printer_info
, /* printer-info attribute */
5427 *printer_location
, /* printer-location attribute */
5428 *printer_name
; /* printer-name attribute */
5429 cupsd_printer_t
*printer
; /* New printer */
5430 http_status_t status
; /* Policy status */
5431 char name
[128], /* Sanitized printer name */
5432 *nameptr
, /* Pointer into name */
5433 uri
[1024]; /* printer-uri-supported value */
5434 const char *ptr
; /* Pointer into attribute value */
5438 * Require local access to create a local printer...
5441 if (!httpAddrLocalhost(httpGetAddress(con
->http
)))
5443 send_ipp_status(con
, IPP_STATUS_ERROR_FORBIDDEN
, _("Only local users can create a local printer."));
5448 * Check any other policy limits...
5451 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5453 send_http_error(con
, status
, NULL
);
5458 * Grab needed attributes...
5461 if ((printer_name
= ippFindAttribute(con
->request
, "printer-name", IPP_TAG_ZERO
)) == NULL
|| ippGetGroupTag(printer_name
) != IPP_TAG_PRINTER
|| ippGetValueTag(printer_name
) != IPP_TAG_NAME
)
5464 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Missing required attribute \"%s\"."), "printer-name");
5465 else if (ippGetGroupTag(printer_name
) != IPP_TAG_PRINTER
)
5466 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Attribute \"%s\" is in the wrong group."), "printer-name");
5468 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Attribute \"%s\" is the wrong value type."), "printer-name");
5473 for (nameptr
= name
, ptr
= ippGetString(printer_name
, 0, NULL
); *ptr
&& nameptr
< (name
+ sizeof(name
) - 1); ptr
++)
5476 * Sanitize the printer name...
5479 if (_cups_isalnum(*ptr
))
5481 else if (nameptr
== name
|| nameptr
[-1] != '_')
5487 if ((device_uri
= ippFindAttribute(con
->request
, "device-uri", IPP_TAG_ZERO
)) == NULL
|| ippGetGroupTag(device_uri
) != IPP_TAG_PRINTER
|| ippGetValueTag(device_uri
) != IPP_TAG_URI
)
5490 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Missing required attribute \"%s\"."), "device-uri");
5491 else if (ippGetGroupTag(device_uri
) != IPP_TAG_PRINTER
)
5492 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Attribute \"%s\" is in the wrong group."), "device-uri");
5494 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Attribute \"%s\" is the wrong value type."), "device-uri");
5499 printer_geo_location
= ippFindAttribute(con
->request
, "printer-geo-location", IPP_TAG_URI
);
5500 printer_info
= ippFindAttribute(con
->request
, "printer-info", IPP_TAG_TEXT
);
5501 printer_location
= ippFindAttribute(con
->request
, "printer-location", IPP_TAG_TEXT
);
5504 * See if the printer already exists...
5507 if ((printer
= cupsdFindDest(name
)) != NULL
)
5509 send_ipp_status(con
, IPP_STATUS_ERROR_NOT_POSSIBLE
, _("Printer \"%s\" already exists."), name
);
5510 goto add_printer_attributes
;
5514 * Create the printer...
5517 if ((printer
= cupsdAddPrinter(name
)) == NULL
)
5519 send_ipp_status(con
, IPP_STATUS_ERROR_INTERNAL
, _("Unable to create printer."));
5523 printer
->shared
= 0;
5524 printer
->temporary
= 1;
5526 cupsdSetDeviceURI(printer
, ippGetString(device_uri
, 0, NULL
));
5528 if (printer_geo_location
)
5529 cupsdSetString(&printer
->geo_location
, ippGetString(printer_geo_location
, 0, NULL
));
5531 cupsdSetString(&printer
->info
, ippGetString(printer_info
, 0, NULL
));
5532 if (printer_location
)
5533 cupsdSetString(&printer
->location
, ippGetString(printer_location
, 0, NULL
));
5535 cupsdSetPrinterAttrs(printer
);
5538 * Run a background thread to create the PPD...
5541 _cupsThreadCreate((_cups_thread_func_t
)create_local_bg_thread
, printer
);
5544 * Return printer attributes...
5547 send_ipp_status(con
, IPP_STATUS_OK
, _("Local printer created."));
5549 add_printer_attributes
:
5551 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs", (char)printer
->accepting
);
5552 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state", printer
->state
);
5553 add_printer_state_reasons(con
, printer
);
5555 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), httpIsEncrypted(con
->http
) ? "ipps" : "ipp", NULL
, con
->clientname
, con
->clientport
, "/printers/%s", printer
->name
);
5556 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-uri-supported", NULL
, uri
);
5561 * 'create_requested_array()' - Create an array for the requested-attributes.
5564 static cups_array_t
* /* O - Array of attributes or NULL */
5565 create_requested_array(ipp_t
*request
) /* I - IPP request */
5567 cups_array_t
*ra
; /* Requested attributes array */
5571 * Create the array for standard attributes...
5574 ra
= ippCreateRequestedArray(request
);
5577 * Add CUPS defaults as needed...
5580 if (cupsArrayFind(ra
, "printer-defaults"))
5583 * Include user-set defaults...
5586 char *name
; /* Option name */
5588 cupsArrayRemove(ra
, "printer-defaults");
5590 for (name
= (char *)cupsArrayFirst(CommonDefaults
);
5592 name
= (char *)cupsArrayNext(CommonDefaults
))
5593 if (!cupsArrayFind(ra
, name
))
5594 cupsArrayAdd(ra
, name
);
5602 * 'create_subscriptions()' - Create one or more notification subscriptions.
5606 create_subscriptions(
5607 cupsd_client_t
*con
, /* I - Client connection */
5608 ipp_attribute_t
*uri
) /* I - Printer URI */
5610 http_status_t status
; /* Policy status */
5611 int i
; /* Looping var */
5612 ipp_attribute_t
*attr
; /* Current attribute */
5613 cups_ptype_t dtype
; /* Destination type (printer/class) */
5614 char scheme
[HTTP_MAX_URI
],
5615 /* Scheme portion of URI */
5616 userpass
[HTTP_MAX_URI
],
5617 /* Username portion of URI */
5619 /* Host portion of URI */
5620 resource
[HTTP_MAX_URI
];
5621 /* Resource portion of URI */
5622 int port
; /* Port portion of URI */
5623 cupsd_printer_t
*printer
; /* Printer/class */
5624 cupsd_job_t
*job
; /* Job */
5625 int jobid
; /* Job ID */
5626 cupsd_subscription_t
*sub
; /* Subscription object */
5627 const char *username
, /* requesting-user-name or
5628 authenticated username */
5629 *recipient
, /* notify-recipient-uri */
5630 *pullmethod
; /* notify-pull-method */
5631 ipp_attribute_t
*user_data
; /* notify-user-data */
5632 int interval
, /* notify-time-interval */
5633 lease
; /* notify-lease-duration */
5634 unsigned mask
; /* notify-events */
5635 ipp_attribute_t
*notify_events
,/* notify-events(-default) */
5636 *notify_lease
; /* notify-lease-duration(-default) */
5640 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
5642 if (attr
->group_tag
!= IPP_TAG_ZERO
)
5643 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "g%04x v%04x %s", attr
->group_tag
,
5644 attr
->value_tag
, attr
->name
);
5646 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "----SEP----");
5651 * Is the destination valid?
5654 cupsdLogMessage(CUPSD_LOG_DEBUG
, "create_subscriptions(con=%p(%d), uri=\"%s\")", con
, con
->number
, uri
->values
[0].string
.text
);
5656 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
5657 sizeof(scheme
), userpass
, sizeof(userpass
), host
,
5658 sizeof(host
), &port
, resource
, sizeof(resource
));
5660 if (!strcmp(resource
, "/"))
5662 dtype
= (cups_ptype_t
)0;
5665 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
5667 dtype
= (cups_ptype_t
)0;
5670 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
5672 dtype
= CUPS_PRINTER_CLASS
;
5675 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
5681 send_ipp_status(con
, IPP_NOT_FOUND
,
5682 _("The printer or class does not exist."));
5692 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
5695 send_http_error(con
, status
, printer
);
5699 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5701 send_http_error(con
, status
, NULL
);
5706 * Get the user that is requesting the subscription...
5709 username
= get_username(con
);
5712 * Find the first subscription group attribute; return if we have
5716 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
5717 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
5722 send_ipp_status(con
, IPP_BAD_REQUEST
,
5723 _("No subscription attributes in request."));
5728 * Process the subscription attributes in the request...
5731 con
->response
->request
.status
.status_code
= IPP_BAD_REQUEST
;
5739 lease
= DefaultLeaseDuration
;
5741 mask
= CUPSD_EVENT_NONE
;
5745 notify_events
= ippFindAttribute(printer
->attrs
, "notify-events-default",
5747 notify_lease
= ippFindAttribute(printer
->attrs
,
5748 "notify-lease-duration-default",
5752 lease
= notify_lease
->values
[0].integer
;
5756 notify_events
= NULL
;
5757 notify_lease
= NULL
;
5760 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
5762 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
5763 attr
->value_tag
== IPP_TAG_URI
)
5766 * Validate the recipient scheme against the ServerBin/notifier
5770 char notifier
[1024]; /* Notifier filename */
5773 recipient
= attr
->values
[0].string
.text
;
5775 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
5776 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
5777 host
, sizeof(host
), &port
,
5778 resource
, sizeof(resource
)) < HTTP_URI_OK
)
5780 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5781 _("Bad notify-recipient-uri \"%s\"."), recipient
);
5782 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5783 "notify-status-code", IPP_URI_SCHEME
);
5787 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
5789 if (access(notifier
, X_OK
))
5791 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5792 _("notify-recipient-uri URI \"%s\" uses unknown "
5793 "scheme."), recipient
);
5794 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5795 "notify-status-code", IPP_URI_SCHEME
);
5799 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
5801 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5802 _("notify-recipient-uri URI \"%s\" is already used."),
5804 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5805 "notify-status-code", IPP_ATTRIBUTES
);
5809 else if (!strcmp(attr
->name
, "notify-pull-method") &&
5810 attr
->value_tag
== IPP_TAG_KEYWORD
)
5812 pullmethod
= attr
->values
[0].string
.text
;
5814 if (strcmp(pullmethod
, "ippget"))
5816 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5817 _("Bad notify-pull-method \"%s\"."), pullmethod
);
5818 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5819 "notify-status-code", IPP_ATTRIBUTES
);
5823 else if (!strcmp(attr
->name
, "notify-charset") &&
5824 attr
->value_tag
== IPP_TAG_CHARSET
&&
5825 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
5826 strcmp(attr
->values
[0].string
.text
, "utf-8"))
5828 send_ipp_status(con
, IPP_CHARSET
,
5829 _("Character set \"%s\" not supported."),
5830 attr
->values
[0].string
.text
);
5833 else if (!strcmp(attr
->name
, "notify-natural-language") &&
5834 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
5835 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
5837 send_ipp_status(con
, IPP_CHARSET
,
5838 _("Language \"%s\" not supported."),
5839 attr
->values
[0].string
.text
);
5842 else if (!strcmp(attr
->name
, "notify-user-data") &&
5843 attr
->value_tag
== IPP_TAG_STRING
)
5845 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
5847 send_ipp_status(con
, IPP_REQUEST_VALUE
,
5848 _("The notify-user-data value is too large "
5849 "(%d > 63 octets)."),
5850 attr
->values
[0].unknown
.length
);
5856 else if (!strcmp(attr
->name
, "notify-events") &&
5857 attr
->value_tag
== IPP_TAG_KEYWORD
)
5858 notify_events
= attr
;
5859 else if (!strcmp(attr
->name
, "notify-lease-duration") &&
5860 attr
->value_tag
== IPP_TAG_INTEGER
)
5861 lease
= attr
->values
[0].integer
;
5862 else if (!strcmp(attr
->name
, "notify-time-interval") &&
5863 attr
->value_tag
== IPP_TAG_INTEGER
)
5864 interval
= attr
->values
[0].integer
;
5865 else if (!strcmp(attr
->name
, "notify-job-id") &&
5866 attr
->value_tag
== IPP_TAG_INTEGER
)
5867 jobid
= attr
->values
[0].integer
;
5874 for (i
= 0; i
< notify_events
->num_values
; i
++)
5875 mask
|= cupsdEventValue(notify_events
->values
[i
].string
.text
);
5879 cupsdLogMessage(CUPSD_LOG_DEBUG
, "recipient=\"%s\"", recipient
);
5881 cupsdLogMessage(CUPSD_LOG_DEBUG
, "pullmethod=\"%s\"", pullmethod
);
5882 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-lease-duration=%d", lease
);
5883 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-time-interval=%d", interval
);
5885 if (!recipient
&& !pullmethod
)
5888 if (mask
== CUPSD_EVENT_NONE
)
5891 mask
= CUPSD_EVENT_JOB_COMPLETED
;
5893 mask
= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
5896 send_ipp_status(con
, IPP_BAD_REQUEST
,
5897 _("notify-events not specified."));
5902 if (MaxLeaseDuration
&& (lease
== 0 || lease
> MaxLeaseDuration
))
5904 cupsdLogMessage(CUPSD_LOG_INFO
,
5905 "create_subscriptions: Limiting notify-lease-duration to "
5908 lease
= MaxLeaseDuration
;
5913 if ((job
= cupsdFindJob(jobid
)) == NULL
)
5915 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
5923 if ((sub
= cupsdAddSubscription(mask
, printer
, job
, recipient
, 0)) == NULL
)
5925 send_ipp_status(con
, IPP_TOO_MANY_SUBSCRIPTIONS
,
5926 _("There are too many subscriptions."));
5931 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription #%d for job %d.",
5934 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5935 "Added subscription #%d for printer \"%s\".",
5936 sub
->id
, printer
->name
);
5938 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription #%d for server.",
5941 sub
->interval
= interval
;
5943 sub
->expire
= lease
? time(NULL
) + lease
: 0;
5945 cupsdSetString(&sub
->owner
, username
);
5949 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
5950 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
5951 (size_t)sub
->user_data_len
);
5954 ippAddSeparator(con
->response
);
5955 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5956 "notify-subscription-id", sub
->id
);
5958 con
->response
->request
.status
.status_code
= IPP_OK
;
5964 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
5969 * 'delete_printer()' - Remove a printer or class from the system.
5973 delete_printer(cupsd_client_t
*con
, /* I - Client connection */
5974 ipp_attribute_t
*uri
) /* I - URI of printer or class */
5976 http_status_t status
; /* Policy status */
5977 cups_ptype_t dtype
; /* Destination type (printer/class) */
5978 cupsd_printer_t
*printer
; /* Printer/class */
5979 char filename
[1024]; /* Script/PPD filename */
5980 int temporary
; /* Temporary queue? */
5983 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "delete_printer(%p[%d], %s)", con
,
5984 con
->number
, uri
->values
[0].string
.text
);
5987 * Do we have a valid URI?
5990 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
5996 send_ipp_status(con
, IPP_NOT_FOUND
,
5997 _("The printer or class does not exist."));
6005 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6007 send_http_error(con
, status
, NULL
);
6012 * Remove old jobs...
6015 cupsdCancelJobs(printer
->name
, NULL
, 1);
6018 * Remove old subscriptions and send a "deleted printer" event...
6021 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED
, printer
, NULL
,
6022 "%s \"%s\" deleted by \"%s\".",
6023 (dtype
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
6024 printer
->name
, get_username(con
));
6026 cupsdExpireSubscriptions(printer
, NULL
);
6029 * Remove any old PPD or script files...
6032 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
6035 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd.O", ServerRoot
,
6039 snprintf(filename
, sizeof(filename
), "%s/%s.png", CacheDir
, printer
->name
);
6042 snprintf(filename
, sizeof(filename
), "%s/%s.data", CacheDir
, printer
->name
);
6046 * Unregister color profiles...
6049 cupsdUnregisterColor(printer
);
6051 temporary
= printer
->temporary
;
6053 if (dtype
& CUPS_PRINTER_CLASS
)
6055 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" deleted by \"%s\".",
6056 printer
->name
, get_username(con
));
6058 cupsdDeletePrinter(printer
, 0);
6060 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
6064 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" deleted by \"%s\".",
6065 printer
->name
, get_username(con
));
6067 if (cupsdDeletePrinter(printer
, 0) && !temporary
)
6068 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
6071 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
6075 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
6078 * Return with no errors...
6081 con
->response
->request
.status
.status_code
= IPP_OK
;
6086 * 'get_default()' - Get the default destination.
6090 get_default(cupsd_client_t
*con
) /* I - Client connection */
6092 http_status_t status
; /* Policy status */
6093 cups_array_t
*ra
; /* Requested attributes array */
6096 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_default(%p[%d])", con
, con
->number
);
6102 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6104 send_http_error(con
, status
, NULL
);
6110 ra
= create_requested_array(con
->request
);
6112 copy_printer_attrs(con
, DefaultPrinter
, ra
);
6114 cupsArrayDelete(ra
);
6116 con
->response
->request
.status
.status_code
= IPP_OK
;
6119 send_ipp_status(con
, IPP_NOT_FOUND
, _("No default printer."));
6124 * 'get_devices()' - Get the list of available devices on the local system.
6128 get_devices(cupsd_client_t
*con
) /* I - Client connection */
6130 http_status_t status
; /* Policy status */
6131 ipp_attribute_t
*limit
, /* limit attribute */
6132 *timeout
, /* timeout attribute */
6133 *requested
, /* requested-attributes attribute */
6134 *exclude
, /* exclude-schemes attribute */
6135 *include
; /* include-schemes attribute */
6136 char command
[1024], /* cups-deviced command */
6137 options
[2048], /* Options to pass to command */
6139 /* String for requested attributes */
6141 /* String for excluded schemes */
6143 /* String for included schemes */
6146 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_devices(%p[%d])", con
, con
->number
);
6152 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6154 send_http_error(con
, status
, NULL
);
6159 * Run cups-deviced command with the given options...
6162 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
6163 timeout
= ippFindAttribute(con
->request
, "timeout", IPP_TAG_INTEGER
);
6164 requested
= ippFindAttribute(con
->request
, "requested-attributes",
6166 exclude
= ippFindAttribute(con
->request
, "exclude-schemes", IPP_TAG_NAME
);
6167 include
= ippFindAttribute(con
->request
, "include-schemes", IPP_TAG_NAME
);
6170 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
6172 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
6175 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
6177 exclude_str
[0] = '\0';
6180 url_encode_attr(include
, include_str
, sizeof(include_str
));
6182 include_str
[0] = '\0';
6184 snprintf(command
, sizeof(command
), "%s/daemon/cups-deviced", ServerBin
);
6185 snprintf(options
, sizeof(options
),
6186 "%d+%d+%d+%d+%s%s%s%s%s",
6187 con
->request
->request
.op
.request_id
,
6188 limit
? limit
->values
[0].integer
: 0,
6189 timeout
? timeout
->values
[0].integer
: 15,
6192 exclude_str
[0] ? "%20" : "", exclude_str
,
6193 include_str
[0] ? "%20" : "", include_str
);
6195 if (cupsdSendCommand(con
, command
, options
, 1))
6198 * Command started successfully, don't send an IPP response here...
6201 ippDelete(con
->response
);
6202 con
->response
= NULL
;
6207 * Command failed, return "internal error" so the user knows something
6211 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
6212 _("cups-deviced failed to execute."));
6218 * 'get_document()' - Get a copy of a job file.
6222 get_document(cupsd_client_t
*con
, /* I - Client connection */
6223 ipp_attribute_t
*uri
) /* I - Job URI */
6225 http_status_t status
; /* Policy status */
6226 ipp_attribute_t
*attr
; /* Current attribute */
6227 int jobid
; /* Job ID */
6228 int docnum
; /* Document number */
6229 cupsd_job_t
*job
; /* Current job */
6230 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
6231 username
[HTTP_MAX_URI
], /* Username portion of URI */
6232 host
[HTTP_MAX_URI
], /* Host portion of URI */
6233 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6234 int port
; /* Port portion of URI */
6235 char filename
[1024], /* Filename for document */
6236 format
[1024]; /* Format for document */
6239 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_document(%p[%d], %s)", con
,
6240 con
->number
, uri
->values
[0].string
.text
);
6243 * See if we have a job URI or a printer URI...
6246 if (!strcmp(uri
->name
, "printer-uri"))
6249 * Got a printer URI; see if we also have a job-id attribute...
6252 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6253 IPP_TAG_INTEGER
)) == NULL
)
6255 send_ipp_status(con
, IPP_BAD_REQUEST
,
6256 _("Got a printer-uri attribute but no job-id."));
6260 jobid
= attr
->values
[0].integer
;
6265 * Got a job URI; parse it to get the job ID...
6268 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6269 sizeof(scheme
), username
, sizeof(username
), host
,
6270 sizeof(host
), &port
, resource
, sizeof(resource
));
6272 if (strncmp(resource
, "/jobs/", 6))
6278 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
6279 uri
->values
[0].string
.text
);
6283 jobid
= atoi(resource
+ 6);
6287 * See if the job exists...
6290 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6293 * Nope - return a "not found" error...
6296 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
6304 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
,
6305 job
->username
)) != HTTP_OK
)
6307 send_http_error(con
, status
, NULL
);
6312 * Get the document number...
6315 if ((attr
= ippFindAttribute(con
->request
, "document-number",
6316 IPP_TAG_INTEGER
)) == NULL
)
6318 send_ipp_status(con
, IPP_BAD_REQUEST
,
6319 _("Missing document-number attribute."));
6323 if ((docnum
= attr
->values
[0].integer
) < 1 || docnum
> job
->num_files
||
6324 attr
->num_values
> 1)
6326 send_ipp_status(con
, IPP_NOT_FOUND
,
6327 _("Document #%d does not exist in job #%d."), docnum
,
6332 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, jobid
,
6334 if ((con
->file
= open(filename
, O_RDONLY
)) == -1)
6336 cupsdLogMessage(CUPSD_LOG_ERROR
,
6337 "Unable to open document %d in job %d - %s", docnum
, jobid
,
6339 send_ipp_status(con
, IPP_NOT_FOUND
,
6340 _("Unable to open document #%d in job #%d."), docnum
,
6345 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
6349 snprintf(format
, sizeof(format
), "%s/%s", job
->filetypes
[docnum
- 1]->super
,
6350 job
->filetypes
[docnum
- 1]->type
);
6352 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format",
6354 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "document-number",
6356 if ((attr
= ippFindAttribute(job
->attrs
, "document-name",
6357 IPP_TAG_NAME
)) != NULL
)
6358 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name",
6359 NULL
, attr
->values
[0].string
.text
);
6364 * 'get_job_attrs()' - Get job attributes.
6368 get_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
6369 ipp_attribute_t
*uri
) /* I - Job URI */
6371 http_status_t status
; /* Policy status */
6372 ipp_attribute_t
*attr
; /* Current attribute */
6373 int jobid
; /* Job ID */
6374 cupsd_job_t
*job
; /* Current job */
6375 cupsd_printer_t
*printer
; /* Current printer */
6376 cupsd_policy_t
*policy
; /* Current security policy */
6377 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6378 username
[HTTP_MAX_URI
], /* Username portion of URI */
6379 host
[HTTP_MAX_URI
], /* Host portion of URI */
6380 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6381 int port
; /* Port portion of URI */
6382 cups_array_t
*ra
, /* Requested attributes array */
6383 *exclude
; /* Private attributes array */
6386 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_job_attrs(%p[%d], %s)", con
,
6387 con
->number
, uri
->values
[0].string
.text
);
6390 * See if we have a job URI or a printer URI...
6393 if (!strcmp(uri
->name
, "printer-uri"))
6396 * Got a printer URI; see if we also have a job-id attribute...
6399 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6400 IPP_TAG_INTEGER
)) == NULL
)
6402 send_ipp_status(con
, IPP_BAD_REQUEST
,
6403 _("Got a printer-uri attribute but no job-id."));
6407 jobid
= attr
->values
[0].integer
;
6412 * Got a job URI; parse it to get the job ID...
6415 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6416 sizeof(scheme
), username
, sizeof(username
), host
,
6417 sizeof(host
), &port
, resource
, sizeof(resource
));
6419 if (strncmp(resource
, "/jobs/", 6))
6425 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
6426 uri
->values
[0].string
.text
);
6430 jobid
= atoi(resource
+ 6);
6434 * See if the job exists...
6437 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6440 * Nope - return a "not found" error...
6443 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
6451 if ((printer
= job
->printer
) == NULL
)
6452 printer
= cupsdFindDest(job
->dest
);
6455 policy
= printer
->op_policy_ptr
;
6457 policy
= DefaultPolicyPtr
;
6459 if ((status
= cupsdCheckPolicy(policy
, con
, job
->username
)) != HTTP_OK
)
6461 send_http_error(con
, status
, NULL
);
6465 exclude
= cupsdGetPrivateAttrs(policy
, con
, printer
, job
->username
);
6468 * Copy attributes...
6473 ra
= create_requested_array(con
->request
);
6474 copy_job_attrs(con
, job
, ra
, exclude
);
6475 cupsArrayDelete(ra
);
6477 con
->response
->request
.status
.status_code
= IPP_OK
;
6482 * 'get_jobs()' - Get a list of jobs for the specified printer.
6486 get_jobs(cupsd_client_t
*con
, /* I - Client connection */
6487 ipp_attribute_t
*uri
) /* I - Printer URI */
6489 http_status_t status
; /* Policy status */
6490 ipp_attribute_t
*attr
; /* Current attribute */
6491 const char *dest
; /* Destination */
6492 cups_ptype_t dtype
; /* Destination type (printer/class) */
6493 cups_ptype_t dmask
; /* Destination type mask */
6494 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6495 username
[HTTP_MAX_URI
], /* Username portion of URI */
6496 host
[HTTP_MAX_URI
], /* Host portion of URI */
6497 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6498 int port
; /* Port portion of URI */
6499 int job_comparison
; /* Job comparison */
6500 ipp_jstate_t job_state
; /* job-state value */
6501 int first_job_id
= 1, /* First job ID */
6502 first_index
= 1, /* First index */
6503 limit
= 0, /* Maximum number of jobs to return */
6504 count
, /* Number of jobs that match */
6505 need_load_job
= 0; /* Do we need to load the job? */
6506 const char *job_attr
; /* Job attribute requested */
6507 ipp_attribute_t
*job_ids
; /* job-ids attribute */
6508 cupsd_job_t
*job
; /* Current job pointer */
6509 cupsd_printer_t
*printer
; /* Printer */
6510 cups_array_t
*list
; /* Which job list... */
6511 int delete_list
= 0; /* Delete the list afterwards? */
6512 cups_array_t
*ra
, /* Requested attributes array */
6513 *exclude
; /* Private attributes array */
6514 cupsd_policy_t
*policy
; /* Current policy */
6517 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs(%p[%d], %s)", con
, con
->number
,
6518 uri
->values
[0].string
.text
);
6521 * Is the destination valid?
6524 if (strcmp(uri
->name
, "printer-uri"))
6526 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No printer-uri in request."));
6530 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6531 sizeof(scheme
), username
, sizeof(username
), host
,
6532 sizeof(host
), &port
, resource
, sizeof(resource
));
6534 if (!strcmp(resource
, "/") || !strcmp(resource
, "/jobs"))
6537 dtype
= (cups_ptype_t
)0;
6538 dmask
= (cups_ptype_t
)0;
6541 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6544 dtype
= (cups_ptype_t
)0;
6545 dmask
= CUPS_PRINTER_CLASS
;
6548 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6551 dtype
= CUPS_PRINTER_CLASS
;
6552 dmask
= CUPS_PRINTER_CLASS
;
6555 else if ((dest
= cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
,
6562 send_ipp_status(con
, IPP_NOT_FOUND
,
6563 _("The printer or class does not exist."));
6568 dtype
&= CUPS_PRINTER_CLASS
;
6569 dmask
= CUPS_PRINTER_CLASS
;
6577 policy
= printer
->op_policy_ptr
;
6579 policy
= DefaultPolicyPtr
;
6581 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
6583 send_http_error(con
, status
, NULL
);
6587 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
6590 * See if the "which-jobs" attribute have been specified...
6593 if ((attr
= ippFindAttribute(con
->request
, "which-jobs",
6594 IPP_TAG_KEYWORD
)) != NULL
&& job_ids
)
6596 send_ipp_status(con
, IPP_CONFLICT
,
6597 _("The %s attribute cannot be provided with job-ids."),
6601 else if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "not-completed"))
6603 job_comparison
= -1;
6604 job_state
= IPP_JOB_STOPPED
;
6607 else if (!strcmp(attr
->values
[0].string
.text
, "completed"))
6610 job_state
= IPP_JOB_CANCELED
;
6611 list
= cupsdGetCompletedJobs(printer
);
6614 else if (!strcmp(attr
->values
[0].string
.text
, "aborted"))
6617 job_state
= IPP_JOB_ABORTED
;
6618 list
= cupsdGetCompletedJobs(printer
);
6621 else if (!strcmp(attr
->values
[0].string
.text
, "all"))
6624 job_state
= IPP_JOB_PENDING
;
6627 else if (!strcmp(attr
->values
[0].string
.text
, "canceled"))
6630 job_state
= IPP_JOB_CANCELED
;
6631 list
= cupsdGetCompletedJobs(printer
);
6634 else if (!strcmp(attr
->values
[0].string
.text
, "pending"))
6637 job_state
= IPP_JOB_PENDING
;
6640 else if (!strcmp(attr
->values
[0].string
.text
, "pending-held"))
6643 job_state
= IPP_JOB_HELD
;
6646 else if (!strcmp(attr
->values
[0].string
.text
, "processing"))
6649 job_state
= IPP_JOB_PROCESSING
;
6650 list
= PrintingJobs
;
6652 else if (!strcmp(attr
->values
[0].string
.text
, "processing-stopped"))
6655 job_state
= IPP_JOB_STOPPED
;
6660 send_ipp_status(con
, IPP_ATTRIBUTES
,
6661 _("The which-jobs value \"%s\" is not supported."),
6662 attr
->values
[0].string
.text
);
6663 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
6664 "which-jobs", NULL
, attr
->values
[0].string
.text
);
6669 * See if they want to limit the number of jobs reported...
6672 if ((attr
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
)) != NULL
)
6676 send_ipp_status(con
, IPP_CONFLICT
,
6677 _("The %s attribute cannot be provided with job-ids."),
6682 limit
= attr
->values
[0].integer
;
6685 if ((attr
= ippFindAttribute(con
->request
, "first-index", IPP_TAG_INTEGER
)) != NULL
)
6689 send_ipp_status(con
, IPP_CONFLICT
,
6690 _("The %s attribute cannot be provided with job-ids."),
6695 first_index
= attr
->values
[0].integer
;
6697 else if ((attr
= ippFindAttribute(con
->request
, "first-job-id", IPP_TAG_INTEGER
)) != NULL
)
6701 send_ipp_status(con
, IPP_CONFLICT
,
6702 _("The %s attribute cannot be provided with job-ids."),
6707 first_job_id
= attr
->values
[0].integer
;
6711 * See if we only want to see jobs for a specific user...
6714 if ((attr
= ippFindAttribute(con
->request
, "my-jobs", IPP_TAG_BOOLEAN
)) != NULL
&& job_ids
)
6716 send_ipp_status(con
, IPP_CONFLICT
,
6717 _("The %s attribute cannot be provided with job-ids."),
6721 else if (attr
&& attr
->values
[0].boolean
)
6722 strlcpy(username
, get_username(con
), sizeof(username
));
6726 ra
= create_requested_array(con
->request
);
6727 for (job_attr
= (char *)cupsArrayFirst(ra
); job_attr
; job_attr
= (char *)cupsArrayNext(ra
))
6728 if (strcmp(job_attr
, "job-id") &&
6729 strcmp(job_attr
, "job-k-octets") &&
6730 strcmp(job_attr
, "job-media-progress") &&
6731 strcmp(job_attr
, "job-more-info") &&
6732 strcmp(job_attr
, "job-name") &&
6733 strcmp(job_attr
, "job-originating-user-name") &&
6734 strcmp(job_attr
, "job-preserved") &&
6735 strcmp(job_attr
, "job-printer-up-time") &&
6736 strcmp(job_attr
, "job-printer-uri") &&
6737 strcmp(job_attr
, "job-state") &&
6738 strcmp(job_attr
, "job-state-reasons") &&
6739 strcmp(job_attr
, "job-uri") &&
6740 strcmp(job_attr
, "time-at-completed") &&
6741 strcmp(job_attr
, "time-at-creation") &&
6742 strcmp(job_attr
, "number-of-documents"))
6748 if (need_load_job
&& (limit
== 0 || limit
> 500) && (list
== Jobs
|| delete_list
))
6751 * Limit expensive Get-Jobs for job history to 500 jobs...
6754 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
, "limit", 500);
6757 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
, "limit", limit
);
6761 cupsdLogClient(con
, CUPSD_LOG_INFO
, "Limiting Get-Jobs response to %d jobs.", limit
);
6765 * OK, build a list of jobs for this printer...
6770 int i
; /* Looping var */
6772 for (i
= 0; i
< job_ids
->num_values
; i
++)
6774 if (!cupsdFindJob(job_ids
->values
[i
].integer
))
6778 if (i
< job_ids
->num_values
)
6780 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
6781 job_ids
->values
[i
].integer
);
6785 for (i
= 0; i
< job_ids
->num_values
; i
++)
6787 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
6789 if (need_load_job
&& !job
->attrs
)
6795 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d", job
->id
);
6801 ippAddSeparator(con
->response
);
6803 exclude
= cupsdGetPrivateAttrs(job
->printer
?
6804 job
->printer
->op_policy_ptr
:
6805 policy
, con
, job
->printer
,
6808 copy_job_attrs(con
, job
, ra
, exclude
);
6813 if (first_index
> 1)
6814 job
= (cupsd_job_t
*)cupsArrayIndex(list
, first_index
- 1);
6816 job
= (cupsd_job_t
*)cupsArrayFirst(list
);
6818 for (count
= 0; (limit
<= 0 || count
< limit
) && job
; job
= (cupsd_job_t
*)cupsArrayNext(list
))
6821 * Filter out jobs that don't match...
6824 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
6825 "get_jobs: job->id=%d, dest=\"%s\", username=\"%s\", "
6826 "state_value=%d, attrs=%p", job
->id
, job
->dest
,
6827 job
->username
, job
->state_value
, job
->attrs
);
6829 if (!job
->dest
|| !job
->username
)
6832 if (!job
->dest
|| !job
->username
)
6835 if ((dest
&& strcmp(job
->dest
, dest
)) &&
6836 (!job
->printer
|| !dest
|| strcmp(job
->printer
->name
, dest
)))
6838 if ((job
->dtype
& dmask
) != dtype
&&
6839 (!job
->printer
|| (job
->printer
->type
& dmask
) != dtype
))
6842 if ((job_comparison
< 0 && job
->state_value
> job_state
) ||
6843 (job_comparison
== 0 && job
->state_value
!= job_state
) ||
6844 (job_comparison
> 0 && job
->state_value
< job_state
))
6847 if (job
->id
< first_job_id
)
6850 if (need_load_job
&& !job
->attrs
)
6856 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d", job
->id
);
6861 if (username
[0] && _cups_strcasecmp(username
, job
->username
))
6865 ippAddSeparator(con
->response
);
6869 exclude
= cupsdGetPrivateAttrs(job
->printer
?
6870 job
->printer
->op_policy_ptr
:
6871 policy
, con
, job
->printer
,
6874 copy_job_attrs(con
, job
, ra
, exclude
);
6877 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: count=%d", count
);
6880 cupsArrayDelete(ra
);
6883 cupsArrayDelete(list
);
6885 con
->response
->request
.status
.status_code
= IPP_OK
;
6890 * 'get_notifications()' - Get events for a subscription.
6894 get_notifications(cupsd_client_t
*con
) /* I - Client connection */
6896 int i
, j
; /* Looping vars */
6897 http_status_t status
; /* Policy status */
6898 cupsd_subscription_t
*sub
; /* Subscription */
6899 ipp_attribute_t
*ids
, /* notify-subscription-ids */
6900 *sequences
; /* notify-sequence-numbers */
6901 int min_seq
; /* Minimum sequence number */
6902 int interval
; /* Poll interval */
6905 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_notifications(con=%p[%d])",
6909 * Get subscription attributes...
6912 ids
= ippFindAttribute(con
->request
, "notify-subscription-ids",
6914 sequences
= ippFindAttribute(con
->request
, "notify-sequence-numbers",
6919 send_ipp_status(con
, IPP_BAD_REQUEST
,
6920 _("Missing notify-subscription-ids attribute."));
6925 * Are the subscription IDs valid?
6928 for (i
= 0, interval
= 60; i
< ids
->num_values
; i
++)
6930 if ((sub
= cupsdFindSubscription(ids
->values
[i
].integer
)) == NULL
)
6933 * Bad subscription ID...
6936 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
6937 ids
->values
[i
].integer
);
6945 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
6947 con
, sub
->owner
)) != HTTP_OK
)
6949 send_http_error(con
, status
, sub
->dest
);
6954 * Check the subscription type and update the interval accordingly.
6957 if (sub
->job
&& sub
->job
->state_value
== IPP_JOB_PROCESSING
&&
6960 else if (sub
->job
&& sub
->job
->state_value
>= IPP_JOB_STOPPED
)
6962 else if (sub
->dest
&& sub
->dest
->state
== IPP_PRINTER_PROCESSING
&&
6968 * Tell the client to poll again in N seconds...
6972 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
6973 "notify-get-interval", interval
);
6975 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
6976 "printer-up-time", time(NULL
));
6979 * Copy the subscription event attributes to the response.
6982 con
->response
->request
.status
.status_code
=
6983 interval
? IPP_OK
: IPP_OK_EVENTS_COMPLETE
;
6985 for (i
= 0; i
< ids
->num_values
; i
++)
6988 * Get the subscription and sequence number...
6991 sub
= cupsdFindSubscription(ids
->values
[i
].integer
);
6993 if (sequences
&& i
< sequences
->num_values
)
6994 min_seq
= sequences
->values
[i
].integer
;
6999 * If we don't have any new events, nothing to do here...
7002 if (min_seq
> (sub
->first_event_id
+ cupsArrayCount(sub
->events
)))
7006 * Otherwise copy all of the new events...
7009 if (sub
->first_event_id
> min_seq
)
7012 j
= min_seq
- sub
->first_event_id
;
7014 for (; j
< cupsArrayCount(sub
->events
); j
++)
7016 ippAddSeparator(con
->response
);
7018 copy_attrs(con
->response
,
7019 ((cupsd_event_t
*)cupsArrayIndex(sub
->events
, j
))->attrs
, NULL
,
7020 IPP_TAG_EVENT_NOTIFICATION
, 0, NULL
);
7027 * 'get_ppd()' - Get a named PPD from the local system.
7031 get_ppd(cupsd_client_t
*con
, /* I - Client connection */
7032 ipp_attribute_t
*uri
) /* I - Printer URI or PPD name */
7034 http_status_t status
; /* Policy status */
7035 cupsd_printer_t
*dest
; /* Destination */
7036 cups_ptype_t dtype
; /* Destination type */
7039 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppd(%p[%d], %p[%s=%s])", con
,
7040 con
->number
, uri
, uri
->name
, uri
->values
[0].string
.text
);
7042 if (!strcmp(ippGetName(uri
), "ppd-name"))
7045 * Return a PPD file from cups-driverd...
7048 const char *ppd_name
= ippGetString(uri
, 0, NULL
);
7049 /* ppd-name value */
7050 char command
[1024], /* cups-driverd command */
7051 options
[1024], /* Options to pass to command */
7052 oppd_name
[1024]; /* Escaped ppd-name */
7058 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7060 send_http_error(con
, status
, NULL
);
7065 * Check ppd-name value...
7068 if (strstr(ppd_name
, "../"))
7070 send_ipp_status(con
, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES
, _("Invalid ppd-name value."));
7075 * Run cups-driverd command with the given options...
7078 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7079 url_encode_string(ppd_name
, oppd_name
, sizeof(oppd_name
));
7080 snprintf(options
, sizeof(options
), "get+%d+%s", ippGetRequestId(con
->request
), oppd_name
);
7082 if (cupsdSendCommand(con
, command
, options
, 0))
7085 * Command started successfully, don't send an IPP response here...
7088 ippDelete(con
->response
);
7089 con
->response
= NULL
;
7094 * Command failed, return "internal error" so the user knows something
7098 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("cups-driverd failed to execute."));
7101 else if (!strcmp(ippGetName(uri
), "printer-uri") && cupsdValidateDest(ippGetString(uri
, 0, NULL
), &dtype
, &dest
))
7103 int i
; /* Looping var */
7104 char filename
[1024]; /* PPD filename */
7110 if ((status
= cupsdCheckPolicy(dest
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7112 send_http_error(con
, status
, dest
);
7117 * See if we need the PPD for a class or remote printer...
7120 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
, dest
->name
);
7122 if ((dtype
& CUPS_PRINTER_REMOTE
) && access(filename
, 0))
7124 send_ipp_status(con
, IPP_STATUS_CUPS_SEE_OTHER
, _("See remote printer."));
7125 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
, dest
->uri
);
7128 else if (dtype
& CUPS_PRINTER_CLASS
)
7130 for (i
= 0; i
< dest
->num_printers
; i
++)
7131 if (!(dest
->printers
[i
]->type
& CUPS_PRINTER_CLASS
))
7133 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
, dest
->printers
[i
]->name
);
7135 if (!access(filename
, 0))
7139 if (i
< dest
->num_printers
)
7140 dest
= dest
->printers
[i
];
7143 send_ipp_status(con
, IPP_STATUS_CUPS_SEE_OTHER
, _("See remote printer."));
7144 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
, dest
->printers
[0]->uri
);
7150 * Found the printer with the PPD file, now see if there is one...
7153 if ((con
->file
= open(filename
, O_RDONLY
)) < 0)
7155 send_ipp_status(con
, IPP_STATUS_ERROR_NOT_FOUND
, _("The PPD file \"%s\" could not be opened: %s"), ippGetString(uri
, 0, NULL
), strerror(errno
));
7159 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
7163 ippSetStatusCode(con
->response
, IPP_STATUS_OK
);
7166 send_ipp_status(con
, IPP_STATUS_ERROR_NOT_FOUND
, _("The PPD file \"%s\" could not be found."), ippGetString(uri
, 0, NULL
));
7171 * 'get_ppds()' - Get the list of PPD files on the local system.
7175 get_ppds(cupsd_client_t
*con
) /* I - Client connection */
7177 http_status_t status
; /* Policy status */
7178 ipp_attribute_t
*limit
, /* Limit attribute */
7179 *device
, /* ppd-device-id attribute */
7180 *language
, /* ppd-natural-language attribute */
7181 *make
, /* ppd-make attribute */
7182 *model
, /* ppd-make-and-model attribute */
7183 *model_number
, /* ppd-model-number attribute */
7184 *product
, /* ppd-product attribute */
7185 *psversion
, /* ppd-psverion attribute */
7186 *type
, /* ppd-type attribute */
7187 *requested
, /* requested-attributes attribute */
7188 *exclude
, /* exclude-schemes attribute */
7189 *include
; /* include-schemes attribute */
7190 char command
[1024], /* cups-driverd command */
7191 options
[4096], /* Options to pass to command */
7192 device_str
[256],/* Escaped ppd-device-id string */
7194 /* Escaped ppd-natural-language */
7195 make_str
[256], /* Escaped ppd-make string */
7196 model_str
[256], /* Escaped ppd-make-and-model string */
7197 model_number_str
[256],
7198 /* ppd-model-number string */
7200 /* Escaped ppd-product string */
7202 /* Escaped ppd-psversion string */
7203 type_str
[256], /* Escaped ppd-type string */
7205 /* String for requested attributes */
7207 /* String for excluded schemes */
7209 /* String for included schemes */
7212 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppds(%p[%d])", con
, con
->number
);
7218 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7220 send_http_error(con
, status
, NULL
);
7225 * Run cups-driverd command with the given options...
7228 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
7229 device
= ippFindAttribute(con
->request
, "ppd-device-id", IPP_TAG_TEXT
);
7230 language
= ippFindAttribute(con
->request
, "ppd-natural-language",
7232 make
= ippFindAttribute(con
->request
, "ppd-make", IPP_TAG_TEXT
);
7233 model
= ippFindAttribute(con
->request
, "ppd-make-and-model",
7235 model_number
= ippFindAttribute(con
->request
, "ppd-model-number",
7237 product
= ippFindAttribute(con
->request
, "ppd-product", IPP_TAG_TEXT
);
7238 psversion
= ippFindAttribute(con
->request
, "ppd-psversion", IPP_TAG_TEXT
);
7239 type
= ippFindAttribute(con
->request
, "ppd-type", IPP_TAG_KEYWORD
);
7240 requested
= ippFindAttribute(con
->request
, "requested-attributes",
7242 exclude
= ippFindAttribute(con
->request
, "exclude-schemes",
7244 include
= ippFindAttribute(con
->request
, "include-schemes",
7248 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
7250 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
7253 url_encode_attr(device
, device_str
, sizeof(device_str
));
7255 device_str
[0] = '\0';
7258 url_encode_attr(language
, language_str
, sizeof(language_str
));
7260 language_str
[0] = '\0';
7263 url_encode_attr(make
, make_str
, sizeof(make_str
));
7268 url_encode_attr(model
, model_str
, sizeof(model_str
));
7270 model_str
[0] = '\0';
7273 snprintf(model_number_str
, sizeof(model_number_str
), "ppd-model-number=%d",
7274 model_number
->values
[0].integer
);
7276 model_number_str
[0] = '\0';
7279 url_encode_attr(product
, product_str
, sizeof(product_str
));
7281 product_str
[0] = '\0';
7284 url_encode_attr(psversion
, psversion_str
, sizeof(psversion_str
));
7286 psversion_str
[0] = '\0';
7289 url_encode_attr(type
, type_str
, sizeof(type_str
));
7294 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
7296 exclude_str
[0] = '\0';
7299 url_encode_attr(include
, include_str
, sizeof(include_str
));
7301 include_str
[0] = '\0';
7303 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7304 snprintf(options
, sizeof(options
),
7305 "list+%d+%d+%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
7306 con
->request
->request
.op
.request_id
,
7307 limit
? limit
->values
[0].integer
: 0,
7309 device
? "%20" : "", device_str
,
7310 language
? "%20" : "", language_str
,
7311 make
? "%20" : "", make_str
,
7312 model
? "%20" : "", model_str
,
7313 model_number
? "%20" : "", model_number_str
,
7314 product
? "%20" : "", product_str
,
7315 psversion
? "%20" : "", psversion_str
,
7316 type
? "%20" : "", type_str
,
7317 exclude_str
[0] ? "%20" : "", exclude_str
,
7318 include_str
[0] ? "%20" : "", include_str
);
7320 if (cupsdSendCommand(con
, command
, options
, 0))
7323 * Command started successfully, don't send an IPP response here...
7326 ippDelete(con
->response
);
7327 con
->response
= NULL
;
7332 * Command failed, return "internal error" so the user knows something
7336 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7337 _("cups-driverd failed to execute."));
7343 * 'get_printer_attrs()' - Get printer attributes.
7347 get_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
7348 ipp_attribute_t
*uri
) /* I - Printer URI */
7350 http_status_t status
; /* Policy status */
7351 cups_ptype_t dtype
; /* Destination type (printer/class) */
7352 cupsd_printer_t
*printer
; /* Printer/class */
7353 cups_array_t
*ra
; /* Requested attributes array */
7356 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_attrs(%p[%d], %s)", con
,
7357 con
->number
, uri
->values
[0].string
.text
);
7360 * Is the destination valid?
7363 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7369 send_ipp_status(con
, IPP_NOT_FOUND
,
7370 _("The printer or class does not exist."));
7378 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7380 send_http_error(con
, status
, printer
);
7385 * Send the attributes...
7388 ra
= create_requested_array(con
->request
);
7390 copy_printer_attrs(con
, printer
, ra
);
7392 cupsArrayDelete(ra
);
7394 con
->response
->request
.status
.status_code
= IPP_OK
;
7399 * 'get_printer_supported()' - Get printer supported values.
7403 get_printer_supported(
7404 cupsd_client_t
*con
, /* I - Client connection */
7405 ipp_attribute_t
*uri
) /* I - Printer URI */
7407 http_status_t status
; /* Policy status */
7408 cups_ptype_t dtype
; /* Destination type (printer/class) */
7409 cupsd_printer_t
*printer
; /* Printer/class */
7412 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_supported(%p[%d], %s)", con
,
7413 con
->number
, uri
->values
[0].string
.text
);
7416 * Is the destination valid?
7419 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7425 send_ipp_status(con
, IPP_NOT_FOUND
,
7426 _("The printer or class does not exist."));
7434 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7436 send_http_error(con
, status
, printer
);
7441 * Return a list of attributes that can be set via Set-Printer-Attributes.
7444 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7445 "printer-geo-location", 0);
7446 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7448 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7449 "printer-location", 0);
7450 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7451 "printer-organization", 0);
7452 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7453 "printer-organizational-unit", 0);
7455 con
->response
->request
.status
.status_code
= IPP_OK
;
7460 * 'get_printers()' - Get a list of printers or classes.
7464 get_printers(cupsd_client_t
*con
, /* I - Client connection */
7465 int type
) /* I - 0 or CUPS_PRINTER_CLASS */
7467 http_status_t status
; /* Policy status */
7468 ipp_attribute_t
*attr
; /* Current attribute */
7469 int limit
; /* Max number of printers to return */
7470 int count
; /* Number of printers that match */
7471 int printer_id
; /* Printer we are interested in */
7472 cupsd_printer_t
*printer
; /* Current printer pointer */
7473 cups_ptype_t printer_type
, /* printer-type attribute */
7474 printer_mask
; /* printer-type-mask attribute */
7475 char *location
; /* Location string */
7476 const char *username
; /* Current user */
7477 char *first_printer_name
; /* first-printer-name attribute */
7478 cups_array_t
*ra
; /* Requested attributes array */
7479 int local
; /* Local connection? */
7482 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printers(%p[%d], %x)", con
,
7489 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7491 send_http_error(con
, status
, NULL
);
7496 * Check for printers...
7499 if (!Printers
|| !cupsArrayCount(Printers
))
7501 send_ipp_status(con
, IPP_NOT_FOUND
, _("No destinations added."));
7506 * See if they want to limit the number of printers reported...
7509 if ((attr
= ippFindAttribute(con
->request
, "limit",
7510 IPP_TAG_INTEGER
)) != NULL
)
7511 limit
= attr
->values
[0].integer
;
7515 if ((attr
= ippFindAttribute(con
->request
, "first-printer-name",
7516 IPP_TAG_NAME
)) != NULL
)
7517 first_printer_name
= attr
->values
[0].string
.text
;
7519 first_printer_name
= NULL
;
7522 * Support filtering...
7525 if ((attr
= ippFindAttribute(con
->request
, "printer-id", IPP_TAG_INTEGER
)) != NULL
)
7527 if ((printer_id
= ippGetInteger(attr
, 0)) <= 0)
7529 send_ipp_status(con
, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES
, _("Bad \"printer-id\" value %d."), printer_id
);
7536 if ((attr
= ippFindAttribute(con
->request
, "printer-type",
7537 IPP_TAG_ENUM
)) != NULL
)
7538 printer_type
= (cups_ptype_t
)attr
->values
[0].integer
;
7540 printer_type
= (cups_ptype_t
)0;
7542 if ((attr
= ippFindAttribute(con
->request
, "printer-type-mask",
7543 IPP_TAG_ENUM
)) != NULL
)
7544 printer_mask
= (cups_ptype_t
)attr
->values
[0].integer
;
7546 printer_mask
= (cups_ptype_t
)0;
7548 local
= httpAddrLocalhost(&(con
->clientaddr
));
7550 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
7551 IPP_TAG_TEXT
)) != NULL
)
7552 location
= attr
->values
[0].string
.text
;
7556 if (con
->username
[0])
7557 username
= con
->username
;
7558 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7559 IPP_TAG_NAME
)) != NULL
)
7560 username
= attr
->values
[0].string
.text
;
7564 ra
= create_requested_array(con
->request
);
7567 * OK, build a list of printers for this printer...
7570 if (first_printer_name
)
7572 if ((printer
= cupsdFindDest(first_printer_name
)) == NULL
)
7573 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7576 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7579 count
< limit
&& printer
;
7580 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
7582 if (!local
&& !printer
->shared
)
7585 if (printer_id
&& printer
->printer_id
!= printer_id
)
7588 if ((!type
|| (printer
->type
& CUPS_PRINTER_CLASS
) == type
) &&
7589 (printer
->type
& printer_mask
) == printer_type
&&
7591 (printer
->location
&& !_cups_strcasecmp(printer
->location
, location
))))
7594 * If a username is specified, see if it is allowed or denied
7598 if (cupsArrayCount(printer
->users
) && username
&&
7599 !user_allowed(printer
, username
))
7603 * Add the group separator as needed...
7607 ippAddSeparator(con
->response
);
7612 * Send the attributes...
7615 copy_printer_attrs(con
, printer
, ra
);
7619 cupsArrayDelete(ra
);
7621 con
->response
->request
.status
.status_code
= IPP_OK
;
7626 * 'get_subscription_attrs()' - Get subscription attributes.
7630 get_subscription_attrs(
7631 cupsd_client_t
*con
, /* I - Client connection */
7632 int sub_id
) /* I - Subscription ID */
7634 http_status_t status
; /* Policy status */
7635 cupsd_subscription_t
*sub
; /* Subscription */
7636 cupsd_policy_t
*policy
; /* Current security policy */
7637 cups_array_t
*ra
, /* Requested attributes array */
7638 *exclude
; /* Private attributes array */
7641 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7642 "get_subscription_attrs(con=%p[%d], sub_id=%d)",
7643 con
, con
->number
, sub_id
);
7646 * Expire subscriptions as needed...
7649 cupsdExpireSubscriptions(NULL
, NULL
);
7652 * Is the subscription ID valid?
7655 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
7658 * Bad subscription ID...
7661 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
7671 policy
= sub
->dest
->op_policy_ptr
;
7673 policy
= DefaultPolicyPtr
;
7675 if ((status
= cupsdCheckPolicy(policy
, con
, sub
->owner
)) != HTTP_OK
)
7677 send_http_error(con
, status
, sub
->dest
);
7681 exclude
= cupsdGetPrivateAttrs(policy
, con
, sub
->dest
, sub
->owner
);
7684 * Copy the subscription attributes to the response using the
7685 * requested-attributes attribute that may be provided by the client.
7688 ra
= create_requested_array(con
->request
);
7690 copy_subscription_attrs(con
, sub
, ra
, exclude
);
7692 cupsArrayDelete(ra
);
7694 con
->response
->request
.status
.status_code
= IPP_OK
;
7699 * 'get_subscriptions()' - Get subscriptions.
7703 get_subscriptions(cupsd_client_t
*con
, /* I - Client connection */
7704 ipp_attribute_t
*uri
) /* I - Printer/job URI */
7706 http_status_t status
; /* Policy status */
7707 int count
; /* Number of subscriptions */
7708 int limit
; /* Limit */
7709 cupsd_subscription_t
*sub
; /* Subscription */
7710 cups_array_t
*ra
; /* Requested attributes array */
7711 ipp_attribute_t
*attr
; /* Attribute */
7712 cups_ptype_t dtype
; /* Destination type (printer/class) */
7713 char scheme
[HTTP_MAX_URI
],
7714 /* Scheme portion of URI */
7715 username
[HTTP_MAX_URI
],
7716 /* Username portion of URI */
7718 /* Host portion of URI */
7719 resource
[HTTP_MAX_URI
];
7720 /* Resource portion of URI */
7721 int port
; /* Port portion of URI */
7722 cupsd_job_t
*job
; /* Job pointer */
7723 cupsd_printer_t
*printer
; /* Printer */
7724 cupsd_policy_t
*policy
; /* Policy */
7725 cups_array_t
*exclude
; /* Private attributes array */
7728 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7729 "get_subscriptions(con=%p[%d], uri=%s)",
7730 con
, con
->number
, uri
->values
[0].string
.text
);
7733 * Is the destination valid?
7736 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7737 sizeof(scheme
), username
, sizeof(username
), host
,
7738 sizeof(host
), &port
, resource
, sizeof(resource
));
7740 if (!strcmp(resource
, "/") ||
7741 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6) ||
7742 (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10) ||
7743 (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9))
7748 else if (!strncmp(resource
, "/jobs/", 6) && resource
[6])
7751 job
= cupsdFindJob(atoi(resource
+ 6));
7755 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
7756 atoi(resource
+ 6));
7760 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7766 send_ipp_status(con
, IPP_NOT_FOUND
,
7767 _("The printer or class does not exist."));
7770 else if ((attr
= ippFindAttribute(con
->request
, "notify-job-id",
7771 IPP_TAG_INTEGER
)) != NULL
)
7773 job
= cupsdFindJob(attr
->values
[0].integer
);
7777 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
7778 attr
->values
[0].integer
);
7790 policy
= printer
->op_policy_ptr
;
7792 policy
= DefaultPolicyPtr
;
7794 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
7796 send_http_error(con
, status
, printer
);
7801 * Expire subscriptions as needed...
7804 cupsdExpireSubscriptions(NULL
, NULL
);
7807 * Copy the subscription attributes to the response using the
7808 * requested-attributes attribute that may be provided by the client.
7811 ra
= create_requested_array(con
->request
);
7813 if ((attr
= ippFindAttribute(con
->request
, "limit",
7814 IPP_TAG_INTEGER
)) != NULL
)
7815 limit
= attr
->values
[0].integer
;
7820 * See if we only want to see subscriptions for a specific user...
7823 if ((attr
= ippFindAttribute(con
->request
, "my-subscriptions",
7824 IPP_TAG_BOOLEAN
)) != NULL
&&
7825 attr
->values
[0].boolean
)
7826 strlcpy(username
, get_username(con
), sizeof(username
));
7830 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
), count
= 0;
7832 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
7833 if ((!printer
|| sub
->dest
== printer
) && (!job
|| sub
->job
== job
) &&
7834 (!username
[0] || !_cups_strcasecmp(username
, sub
->owner
)))
7836 ippAddSeparator(con
->response
);
7838 exclude
= cupsdGetPrivateAttrs(sub
->dest
? sub
->dest
->op_policy_ptr
:
7839 policy
, con
, sub
->dest
,
7842 copy_subscription_attrs(con
, sub
, ra
, exclude
);
7845 if (limit
&& count
>= limit
)
7849 cupsArrayDelete(ra
);
7852 con
->response
->request
.status
.status_code
= IPP_OK
;
7854 send_ipp_status(con
, IPP_NOT_FOUND
, _("No subscriptions found."));
7859 * 'get_username()' - Get the username associated with a request.
7862 static const char * /* O - Username */
7863 get_username(cupsd_client_t
*con
) /* I - Connection */
7865 ipp_attribute_t
*attr
; /* Attribute */
7868 if (con
->username
[0])
7869 return (con
->username
);
7870 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7871 IPP_TAG_NAME
)) != NULL
)
7872 return (attr
->values
[0].string
.text
);
7874 return ("anonymous");
7879 * 'hold_job()' - Hold a print job.
7883 hold_job(cupsd_client_t
*con
, /* I - Client connection */
7884 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
7886 ipp_attribute_t
*attr
; /* Current job-hold-until */
7887 const char *when
; /* New value */
7888 int jobid
; /* Job ID */
7889 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
7890 username
[HTTP_MAX_URI
], /* Username portion of URI */
7891 host
[HTTP_MAX_URI
], /* Host portion of URI */
7892 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7893 int port
; /* Port portion of URI */
7894 cupsd_job_t
*job
; /* Job information */
7897 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_job(%p[%d], %s)", con
, con
->number
,
7898 uri
->values
[0].string
.text
);
7901 * See if we have a job URI or a printer URI...
7904 if (!strcmp(uri
->name
, "printer-uri"))
7907 * Got a printer URI; see if we also have a job-id attribute...
7910 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7911 IPP_TAG_INTEGER
)) == NULL
)
7913 send_ipp_status(con
, IPP_BAD_REQUEST
,
7914 _("Got a printer-uri attribute but no job-id."));
7918 jobid
= attr
->values
[0].integer
;
7923 * Got a job URI; parse it to get the job ID...
7926 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7927 sizeof(scheme
), username
, sizeof(username
), host
,
7928 sizeof(host
), &port
, resource
, sizeof(resource
));
7930 if (strncmp(resource
, "/jobs/", 6))
7936 send_ipp_status(con
, IPP_BAD_REQUEST
,
7937 _("Bad job-uri \"%s\"."),
7938 uri
->values
[0].string
.text
);
7942 jobid
= atoi(resource
+ 6);
7946 * See if the job exists...
7949 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7952 * Nope - return a "not found" error...
7955 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
7960 * See if the job is owned by the requesting user...
7963 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7965 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
7966 cupsdFindDest(job
->dest
));
7971 * See if the job is in a state that allows holding...
7974 if (job
->state_value
> IPP_JOB_STOPPED
)
7977 * Return a "not-possible" error...
7980 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
7981 _("Job #%d is finished and cannot be altered."),
7987 * Hold the job and return...
7990 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
7991 IPP_TAG_KEYWORD
)) == NULL
)
7992 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
7996 when
= attr
->values
[0].string
.text
;
7998 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
7999 "Job job-hold-until value changed by user.");
8002 when
= "indefinite";
8004 cupsdSetJobHoldUntil(job
, when
, 1);
8005 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
, "Job held by \"%s\".",
8008 con
->response
->request
.status
.status_code
= IPP_OK
;
8013 * 'hold_new_jobs()' - Hold pending/new jobs on a printer or class.
8017 hold_new_jobs(cupsd_client_t
*con
, /* I - Connection */
8018 ipp_attribute_t
*uri
) /* I - Printer URI */
8020 http_status_t status
; /* Policy status */
8021 cups_ptype_t dtype
; /* Destination type (printer/class) */
8022 cupsd_printer_t
*printer
; /* Printer data */
8025 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_new_jobs(%p[%d], %s)", con
,
8026 con
->number
, uri
->values
[0].string
.text
);
8029 * Is the destination valid?
8032 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8038 send_ipp_status(con
, IPP_NOT_FOUND
,
8039 _("The printer or class does not exist."));
8047 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8049 send_http_error(con
, status
, printer
);
8054 * Hold pending/new jobs sent to the printer...
8057 printer
->holding_new_jobs
= 1;
8059 cupsdSetPrinterReasons(printer
, "+hold-new-jobs");
8061 if (dtype
& CUPS_PRINTER_CLASS
)
8062 cupsdLogMessage(CUPSD_LOG_INFO
,
8063 "Class \"%s\" now holding pending/new jobs (\"%s\").",
8064 printer
->name
, get_username(con
));
8066 cupsdLogMessage(CUPSD_LOG_INFO
,
8067 "Printer \"%s\" now holding pending/new jobs (\"%s\").",
8068 printer
->name
, get_username(con
));
8071 * Everything was ok, so return OK status...
8074 con
->response
->request
.status
.status_code
= IPP_OK
;
8079 * 'move_job()' - Move a job to a new destination.
8083 move_job(cupsd_client_t
*con
, /* I - Client connection */
8084 ipp_attribute_t
*uri
) /* I - Job URI */
8086 http_status_t status
; /* Policy status */
8087 ipp_attribute_t
*attr
; /* Current attribute */
8088 int jobid
; /* Job ID */
8089 cupsd_job_t
*job
; /* Current job */
8090 const char *src
; /* Source printer/class */
8091 cups_ptype_t stype
, /* Source type (printer or class) */
8092 dtype
; /* Destination type (printer/class) */
8093 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
8094 username
[HTTP_MAX_URI
], /* Username portion of URI */
8095 host
[HTTP_MAX_URI
], /* Host portion of URI */
8096 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8097 int port
; /* Port portion of URI */
8098 cupsd_printer_t
*sprinter
, /* Source printer */
8099 *dprinter
; /* Destination printer */
8102 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "move_job(%p[%d], %s)", con
, con
->number
,
8103 uri
->values
[0].string
.text
);
8106 * Get the new printer or class...
8109 if ((attr
= ippFindAttribute(con
->request
, "job-printer-uri",
8110 IPP_TAG_URI
)) == NULL
)
8113 * Need job-printer-uri...
8116 send_ipp_status(con
, IPP_BAD_REQUEST
,
8117 _("job-printer-uri attribute missing."));
8121 if (!cupsdValidateDest(attr
->values
[0].string
.text
, &dtype
, &dprinter
))
8127 send_ipp_status(con
, IPP_NOT_FOUND
,
8128 _("The printer or class does not exist."));
8133 * See if we have a job URI or a printer URI...
8136 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8137 sizeof(scheme
), username
, sizeof(username
), host
,
8138 sizeof(host
), &port
, resource
, sizeof(resource
));
8140 if (!strcmp(uri
->name
, "printer-uri"))
8143 * Got a printer URI; see if we also have a job-id attribute...
8146 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8147 IPP_TAG_INTEGER
)) == NULL
)
8153 if ((src
= cupsdValidateDest(uri
->values
[0].string
.text
, &stype
,
8154 &sprinter
)) == NULL
)
8160 send_ipp_status(con
, IPP_NOT_FOUND
,
8161 _("The printer or class does not exist."));
8170 * Otherwise, just move a single job...
8173 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
8176 * Nope - return a "not found" error...
8179 send_ipp_status(con
, IPP_NOT_FOUND
,
8180 _("Job #%d does not exist."), attr
->values
[0].integer
);
8186 * Job found, initialize source pointers...
8197 * Got a job URI; parse it to get the job ID...
8200 if (strncmp(resource
, "/jobs/", 6))
8206 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
8207 uri
->values
[0].string
.text
);
8212 * See if the job exists...
8215 jobid
= atoi(resource
+ 6);
8217 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8220 * Nope - return a "not found" error...
8223 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
8229 * Job found, initialize source pointers...
8238 * Check the policy of the destination printer...
8241 if ((status
= cupsdCheckPolicy(dprinter
->op_policy_ptr
, con
,
8242 job
? job
->username
: NULL
)) != HTTP_OK
)
8244 send_http_error(con
, status
, dprinter
);
8249 * Now move the job or jobs...
8255 * See if the job has been completed...
8258 if (job
->state_value
> IPP_JOB_STOPPED
)
8261 * Return a "not-possible" error...
8264 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8265 _("Job #%d is finished and cannot be altered."),
8271 * See if the job is owned by the requesting user...
8274 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8276 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8277 cupsdFindDest(job
->dest
));
8282 * Move the job to a different printer or class...
8285 cupsdMoveJob(job
, dprinter
);
8290 * Got the source printer, now look through the jobs...
8293 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
8295 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
8298 * See if the job is pointing at the source printer or has not been
8302 if (_cups_strcasecmp(job
->dest
, src
) ||
8303 job
->state_value
> IPP_JOB_STOPPED
)
8307 * See if the job can be moved by the requesting user...
8310 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8314 * Move the job to a different printer or class...
8317 cupsdMoveJob(job
, dprinter
);
8322 * Start jobs if possible...
8328 * Return with "everything is OK" status...
8331 con
->response
->request
.status
.status_code
= IPP_OK
;
8336 * 'ppd_parse_line()' - Parse a PPD default line.
8339 static int /* O - 0 on success, -1 on failure */
8340 ppd_parse_line(const char *line
, /* I - Line */
8341 char *option
, /* O - Option name */
8342 int olen
, /* I - Size of option name */
8343 char *choice
, /* O - Choice name */
8344 int clen
) /* I - Size of choice name */
8347 * Verify this is a default option line...
8350 if (strncmp(line
, "*Default", 8))
8354 * Read the option name...
8357 for (line
+= 8, olen
--;
8358 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
8369 * Skip everything else up to the colon (:)...
8372 while (*line
&& *line
!= ':')
8381 * Now grab the option choice, skipping leading whitespace...
8384 while (isspace(*line
& 255))
8388 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
8399 * Return with no errors...
8407 * 'print_job()' - Print a file to a printer or class.
8411 print_job(cupsd_client_t
*con
, /* I - Client connection */
8412 ipp_attribute_t
*uri
) /* I - Printer URI */
8414 ipp_attribute_t
*attr
; /* Current attribute */
8415 ipp_attribute_t
*doc_name
; /* document-name attribute */
8416 ipp_attribute_t
*format
; /* Document-format attribute */
8417 const char *default_format
; /* document-format-default value */
8418 cupsd_job_t
*job
; /* New job */
8419 char filename
[1024]; /* Job filename */
8420 mime_type_t
*filetype
; /* Type of file */
8421 char super
[MIME_MAX_SUPER
], /* Supertype of file */
8422 type
[MIME_MAX_TYPE
], /* Subtype of file */
8423 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
8424 /* Textual name of mime type */
8425 cupsd_printer_t
*printer
; /* Printer data */
8426 struct stat fileinfo
; /* File information */
8427 int kbytes
; /* Size of file */
8428 int compression
; /* Document compression */
8431 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "print_job(%p[%d], %s)", con
, con
->number
,
8432 uri
->values
[0].string
.text
);
8435 * Validate print file attributes, for now just document-format and
8436 * compression (CUPS only supports "none" and "gzip")...
8439 compression
= CUPS_FILE_NONE
;
8441 if ((attr
= ippFindAttribute(con
->request
, "compression",
8442 IPP_TAG_KEYWORD
)) != NULL
)
8444 if (strcmp(attr
->values
[0].string
.text
, "none")
8446 && strcmp(attr
->values
[0].string
.text
, "gzip")
8447 #endif /* HAVE_LIBZ */
8450 send_ipp_status(con
, IPP_ATTRIBUTES
,
8451 _("Unsupported compression \"%s\"."),
8452 attr
->values
[0].string
.text
);
8453 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
8454 "compression", NULL
, attr
->values
[0].string
.text
);
8459 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
8460 compression
= CUPS_FILE_GZIP
;
8461 #endif /* HAVE_LIBZ */
8465 * Do we have a file to print?
8470 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file in print request."));
8475 * Is the destination valid?
8478 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
8484 send_ipp_status(con
, IPP_NOT_FOUND
,
8485 _("The printer or class does not exist."));
8490 * Is it a format we support?
8493 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
8495 ippSetName(con
->request
, &doc_name
, "document-name-supplied");
8497 if ((format
= ippFindAttribute(con
->request
, "document-format",
8498 IPP_TAG_MIMETYPE
)) != NULL
)
8501 * Grab format from client...
8504 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%255[^;]", super
,
8507 send_ipp_status(con
, IPP_BAD_REQUEST
,
8508 _("Bad document-format \"%s\"."),
8509 format
->values
[0].string
.text
);
8513 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format-supplied", NULL
, ippGetString(format
, 0, NULL
));
8515 else if ((default_format
= cupsGetOption("document-format",
8516 printer
->num_options
,
8517 printer
->options
)) != NULL
)
8520 * Use default document format...
8523 if (sscanf(default_format
, "%15[^/]/%255[^;]", super
, type
) != 2)
8525 send_ipp_status(con
, IPP_BAD_REQUEST
,
8526 _("Bad document-format \"%s\"."),
8537 strlcpy(super
, "application", sizeof(super
));
8538 strlcpy(type
, "octet-stream", sizeof(type
));
8541 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
8544 * Auto-type the file...
8547 cupsdLogMessage(CUPSD_LOG_DEBUG
, "[Job ???] Auto-typing file...");
8550 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
8551 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
8555 filetype
= mimeType(MimeDatabase
, super
, type
);
8557 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job ???] Request file type is %s/%s.",
8558 filetype
->super
, filetype
->type
);
8560 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
, filetype
->type
);
8561 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format-detected", NULL
, mimetype
);
8564 filetype
= mimeType(MimeDatabase
, super
, type
);
8568 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
8571 * Replace the document-format attribute value with the auto-typed or
8575 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
8579 ippSetString(con
->request
, &format
, 0, mimetype
);
8581 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
8582 "document-format", NULL
, mimetype
);
8586 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
8587 _("Unsupported document-format \"%s\"."),
8588 format
? format
->values
[0].string
.text
:
8589 "application/octet-stream");
8590 cupsdLogMessage(CUPSD_LOG_INFO
,
8591 "Hint: Do you have the raw file printing rules enabled?");
8594 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
8595 "document-format", NULL
, format
->values
[0].string
.text
);
8601 * Read any embedded job ticket info from PS files...
8604 if (!_cups_strcasecmp(filetype
->super
, "application") &&
8605 (!_cups_strcasecmp(filetype
->type
, "postscript") ||
8606 !_cups_strcasecmp(filetype
->type
, "pdf")))
8607 read_job_ticket(con
);
8610 * Create the job object...
8613 if ((job
= add_job(con
, printer
, filetype
)) == NULL
)
8617 * Update quota data...
8620 if (stat(con
->filename
, &fileinfo
))
8623 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
8625 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
8627 job
->koctets
+= kbytes
;
8629 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets", IPP_TAG_INTEGER
)) != NULL
)
8630 attr
->values
[0].integer
+= kbytes
;
8633 * Add the job file...
8636 if (add_file(con
, job
, filetype
, compression
))
8639 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
, job
->num_files
);
8640 if (rename(con
->filename
, filename
))
8642 cupsdLogJob(job
, CUPSD_LOG_ERROR
, "Unable to rename job document file \"%s\": %s", filename
, strerror(errno
));
8644 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to rename job document file."));
8648 cupsdClearString(&con
->filename
);
8651 * See if we need to add the ending sheet...
8654 if (cupsdTimeoutJob(job
))
8658 * Log and save the job...
8661 cupsdLogJob(job
, CUPSD_LOG_INFO
,
8662 "File of type %s/%s queued by \"%s\".",
8663 filetype
->super
, filetype
->type
, job
->username
);
8664 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "hold_until=%d", (int)job
->hold_until
);
8665 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
8666 job
->dest
, job
->username
);
8669 * Start the job if possible...
8677 * 'read_job_ticket()' - Read a job ticket embedded in a print file.
8679 * This function only gets called when printing a single PDF or PostScript
8680 * file using the Print-Job operation. It doesn't work for Create-Job +
8681 * Send-File, since the job attributes need to be set at job creation
8682 * time for banners to work. The embedded job ticket stuff is here
8683 * primarily to allow the Windows printer driver for CUPS to pass in JCL
8684 * options and IPP attributes which otherwise would be lost.
8686 * The format of a job ticket is simple:
8688 * %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
8690 * %cupsJobTicket: attr1=value1
8691 * %cupsJobTicket: attr2=value2
8693 * %cupsJobTicket: attrN=valueN
8695 * Job ticket lines must appear immediately after the first line that
8696 * specifies PostScript (%!PS-Adobe-3.0) or PDF (%PDF) format, and CUPS
8697 * stops looking for job ticket info when it finds a line that does not begin
8698 * with "%cupsJobTicket:".
8700 * The maximum length of a job ticket line, including the prefix, is
8701 * 255 characters to conform with the Adobe DSC.
8703 * Read-only attributes are rejected with a notice to the error log in
8704 * case a malicious user tries anything. Since the job ticket is read
8705 * prior to attribute validation in print_job(), job ticket attributes
8706 * will go through the same validation as IPP attributes...
8710 read_job_ticket(cupsd_client_t
*con
) /* I - Client connection */
8712 cups_file_t
*fp
; /* File to read from */
8713 char line
[256]; /* Line data */
8714 int num_options
; /* Number of options */
8715 cups_option_t
*options
; /* Options */
8716 ipp_t
*ticket
; /* New attributes */
8717 ipp_attribute_t
*attr
, /* Current attribute */
8718 *attr2
, /* Job attribute */
8719 *prev2
; /* Previous job attribute */
8723 * First open the print file...
8726 if ((fp
= cupsFileOpen(con
->filename
, "rb")) == NULL
)
8728 cupsdLogMessage(CUPSD_LOG_ERROR
,
8729 "Unable to open print file for job ticket - %s",
8735 * Skip the first line...
8738 if (cupsFileGets(fp
, line
, sizeof(line
)) == NULL
)
8740 cupsdLogMessage(CUPSD_LOG_ERROR
,
8741 "Unable to read from print file for job ticket - %s",
8747 if (strncmp(line
, "%!PS-Adobe-", 11) && strncmp(line
, "%PDF-", 5))
8750 * Not a DSC-compliant file, so no job ticket info will be available...
8758 * Read job ticket info from the file...
8764 while (cupsFileGets(fp
, line
, sizeof(line
)))
8767 * Stop at the first non-ticket line...
8770 if (strncmp(line
, "%cupsJobTicket:", 15))
8774 * Add the options to the option array...
8777 num_options
= cupsParseOptions(line
+ 15, num_options
, &options
);
8781 * Done with the file; see if we have any options...
8786 if (num_options
== 0)
8790 * OK, convert the options to an attribute list, and apply them to
8795 cupsEncodeOptions(ticket
, num_options
, options
);
8798 * See what the user wants to change.
8801 for (attr
= ticket
->attrs
; attr
; attr
= attr
->next
)
8803 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
8806 if (!strncmp(attr
->name
, "date-time-at-", 13) ||
8807 !strcmp(attr
->name
, "job-impressions-completed") ||
8808 !strcmp(attr
->name
, "job-media-sheets-completed") ||
8809 !strncmp(attr
->name
, "job-k-octets", 12) ||
8810 !strcmp(attr
->name
, "job-id") ||
8811 !strcmp(attr
->name
, "job-originating-host-name") ||
8812 !strcmp(attr
->name
, "job-originating-user-name") ||
8813 !strcmp(attr
->name
, "job-pages-completed") ||
8814 !strcmp(attr
->name
, "job-printer-uri") ||
8815 !strncmp(attr
->name
, "job-state", 9) ||
8816 !strcmp(attr
->name
, "job-uri") ||
8817 !strncmp(attr
->name
, "time-at-", 8))
8818 continue; /* Read-only attrs */
8820 if ((attr2
= ippFindAttribute(con
->request
, attr
->name
,
8821 IPP_TAG_ZERO
)) != NULL
)
8824 * Some other value; first free the old value...
8827 if (con
->request
->attrs
== attr2
)
8829 con
->request
->attrs
= attr2
->next
;
8834 for (prev2
= con
->request
->attrs
; prev2
; prev2
= prev2
->next
)
8835 if (prev2
->next
== attr2
)
8837 prev2
->next
= attr2
->next
;
8842 if (con
->request
->last
== attr2
)
8843 con
->request
->last
= prev2
;
8845 ippDeleteAttribute(NULL
, attr2
);
8849 * Add new option by copying it...
8852 ippCopyAttribute(con
->request
, attr
, 0);
8856 * Then free the attribute list and option array...
8860 cupsFreeOptions(num_options
, options
);
8865 * 'reject_jobs()' - Reject print jobs to a printer.
8869 reject_jobs(cupsd_client_t
*con
, /* I - Client connection */
8870 ipp_attribute_t
*uri
) /* I - Printer or class URI */
8872 http_status_t status
; /* Policy status */
8873 cups_ptype_t dtype
; /* Destination type (printer/class) */
8874 cupsd_printer_t
*printer
; /* Printer data */
8875 ipp_attribute_t
*attr
; /* printer-state-message text */
8878 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "reject_jobs(%p[%d], %s)", con
,
8879 con
->number
, uri
->values
[0].string
.text
);
8882 * Is the destination valid?
8885 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8891 send_ipp_status(con
, IPP_NOT_FOUND
,
8892 _("The printer or class does not exist."));
8900 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8902 send_http_error(con
, status
, printer
);
8907 * Reject jobs sent to the printer...
8910 printer
->accepting
= 0;
8912 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
8913 IPP_TAG_TEXT
)) == NULL
)
8914 strlcpy(printer
->state_message
, "Rejecting Jobs",
8915 sizeof(printer
->state_message
));
8917 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
8918 sizeof(printer
->state_message
));
8920 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
8921 "No longer accepting jobs.");
8923 if (dtype
& CUPS_PRINTER_CLASS
)
8925 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
8927 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" rejecting jobs (\"%s\").",
8928 printer
->name
, get_username(con
));
8932 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
8934 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" rejecting jobs (\"%s\").",
8935 printer
->name
, get_username(con
));
8939 * Everything was ok, so return OK status...
8942 con
->response
->request
.status
.status_code
= IPP_OK
;
8947 * 'release_held_new_jobs()' - Release pending/new jobs on a printer or class.
8951 release_held_new_jobs(
8952 cupsd_client_t
*con
, /* I - Connection */
8953 ipp_attribute_t
*uri
) /* I - Printer URI */
8955 http_status_t status
; /* Policy status */
8956 cups_ptype_t dtype
; /* Destination type (printer/class) */
8957 cupsd_printer_t
*printer
; /* Printer data */
8960 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_held_new_jobs(%p[%d], %s)", con
,
8961 con
->number
, uri
->values
[0].string
.text
);
8964 * Is the destination valid?
8967 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8973 send_ipp_status(con
, IPP_NOT_FOUND
,
8974 _("The printer or class does not exist."));
8982 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8984 send_http_error(con
, status
, printer
);
8989 * Hold pending/new jobs sent to the printer...
8992 printer
->holding_new_jobs
= 0;
8994 cupsdSetPrinterReasons(printer
, "-hold-new-jobs");
8996 if (dtype
& CUPS_PRINTER_CLASS
)
8997 cupsdLogMessage(CUPSD_LOG_INFO
,
8998 "Class \"%s\" now printing pending/new jobs (\"%s\").",
8999 printer
->name
, get_username(con
));
9001 cupsdLogMessage(CUPSD_LOG_INFO
,
9002 "Printer \"%s\" now printing pending/new jobs (\"%s\").",
9003 printer
->name
, get_username(con
));
9008 * Everything was ok, so return OK status...
9011 con
->response
->request
.status
.status_code
= IPP_OK
;
9016 * 'release_job()' - Release a held print job.
9020 release_job(cupsd_client_t
*con
, /* I - Client connection */
9021 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9023 ipp_attribute_t
*attr
; /* Current attribute */
9024 int jobid
; /* Job ID */
9025 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9026 username
[HTTP_MAX_URI
], /* Username portion of URI */
9027 host
[HTTP_MAX_URI
], /* Host portion of URI */
9028 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9029 int port
; /* Port portion of URI */
9030 cupsd_job_t
*job
; /* Job information */
9033 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_job(%p[%d], %s)", con
,
9034 con
->number
, uri
->values
[0].string
.text
);
9037 * See if we have a job URI or a printer URI...
9040 if (!strcmp(uri
->name
, "printer-uri"))
9043 * Got a printer URI; see if we also have a job-id attribute...
9046 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9047 IPP_TAG_INTEGER
)) == NULL
)
9049 send_ipp_status(con
, IPP_BAD_REQUEST
,
9050 _("Got a printer-uri attribute but no job-id."));
9054 jobid
= attr
->values
[0].integer
;
9059 * Got a job URI; parse it to get the job ID...
9062 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9063 sizeof(scheme
), username
, sizeof(username
), host
,
9064 sizeof(host
), &port
, resource
, sizeof(resource
));
9066 if (strncmp(resource
, "/jobs/", 6))
9072 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9073 uri
->values
[0].string
.text
);
9077 jobid
= atoi(resource
+ 6);
9081 * See if the job exists...
9084 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9087 * Nope - return a "not found" error...
9090 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9095 * See if job is "held"...
9098 if (job
->state_value
!= IPP_JOB_HELD
)
9101 * Nope - return a "not possible" error...
9104 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not held."), jobid
);
9109 * See if the job is owned by the requesting user...
9112 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9114 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9115 cupsdFindDest(job
->dest
));
9120 * Reset the job-hold-until value to "no-hold"...
9123 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9124 IPP_TAG_KEYWORD
)) == NULL
)
9125 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9129 ippSetValueTag(job
->attrs
, &attr
, IPP_TAG_KEYWORD
);
9130 ippSetString(job
->attrs
, &attr
, 0, "no-hold");
9132 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
9133 "Job job-hold-until value changed by user.");
9134 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
9138 * Release the job and return...
9141 cupsdReleaseJob(job
);
9143 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
9144 "Job released by user.");
9146 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Released by \"%s\".", username
);
9148 con
->response
->request
.status
.status_code
= IPP_OK
;
9155 * 'renew_subscription()' - Renew an existing subscription...
9160 cupsd_client_t
*con
, /* I - Client connection */
9161 int sub_id
) /* I - Subscription ID */
9163 http_status_t status
; /* Policy status */
9164 cupsd_subscription_t
*sub
; /* Subscription */
9165 ipp_attribute_t
*lease
; /* notify-lease-duration */
9168 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
9169 "renew_subscription(con=%p[%d], sub_id=%d)",
9170 con
, con
->number
, sub_id
);
9173 * Is the subscription ID valid?
9176 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
9179 * Bad subscription ID...
9182 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
9190 * Job subscriptions cannot be renewed...
9193 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9194 _("Job subscriptions cannot be renewed."));
9202 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
9204 con
, sub
->owner
)) != HTTP_OK
)
9206 send_http_error(con
, status
, sub
->dest
);
9211 * Renew the subscription...
9214 lease
= ippFindAttribute(con
->request
, "notify-lease-duration",
9217 sub
->lease
= lease
? lease
->values
[0].integer
: DefaultLeaseDuration
;
9219 if (MaxLeaseDuration
&& (sub
->lease
== 0 || sub
->lease
> MaxLeaseDuration
))
9221 cupsdLogMessage(CUPSD_LOG_INFO
,
9222 "renew_subscription: Limiting notify-lease-duration to "
9225 sub
->lease
= MaxLeaseDuration
;
9228 sub
->expire
= sub
->lease
? time(NULL
) + sub
->lease
: 0;
9230 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
9232 con
->response
->request
.status
.status_code
= IPP_OK
;
9234 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
9235 "notify-lease-duration", sub
->lease
);
9240 * 'restart_job()' - Restart an old print job.
9244 restart_job(cupsd_client_t
*con
, /* I - Client connection */
9245 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9247 ipp_attribute_t
*attr
; /* Current attribute */
9248 int jobid
; /* Job ID */
9249 cupsd_job_t
*job
; /* Job information */
9250 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9251 username
[HTTP_MAX_URI
], /* Username portion of URI */
9252 host
[HTTP_MAX_URI
], /* Host portion of URI */
9253 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9254 int port
; /* Port portion of URI */
9257 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "restart_job(%p[%d], %s)", con
,
9258 con
->number
, uri
->values
[0].string
.text
);
9261 * See if we have a job URI or a printer URI...
9264 if (!strcmp(uri
->name
, "printer-uri"))
9267 * Got a printer URI; see if we also have a job-id attribute...
9270 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9271 IPP_TAG_INTEGER
)) == NULL
)
9273 send_ipp_status(con
, IPP_BAD_REQUEST
,
9274 _("Got a printer-uri attribute but no job-id."));
9278 jobid
= attr
->values
[0].integer
;
9283 * Got a job URI; parse it to get the job ID...
9286 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9287 sizeof(scheme
), username
, sizeof(username
), host
,
9288 sizeof(host
), &port
, resource
, sizeof(resource
));
9290 if (strncmp(resource
, "/jobs/", 6))
9296 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9297 uri
->values
[0].string
.text
);
9301 jobid
= atoi(resource
+ 6);
9305 * See if the job exists...
9308 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9311 * Nope - return a "not found" error...
9314 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9319 * See if job is in any of the "completed" states...
9322 if (job
->state_value
<= IPP_JOB_PROCESSING
)
9325 * Nope - return a "not possible" error...
9328 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not complete."),
9334 * See if we have retained the job files...
9339 if (!job
->attrs
|| job
->num_files
== 0)
9342 * Nope - return a "not possible" error...
9345 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9346 _("Job #%d cannot be restarted - no files."), jobid
);
9351 * See if the job is owned by the requesting user...
9354 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9356 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9357 cupsdFindDest(job
->dest
));
9362 * See if the job-hold-until attribute is specified...
9365 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
9366 IPP_TAG_KEYWORD
)) == NULL
)
9367 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
9369 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
9372 * Return the job to a held state...
9375 cupsdLogJob(job
, CUPSD_LOG_DEBUG
,
9376 "Restarted by \"%s\" with job-hold-until=%s.",
9377 username
, attr
->values
[0].string
.text
);
9378 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
9380 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
,
9381 NULL
, job
, "Job restarted by user with job-hold-until=%s",
9382 attr
->values
[0].string
.text
);
9387 * Restart the job...
9390 cupsdRestartJob(job
);
9394 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Restarted by \"%s\".", username
);
9396 con
->response
->request
.status
.status_code
= IPP_OK
;
9401 * 'save_auth_info()' - Save authentication information for a job.
9406 cupsd_client_t
*con
, /* I - Client connection */
9407 cupsd_job_t
*job
, /* I - Job */
9408 ipp_attribute_t
*auth_info
) /* I - auth-info attribute, if any */
9410 int i
; /* Looping var */
9411 char filename
[1024]; /* Job authentication filename */
9412 cups_file_t
*fp
; /* Job authentication file */
9413 char line
[65536]; /* Line for file */
9414 cupsd_printer_t
*dest
; /* Destination printer/class */
9418 * This function saves the in-memory authentication information for
9419 * a job so that it can be used to authenticate with a remote host.
9420 * The information is stored in a file that is readable only by the
9421 * root user. The fields are Base-64 encoded, each on a separate line,
9422 * followed by random number (up to 1024) of newlines to limit the
9423 * amount of information that is exposed.
9425 * Because of the potential for exposing of authentication information,
9426 * this functionality is only enabled when running cupsd as root.
9428 * This caching only works for the Basic and BasicDigest authentication
9429 * types. Digest authentication cannot be cached this way, and in
9430 * the future Kerberos authentication may make all of this obsolete.
9432 * Authentication information is saved whenever an authenticated
9433 * Print-Job, Create-Job, or CUPS-Authenticate-Job operation is
9436 * This information is deleted after a job is completed or canceled,
9437 * so reprints may require subsequent re-authentication.
9443 if ((dest
= cupsdFindDest(job
->dest
)) == NULL
)
9447 * Create the authentication file and change permissions...
9450 snprintf(filename
, sizeof(filename
), "%s/a%05d", RequestRoot
, job
->id
);
9451 if ((fp
= cupsFileOpen(filename
, "w")) == NULL
)
9453 cupsdLogMessage(CUPSD_LOG_ERROR
,
9454 "Unable to save authentication info to \"%s\" - %s",
9455 filename
, strerror(errno
));
9459 fchown(cupsFileNumber(fp
), 0, 0);
9460 fchmod(cupsFileNumber(fp
), 0400);
9462 cupsFilePuts(fp
, "CUPSD-AUTH-V3\n");
9465 i
< (int)(sizeof(job
->auth_env
) / sizeof(job
->auth_env
[0]));
9467 cupsdClearString(job
->auth_env
+ i
);
9469 if (auth_info
&& auth_info
->num_values
== dest
->num_auth_info_required
)
9472 * Write 1 to 3 auth values...
9476 i
< auth_info
->num_values
&&
9477 i
< (int)(sizeof(job
->auth_env
) / sizeof(job
->auth_env
[0]));
9480 if (strcmp(dest
->auth_info_required
[i
], "negotiate"))
9482 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[i
].string
.text
, (int)strlen(auth_info
->values
[i
].string
.text
));
9483 cupsFilePutConf(fp
, dest
->auth_info_required
[i
], line
);
9486 cupsFilePutConf(fp
, dest
->auth_info_required
[i
],
9487 auth_info
->values
[i
].string
.text
);
9489 if (!strcmp(dest
->auth_info_required
[i
], "username"))
9490 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_USERNAME=%s",
9491 auth_info
->values
[i
].string
.text
);
9492 else if (!strcmp(dest
->auth_info_required
[i
], "domain"))
9493 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_DOMAIN=%s",
9494 auth_info
->values
[i
].string
.text
);
9495 else if (!strcmp(dest
->auth_info_required
[i
], "password"))
9496 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_PASSWORD=%s",
9497 auth_info
->values
[i
].string
.text
);
9498 else if (!strcmp(dest
->auth_info_required
[i
], "negotiate"))
9499 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_NEGOTIATE=%s",
9500 auth_info
->values
[i
].string
.text
);
9505 else if (auth_info
&& auth_info
->num_values
== 2 &&
9506 dest
->num_auth_info_required
== 1 &&
9507 !strcmp(dest
->auth_info_required
[0], "negotiate"))
9510 * Allow fallback to username+password for Kerberized queues...
9513 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[0].string
.text
, (int)strlen(auth_info
->values
[0].string
.text
));
9514 cupsFilePutConf(fp
, "username", line
);
9516 cupsdSetStringf(job
->auth_env
+ 0, "AUTH_USERNAME=%s",
9517 auth_info
->values
[0].string
.text
);
9519 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[1].string
.text
, (int)strlen(auth_info
->values
[1].string
.text
));
9520 cupsFilePutConf(fp
, "password", line
);
9522 cupsdSetStringf(job
->auth_env
+ 1, "AUTH_PASSWORD=%s",
9523 auth_info
->values
[1].string
.text
);
9525 else if (con
->username
[0])
9528 * Write the authenticated username...
9531 httpEncode64_2(line
, sizeof(line
), con
->username
, (int)strlen(con
->username
));
9532 cupsFilePutConf(fp
, "username", line
);
9534 cupsdSetStringf(job
->auth_env
+ 0, "AUTH_USERNAME=%s", con
->username
);
9537 * Write the authenticated password...
9540 httpEncode64_2(line
, sizeof(line
), con
->password
, (int)strlen(con
->password
));
9541 cupsFilePutConf(fp
, "password", line
);
9543 cupsdSetStringf(job
->auth_env
+ 1, "AUTH_PASSWORD=%s", con
->password
);
9547 if (con
->gss_uid
> 0)
9549 cupsFilePrintf(fp
, "uid %d\n", (int)con
->gss_uid
);
9550 cupsdSetStringf(&job
->auth_uid
, "AUTH_UID=%d", (int)con
->gss_uid
);
9552 #endif /* HAVE_GSSAPI */
9555 * Write a random number of newlines to the end of the file...
9558 for (i
= (CUPS_RAND() % 1024); i
>= 0; i
--)
9559 cupsFilePutChar(fp
, '\n');
9562 * Close the file and return...
9570 * 'send_document()' - Send a file to a printer or class.
9574 send_document(cupsd_client_t
*con
, /* I - Client connection */
9575 ipp_attribute_t
*uri
) /* I - Printer URI */
9577 ipp_attribute_t
*attr
; /* Current attribute */
9578 ipp_attribute_t
*format
; /* Request's document-format attribute */
9579 ipp_attribute_t
*jformat
; /* Job's document-format attribute */
9580 const char *default_format
;/* document-format-default value */
9581 int jobid
; /* Job ID number */
9582 cupsd_job_t
*job
; /* Current job */
9583 char job_uri
[HTTP_MAX_URI
],
9585 scheme
[HTTP_MAX_URI
],
9586 /* Method portion of URI */
9587 username
[HTTP_MAX_URI
],
9588 /* Username portion of URI */
9590 /* Host portion of URI */
9591 resource
[HTTP_MAX_URI
];
9592 /* Resource portion of URI */
9593 int port
; /* Port portion of URI */
9594 mime_type_t
*filetype
; /* Type of file */
9595 char super
[MIME_MAX_SUPER
],
9596 /* Supertype of file */
9597 type
[MIME_MAX_TYPE
],
9598 /* Subtype of file */
9599 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
9600 /* Textual name of mime type */
9601 char filename
[1024]; /* Job filename */
9602 cupsd_printer_t
*printer
; /* Current printer */
9603 struct stat fileinfo
; /* File information */
9604 int kbytes
; /* Size of file */
9605 int compression
; /* Type of compression */
9606 int start_job
; /* Start the job? */
9609 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "send_document(%p[%d], %s)", con
,
9610 con
->number
, uri
->values
[0].string
.text
);
9613 * See if we have a job URI or a printer URI...
9616 if (!strcmp(uri
->name
, "printer-uri"))
9619 * Got a printer URI; see if we also have a job-id attribute...
9622 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9623 IPP_TAG_INTEGER
)) == NULL
)
9625 send_ipp_status(con
, IPP_BAD_REQUEST
,
9626 _("Got a printer-uri attribute but no job-id."));
9630 jobid
= attr
->values
[0].integer
;
9635 * Got a job URI; parse it to get the job ID...
9638 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9639 sizeof(scheme
), username
, sizeof(username
), host
,
9640 sizeof(host
), &port
, resource
, sizeof(resource
));
9642 if (strncmp(resource
, "/jobs/", 6))
9648 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9649 uri
->values
[0].string
.text
);
9653 jobid
= atoi(resource
+ 6);
9657 * See if the job exists...
9660 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9663 * Nope - return a "not found" error...
9666 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9670 printer
= cupsdFindDest(job
->dest
);
9673 * See if the job is owned by the requesting user...
9676 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9678 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9679 cupsdFindDest(job
->dest
));
9684 * OK, see if the client is sending the document compressed - CUPS
9685 * only supports "none" and "gzip".
9688 compression
= CUPS_FILE_NONE
;
9690 if ((attr
= ippFindAttribute(con
->request
, "compression",
9691 IPP_TAG_KEYWORD
)) != NULL
)
9693 if (strcmp(attr
->values
[0].string
.text
, "none")
9695 && strcmp(attr
->values
[0].string
.text
, "gzip")
9696 #endif /* HAVE_LIBZ */
9699 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Unsupported compression \"%s\"."),
9700 attr
->values
[0].string
.text
);
9701 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
9702 "compression", NULL
, attr
->values
[0].string
.text
);
9707 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
9708 compression
= CUPS_FILE_GZIP
;
9709 #endif /* HAVE_LIBZ */
9713 * Do we have a file to print?
9716 if ((attr
= ippFindAttribute(con
->request
, "last-document",
9717 IPP_TAG_BOOLEAN
)) == NULL
)
9719 send_ipp_status(con
, IPP_BAD_REQUEST
,
9720 _("Missing last-document attribute in request."));
9727 * Check for an empty request with "last-document" set to true, which is
9728 * used to close an "open" job by RFC 2911, section 3.3.2.
9731 if (job
->num_files
> 0 && attr
->values
[0].boolean
)
9734 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file in print request."));
9739 * Is it a format we support?
9744 if ((format
= ippFindAttribute(con
->request
, "document-format",
9745 IPP_TAG_MIMETYPE
)) != NULL
)
9748 * Grab format from client...
9751 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%255[^;]",
9754 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"."),
9755 format
->values
[0].string
.text
);
9759 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format-supplied", NULL
, ippGetString(format
, 0, NULL
));
9761 else if ((default_format
= cupsGetOption("document-format",
9762 printer
->num_options
,
9763 printer
->options
)) != NULL
)
9766 * Use default document format...
9769 if (sscanf(default_format
, "%15[^/]/%255[^;]", super
, type
) != 2)
9771 send_ipp_status(con
, IPP_BAD_REQUEST
,
9772 _("Bad document-format-default \"%s\"."), default_format
);
9779 * No document format attribute? Auto-type it!
9782 strlcpy(super
, "application", sizeof(super
));
9783 strlcpy(type
, "octet-stream", sizeof(type
));
9786 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
9789 * Auto-type the file...
9792 ipp_attribute_t
*doc_name
; /* document-name attribute */
9795 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Auto-typing file...");
9797 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
9798 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
9799 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
9803 filetype
= mimeType(MimeDatabase
, super
, type
);
9806 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Request file type is %s/%s.",
9807 filetype
->super
, filetype
->type
);
9809 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
, filetype
->type
);
9810 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format-detected", NULL
, mimetype
);
9813 filetype
= mimeType(MimeDatabase
, super
, type
);
9818 * Replace the document-format attribute value with the auto-typed or
9822 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9825 if ((jformat
= ippFindAttribute(job
->attrs
, "document-format",
9826 IPP_TAG_MIMETYPE
)) != NULL
)
9827 ippSetString(job
->attrs
, &jformat
, 0, mimetype
);
9829 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
9830 "document-format", NULL
, mimetype
);
9834 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9835 _("Unsupported document-format \"%s/%s\"."), super
, type
);
9836 cupsdLogMessage(CUPSD_LOG_INFO
,
9837 "Hint: Do you have the raw file printing rules enabled?");
9840 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9841 "document-format", NULL
, format
->values
[0].string
.text
);
9846 if (printer
->filetypes
&& !cupsArrayFind(printer
->filetypes
, filetype
))
9848 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9851 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9852 _("Unsupported document-format \"%s\"."), mimetype
);
9854 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9855 "document-format", NULL
, mimetype
);
9861 * Add the file to the job...
9864 if (add_file(con
, job
, filetype
, compression
))
9867 if ((attr
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
)) != NULL
)
9868 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name-supplied", NULL
, ippGetString(attr
, 0, NULL
));
9870 if (stat(con
->filename
, &fileinfo
))
9873 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
9875 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
9877 job
->koctets
+= kbytes
;
9879 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets", IPP_TAG_INTEGER
)) != NULL
)
9880 attr
->values
[0].integer
+= kbytes
;
9882 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
, job
->num_files
);
9883 if (rename(con
->filename
, filename
))
9885 cupsdLogJob(job
, CUPSD_LOG_ERROR
, "Unable to rename job document file \"%s\": %s", filename
, strerror(errno
));
9887 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to rename job document file."));
9891 cupsdClearString(&con
->filename
);
9893 cupsdLogJob(job
, CUPSD_LOG_INFO
, "File of type %s/%s queued by \"%s\".",
9894 filetype
->super
, filetype
->type
, job
->username
);
9897 * Start the job if this is the last document...
9902 if ((attr
= ippFindAttribute(con
->request
, "last-document",
9903 IPP_TAG_BOOLEAN
)) != NULL
&&
9904 attr
->values
[0].boolean
)
9907 * See if we need to add the ending sheet...
9910 if (cupsdTimeoutJob(job
))
9913 if (job
->state_value
== IPP_JOB_STOPPED
)
9915 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9916 job
->state_value
= IPP_JOB_PENDING
;
9918 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
9920 else if (job
->state_value
== IPP_JOB_HELD
)
9922 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9923 IPP_TAG_KEYWORD
)) == NULL
)
9924 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9926 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9928 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9929 job
->state_value
= IPP_JOB_PENDING
;
9931 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
9934 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-hold-until-specified");
9938 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
9944 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9945 IPP_TAG_KEYWORD
)) == NULL
)
9946 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9948 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9950 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
9951 job
->state_value
= IPP_JOB_HELD
;
9952 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
9954 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-incoming");
9957 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
9964 * Fill in the response info...
9967 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
9968 con
->clientname
, con
->clientport
, "/jobs/%d", jobid
);
9969 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
9972 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", jobid
);
9974 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
9976 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons",
9977 NULL
, job
->reasons
->values
[0].string
.text
);
9979 con
->response
->request
.status
.status_code
= IPP_OK
;
9982 * Start the job if necessary...
9991 * 'send_http_error()' - Send a HTTP error back to the IPP client.
9996 cupsd_client_t
*con
, /* I - Client connection */
9997 http_status_t status
, /* I - HTTP status code */
9998 cupsd_printer_t
*printer
) /* I - Printer, if any */
10000 ipp_attribute_t
*uri
; /* Request URI, if any */
10003 if ((uri
= ippFindAttribute(con
->request
, "printer-uri",
10004 IPP_TAG_URI
)) == NULL
)
10005 uri
= ippFindAttribute(con
->request
, "job-uri", IPP_TAG_URI
);
10007 cupsdLogMessage(status
== HTTP_FORBIDDEN
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
10008 "[Client %d] Returning HTTP %s for %s (%s) from %s",
10009 con
->number
, httpStatus(status
),
10011 ippOpString(con
->request
->request
.op
.operation_id
) :
10013 uri
? uri
->values
[0].string
.text
: "no URI",
10014 con
->http
->hostname
);
10018 int auth_type
; /* Type of authentication required */
10021 auth_type
= CUPSD_AUTH_NONE
;
10023 if (status
== HTTP_UNAUTHORIZED
&&
10024 printer
->num_auth_info_required
> 0 &&
10025 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
10027 (con
->request
->request
.op
.operation_id
== IPP_PRINT_JOB
||
10028 con
->request
->request
.op
.operation_id
== IPP_CREATE_JOB
||
10029 con
->request
->request
.op
.operation_id
== CUPS_AUTHENTICATE_JOB
))
10032 * Creating and authenticating jobs requires Kerberos...
10035 auth_type
= CUPSD_AUTH_NEGOTIATE
;
10040 * Use policy/location-defined authentication requirements...
10043 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
10044 cupsd_location_t
*auth
; /* Pointer to authentication element */
10047 if (printer
->type
& CUPS_PRINTER_CLASS
)
10048 snprintf(resource
, sizeof(resource
), "/classes/%s", printer
->name
);
10050 snprintf(resource
, sizeof(resource
), "/printers/%s", printer
->name
);
10052 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
10053 auth
->type
== CUPSD_AUTH_NONE
)
10054 auth
= cupsdFindPolicyOp(printer
->op_policy_ptr
,
10056 con
->request
->request
.op
.operation_id
:
10061 if (auth
->type
== CUPSD_AUTH_DEFAULT
)
10062 auth_type
= cupsdDefaultAuthType();
10064 auth_type
= auth
->type
;
10068 cupsdSendError(con
, status
, auth_type
);
10071 cupsdSendError(con
, status
, CUPSD_AUTH_NONE
);
10073 ippDelete(con
->response
);
10074 con
->response
= NULL
;
10081 * 'send_ipp_status()' - Send a status back to the IPP client.
10085 send_ipp_status(cupsd_client_t
*con
, /* I - Client connection */
10086 ipp_status_t status
, /* I - IPP status code */
10087 const char *message
,/* I - Status message */
10088 ...) /* I - Additional args as needed */
10090 va_list ap
; /* Pointer to additional args */
10091 char formatted
[1024]; /* Formatted errror message */
10094 va_start(ap
, message
);
10095 vsnprintf(formatted
, sizeof(formatted
),
10096 _cupsLangString(con
->language
, message
), ap
);
10099 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s: %s",
10100 ippOpString(con
->request
->request
.op
.operation_id
),
10101 ippErrorString(status
), formatted
);
10103 con
->response
->request
.status
.status_code
= status
;
10105 if (ippFindAttribute(con
->response
, "attributes-charset",
10106 IPP_TAG_ZERO
) == NULL
)
10107 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
10108 "attributes-charset", NULL
, "utf-8");
10110 if (ippFindAttribute(con
->response
, "attributes-natural-language",
10111 IPP_TAG_ZERO
) == NULL
)
10112 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
10113 "attributes-natural-language", NULL
, DefaultLanguage
);
10115 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
10116 "status-message", NULL
, formatted
);
10121 * 'set_default()' - Set the default destination...
10125 set_default(cupsd_client_t
*con
, /* I - Client connection */
10126 ipp_attribute_t
*uri
) /* I - Printer URI */
10128 http_status_t status
; /* Policy status */
10129 cups_ptype_t dtype
; /* Destination type (printer/class) */
10130 cupsd_printer_t
*printer
, /* Printer */
10131 *oldprinter
; /* Old default printer */
10134 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_default(%p[%d], %s)", con
,
10135 con
->number
, uri
->values
[0].string
.text
);
10138 * Is the destination valid?
10141 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10147 send_ipp_status(con
, IPP_NOT_FOUND
,
10148 _("The printer or class does not exist."));
10156 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
10158 send_http_error(con
, status
, NULL
);
10163 * Set it as the default...
10166 oldprinter
= DefaultPrinter
;
10167 DefaultPrinter
= printer
;
10170 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, oldprinter
, NULL
,
10171 "%s is no longer the default printer.", oldprinter
->name
);
10173 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
10174 "%s is now the default printer.", printer
->name
);
10176 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
| CUPSD_DIRTY_CLASSES
|
10177 CUPSD_DIRTY_PRINTCAP
);
10179 cupsdLogMessage(CUPSD_LOG_INFO
,
10180 "Default destination set to \"%s\" by \"%s\".",
10181 printer
->name
, get_username(con
));
10184 * Everything was ok, so return OK status...
10187 con
->response
->request
.status
.status_code
= IPP_OK
;
10192 * 'set_job_attrs()' - Set job attributes.
10196 set_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
10197 ipp_attribute_t
*uri
) /* I - Job URI */
10199 ipp_attribute_t
*attr
, /* Current attribute */
10200 *attr2
; /* Job attribute */
10201 int jobid
; /* Job ID */
10202 cupsd_job_t
*job
; /* Current job */
10203 char scheme
[HTTP_MAX_URI
],
10204 /* Method portion of URI */
10205 username
[HTTP_MAX_URI
],
10206 /* Username portion of URI */
10207 host
[HTTP_MAX_URI
],
10208 /* Host portion of URI */
10209 resource
[HTTP_MAX_URI
];
10210 /* Resource portion of URI */
10211 int port
; /* Port portion of URI */
10212 int event
; /* Events? */
10213 int check_jobs
; /* Check jobs? */
10216 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_job_attrs(%p[%d], %s)", con
,
10217 con
->number
, uri
->values
[0].string
.text
);
10220 * Start with "everything is OK" status...
10223 con
->response
->request
.status
.status_code
= IPP_OK
;
10226 * See if we have a job URI or a printer URI...
10229 if (!strcmp(uri
->name
, "printer-uri"))
10232 * Got a printer URI; see if we also have a job-id attribute...
10235 if ((attr
= ippFindAttribute(con
->request
, "job-id",
10236 IPP_TAG_INTEGER
)) == NULL
)
10238 send_ipp_status(con
, IPP_BAD_REQUEST
,
10239 _("Got a printer-uri attribute but no job-id."));
10243 jobid
= attr
->values
[0].integer
;
10248 * Got a job URI; parse it to get the job ID...
10251 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
10252 sizeof(scheme
), username
, sizeof(username
), host
,
10253 sizeof(host
), &port
, resource
, sizeof(resource
));
10255 if (strncmp(resource
, "/jobs/", 6))
10261 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
10262 uri
->values
[0].string
.text
);
10266 jobid
= atoi(resource
+ 6);
10270 * See if the job exists...
10273 if ((job
= cupsdFindJob(jobid
)) == NULL
)
10276 * Nope - return a "not found" error...
10279 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
10284 * See if the job has been completed...
10287 if (job
->state_value
> IPP_JOB_STOPPED
)
10290 * Return a "not-possible" error...
10293 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10294 _("Job #%d is finished and cannot be altered."), jobid
);
10299 * See if the job is owned by the requesting user...
10302 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10304 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
10305 cupsdFindDest(job
->dest
));
10310 * See what the user wants to change.
10318 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10320 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
10323 if (!strcmp(attr
->name
, "attributes-charset") ||
10324 !strcmp(attr
->name
, "attributes-natural-language") ||
10325 !strncmp(attr
->name
, "date-time-at-", 13) ||
10326 !strncmp(attr
->name
, "document-compression", 20) ||
10327 !strncmp(attr
->name
, "document-format", 15) ||
10328 !strcmp(attr
->name
, "job-detailed-status-messages") ||
10329 !strcmp(attr
->name
, "job-document-access-errors") ||
10330 !strcmp(attr
->name
, "job-id") ||
10331 !strcmp(attr
->name
, "job-impressions-completed") ||
10332 !strcmp(attr
->name
, "job-k-octets-completed") ||
10333 !strcmp(attr
->name
, "job-media-sheets-completed") ||
10334 !strcmp(attr
->name
, "job-originating-host-name") ||
10335 !strcmp(attr
->name
, "job-originating-user-name") ||
10336 !strcmp(attr
->name
, "job-pages-completed") ||
10337 !strcmp(attr
->name
, "job-printer-up-time") ||
10338 !strcmp(attr
->name
, "job-printer-uri") ||
10339 !strcmp(attr
->name
, "job-sheets") ||
10340 !strcmp(attr
->name
, "job-state-message") ||
10341 !strcmp(attr
->name
, "job-state-reasons") ||
10342 !strcmp(attr
->name
, "job-uri") ||
10343 !strcmp(attr
->name
, "number-of-documents") ||
10344 !strcmp(attr
->name
, "number-of-intervening-jobs") ||
10345 !strcmp(attr
->name
, "output-device-assigned") ||
10346 !strncmp(attr
->name
, "time-at-", 8))
10352 send_ipp_status(con
, IPP_ATTRIBUTES_NOT_SETTABLE
,
10353 _("%s cannot be changed."), attr
->name
);
10355 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
10356 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
10360 if (!strcmp(attr
->name
, "job-priority"))
10363 * Change the job priority...
10366 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10368 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-priority value."));
10370 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
10371 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
10373 else if (job
->state_value
>= IPP_JOB_PROCESSING
)
10375 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10376 _("Job is completed and cannot be changed."));
10379 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10381 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-priority to %d",
10382 attr
->values
[0].integer
);
10383 cupsdSetJobPriority(job
, attr
->values
[0].integer
);
10386 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
|
10387 CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
;
10390 else if (!strcmp(attr
->name
, "job-state"))
10393 * Change the job state...
10396 if (attr
->value_tag
!= IPP_TAG_ENUM
)
10398 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-state value."));
10400 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
10401 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
10405 switch (attr
->values
[0].integer
)
10407 case IPP_JOB_PENDING
:
10408 case IPP_JOB_HELD
:
10409 if (job
->state_value
> IPP_JOB_HELD
)
10411 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10412 _("Job state cannot be changed."));
10415 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10417 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10418 attr
->values
[0].integer
);
10419 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
, CUPSD_JOB_DEFAULT
, "Job state changed by \"%s\"", username
);
10424 case IPP_JOB_PROCESSING
:
10425 case IPP_JOB_STOPPED
:
10426 if (job
->state_value
!= attr
->values
[0].integer
)
10428 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10429 _("Job state cannot be changed."));
10434 case IPP_JOB_CANCELED
:
10435 case IPP_JOB_ABORTED
:
10436 case IPP_JOB_COMPLETED
:
10437 if (job
->state_value
> IPP_JOB_PROCESSING
)
10439 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10440 _("Job state cannot be changed."));
10443 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10445 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10446 attr
->values
[0].integer
);
10447 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
,
10449 "Job state changed by \"%s\"", username
);
10456 else if (con
->response
->request
.status
.status_code
!= IPP_OK
)
10458 else if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10459 IPP_TAG_ZERO
)) != NULL
)
10462 * Some other value; first free the old value...
10465 if (job
->attrs
->prev
)
10466 job
->attrs
->prev
->next
= attr2
->next
;
10468 job
->attrs
->attrs
= attr2
->next
;
10470 if (job
->attrs
->last
== attr2
)
10471 job
->attrs
->last
= job
->attrs
->prev
;
10473 ippDeleteAttribute(NULL
, attr2
);
10476 * Then copy the attribute...
10479 ippCopyAttribute(job
->attrs
, attr
, 0);
10482 * See if the job-name or job-hold-until is being changed.
10485 if (!strcmp(attr
->name
, "job-hold-until"))
10487 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-hold-until to %s",
10488 attr
->values
[0].string
.text
);
10489 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
10491 if (!strcmp(attr
->values
[0].string
.text
, "no-hold"))
10493 cupsdReleaseJob(job
);
10497 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
,
10498 "Job held by \"%s\".", username
);
10500 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
;
10503 else if (attr
->value_tag
== IPP_TAG_DELETEATTR
)
10506 * Delete the attribute...
10509 if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10510 IPP_TAG_ZERO
)) != NULL
)
10512 if (job
->attrs
->prev
)
10513 job
->attrs
->prev
->next
= attr2
->next
;
10515 job
->attrs
->attrs
= attr2
->next
;
10517 if (attr2
== job
->attrs
->last
)
10518 job
->attrs
->last
= job
->attrs
->prev
;
10520 ippDeleteAttribute(NULL
, attr2
);
10522 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10528 * Add new option by copying it...
10531 ippCopyAttribute(job
->attrs
, attr
, 0);
10533 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10542 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10545 * Send events as needed...
10548 if (event
& CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
)
10549 cupsdAddEvent(CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
,
10550 cupsdFindDest(job
->dest
), job
,
10551 "Job priority changed by user.");
10553 if (event
& CUPSD_EVENT_JOB_STATE
)
10554 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
10555 job
->state_value
== IPP_JOB_HELD
?
10556 "Job held by user." : "Job restarted by user.");
10558 if (event
& CUPSD_EVENT_JOB_CONFIG_CHANGED
)
10559 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
10560 "Job options changed by user.");
10563 * Start jobs if possible...
10572 * 'set_printer_attrs()' - Set printer attributes.
10576 set_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
10577 ipp_attribute_t
*uri
) /* I - Printer */
10579 http_status_t status
; /* Policy status */
10580 cups_ptype_t dtype
; /* Destination type (printer/class) */
10581 cupsd_printer_t
*printer
; /* Printer/class */
10582 ipp_attribute_t
*attr
; /* Printer attribute */
10583 int changed
= 0; /* Was anything changed? */
10586 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_attrs(%p[%d], %s)", con
,
10587 con
->number
, uri
->values
[0].string
.text
);
10590 * Is the destination valid?
10593 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10599 send_ipp_status(con
, IPP_NOT_FOUND
,
10600 _("The printer or class does not exist."));
10608 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10610 send_http_error(con
, status
, printer
);
10615 * Return a list of attributes that can be set via Set-Printer-Attributes.
10618 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
10619 IPP_TAG_TEXT
)) != NULL
)
10621 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
10625 if ((attr
= ippFindAttribute(con
->request
, "printer-geo-location", IPP_TAG_URI
)) != NULL
&& !strncmp(attr
->values
[0].string
.text
, "geo:", 4))
10627 cupsdSetString(&printer
->geo_location
, attr
->values
[0].string
.text
);
10631 if ((attr
= ippFindAttribute(con
->request
, "printer-organization", IPP_TAG_TEXT
)) != NULL
)
10633 cupsdSetString(&printer
->organization
, attr
->values
[0].string
.text
);
10637 if ((attr
= ippFindAttribute(con
->request
, "printer-organizational-unit", IPP_TAG_TEXT
)) != NULL
)
10639 cupsdSetString(&printer
->organizational_unit
, attr
->values
[0].string
.text
);
10643 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
10644 IPP_TAG_TEXT
)) != NULL
)
10646 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
10651 * Update the printer attributes and return...
10656 printer
->config_time
= time(NULL
);
10658 cupsdSetPrinterAttrs(printer
);
10659 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
10661 cupsdAddEvent(CUPSD_EVENT_PRINTER_CONFIG
, printer
, NULL
,
10662 "Printer \"%s\" description or location changed by \"%s\".",
10663 printer
->name
, get_username(con
));
10665 cupsdLogMessage(CUPSD_LOG_INFO
,
10666 "Printer \"%s\" description or location changed by \"%s\".",
10667 printer
->name
, get_username(con
));
10670 con
->response
->request
.status
.status_code
= IPP_OK
;
10675 * 'set_printer_defaults()' - Set printer default options from a request.
10678 static int /* O - 1 on success, 0 on failure */
10679 set_printer_defaults(
10680 cupsd_client_t
*con
, /* I - Client connection */
10681 cupsd_printer_t
*printer
) /* I - Printer */
10683 int i
; /* Looping var */
10684 ipp_attribute_t
*attr
; /* Current attribute */
10685 size_t namelen
; /* Length of attribute name */
10686 char name
[256], /* New attribute name */
10687 value
[256]; /* String version of integer attrs */
10690 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10693 * Skip non-printer attributes...
10696 if (attr
->group_tag
!= IPP_TAG_PRINTER
|| !attr
->name
)
10699 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_defaults: %s", attr
->name
);
10701 if (!strcmp(attr
->name
, "job-sheets-default"))
10704 * Only allow keywords and names...
10707 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10711 * Only allow job-sheets-default to be set when running without a
10712 * system high classification level...
10715 if (Classification
)
10718 cupsdSetString(&printer
->job_sheets
[0], attr
->values
[0].string
.text
);
10720 if (attr
->num_values
> 1)
10721 cupsdSetString(&printer
->job_sheets
[1], attr
->values
[1].string
.text
);
10723 cupsdSetString(&printer
->job_sheets
[1], "none");
10725 else if (!strcmp(attr
->name
, "requesting-user-name-allowed"))
10727 cupsdFreeStrings(&(printer
->users
));
10729 printer
->deny_users
= 0;
10731 if (attr
->value_tag
== IPP_TAG_NAME
&&
10732 (attr
->num_values
> 1 ||
10733 strcmp(attr
->values
[0].string
.text
, "all")))
10735 for (i
= 0; i
< attr
->num_values
; i
++)
10736 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
10739 else if (!strcmp(attr
->name
, "requesting-user-name-denied"))
10741 cupsdFreeStrings(&(printer
->users
));
10743 printer
->deny_users
= 1;
10745 if (attr
->value_tag
== IPP_TAG_NAME
&&
10746 (attr
->num_values
> 1 ||
10747 strcmp(attr
->values
[0].string
.text
, "none")))
10749 for (i
= 0; i
< attr
->num_values
; i
++)
10750 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
10753 else if (!strcmp(attr
->name
, "job-quota-period"))
10755 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10758 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-quota-period to %d...",
10759 attr
->values
[0].integer
);
10760 cupsdFreeQuotas(printer
);
10762 printer
->quota_period
= attr
->values
[0].integer
;
10764 else if (!strcmp(attr
->name
, "job-k-limit"))
10766 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10769 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-k-limit to %d...",
10770 attr
->values
[0].integer
);
10771 cupsdFreeQuotas(printer
);
10773 printer
->k_limit
= attr
->values
[0].integer
;
10775 else if (!strcmp(attr
->name
, "job-page-limit"))
10777 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10780 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-page-limit to %d...",
10781 attr
->values
[0].integer
);
10782 cupsdFreeQuotas(printer
);
10784 printer
->page_limit
= attr
->values
[0].integer
;
10786 else if (!strcmp(attr
->name
, "printer-op-policy"))
10788 cupsd_policy_t
*p
; /* Policy */
10791 if (attr
->value_tag
!= IPP_TAG_NAME
)
10794 if ((p
= cupsdFindPolicy(attr
->values
[0].string
.text
)) != NULL
)
10796 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10797 "Setting printer-op-policy to \"%s\"...",
10798 attr
->values
[0].string
.text
);
10799 cupsdSetString(&printer
->op_policy
, attr
->values
[0].string
.text
);
10800 printer
->op_policy_ptr
= p
;
10804 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10805 _("Unknown printer-op-policy \"%s\"."),
10806 attr
->values
[0].string
.text
);
10810 else if (!strcmp(attr
->name
, "printer-error-policy"))
10812 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10815 if (strcmp(attr
->values
[0].string
.text
, "retry-current-job") &&
10816 ((printer
->type
& CUPS_PRINTER_CLASS
) ||
10817 (strcmp(attr
->values
[0].string
.text
, "abort-job") &&
10818 strcmp(attr
->values
[0].string
.text
, "retry-job") &&
10819 strcmp(attr
->values
[0].string
.text
, "stop-printer"))))
10821 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10822 _("Unknown printer-error-policy \"%s\"."),
10823 attr
->values
[0].string
.text
);
10827 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10828 "Setting printer-error-policy to \"%s\"...",
10829 attr
->values
[0].string
.text
);
10830 cupsdSetString(&printer
->error_policy
, attr
->values
[0].string
.text
);
10834 * Skip any other non-default attributes...
10837 namelen
= strlen(attr
->name
);
10838 if (namelen
< 9 || strcmp(attr
->name
+ namelen
- 8, "-default") ||
10839 namelen
> (sizeof(name
) - 1) || attr
->num_values
!= 1)
10843 * OK, anything else must be a user-defined default...
10846 strlcpy(name
, attr
->name
, sizeof(name
));
10847 name
[namelen
- 8] = '\0'; /* Strip "-default" */
10849 switch (attr
->value_tag
)
10851 case IPP_TAG_DELETEATTR
:
10852 printer
->num_options
= cupsRemoveOption(name
,
10853 printer
->num_options
,
10854 &(printer
->options
));
10855 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10856 "Deleting %s", attr
->name
);
10859 case IPP_TAG_NAME
:
10860 case IPP_TAG_TEXT
:
10861 case IPP_TAG_KEYWORD
:
10863 printer
->num_options
= cupsAddOption(name
,
10864 attr
->values
[0].string
.text
,
10865 printer
->num_options
,
10866 &(printer
->options
));
10867 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10868 "Setting %s to \"%s\"...", attr
->name
,
10869 attr
->values
[0].string
.text
);
10872 case IPP_TAG_BOOLEAN
:
10873 printer
->num_options
= cupsAddOption(name
,
10874 attr
->values
[0].boolean
?
10876 printer
->num_options
,
10877 &(printer
->options
));
10878 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10879 "Setting %s to %s...", attr
->name
,
10880 attr
->values
[0].boolean
? "true" : "false");
10883 case IPP_TAG_INTEGER
:
10884 case IPP_TAG_ENUM
:
10885 sprintf(value
, "%d", attr
->values
[0].integer
);
10886 printer
->num_options
= cupsAddOption(name
, value
,
10887 printer
->num_options
,
10888 &(printer
->options
));
10889 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10890 "Setting %s to %s...", attr
->name
, value
);
10893 case IPP_TAG_RANGE
:
10894 sprintf(value
, "%d-%d", attr
->values
[0].range
.lower
,
10895 attr
->values
[0].range
.upper
);
10896 printer
->num_options
= cupsAddOption(name
, value
,
10897 printer
->num_options
,
10898 &(printer
->options
));
10899 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10900 "Setting %s to %s...", attr
->name
, value
);
10903 case IPP_TAG_RESOLUTION
:
10904 sprintf(value
, "%dx%d%s", attr
->values
[0].resolution
.xres
,
10905 attr
->values
[0].resolution
.yres
,
10906 attr
->values
[0].resolution
.units
== IPP_RES_PER_INCH
?
10908 printer
->num_options
= cupsAddOption(name
, value
,
10909 printer
->num_options
,
10910 &(printer
->options
));
10911 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10912 "Setting %s to %s...", attr
->name
, value
);
10916 /* Do nothing for other values */
10926 * 'start_printer()' - Start a printer.
10930 start_printer(cupsd_client_t
*con
, /* I - Client connection */
10931 ipp_attribute_t
*uri
) /* I - Printer URI */
10933 int i
; /* Temporary variable */
10934 http_status_t status
; /* Policy status */
10935 cups_ptype_t dtype
; /* Destination type (printer/class) */
10936 cupsd_printer_t
*printer
; /* Printer data */
10939 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_printer(%p[%d], %s)", con
,
10940 con
->number
, uri
->values
[0].string
.text
);
10943 * Is the destination valid?
10946 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10952 send_ipp_status(con
, IPP_NOT_FOUND
,
10953 _("The printer or class does not exist."));
10961 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10963 send_http_error(con
, status
, printer
);
10968 * Start the printer...
10971 printer
->state_message
[0] = '\0';
10973 cupsdStartPrinter(printer
, 1);
10975 if (dtype
& CUPS_PRINTER_CLASS
)
10976 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" started by \"%s\".",
10977 printer
->name
, get_username(con
));
10979 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" started by \"%s\".",
10980 printer
->name
, get_username(con
));
10988 if ((i
= check_quotas(con
, printer
)) < 0)
10990 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
10995 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
11000 * Everything was ok, so return OK status...
11003 con
->response
->request
.status
.status_code
= IPP_OK
;
11008 * 'stop_printer()' - Stop a printer.
11012 stop_printer(cupsd_client_t
*con
, /* I - Client connection */
11013 ipp_attribute_t
*uri
) /* I - Printer URI */
11015 http_status_t status
; /* Policy status */
11016 cups_ptype_t dtype
; /* Destination type (printer/class) */
11017 cupsd_printer_t
*printer
; /* Printer data */
11018 ipp_attribute_t
*attr
; /* printer-state-message attribute */
11021 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "stop_printer(%p[%d], %s)", con
,
11022 con
->number
, uri
->values
[0].string
.text
);
11025 * Is the destination valid?
11028 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11034 send_ipp_status(con
, IPP_NOT_FOUND
,
11035 _("The printer or class does not exist."));
11043 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11045 send_http_error(con
, status
, printer
);
11050 * Stop the printer...
11053 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
11054 IPP_TAG_TEXT
)) == NULL
)
11055 strlcpy(printer
->state_message
, "Paused", sizeof(printer
->state_message
));
11058 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
11059 sizeof(printer
->state_message
));
11062 cupsdStopPrinter(printer
, 1);
11064 if (dtype
& CUPS_PRINTER_CLASS
)
11065 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" stopped by \"%s\".",
11066 printer
->name
, get_username(con
));
11068 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" stopped by \"%s\".",
11069 printer
->name
, get_username(con
));
11072 * Everything was ok, so return OK status...
11075 con
->response
->request
.status
.status_code
= IPP_OK
;
11080 * 'url_encode_attr()' - URL-encode a string attribute.
11084 url_encode_attr(ipp_attribute_t
*attr
, /* I - Attribute */
11085 char *buffer
,/* I - String buffer */
11086 size_t bufsize
)/* I - Size of buffer */
11088 int i
; /* Looping var */
11089 char *bufptr
, /* Pointer into buffer */
11090 *bufend
; /* End of buffer */
11093 strlcpy(buffer
, attr
->name
, bufsize
);
11094 bufptr
= buffer
+ strlen(buffer
);
11095 bufend
= buffer
+ bufsize
- 1;
11097 for (i
= 0; i
< attr
->num_values
; i
++)
11099 if (bufptr
>= bufend
)
11107 if (bufptr
>= bufend
)
11112 bufptr
= url_encode_string(attr
->values
[i
].string
.text
, bufptr
, (size_t)(bufend
- bufptr
+ 1));
11114 if (bufptr
>= bufend
)
11125 * 'url_encode_string()' - URL-encode a string.
11128 static char * /* O - End of string */
11129 url_encode_string(const char *s
, /* I - String */
11130 char *buffer
, /* I - String buffer */
11131 size_t bufsize
) /* I - Size of buffer */
11133 char *bufptr
, /* Pointer into buffer */
11134 *bufend
; /* End of buffer */
11135 static const char *hex
= "0123456789ABCDEF";
11140 bufend
= buffer
+ bufsize
- 1;
11142 while (*s
&& bufptr
< bufend
)
11144 if (*s
== ' ' || *s
== '%' || *s
== '+')
11146 if (bufptr
>= (bufend
- 2))
11150 *bufptr
++ = hex
[(*s
>> 4) & 15];
11151 *bufptr
++ = hex
[*s
& 15];
11155 else if (*s
== '\'' || *s
== '\\')
11157 if (bufptr
>= (bufend
- 1))
11174 * 'user_allowed()' - See if a user is allowed to print to a queue.
11177 static int /* O - 0 if not allowed, 1 if allowed */
11178 user_allowed(cupsd_printer_t
*p
, /* I - Printer or class */
11179 const char *username
) /* I - Username */
11181 struct passwd
*pw
; /* User password data */
11182 char baseuser
[256], /* Base username */
11183 *baseptr
, /* Pointer to "@" in base username */
11184 *name
; /* Current user name */
11187 if (cupsArrayCount(p
->users
) == 0)
11190 if (!strcmp(username
, "root"))
11193 if (strchr(username
, '@'))
11196 * Strip @REALM for username check...
11199 strlcpy(baseuser
, username
, sizeof(baseuser
));
11201 if ((baseptr
= strchr(baseuser
, '@')) != NULL
)
11204 username
= baseuser
;
11207 pw
= getpwnam(username
);
11210 for (name
= (char *)cupsArrayFirst(p
->users
);
11212 name
= (char *)cupsArrayNext(p
->users
))
11214 if (name
[0] == '@')
11217 * Check group membership...
11220 if (cupsdCheckGroup(username
, pw
, name
+ 1))
11223 else if (name
[0] == '#')
11229 if (cupsdCheckGroup(username
, pw
, name
))
11232 else if (!_cups_strcasecmp(username
, name
))
11236 return ((name
!= NULL
) != p
->deny_users
);
11241 * 'validate_job()' - Validate printer options and destination.
11245 validate_job(cupsd_client_t
*con
, /* I - Client connection */
11246 ipp_attribute_t
*uri
) /* I - Printer URI */
11248 http_status_t status
; /* Policy status */
11249 ipp_attribute_t
*attr
; /* Current attribute */
11251 ipp_attribute_t
*auth_info
; /* auth-info attribute */
11252 #endif /* HAVE_SSL */
11253 ipp_attribute_t
*format
, /* Document-format attribute */
11254 *name
; /* Job-name attribute */
11255 cups_ptype_t dtype
; /* Destination type (printer/class) */
11256 char super
[MIME_MAX_SUPER
],
11257 /* Supertype of file */
11258 type
[MIME_MAX_TYPE
];
11259 /* Subtype of file */
11260 cupsd_printer_t
*printer
; /* Printer */
11263 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_job(%p[%d], %s)", con
,
11264 con
->number
, uri
->values
[0].string
.text
);
11267 * OK, see if the client is sending the document compressed - CUPS
11268 * doesn't support compression yet...
11271 if ((attr
= ippFindAttribute(con
->request
, "compression",
11272 IPP_TAG_KEYWORD
)) != NULL
)
11274 if (strcmp(attr
->values
[0].string
.text
, "none")
11276 && strcmp(attr
->values
[0].string
.text
, "gzip")
11277 #endif /* HAVE_LIBZ */
11280 send_ipp_status(con
, IPP_ATTRIBUTES
,
11281 _("Unsupported 'compression' value \"%s\"."),
11282 attr
->values
[0].string
.text
);
11283 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
11284 "compression", NULL
, attr
->values
[0].string
.text
);
11290 * Is it a format we support?
11293 if ((format
= ippFindAttribute(con
->request
, "document-format",
11294 IPP_TAG_MIMETYPE
)) != NULL
)
11296 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%255[^;]",
11299 send_ipp_status(con
, IPP_BAD_REQUEST
,
11300 _("Bad 'document-format' value \"%s\"."),
11301 format
->values
[0].string
.text
);
11305 if ((strcmp(super
, "application") || strcmp(type
, "octet-stream")) &&
11306 !mimeType(MimeDatabase
, super
, type
))
11308 cupsdLogMessage(CUPSD_LOG_INFO
,
11309 "Hint: Do you have the raw file printing rules enabled?");
11310 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
11311 _("Unsupported 'document-format' value \"%s\"."),
11312 format
->values
[0].string
.text
);
11313 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
11314 "document-format", NULL
, format
->values
[0].string
.text
);
11320 * Is the job-name valid?
11323 if ((name
= ippFindAttribute(con
->request
, "job-name", IPP_TAG_ZERO
)) != NULL
)
11325 int bad_name
= 0; /* Is the job-name value bad? */
11327 if ((name
->value_tag
!= IPP_TAG_NAME
&& name
->value_tag
!= IPP_TAG_NAMELANG
) ||
11328 name
->num_values
!= 1)
11335 * Validate that job-name conforms to RFC 5198 (Network Unicode) and
11336 * IPP Everywhere requirements for "name" values...
11339 const unsigned char *nameptr
; /* Pointer into "job-name" attribute */
11341 for (nameptr
= (unsigned char *)name
->values
[0].string
.text
;
11345 if (*nameptr
< ' ' && *nameptr
!= '\t')
11347 else if (*nameptr
== 0x7f)
11349 else if ((*nameptr
& 0xe0) == 0xc0)
11351 if ((nameptr
[1] & 0xc0) != 0x80)
11356 else if ((*nameptr
& 0xf0) == 0xe0)
11358 if ((nameptr
[1] & 0xc0) != 0x80 ||
11359 (nameptr
[2] & 0xc0) != 0x80)
11364 else if ((*nameptr
& 0xf8) == 0xf0)
11366 if ((nameptr
[1] & 0xc0) != 0x80 ||
11367 (nameptr
[2] & 0xc0) != 0x80 ||
11368 (nameptr
[3] & 0xc0) != 0x80)
11373 else if (*nameptr
& 0x80)
11383 if (StrictConformance
)
11385 send_ipp_status(con
, IPP_ATTRIBUTES
,
11386 _("Unsupported 'job-name' value."));
11387 ippCopyAttribute(con
->response
, name
, 0);
11392 cupsdLogMessage(CUPSD_LOG_WARN
,
11393 "Unsupported 'job-name' value, deleting from request.");
11394 ippDeleteAttribute(con
->request
, name
);
11400 * Is the destination valid?
11403 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11409 send_ipp_status(con
, IPP_NOT_FOUND
,
11410 _("The printer or class does not exist."));
11419 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
11420 #endif /* HAVE_SSL */
11422 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11424 send_http_error(con
, status
, printer
);
11427 else if (printer
->num_auth_info_required
== 1 &&
11428 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
11431 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
11435 else if (auth_info
&& !con
->http
->tls
&&
11436 !httpAddrLocalhost(con
->http
->hostaddr
))
11439 * Require encryption of auth-info over non-local connections...
11442 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
11445 #endif /* HAVE_SSL */
11448 * Everything was ok, so return OK status...
11451 con
->response
->request
.status
.status_code
= IPP_OK
;
11456 * 'validate_name()' - Make sure the printer name only contains valid chars.
11459 static int /* O - 0 if name is no good, 1 if good */
11460 validate_name(const char *name
) /* I - Name to check */
11462 const char *ptr
; /* Pointer into name */
11466 * Scan the whole name...
11469 for (ptr
= name
; *ptr
; ptr
++)
11470 if ((*ptr
> 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
11474 * All the characters are good; validate the length, too...
11477 return ((ptr
- name
) < 128);
11482 * 'validate_user()' - Validate the user for the request.
11485 static int /* O - 1 if permitted, 0 otherwise */
11486 validate_user(cupsd_job_t
*job
, /* I - Job */
11487 cupsd_client_t
*con
, /* I - Client connection */
11488 const char *owner
, /* I - Owner of job/resource */
11489 char *username
, /* O - Authenticated username */
11490 size_t userlen
) /* I - Length of username */
11492 cupsd_printer_t
*printer
; /* Printer for job */
11495 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
);
11498 * Validate input...
11501 if (!con
|| !owner
|| !username
|| userlen
<= 0)
11505 * Get the best authenticated username that is available.
11508 strlcpy(username
, get_username(con
), userlen
);
11511 * Check the username against the owner...
11514 printer
= cupsdFindDest(job
->dest
);
11516 return (cupsdCheckPolicy(printer
? printer
->op_policy_ptr
: DefaultPolicyPtr
,
11517 con
, owner
) == HTTP_OK
);