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 * These coded instructions, statements, and computer programs are the
11 * property of Apple Inc. and are protected by Federal copyright
12 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
13 * which should have been included with this file. If this file is
14 * missing or damaged, see the license at "http://www.cups.org/".
18 * Include necessary headers...
22 #include <cups/ppd-private.h>
25 /*# include <ApplicationServices/ApplicationServices.h>
26 extern CFUUIDRef ColorSyncCreateUUIDFromUInt32(unsigned id);
27 # include <CoreFoundation/CoreFoundation.h>*/
28 # ifdef HAVE_MEMBERSHIP_H
29 # include <membership.h>
30 # endif /* HAVE_MEMBERSHIP_H */
31 # ifdef HAVE_MEMBERSHIPPRIV_H
32 # include <membershipPriv.h>
34 extern int mbr_user_name_to_uuid(const char* name
, uuid_t uu
);
35 extern int mbr_group_name_to_uuid(const char* name
, uuid_t uu
);
36 extern int mbr_check_membership_by_id(uuid_t user
, gid_t group
, int* ismember
);
37 # endif /* HAVE_MEMBERSHIPPRIV_H */
38 #endif /* __APPLE__ */
45 static void accept_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
46 static void add_class(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
47 static int add_file(cupsd_client_t
*con
, cupsd_job_t
*job
,
48 mime_type_t
*filetype
, int compression
);
49 static cupsd_job_t
*add_job(cupsd_client_t
*con
, cupsd_printer_t
*printer
,
50 mime_type_t
*filetype
);
51 static void add_job_subscriptions(cupsd_client_t
*con
, cupsd_job_t
*job
);
52 static void add_job_uuid(cupsd_job_t
*job
);
53 static void add_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
54 static void add_printer_state_reasons(cupsd_client_t
*con
,
56 static void add_queued_job_count(cupsd_client_t
*con
, cupsd_printer_t
*p
);
57 static void apply_printer_defaults(cupsd_printer_t
*printer
,
59 static void authenticate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
60 static void cancel_all_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
61 static void cancel_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
62 static void cancel_subscription(cupsd_client_t
*con
, int id
);
63 static int check_rss_recipient(const char *recipient
);
64 static int check_quotas(cupsd_client_t
*con
, cupsd_printer_t
*p
);
65 static void close_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
66 static void copy_attrs(ipp_t
*to
, ipp_t
*from
, cups_array_t
*ra
,
67 ipp_tag_t group
, int quickcopy
,
68 cups_array_t
*exclude
);
69 static int copy_banner(cupsd_client_t
*con
, cupsd_job_t
*job
,
71 static int copy_file(const char *from
, const char *to
, mode_t mode
);
72 static int copy_model(cupsd_client_t
*con
, const char *from
,
74 static void copy_job_attrs(cupsd_client_t
*con
,
76 cups_array_t
*ra
, cups_array_t
*exclude
);
77 static void copy_printer_attrs(cupsd_client_t
*con
,
78 cupsd_printer_t
*printer
,
80 static void copy_subscription_attrs(cupsd_client_t
*con
,
81 cupsd_subscription_t
*sub
,
83 cups_array_t
*exclude
);
84 static void create_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
85 static void create_local_printer(cupsd_client_t
*con
);
86 static cups_array_t
*create_requested_array(ipp_t
*request
);
87 static void create_subscriptions(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
88 static void delete_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
89 static void get_default(cupsd_client_t
*con
);
90 static void get_devices(cupsd_client_t
*con
);
91 static void get_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
92 static void get_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
93 static void get_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
94 static void get_notifications(cupsd_client_t
*con
);
95 static void get_ppd(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
96 static void get_ppds(cupsd_client_t
*con
);
97 static void get_printers(cupsd_client_t
*con
, int type
);
98 static void get_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
99 static void get_printer_supported(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
100 static void get_subscription_attrs(cupsd_client_t
*con
, int sub_id
);
101 static void get_subscriptions(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
102 static const char *get_username(cupsd_client_t
*con
);
103 static void hold_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
104 static void hold_new_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
105 static void move_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
106 static int ppd_parse_line(const char *line
, char *option
, int olen
,
107 char *choice
, int clen
);
108 static void print_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
109 static void read_job_ticket(cupsd_client_t
*con
);
110 static void reject_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
111 static void release_held_new_jobs(cupsd_client_t
*con
,
112 ipp_attribute_t
*uri
);
113 static void release_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
114 static void renew_subscription(cupsd_client_t
*con
, int sub_id
);
115 static void restart_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
116 static void save_auth_info(cupsd_client_t
*con
, cupsd_job_t
*job
,
117 ipp_attribute_t
*auth_info
);
118 static void send_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
119 static void send_http_error(cupsd_client_t
*con
, http_status_t status
,
120 cupsd_printer_t
*printer
);
121 static void send_ipp_status(cupsd_client_t
*con
, ipp_status_t status
,
122 const char *message
, ...)
123 __attribute__((__format__(__printf__
, 3, 4)));
124 static void set_default(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
125 static void set_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
126 static void set_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
127 static int set_printer_defaults(cupsd_client_t
*con
, cupsd_printer_t
*printer
);
128 static void start_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
129 static void stop_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
130 static void url_encode_attr(ipp_attribute_t
*attr
, char *buffer
, size_t bufsize
);
131 static char *url_encode_string(const char *s
, char *buffer
, size_t bufsize
);
132 static int user_allowed(cupsd_printer_t
*p
, const char *username
);
133 static void validate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
134 static int validate_name(const char *name
);
135 static int validate_user(cupsd_job_t
*job
, cupsd_client_t
*con
, const char *owner
, char *username
, size_t userlen
);
139 * 'cupsdProcessIPPRequest()' - Process an incoming IPP request.
142 int /* O - 1 on success, 0 on failure */
143 cupsdProcessIPPRequest(
144 cupsd_client_t
*con
) /* I - Client connection */
146 ipp_tag_t group
; /* Current group tag */
147 ipp_attribute_t
*attr
; /* Current attribute */
148 ipp_attribute_t
*charset
; /* Character set attribute */
149 ipp_attribute_t
*language
; /* Language attribute */
150 ipp_attribute_t
*uri
= NULL
; /* Printer or job URI attribute */
151 ipp_attribute_t
*username
; /* requesting-user-name attr */
152 int sub_id
; /* Subscription ID */
155 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
));
157 if (LogLevel
>= CUPSD_LOG_DEBUG2
)
159 for (group
= IPP_TAG_ZERO
, attr
= ippFirstAttribute(con
->request
); attr
; attr
= ippNextAttribute(con
->request
))
161 const char *name
; /* Attribute name */
162 char value
[1024]; /* Attribute value */
164 if (group
!= ippGetGroupTag(attr
))
166 group
= ippGetGroupTag(attr
);
167 if (group
!= IPP_TAG_ZERO
)
168 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdProcessIPPRequest: %s", ippTagString(group
));
171 if ((name
= ippGetName(attr
)) == NULL
)
174 ippAttributeString(attr
, value
, sizeof(value
));
176 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdProcessIPPRequest: %s %s%s '%s'", name
, ippGetCount(attr
) > 1 ? "1setOf " : "", ippTagString(ippGetValueTag(attr
)), value
);
181 * First build an empty response message for this request...
184 con
->response
= ippNew();
186 con
->response
->request
.status
.version
[0] =
187 con
->request
->request
.op
.version
[0];
188 con
->response
->request
.status
.version
[1] =
189 con
->request
->request
.op
.version
[1];
190 con
->response
->request
.status
.request_id
=
191 con
->request
->request
.op
.request_id
;
194 * Then validate the request header and required attributes...
197 if (con
->request
->request
.any
.version
[0] != 1 &&
198 con
->request
->request
.any
.version
[0] != 2)
201 * Return an error, since we only support IPP 1.x and 2.x.
204 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
205 "%04X %s Bad request version number %d.%d",
206 IPP_VERSION_NOT_SUPPORTED
, con
->http
->hostname
,
207 con
->request
->request
.any
.version
[0],
208 con
->request
->request
.any
.version
[1]);
210 send_ipp_status(con
, IPP_VERSION_NOT_SUPPORTED
,
211 _("Bad request version number %d.%d."),
212 con
->request
->request
.any
.version
[0],
213 con
->request
->request
.any
.version
[1]);
215 else if (con
->request
->request
.any
.request_id
< 1)
218 * Return an error, since request IDs must be between 1 and 2^31-1
221 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
222 "%04X %s Bad request ID %d",
223 IPP_BAD_REQUEST
, con
->http
->hostname
,
224 con
->request
->request
.any
.request_id
);
226 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad request ID %d."),
227 con
->request
->request
.any
.request_id
);
229 else if (!con
->request
->attrs
)
231 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
232 "%04X %s No attributes in request",
233 IPP_BAD_REQUEST
, con
->http
->hostname
);
235 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No attributes in request."));
240 * Make sure that the attributes are provided in the correct order and
241 * don't repeat groups...
244 for (attr
= con
->request
->attrs
, group
= attr
->group_tag
;
247 if (attr
->group_tag
< group
&& attr
->group_tag
!= IPP_TAG_ZERO
)
250 * Out of order; return an error...
253 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
254 "%04X %s Attribute groups are out of order",
255 IPP_BAD_REQUEST
, con
->http
->hostname
);
257 send_ipp_status(con
, IPP_BAD_REQUEST
,
258 _("Attribute groups are out of order (%x < %x)."),
259 attr
->group_tag
, group
);
263 group
= attr
->group_tag
;
268 * Then make sure that the first three attributes are:
271 * attributes-natural-language
272 * printer-uri/job-uri
275 attr
= con
->request
->attrs
;
276 if (attr
&& attr
->name
&&
277 !strcmp(attr
->name
, "attributes-charset") &&
278 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_CHARSET
)
286 if (attr
&& attr
->name
&&
287 !strcmp(attr
->name
, "attributes-natural-language") &&
288 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_LANGUAGE
)
293 * Reset language for this request if different from Accept-Language.
296 if (!con
->language
||
297 strcmp(attr
->values
[0].string
.text
, con
->language
->language
))
299 cupsLangFree(con
->language
);
300 con
->language
= cupsLangGet(attr
->values
[0].string
.text
);
306 if ((attr
= ippFindAttribute(con
->request
, "printer-uri",
307 IPP_TAG_URI
)) != NULL
)
309 else if ((attr
= ippFindAttribute(con
->request
, "job-uri",
310 IPP_TAG_URI
)) != NULL
)
312 else if (con
->request
->request
.op
.operation_id
== CUPS_GET_PPD
)
313 uri
= ippFindAttribute(con
->request
, "ppd-name", IPP_TAG_NAME
);
318 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
319 "attributes-charset", NULL
,
320 charset
->values
[0].string
.text
);
322 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
323 "attributes-charset", NULL
, "utf-8");
326 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
327 "attributes-natural-language", NULL
,
328 language
->values
[0].string
.text
);
330 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
331 "attributes-natural-language", NULL
, DefaultLanguage
);
334 _cups_strcasecmp(charset
->values
[0].string
.text
, "us-ascii") &&
335 _cups_strcasecmp(charset
->values
[0].string
.text
, "utf-8"))
338 * Bad character set...
341 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unsupported character set \"%s\"",
342 charset
->values
[0].string
.text
);
343 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
344 "%04X %s Unsupported attributes-charset value \"%s\"",
345 IPP_CHARSET
, con
->http
->hostname
,
346 charset
->values
[0].string
.text
);
347 send_ipp_status(con
, IPP_BAD_REQUEST
,
348 _("Unsupported character set \"%s\"."),
349 charset
->values
[0].string
.text
);
351 else if (!charset
|| !language
||
353 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEFAULT
&&
354 con
->request
->request
.op
.operation_id
!= CUPS_GET_PRINTERS
&&
355 con
->request
->request
.op
.operation_id
!= CUPS_GET_CLASSES
&&
356 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEVICES
&&
357 con
->request
->request
.op
.operation_id
!= CUPS_GET_PPDS
))
360 * Return an error, since attributes-charset,
361 * attributes-natural-language, and printer-uri/job-uri are required
362 * for all operations.
367 cupsdLogMessage(CUPSD_LOG_ERROR
,
368 "Missing attributes-charset attribute");
370 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
371 "%04X %s Missing attributes-charset attribute",
372 IPP_BAD_REQUEST
, con
->http
->hostname
);
377 cupsdLogMessage(CUPSD_LOG_ERROR
,
378 "Missing attributes-natural-language attribute");
380 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
381 "%04X %s Missing attributes-natural-language attribute",
382 IPP_BAD_REQUEST
, con
->http
->hostname
);
387 cupsdLogMessage(CUPSD_LOG_ERROR
,
388 "Missing printer-uri, job-uri, or ppd-name "
391 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
392 "%04X %s Missing printer-uri, job-uri, or ppd-name "
393 "attribute", IPP_BAD_REQUEST
, con
->http
->hostname
);
396 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Request attributes follow...");
398 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
399 cupsdLogMessage(CUPSD_LOG_DEBUG
,
400 "attr \"%s\": group_tag = %x, value_tag = %x",
401 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
404 cupsdLogMessage(CUPSD_LOG_DEBUG
, "End of attributes...");
406 send_ipp_status(con
, IPP_BAD_REQUEST
,
407 _("Missing required attributes."));
412 * OK, all the checks pass so far; make sure requesting-user-name is
413 * not "root" from a remote host...
416 if ((username
= ippFindAttribute(con
->request
, "requesting-user-name",
417 IPP_TAG_NAME
)) != NULL
)
420 * Check for root user...
423 if (!strcmp(username
->values
[0].string
.text
, "root") &&
424 _cups_strcasecmp(con
->http
->hostname
, "localhost") &&
425 strcmp(con
->username
, "root"))
428 * Remote unauthenticated user masquerading as local root...
431 ippSetString(con
->request
, &username
, 0, RemoteRoot
);
435 if ((attr
= ippFindAttribute(con
->request
, "notify-subscription-id",
436 IPP_TAG_INTEGER
)) != NULL
)
437 sub_id
= attr
->values
[0].integer
;
442 * Then try processing the operation...
446 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s",
447 ippOpString(con
->request
->request
.op
.operation_id
),
448 uri
->values
[0].string
.text
);
450 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s",
451 ippOpString(con
->request
->request
.op
.operation_id
));
453 switch (con
->request
->request
.op
.operation_id
)
455 case IPP_OP_PRINT_JOB
:
459 case IPP_OP_VALIDATE_JOB
:
460 validate_job(con
, uri
);
463 case IPP_OP_CREATE_JOB
:
464 create_job(con
, uri
);
467 case IPP_OP_SEND_DOCUMENT
:
468 send_document(con
, uri
);
471 case IPP_OP_CANCEL_JOB
:
472 cancel_job(con
, uri
);
475 case IPP_OP_GET_JOB_ATTRIBUTES
:
476 get_job_attrs(con
, uri
);
479 case IPP_OP_GET_JOBS
:
483 case IPP_OP_GET_PRINTER_ATTRIBUTES
:
484 get_printer_attrs(con
, uri
);
487 case IPP_OP_GET_PRINTER_SUPPORTED_VALUES
:
488 get_printer_supported(con
, uri
);
491 case IPP_OP_HOLD_JOB
:
495 case IPP_OP_RELEASE_JOB
:
496 release_job(con
, uri
);
499 case IPP_OP_RESTART_JOB
:
500 restart_job(con
, uri
);
503 case IPP_OP_PAUSE_PRINTER
:
504 stop_printer(con
, uri
);
507 case IPP_OP_RESUME_PRINTER
:
508 start_printer(con
, uri
);
511 case IPP_OP_PURGE_JOBS
:
512 case IPP_OP_CANCEL_JOBS
:
513 case IPP_OP_CANCEL_MY_JOBS
:
514 cancel_all_jobs(con
, uri
);
517 case IPP_OP_SET_JOB_ATTRIBUTES
:
518 set_job_attrs(con
, uri
);
521 case IPP_OP_SET_PRINTER_ATTRIBUTES
:
522 set_printer_attrs(con
, uri
);
525 case IPP_OP_HOLD_NEW_JOBS
:
526 hold_new_jobs(con
, uri
);
529 case IPP_OP_RELEASE_HELD_NEW_JOBS
:
530 release_held_new_jobs(con
, uri
);
533 case IPP_OP_CLOSE_JOB
:
537 case IPP_OP_CUPS_GET_DEFAULT
:
541 case IPP_OP_CUPS_GET_PRINTERS
:
542 get_printers(con
, 0);
545 case IPP_OP_CUPS_GET_CLASSES
:
546 get_printers(con
, CUPS_PRINTER_CLASS
);
549 case IPP_OP_CUPS_ADD_MODIFY_PRINTER
:
550 add_printer(con
, uri
);
553 case IPP_OP_CUPS_DELETE_PRINTER
:
554 delete_printer(con
, uri
);
557 case IPP_OP_CUPS_ADD_MODIFY_CLASS
:
561 case IPP_OP_CUPS_DELETE_CLASS
:
562 delete_printer(con
, uri
);
565 case IPP_OP_CUPS_ACCEPT_JOBS
:
566 case IPP_OP_ENABLE_PRINTER
:
567 accept_jobs(con
, uri
);
570 case IPP_OP_CUPS_REJECT_JOBS
:
571 case IPP_OP_DISABLE_PRINTER
:
572 reject_jobs(con
, uri
);
575 case IPP_OP_CUPS_SET_DEFAULT
:
576 set_default(con
, uri
);
579 case IPP_OP_CUPS_GET_DEVICES
:
583 case IPP_OP_CUPS_GET_DOCUMENT
:
584 get_document(con
, uri
);
587 case IPP_OP_CUPS_GET_PPD
:
591 case IPP_OP_CUPS_GET_PPDS
:
595 case IPP_OP_CUPS_MOVE_JOB
:
599 case IPP_OP_CUPS_AUTHENTICATE_JOB
:
600 authenticate_job(con
, uri
);
603 case IPP_OP_CREATE_PRINTER_SUBSCRIPTIONS
:
604 case IPP_OP_CREATE_JOB_SUBSCRIPTIONS
:
605 create_subscriptions(con
, uri
);
608 case IPP_OP_GET_SUBSCRIPTION_ATTRIBUTES
:
609 get_subscription_attrs(con
, sub_id
);
612 case IPP_OP_GET_SUBSCRIPTIONS
:
613 get_subscriptions(con
, uri
);
616 case IPP_OP_RENEW_SUBSCRIPTION
:
617 renew_subscription(con
, sub_id
);
620 case IPP_OP_CANCEL_SUBSCRIPTION
:
621 cancel_subscription(con
, sub_id
);
624 case IPP_OP_GET_NOTIFICATIONS
:
625 get_notifications(con
);
628 case IPP_OP_CUPS_CREATE_LOCAL_PRINTER
:
629 create_local_printer(con
);
633 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
634 "%04X %s Operation %04X (%s) not supported",
635 IPP_OPERATION_NOT_SUPPORTED
, con
->http
->hostname
,
636 con
->request
->request
.op
.operation_id
,
637 ippOpString(con
->request
->request
.op
.operation_id
));
639 send_ipp_status(con
, IPP_OPERATION_NOT_SUPPORTED
,
640 _("%s not supported."),
642 con
->request
->request
.op
.operation_id
));
652 * Sending data from the scheduler...
655 cupsdLogMessage(con
->response
->request
.status
.status_code
656 >= IPP_BAD_REQUEST
&&
657 con
->response
->request
.status
.status_code
658 != IPP_NOT_FOUND
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
659 "[Client %d] Returning IPP %s for %s (%s) from %s",
661 ippErrorString(con
->response
->request
.status
.status_code
),
662 ippOpString(con
->request
->request
.op
.operation_id
),
663 uri
? uri
->values
[0].string
.text
: "no URI",
664 con
->http
->hostname
);
666 httpClearFields(con
->http
);
668 #ifdef CUPSD_USE_CHUNKING
670 * Because older versions of CUPS (1.1.17 and older) and some IPP
671 * clients do not implement chunking properly, we cannot use
672 * chunking by default. This may become the default in future
673 * CUPS releases, or we might add a configuration directive for
677 if (con
->http
->version
== HTTP_1_1
)
679 cupsdLogMessage(CUPSD_LOG_DEBUG
,
680 "[Client %d] Transfer-Encoding: chunked",
683 cupsdSetLength(con
->http
, 0);
686 #endif /* CUPSD_USE_CHUNKING */
688 size_t length
; /* Length of response */
691 length
= ippLength(con
->response
);
693 if (con
->file
>= 0 && !con
->pipe_pid
)
695 struct stat fileinfo
; /* File information */
697 if (!fstat(con
->file
, &fileinfo
))
698 length
+= (size_t)fileinfo
.st_size
;
701 cupsdLogMessage(CUPSD_LOG_DEBUG
,
702 "[Client %d] Content-Length: " CUPS_LLFMT
,
703 con
->number
, CUPS_LLCAST length
);
704 httpSetLength(con
->http
, length
);
707 if (cupsdSendHeader(con
, HTTP_OK
, "application/ipp", CUPSD_AUTH_NONE
))
710 * Tell the caller the response header was sent successfully...
713 cupsdAddSelect(httpGetFd(con
->http
), (cupsd_selfunc_t
)cupsdReadClient
,
714 (cupsd_selfunc_t
)cupsdWriteClient
, con
);
721 * Tell the caller the response header could not be sent...
730 * Sending data from a subprocess like cups-deviced; tell the caller
731 * everything is A-OK so far...
740 * 'cupsdTimeoutJob()' - Timeout a job waiting on job files.
743 int /* O - 0 on success, -1 on error */
744 cupsdTimeoutJob(cupsd_job_t
*job
) /* I - Job to timeout */
746 cupsd_printer_t
*printer
; /* Destination printer or class */
747 ipp_attribute_t
*attr
; /* job-sheets attribute */
748 int kbytes
; /* Kilobytes in banner */
751 job
->pending_timeout
= 0;
754 * See if we need to add the ending sheet...
757 if (!cupsdLoadJob(job
))
760 printer
= cupsdFindDest(job
->dest
);
761 attr
= ippFindAttribute(job
->attrs
, "job-sheets", IPP_TAG_NAME
);
763 if (printer
&& !(printer
->type
& CUPS_PRINTER_REMOTE
) &&
764 attr
&& attr
->num_values
> 1)
770 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding end banner page \"%s\".",
771 attr
->values
[1].string
.text
);
773 if ((kbytes
= copy_banner(NULL
, job
, attr
->values
[1].string
.text
)) < 0)
776 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
784 * 'accept_jobs()' - Accept print jobs to a printer.
788 accept_jobs(cupsd_client_t
*con
, /* I - Client connection */
789 ipp_attribute_t
*uri
) /* I - Printer or class URI */
791 http_status_t status
; /* Policy status */
792 cups_ptype_t dtype
; /* Destination type (printer/class) */
793 cupsd_printer_t
*printer
; /* Printer data */
796 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "accept_jobs(%p[%d], %s)", con
,
797 con
->number
, uri
->values
[0].string
.text
);
800 * Is the destination valid?
803 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
809 send_ipp_status(con
, IPP_NOT_FOUND
,
810 _("The printer or class does not exist."));
818 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
820 send_http_error(con
, status
, printer
);
825 * Accept jobs sent to the printer...
828 printer
->accepting
= 1;
829 printer
->state_message
[0] = '\0';
831 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
832 "Now accepting jobs.");
834 if (dtype
& CUPS_PRINTER_CLASS
)
836 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
838 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" now accepting jobs (\"%s\").",
839 printer
->name
, get_username(con
));
843 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
845 cupsdLogMessage(CUPSD_LOG_INFO
,
846 "Printer \"%s\" now accepting jobs (\"%s\").",
847 printer
->name
, get_username(con
));
851 * Everything was ok, so return OK status...
854 con
->response
->request
.status
.status_code
= IPP_OK
;
859 * 'add_class()' - Add a class to the system.
863 add_class(cupsd_client_t
*con
, /* I - Client connection */
864 ipp_attribute_t
*uri
) /* I - URI of class */
866 http_status_t status
; /* Policy status */
867 int i
; /* Looping var */
868 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
869 username
[HTTP_MAX_URI
], /* Username portion of URI */
870 host
[HTTP_MAX_URI
], /* Host portion of URI */
871 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
872 int port
; /* Port portion of URI */
873 cupsd_printer_t
*pclass
, /* Class */
874 *member
; /* Member printer/class */
875 cups_ptype_t dtype
; /* Destination type */
876 ipp_attribute_t
*attr
; /* Printer attribute */
877 int modify
; /* Non-zero if we just modified */
878 int need_restart_job
; /* Need to restart job? */
881 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_class(%p[%d], %s)", con
,
882 con
->number
, uri
->values
[0].string
.text
);
885 * Do we have a valid URI?
888 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
889 sizeof(scheme
), username
, sizeof(username
), host
,
890 sizeof(host
), &port
, resource
, sizeof(resource
));
893 if (strncmp(resource
, "/classes/", 9) || strlen(resource
) == 9)
896 * No, return an error...
899 send_ipp_status(con
, IPP_BAD_REQUEST
,
900 _("The printer-uri must be of the form "
901 "\"ipp://HOSTNAME/classes/CLASSNAME\"."));
906 * Do we have a valid printer name?
909 if (!validate_name(resource
+ 9))
912 * No, return an error...
915 send_ipp_status(con
, IPP_BAD_REQUEST
,
916 _("The printer-uri \"%s\" contains invalid characters."),
917 uri
->values
[0].string
.text
);
922 * See if the class already exists; if not, create a new class...
925 if ((pclass
= cupsdFindClass(resource
+ 9)) == NULL
)
928 * Class doesn't exist; see if we have a printer of the same name...
931 if ((pclass
= cupsdFindPrinter(resource
+ 9)) != NULL
)
934 * Yes, return an error...
937 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
938 _("A printer named \"%s\" already exists."),
944 * No, check the default policy and then add the class...
947 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
949 send_http_error(con
, status
, NULL
);
953 pclass
= cupsdAddClass(resource
+ 9);
956 else if ((status
= cupsdCheckPolicy(pclass
->op_policy_ptr
, con
,
959 send_http_error(con
, status
, pclass
);
966 * Look for attributes and copy them over as needed...
969 need_restart_job
= 0;
971 if ((attr
= ippFindAttribute(con
->request
, "printer-location", IPP_TAG_TEXT
)) != NULL
)
972 cupsdSetString(&pclass
->location
, attr
->values
[0].string
.text
);
974 if ((attr
= ippFindAttribute(con
->request
, "printer-geo-location", IPP_TAG_URI
)) != NULL
&& !strncmp(attr
->values
[0].string
.text
, "geo:", 4))
975 cupsdSetString(&pclass
->geo_location
, attr
->values
[0].string
.text
);
977 if ((attr
= ippFindAttribute(con
->request
, "printer-organization", IPP_TAG_TEXT
)) != NULL
)
978 cupsdSetString(&pclass
->organization
, attr
->values
[0].string
.text
);
980 if ((attr
= ippFindAttribute(con
->request
, "printer-organizational-unit", IPP_TAG_TEXT
)) != NULL
)
981 cupsdSetString(&pclass
->organizational_unit
, attr
->values
[0].string
.text
);
983 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
984 IPP_TAG_TEXT
)) != NULL
)
985 cupsdSetString(&pclass
->info
, attr
->values
[0].string
.text
);
987 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
988 IPP_TAG_BOOLEAN
)) != NULL
&&
989 attr
->values
[0].boolean
!= pclass
->accepting
)
991 cupsdLogMessage(CUPSD_LOG_INFO
,
992 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
993 pclass
->name
, attr
->values
[0].boolean
, pclass
->accepting
);
995 pclass
->accepting
= attr
->values
[0].boolean
;
997 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s accepting jobs.",
998 pclass
->accepting
? "Now" : "No longer");
1001 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared", IPP_TAG_BOOLEAN
)) != NULL
)
1003 if (pclass
->type
& CUPS_PRINTER_REMOTE
)
1006 * Cannot re-share remote printers.
1009 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Cannot change printer-is-shared for remote queues."));
1011 cupsdDeletePrinter(pclass
, 0);
1016 if (pclass
->shared
&& !ippGetBoolean(attr
, 0))
1017 cupsdDeregisterPrinter(pclass
, 1);
1019 cupsdLogMessage(CUPSD_LOG_INFO
,
1020 "Setting %s printer-is-shared to %d (was %d.)",
1021 pclass
->name
, attr
->values
[0].boolean
, pclass
->shared
);
1023 pclass
->shared
= ippGetBoolean(attr
, 0);
1026 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
1027 IPP_TAG_ENUM
)) != NULL
)
1029 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
1030 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
1032 send_ipp_status(con
, IPP_BAD_REQUEST
,
1033 _("Attempt to set %s printer-state to bad value %d."),
1034 pclass
->name
, attr
->values
[0].integer
);
1036 cupsdDeletePrinter(pclass
, 0);
1041 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
1042 pclass
->name
, attr
->values
[0].integer
, pclass
->state
);
1044 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
1045 cupsdStopPrinter(pclass
, 0);
1048 cupsdSetPrinterState(pclass
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
1049 need_restart_job
= 1;
1052 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
1053 IPP_TAG_TEXT
)) != NULL
)
1055 strlcpy(pclass
->state_message
, attr
->values
[0].string
.text
,
1056 sizeof(pclass
->state_message
));
1058 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s",
1059 pclass
->state_message
);
1061 if ((attr
= ippFindAttribute(con
->request
, "member-uris",
1062 IPP_TAG_URI
)) != NULL
)
1065 * Clear the printer array as needed...
1068 need_restart_job
= 1;
1070 if (pclass
->num_printers
> 0)
1072 free(pclass
->printers
);
1073 pclass
->num_printers
= 0;
1077 * Add each printer or class that is listed...
1080 for (i
= 0; i
< attr
->num_values
; i
++)
1083 * Search for the printer or class URI...
1086 if (!cupsdValidateDest(attr
->values
[i
].string
.text
, &dtype
, &member
))
1092 send_ipp_status(con
, IPP_NOT_FOUND
,
1093 _("The printer or class does not exist."));
1095 cupsdDeletePrinter(pclass
, 0);
1099 else if (dtype
& CUPS_PRINTER_CLASS
)
1101 send_ipp_status(con
, IPP_BAD_REQUEST
,
1102 _("Nested classes are not allowed."));
1104 cupsdDeletePrinter(pclass
, 0);
1110 * Add it to the class...
1113 cupsdAddPrinterToClass(pclass
, member
);
1117 if (!set_printer_defaults(con
, pclass
))
1120 cupsdDeletePrinter(pclass
, 0);
1125 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
1126 IPP_TAG_KEYWORD
)) != NULL
)
1127 cupsdSetAuthInfoRequired(pclass
, NULL
, attr
);
1129 pclass
->config_time
= time(NULL
);
1132 * Update the printer class attributes and return...
1135 cupsdSetPrinterAttrs(pclass
);
1136 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
1138 if (need_restart_job
&& pclass
->job
)
1141 * Reset the current job to a "pending" status...
1144 cupsdSetJobState(pclass
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
1145 "Job restarted because the class was modified.");
1148 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1152 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
1153 pclass
, NULL
, "Class \"%s\" modified by \"%s\".",
1154 pclass
->name
, get_username(con
));
1156 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" modified by \"%s\".",
1157 pclass
->name
, get_username(con
));
1161 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
1162 pclass
, NULL
, "New class \"%s\" added by \"%s\".",
1163 pclass
->name
, get_username(con
));
1165 cupsdLogMessage(CUPSD_LOG_INFO
, "New class \"%s\" added by \"%s\".",
1166 pclass
->name
, get_username(con
));
1169 con
->response
->request
.status
.status_code
= IPP_OK
;
1174 * 'add_file()' - Add a file to a job.
1177 static int /* O - 0 on success, -1 on error */
1178 add_file(cupsd_client_t
*con
, /* I - Connection to client */
1179 cupsd_job_t
*job
, /* I - Job to add to */
1180 mime_type_t
*filetype
, /* I - Type of file */
1181 int compression
) /* I - Compression */
1183 mime_type_t
**filetypes
; /* New filetypes array... */
1184 int *compressions
; /* New compressions array... */
1187 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1188 "add_file(con=%p[%d], job=%d, filetype=%s/%s, "
1189 "compression=%d)", con
, con
? con
->number
: -1, job
->id
,
1190 filetype
->super
, filetype
->type
, compression
);
1193 * Add the file to the job...
1196 if (job
->num_files
== 0)
1198 compressions
= (int *)malloc(sizeof(int));
1199 filetypes
= (mime_type_t
**)malloc(sizeof(mime_type_t
*));
1203 compressions
= (int *)realloc(job
->compressions
,
1204 (size_t)(job
->num_files
+ 1) * sizeof(int));
1205 filetypes
= (mime_type_t
**)realloc(job
->filetypes
,
1206 (size_t)(job
->num_files
+ 1) *
1207 sizeof(mime_type_t
*));
1211 job
->compressions
= compressions
;
1214 job
->filetypes
= filetypes
;
1216 if (!compressions
|| !filetypes
)
1218 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1219 "Job aborted because the scheduler ran out of memory.");
1222 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1223 _("Unable to allocate memory for file types."));
1228 job
->compressions
[job
->num_files
] = compression
;
1229 job
->filetypes
[job
->num_files
] = filetype
;
1234 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1241 * 'add_job()' - Add a job to a print queue.
1244 static cupsd_job_t
* /* O - Job object */
1245 add_job(cupsd_client_t
*con
, /* I - Client connection */
1246 cupsd_printer_t
*printer
, /* I - Destination printer */
1247 mime_type_t
*filetype
) /* I - First print file type, if any */
1249 http_status_t status
; /* Policy status */
1250 ipp_attribute_t
*attr
, /* Current attribute */
1251 *auth_info
; /* auth-info attribute */
1252 const char *mandatory
; /* Current mandatory job attribute */
1253 const char *val
; /* Default option value */
1254 int priority
; /* Job priority */
1255 cupsd_job_t
*job
; /* Current job */
1256 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
1257 int kbytes
; /* Size of print file */
1258 int i
; /* Looping var */
1259 int lowerpagerange
; /* Page range bound */
1260 int exact
; /* Did we have an exact match? */
1261 ipp_attribute_t
*media_col
, /* media-col attribute */
1262 *media_margin
; /* media-*-margin attribute */
1263 ipp_t
*unsup_col
; /* media-col in unsupported response */
1264 static const char * const readonly
[] =/* List of read-only attributes */
1266 "date-time-at-completed",
1267 "date-time-at-creation",
1268 "date-time-at-processing",
1269 "job-detailed-status-messages",
1270 "job-document-access-errors",
1272 "job-impressions-completed",
1273 "job-k-octets-completed",
1274 "job-media-sheets-completed",
1275 "job-pages-completed",
1276 "job-printer-up-time",
1279 "job-state-message",
1280 "job-state-reasons",
1282 "number-of-documents",
1283 "number-of-intervening-jobs",
1284 "output-device-assigned",
1285 "time-at-completed",
1287 "time-at-processing"
1291 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job(%p[%d], %p(%s), %p(%s/%s))",
1292 con
, con
->number
, printer
, printer
->name
,
1293 filetype
, filetype
? filetype
->super
: "none",
1294 filetype
? filetype
->type
: "none");
1297 * Check remote printing to non-shared printer...
1300 if (!printer
->shared
&&
1301 _cups_strcasecmp(con
->http
->hostname
, "localhost") &&
1302 _cups_strcasecmp(con
->http
->hostname
, ServerName
))
1304 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
1305 _("The printer or class is not shared."));
1313 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
1315 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
1317 send_http_error(con
, status
, printer
);
1320 else if (printer
->num_auth_info_required
== 1 &&
1321 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
1324 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
1328 else if (auth_info
&& !con
->http
->tls
&&
1329 !httpAddrLocalhost(con
->http
->hostaddr
))
1332 * Require encryption of auth-info over non-local connections...
1335 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
1338 #endif /* HAVE_SSL */
1341 * See if the printer is accepting jobs...
1344 if (!printer
->accepting
)
1346 send_ipp_status(con
, IPP_NOT_ACCEPTING
,
1347 _("Destination \"%s\" is not accepting jobs."),
1353 * Validate job template attributes; for now just document-format,
1354 * copies, job-sheets, number-up, page-ranges, mandatory attributes, and
1358 for (i
= 0; i
< (int)(sizeof(readonly
) / sizeof(readonly
[0])); i
++)
1360 if ((attr
= ippFindAttribute(con
->request
, readonly
[i
], IPP_TAG_ZERO
)) != NULL
)
1362 ippDeleteAttribute(con
->request
, attr
);
1364 if (StrictConformance
)
1366 send_ipp_status(con
, IPP_BAD_REQUEST
, _("The '%s' Job Status attribute cannot be supplied in a job creation request."), readonly
[i
]);
1370 cupsdLogMessage(CUPSD_LOG_INFO
, "Unexpected '%s' Job Status attribute in a job creation request.", readonly
[i
]);
1376 for (mandatory
= (char *)cupsArrayFirst(printer
->pc
->mandatory
);
1378 mandatory
= (char *)cupsArrayNext(printer
->pc
->mandatory
))
1380 if (!ippFindAttribute(con
->request
, mandatory
, IPP_TAG_ZERO
))
1383 * Missing a required attribute...
1386 send_ipp_status(con
, IPP_CONFLICT
,
1387 _("The \"%s\" attribute is required for print jobs."),
1394 if (filetype
&& printer
->filetypes
&&
1395 !cupsArrayFind(printer
->filetypes
, filetype
))
1397 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
1398 /* MIME media type string */
1401 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
1404 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
1405 _("Unsupported format \"%s\"."), mimetype
);
1407 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
1408 "document-format", NULL
, mimetype
);
1413 if ((attr
= ippFindAttribute(con
->request
, "copies",
1414 IPP_TAG_INTEGER
)) != NULL
)
1416 if (attr
->values
[0].integer
< 1 || attr
->values
[0].integer
> MaxCopies
)
1418 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad copies value %d."),
1419 attr
->values
[0].integer
);
1420 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1421 "copies", attr
->values
[0].integer
);
1426 if ((attr
= ippFindAttribute(con
->request
, "job-sheets",
1427 IPP_TAG_ZERO
)) != NULL
)
1429 if (attr
->value_tag
!= IPP_TAG_KEYWORD
&&
1430 attr
->value_tag
!= IPP_TAG_NAME
)
1432 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value type."));
1436 if (attr
->num_values
> 2)
1438 send_ipp_status(con
, IPP_BAD_REQUEST
,
1439 _("Too many job-sheets values (%d > 2)."),
1444 for (i
= 0; i
< attr
->num_values
; i
++)
1445 if (strcmp(attr
->values
[i
].string
.text
, "none") &&
1446 !cupsdFindBanner(attr
->values
[i
].string
.text
))
1448 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value \"%s\"."),
1449 attr
->values
[i
].string
.text
);
1454 if ((attr
= ippFindAttribute(con
->request
, "number-up",
1455 IPP_TAG_INTEGER
)) != NULL
)
1457 if (attr
->values
[0].integer
!= 1 &&
1458 attr
->values
[0].integer
!= 2 &&
1459 attr
->values
[0].integer
!= 4 &&
1460 attr
->values
[0].integer
!= 6 &&
1461 attr
->values
[0].integer
!= 9 &&
1462 attr
->values
[0].integer
!= 16)
1464 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad number-up value %d."),
1465 attr
->values
[0].integer
);
1466 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1467 "number-up", attr
->values
[0].integer
);
1472 if ((attr
= ippFindAttribute(con
->request
, "page-ranges",
1473 IPP_TAG_RANGE
)) != NULL
)
1475 for (i
= 0, lowerpagerange
= 1; i
< attr
->num_values
; i
++)
1477 if (attr
->values
[i
].range
.lower
< lowerpagerange
||
1478 attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
1480 send_ipp_status(con
, IPP_BAD_REQUEST
,
1481 _("Bad page-ranges values %d-%d."),
1482 attr
->values
[i
].range
.lower
,
1483 attr
->values
[i
].range
.upper
);
1487 lowerpagerange
= attr
->values
[i
].range
.upper
+ 1;
1492 * Do media selection as needed...
1495 if (!ippFindAttribute(con
->request
, "PageRegion", IPP_TAG_ZERO
) &&
1496 !ippFindAttribute(con
->request
, "PageSize", IPP_TAG_ZERO
) &&
1497 _ppdCacheGetPageSize(printer
->pc
, con
->request
, NULL
, &exact
))
1500 (media_col
= ippFindAttribute(con
->request
, "media-col",
1501 IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
1503 send_ipp_status(con
, IPP_OK_SUBST
, _("Unsupported margins."));
1505 unsup_col
= ippNew();
1506 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1507 "media-bottom-margin",
1508 IPP_TAG_INTEGER
)) != NULL
)
1509 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1510 "media-bottom-margin", media_margin
->values
[0].integer
);
1512 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1513 "media-left-margin",
1514 IPP_TAG_INTEGER
)) != NULL
)
1515 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1516 "media-left-margin", media_margin
->values
[0].integer
);
1518 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1519 "media-right-margin",
1520 IPP_TAG_INTEGER
)) != NULL
)
1521 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1522 "media-right-margin", media_margin
->values
[0].integer
);
1524 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1526 IPP_TAG_INTEGER
)) != NULL
)
1527 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1528 "media-top-margin", media_margin
->values
[0].integer
);
1530 ippAddCollection(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, "media-col",
1532 ippDelete(unsup_col
);
1537 * Make sure we aren't over our limit...
1540 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1543 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1545 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Too many active jobs."));
1549 if ((i
= check_quotas(con
, printer
)) < 0)
1551 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
1556 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
1561 * Create the job and set things up...
1564 if ((attr
= ippFindAttribute(con
->request
, "job-priority",
1565 IPP_TAG_INTEGER
)) != NULL
)
1566 priority
= attr
->values
[0].integer
;
1569 if ((val
= cupsGetOption("job-priority", printer
->num_options
,
1570 printer
->options
)) != NULL
)
1571 priority
= atoi(val
);
1575 ippAddInteger(con
->request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-priority",
1579 if ((attr
= ippFindAttribute(con
->request
, "job-name", IPP_TAG_ZERO
)) == NULL
)
1580 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
, "Untitled");
1581 else if ((attr
->value_tag
!= IPP_TAG_NAME
&&
1582 attr
->value_tag
!= IPP_TAG_NAMELANG
) ||
1583 attr
->num_values
!= 1)
1585 send_ipp_status(con
, IPP_ATTRIBUTES
,
1586 _("Bad job-name value: Wrong type or count."));
1587 if ((attr
= ippCopyAttribute(con
->response
, attr
, 0)) != NULL
)
1588 attr
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
1591 else if (!ippValidateAttribute(attr
))
1593 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad job-name value: %s"),
1594 cupsLastErrorString());
1595 if ((attr
= ippCopyAttribute(con
->response
, attr
, 0)) != NULL
)
1596 attr
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
1600 attr
= ippFindAttribute(con
->request
, "requesting-user-name", IPP_TAG_NAME
);
1602 if (attr
&& !ippValidateAttribute(attr
))
1604 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad requesting-user-name value: %s"), cupsLastErrorString());
1605 if ((attr
= ippCopyAttribute(con
->response
, attr
, 0)) != NULL
)
1606 attr
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
1610 if ((job
= cupsdAddJob(priority
, printer
->name
)) == NULL
)
1612 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1613 _("Unable to add job for destination \"%s\"."),
1618 job
->dtype
= printer
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
1619 job
->attrs
= con
->request
;
1621 con
->request
= ippNewRequest(job
->attrs
->request
.op
.operation_id
);
1623 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1626 apply_printer_defaults(printer
, job
);
1628 if (con
->username
[0])
1630 cupsdSetString(&job
->username
, con
->username
);
1633 ippSetString(job
->attrs
, &attr
, 0, con
->username
);
1637 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1638 "add_job: requesting-user-name=\"%s\"",
1639 attr
->values
[0].string
.text
);
1641 cupsdSetString(&job
->username
, attr
->values
[0].string
.text
);
1644 cupsdSetString(&job
->username
, "anonymous");
1647 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1648 "job-originating-user-name", NULL
, job
->username
);
1651 ippSetGroupTag(job
->attrs
, &attr
, IPP_TAG_JOB
);
1652 ippSetName(job
->attrs
, &attr
, "job-originating-user-name");
1655 if (con
->username
[0] || auth_info
)
1657 save_auth_info(con
, job
, auth_info
);
1660 * Remove the auth-info attribute from the attribute data...
1664 ippDeleteAttribute(job
->attrs
, auth_info
);
1667 if ((attr
= ippFindAttribute(con
->request
, "job-name", IPP_TAG_NAME
)) != NULL
)
1668 cupsdSetString(&(job
->name
), attr
->values
[0].string
.text
);
1670 if ((attr
= ippFindAttribute(job
->attrs
, "job-originating-host-name",
1671 IPP_TAG_ZERO
)) != NULL
)
1674 * Request contains a job-originating-host-name attribute; validate it...
1677 if (attr
->value_tag
!= IPP_TAG_NAME
||
1678 attr
->num_values
!= 1 ||
1679 strcmp(con
->http
->hostname
, "localhost"))
1682 * Can't override the value if we aren't connected via localhost.
1683 * Also, we can only have 1 value and it must be a name value.
1686 ippDeleteAttribute(job
->attrs
, attr
);
1687 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-originating-host-name", NULL
, con
->http
->hostname
);
1690 ippSetGroupTag(job
->attrs
, &attr
, IPP_TAG_JOB
);
1695 * No job-originating-host-name attribute, so use the hostname from
1699 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1700 "job-originating-host-name", NULL
, con
->http
->hostname
);
1703 ippAddOutOfBand(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NOVALUE
, "date-time-at-completed");
1704 ippAddDate(job
->attrs
, IPP_TAG_JOB
, "date-time-at-creation", ippTimeToDate(time(NULL
)));
1705 ippAddOutOfBand(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NOVALUE
, "date-time-at-processing");
1706 ippAddOutOfBand(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NOVALUE
, "time-at-completed");
1707 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation", time(NULL
));
1708 ippAddOutOfBand(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NOVALUE
, "time-at-processing");
1711 * Add remaining job attributes...
1714 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1715 job
->state
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_ENUM
,
1716 "job-state", IPP_JOB_STOPPED
);
1717 job
->state_value
= (ipp_jstate_t
)job
->state
->values
[0].integer
;
1718 job
->reasons
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1719 "job-state-reasons", NULL
, "job-incoming");
1720 job
->impressions
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-impressions-completed", 0);
1721 job
->sheets
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1722 "job-media-sheets-completed", 0);
1723 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-printer-uri", NULL
,
1726 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets", IPP_TAG_INTEGER
)) != NULL
)
1727 attr
->values
[0].integer
= 0;
1729 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-k-octets", 0);
1731 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
1732 IPP_TAG_KEYWORD
)) == NULL
)
1733 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
1736 if ((val
= cupsGetOption("job-hold-until", printer
->num_options
,
1737 printer
->options
)) == NULL
)
1740 attr
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1741 "job-hold-until", NULL
, val
);
1744 if (printer
->holding_new_jobs
)
1747 * Hold all new jobs on this printer...
1750 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
1751 cupsdSetJobHoldUntil(job
, ippGetString(attr
, 0, NULL
), 0);
1753 cupsdSetJobHoldUntil(job
, "indefinite", 0);
1755 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1756 job
->state_value
= IPP_JOB_HELD
;
1758 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-held-on-create");
1760 else if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
1763 * Hold job until specified time...
1766 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
1768 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1769 job
->state_value
= IPP_JOB_HELD
;
1771 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-hold-until-specified");
1773 else if (job
->attrs
->request
.op
.operation_id
== IPP_CREATE_JOB
)
1775 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
1776 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1777 job
->state_value
= IPP_JOB_HELD
;
1781 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1782 job
->state_value
= IPP_JOB_PENDING
;
1784 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
1787 if (!(printer
->type
& CUPS_PRINTER_REMOTE
) || Classification
)
1790 * Add job sheets options...
1793 if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1794 IPP_TAG_ZERO
)) == NULL
)
1796 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1797 "Adding default job-sheets values \"%s,%s\"...",
1798 printer
->job_sheets
[0], printer
->job_sheets
[1]);
1800 attr
= ippAddStrings(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-sheets",
1802 ippSetString(job
->attrs
, &attr
, 0, printer
->job_sheets
[0]);
1803 ippSetString(job
->attrs
, &attr
, 1, printer
->job_sheets
[1]);
1806 job
->job_sheets
= attr
;
1809 * Enforce classification level if set...
1814 cupsdLogMessage(CUPSD_LOG_INFO
,
1815 "Classification=\"%s\", ClassifyOverride=%d",
1816 Classification
? Classification
: "(null)",
1819 if (ClassifyOverride
)
1821 if (!strcmp(attr
->values
[0].string
.text
, "none") &&
1822 (attr
->num_values
== 1 ||
1823 !strcmp(attr
->values
[1].string
.text
, "none")))
1826 * Force the leading banner to have the classification on it...
1829 ippSetString(job
->attrs
, &attr
, 0, Classification
);
1831 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1832 "job-sheets=\"%s,none\", "
1833 "job-originating-user-name=\"%s\"",
1834 Classification
, job
->username
);
1836 else if (attr
->num_values
== 2 &&
1837 strcmp(attr
->values
[0].string
.text
,
1838 attr
->values
[1].string
.text
) &&
1839 strcmp(attr
->values
[0].string
.text
, "none") &&
1840 strcmp(attr
->values
[1].string
.text
, "none"))
1843 * Can't put two different security markings on the same document!
1846 ippSetString(job
->attrs
, &attr
, 1, attr
->values
[0].string
.text
);
1848 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1849 "job-sheets=\"%s,%s\", "
1850 "job-originating-user-name=\"%s\"",
1851 attr
->values
[0].string
.text
,
1852 attr
->values
[1].string
.text
, job
->username
);
1854 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1855 strcmp(attr
->values
[0].string
.text
, "none") &&
1856 (attr
->num_values
== 1 ||
1857 (strcmp(attr
->values
[1].string
.text
, Classification
) &&
1858 strcmp(attr
->values
[1].string
.text
, "none"))))
1860 if (attr
->num_values
== 1)
1861 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1862 "CLASSIFICATION OVERRIDDEN "
1863 "job-sheets=\"%s\", "
1864 "job-originating-user-name=\"%s\"",
1865 attr
->values
[0].string
.text
, job
->username
);
1867 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1868 "CLASSIFICATION OVERRIDDEN "
1869 "job-sheets=\"%s,%s\",fffff "
1870 "job-originating-user-name=\"%s\"",
1871 attr
->values
[0].string
.text
,
1872 attr
->values
[1].string
.text
, job
->username
);
1875 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1876 (attr
->num_values
== 1 ||
1877 strcmp(attr
->values
[1].string
.text
, Classification
)))
1880 * Force the banner to have the classification on it...
1883 if (attr
->num_values
> 1 &&
1884 !strcmp(attr
->values
[0].string
.text
, attr
->values
[1].string
.text
))
1886 ippSetString(job
->attrs
, &attr
, 0, Classification
);
1887 ippSetString(job
->attrs
, &attr
, 1, Classification
);
1891 if (attr
->num_values
== 1 ||
1892 strcmp(attr
->values
[0].string
.text
, "none"))
1893 ippSetString(job
->attrs
, &attr
, 0, Classification
);
1895 if (attr
->num_values
> 1 &&
1896 strcmp(attr
->values
[1].string
.text
, "none"))
1897 ippSetString(job
->attrs
, &attr
, 1, Classification
);
1900 if (attr
->num_values
> 1)
1901 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1902 "CLASSIFICATION FORCED "
1903 "job-sheets=\"%s,%s\", "
1904 "job-originating-user-name=\"%s\"",
1905 attr
->values
[0].string
.text
,
1906 attr
->values
[1].string
.text
, job
->username
);
1908 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1909 "CLASSIFICATION FORCED "
1910 "job-sheets=\"%s\", "
1911 "job-originating-user-name=\"%s\"",
1912 Classification
, job
->username
);
1917 * See if we need to add the starting sheet...
1920 if (!(printer
->type
& CUPS_PRINTER_REMOTE
))
1922 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding start banner page \"%s\".",
1923 attr
->values
[0].string
.text
);
1925 if ((kbytes
= copy_banner(con
, job
, attr
->values
[0].string
.text
)) < 0)
1927 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1928 "Aborting job because the start banner could not be "
1933 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
1936 else if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1937 IPP_TAG_ZERO
)) != NULL
)
1938 job
->job_sheets
= attr
;
1941 * Fill in the response info...
1944 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
1945 con
->clientname
, con
->clientport
, "/jobs/%d", job
->id
);
1946 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
1949 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1951 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
1953 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_TEXT
, "job-state-message", NULL
, "");
1954 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons",
1955 NULL
, job
->reasons
->values
[0].string
.text
);
1957 con
->response
->request
.status
.status_code
= IPP_OK
;
1960 * Add any job subscriptions...
1963 add_job_subscriptions(con
, job
);
1966 * Set all but the first two attributes to the job attributes group...
1969 for (attr
= job
->attrs
->attrs
->next
->next
; attr
; attr
= attr
->next
)
1970 attr
->group_tag
= IPP_TAG_JOB
;
1973 * Fire the "job created" event...
1976 cupsdAddEvent(CUPSD_EVENT_JOB_CREATED
, printer
, job
, "Job created.");
1979 * Return the new job...
1987 * 'add_job_subscriptions()' - Add any subscriptions for a job.
1991 add_job_subscriptions(
1992 cupsd_client_t
*con
, /* I - Client connection */
1993 cupsd_job_t
*job
) /* I - Newly created job */
1995 int i
; /* Looping var */
1996 ipp_attribute_t
*prev
, /* Previous attribute */
1997 *next
, /* Next attribute */
1998 *attr
; /* Current attribute */
1999 cupsd_subscription_t
*sub
; /* Subscription object */
2000 const char *recipient
, /* notify-recipient-uri */
2001 *pullmethod
; /* notify-pull-method */
2002 ipp_attribute_t
*user_data
; /* notify-user-data */
2003 int interval
; /* notify-time-interval */
2004 unsigned mask
; /* notify-events */
2008 * Find the first subscription group attribute; return if we have
2012 for (attr
= job
->attrs
->attrs
; attr
; attr
= attr
->next
)
2013 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
2020 * Process the subscription attributes in the request...
2029 mask
= CUPSD_EVENT_NONE
;
2031 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
2033 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
2034 attr
->value_tag
== IPP_TAG_URI
)
2037 * Validate the recipient scheme against the ServerBin/notifier
2041 char notifier
[1024], /* Notifier filename */
2042 scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
2043 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
2044 host
[HTTP_MAX_URI
], /* Host portion of URI */
2045 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2046 int port
; /* Port portion of URI */
2049 recipient
= attr
->values
[0].string
.text
;
2051 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
2052 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
2053 host
, sizeof(host
), &port
,
2054 resource
, sizeof(resource
)) < HTTP_URI_OK
)
2056 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2057 _("Bad notify-recipient-uri \"%s\"."), recipient
);
2058 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2059 "notify-status-code", IPP_URI_SCHEME
);
2063 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
2065 if (access(notifier
, X_OK
))
2067 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2068 _("notify-recipient-uri URI \"%s\" uses unknown "
2069 "scheme."), recipient
);
2070 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2071 "notify-status-code", IPP_URI_SCHEME
);
2075 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
2077 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2078 _("notify-recipient-uri URI \"%s\" is already used."),
2080 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2081 "notify-status-code", IPP_ATTRIBUTES
);
2085 else if (!strcmp(attr
->name
, "notify-pull-method") &&
2086 attr
->value_tag
== IPP_TAG_KEYWORD
)
2088 pullmethod
= attr
->values
[0].string
.text
;
2090 if (strcmp(pullmethod
, "ippget"))
2092 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2093 _("Bad notify-pull-method \"%s\"."), pullmethod
);
2094 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2095 "notify-status-code", IPP_ATTRIBUTES
);
2099 else if (!strcmp(attr
->name
, "notify-charset") &&
2100 attr
->value_tag
== IPP_TAG_CHARSET
&&
2101 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
2102 strcmp(attr
->values
[0].string
.text
, "utf-8"))
2104 send_ipp_status(con
, IPP_CHARSET
,
2105 _("Character set \"%s\" not supported."),
2106 attr
->values
[0].string
.text
);
2109 else if (!strcmp(attr
->name
, "notify-natural-language") &&
2110 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
2111 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
2113 send_ipp_status(con
, IPP_CHARSET
,
2114 _("Language \"%s\" not supported."),
2115 attr
->values
[0].string
.text
);
2118 else if (!strcmp(attr
->name
, "notify-user-data") &&
2119 attr
->value_tag
== IPP_TAG_STRING
)
2121 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
2123 send_ipp_status(con
, IPP_REQUEST_VALUE
,
2124 _("The notify-user-data value is too large "
2125 "(%d > 63 octets)."),
2126 attr
->values
[0].unknown
.length
);
2132 else if (!strcmp(attr
->name
, "notify-events") &&
2133 attr
->value_tag
== IPP_TAG_KEYWORD
)
2135 for (i
= 0; i
< attr
->num_values
; i
++)
2136 mask
|= cupsdEventValue(attr
->values
[i
].string
.text
);
2138 else if (!strcmp(attr
->name
, "notify-lease-duration"))
2140 send_ipp_status(con
, IPP_BAD_REQUEST
,
2141 _("The notify-lease-duration attribute cannot be "
2142 "used with job subscriptions."));
2145 else if (!strcmp(attr
->name
, "notify-time-interval") &&
2146 attr
->value_tag
== IPP_TAG_INTEGER
)
2147 interval
= attr
->values
[0].integer
;
2152 if (!recipient
&& !pullmethod
)
2155 if (mask
== CUPSD_EVENT_NONE
)
2156 mask
= CUPSD_EVENT_JOB_COMPLETED
;
2158 if ((sub
= cupsdAddSubscription(mask
, cupsdFindDest(job
->dest
), job
,
2159 recipient
, 0)) != NULL
)
2161 sub
->interval
= interval
;
2163 cupsdSetString(&sub
->owner
, job
->username
);
2167 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
2168 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
2169 (size_t)sub
->user_data_len
);
2172 ippAddSeparator(con
->response
);
2173 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
2174 "notify-subscription-id", sub
->id
);
2176 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
2184 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
2187 * Remove all of the subscription attributes from the job request...
2189 * TODO: Optimize this since subscription groups have to come at the
2190 * end of the request...
2193 for (attr
= job
->attrs
->attrs
, prev
= NULL
; attr
; attr
= next
)
2197 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
||
2198 attr
->group_tag
== IPP_TAG_ZERO
)
2201 * Free and remove this attribute...
2204 ippDeleteAttribute(NULL
, attr
);
2209 job
->attrs
->attrs
= next
;
2215 job
->attrs
->last
= prev
;
2216 job
->attrs
->current
= prev
;
2221 * 'add_job_uuid()' - Add job-uuid attribute to a job.
2223 * See RFC 4122 for the definition of UUIDs and the format.
2227 add_job_uuid(cupsd_job_t
*job
) /* I - Job */
2229 char uuid
[64]; /* job-uuid string */
2233 * Add a job-uuid attribute if none exists...
2236 if (!ippFindAttribute(job
->attrs
, "job-uuid", IPP_TAG_URI
))
2237 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uuid", NULL
,
2238 httpAssembleUUID(ServerName
, RemotePort
, job
->dest
, job
->id
,
2239 uuid
, sizeof(uuid
)));
2244 * 'add_printer()' - Add a printer to the system.
2248 add_printer(cupsd_client_t
*con
, /* I - Client connection */
2249 ipp_attribute_t
*uri
) /* I - URI of printer */
2251 http_status_t status
; /* Policy status */
2252 int i
; /* Looping var */
2253 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
2254 username
[HTTP_MAX_URI
], /* Username portion of URI */
2255 host
[HTTP_MAX_URI
], /* Host portion of URI */
2256 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2257 int port
; /* Port portion of URI */
2258 cupsd_printer_t
*printer
; /* Printer/class */
2259 ipp_attribute_t
*attr
; /* Printer attribute */
2260 cups_file_t
*fp
; /* Script/PPD file */
2261 char line
[1024]; /* Line from file... */
2262 char srcfile
[1024], /* Source Script/PPD file */
2263 dstfile
[1024]; /* Destination Script/PPD file */
2264 int modify
; /* Non-zero if we are modifying */
2265 int changed_driver
, /* Changed the PPD? */
2266 need_restart_job
, /* Need to restart job? */
2267 set_device_uri
, /* Did we set the device URI? */
2268 set_port_monitor
; /* Did we set the port monitor? */
2271 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer(%p[%d], %s)", con
,
2272 con
->number
, uri
->values
[0].string
.text
);
2275 * Do we have a valid URI?
2278 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
2279 sizeof(scheme
), username
, sizeof(username
), host
,
2280 sizeof(host
), &port
, resource
, sizeof(resource
));
2282 if (strncmp(resource
, "/printers/", 10) || strlen(resource
) == 10)
2285 * No, return an error...
2288 send_ipp_status(con
, IPP_BAD_REQUEST
,
2289 _("The printer-uri must be of the form "
2290 "\"ipp://HOSTNAME/printers/PRINTERNAME\"."));
2295 * Do we have a valid printer name?
2298 if (!validate_name(resource
+ 10))
2301 * No, return an error...
2304 send_ipp_status(con
, IPP_BAD_REQUEST
,
2305 _("The printer-uri \"%s\" contains invalid characters."),
2306 uri
->values
[0].string
.text
);
2311 * See if the printer already exists; if not, create a new printer...
2314 if ((printer
= cupsdFindPrinter(resource
+ 10)) == NULL
)
2317 * Printer doesn't exist; see if we have a class of the same name...
2320 if ((printer
= cupsdFindClass(resource
+ 10)) != NULL
)
2323 * Yes, return an error...
2326 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2327 _("A class named \"%s\" already exists."),
2333 * No, check the default policy then add the printer...
2336 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2338 send_http_error(con
, status
, NULL
);
2342 printer
= cupsdAddPrinter(resource
+ 10);
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 cupsdSetPrinterAttrs(printer
);
2845 if (!printer
->temporary
)
2846 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2848 if (need_restart_job
&& printer
->job
)
2851 * Restart the current job...
2854 cupsdSetJobState(printer
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
2855 "Job restarted because the printer was modified.");
2858 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2862 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
2863 printer
, NULL
, "Printer \"%s\" modified by \"%s\".",
2864 printer
->name
, get_username(con
));
2866 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" modified by \"%s\".",
2867 printer
->name
, get_username(con
));
2871 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
2872 printer
, NULL
, "New printer \"%s\" added by \"%s\".",
2873 printer
->name
, get_username(con
));
2875 cupsdLogMessage(CUPSD_LOG_INFO
, "New printer \"%s\" added by \"%s\".",
2876 printer
->name
, get_username(con
));
2879 con
->response
->request
.status
.status_code
= IPP_OK
;
2884 * 'add_printer_state_reasons()' - Add the "printer-state-reasons" attribute
2885 * based upon the printer state...
2889 add_printer_state_reasons(
2890 cupsd_client_t
*con
, /* I - Client connection */
2891 cupsd_printer_t
*p
) /* I - Printer info */
2893 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2894 "add_printer_state_reasons(%p[%d], %p[%s])",
2895 con
, con
->number
, p
, p
->name
);
2897 if (p
->num_reasons
== 0)
2898 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2899 "printer-state-reasons", NULL
, "none");
2901 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2902 "printer-state-reasons", p
->num_reasons
, NULL
,
2903 (const char * const *)p
->reasons
);
2908 * 'add_queued_job_count()' - Add the "queued-job-count" attribute for
2909 * the specified printer or class.
2913 add_queued_job_count(
2914 cupsd_client_t
*con
, /* I - Client connection */
2915 cupsd_printer_t
*p
) /* I - Printer or class */
2917 int count
; /* Number of jobs on destination */
2920 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_queued_job_count(%p[%d], %p[%s])",
2921 con
, con
->number
, p
, p
->name
);
2923 count
= cupsdGetPrinterJobCount(p
->name
);
2925 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2926 "queued-job-count", count
);
2931 * 'apply_printer_defaults()' - Apply printer default options to a job.
2935 apply_printer_defaults(
2936 cupsd_printer_t
*printer
, /* I - Printer */
2937 cupsd_job_t
*job
) /* I - Job */
2939 int i
, /* Looping var */
2940 num_options
; /* Number of default options */
2941 cups_option_t
*options
, /* Default options */
2942 *option
; /* Current option */
2945 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Applying default options...");
2948 * Collect all of the default options and add the missing ones to the
2952 for (i
= printer
->num_options
, num_options
= 0, options
= NULL
,
2953 option
= printer
->options
;
2956 if (!ippFindAttribute(job
->attrs
, option
->name
, IPP_TAG_ZERO
))
2958 if (!strcmp(option
->name
, "print-quality") && ippFindAttribute(job
->attrs
, "cupsPrintQuality", IPP_TAG_NAME
))
2959 continue; /* Don't override cupsPrintQuality */
2961 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Adding default %s=%s", option
->name
, option
->value
);
2963 num_options
= cupsAddOption(option
->name
, option
->value
, num_options
, &options
);
2967 * Encode these options as attributes in the job object...
2970 cupsEncodeOptions2(job
->attrs
, num_options
, options
, IPP_TAG_JOB
);
2971 cupsFreeOptions(num_options
, options
);
2976 * 'authenticate_job()' - Set job authentication info.
2980 authenticate_job(cupsd_client_t
*con
, /* I - Client connection */
2981 ipp_attribute_t
*uri
) /* I - Job URI */
2983 ipp_attribute_t
*attr
, /* job-id attribute */
2984 *auth_info
; /* auth-info attribute */
2985 int jobid
; /* Job ID */
2986 cupsd_job_t
*job
; /* Current job */
2987 char scheme
[HTTP_MAX_URI
],
2988 /* Method portion of URI */
2989 username
[HTTP_MAX_URI
],
2990 /* Username portion of URI */
2992 /* Host portion of URI */
2993 resource
[HTTP_MAX_URI
];
2994 /* Resource portion of URI */
2995 int port
; /* Port portion of URI */
2998 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "authenticate_job(%p[%d], %s)",
2999 con
, con
->number
, uri
->values
[0].string
.text
);
3002 * Start with "everything is OK" status...
3005 con
->response
->request
.status
.status_code
= IPP_OK
;
3008 * See if we have a job URI or a printer URI...
3011 if (!strcmp(uri
->name
, "printer-uri"))
3014 * Got a printer URI; see if we also have a job-id attribute...
3017 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3018 IPP_TAG_INTEGER
)) == NULL
)
3020 send_ipp_status(con
, IPP_BAD_REQUEST
,
3021 _("Got a printer-uri attribute but no job-id."));
3025 jobid
= attr
->values
[0].integer
;
3030 * Got a job URI; parse it to get the job ID...
3033 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
3034 sizeof(scheme
), username
, sizeof(username
), host
,
3035 sizeof(host
), &port
, resource
, sizeof(resource
));
3037 if (strncmp(resource
, "/jobs/", 6))
3043 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
3044 uri
->values
[0].string
.text
);
3048 jobid
= atoi(resource
+ 6);
3052 * See if the job exists...
3055 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3058 * Nope - return a "not found" error...
3061 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
3066 * See if the job has been completed...
3069 if (job
->state_value
!= IPP_JOB_HELD
)
3072 * Return a "not-possible" error...
3075 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3076 _("Job #%d is not held for authentication."),
3082 * See if we have already authenticated...
3085 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
3087 if (!con
->username
[0] && !auth_info
)
3089 cupsd_printer_t
*printer
; /* Job destination */
3092 * No auth data. If we need to authenticate via Kerberos, send a
3093 * HTTP auth challenge, otherwise just return an IPP error...
3096 printer
= cupsdFindDest(job
->dest
);
3098 if (printer
&& printer
->num_auth_info_required
> 0 &&
3099 !strcmp(printer
->auth_info_required
[0], "negotiate"))
3100 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
3102 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
3103 _("No authentication information provided."));
3108 * See if the job is owned by the requesting user...
3111 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3113 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3114 cupsdFindDest(job
->dest
));
3119 * Save the authentication information for this job...
3122 save_auth_info(con
, job
, auth_info
);
3125 * Reset the job-hold-until value to "no-hold"...
3128 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
3129 IPP_TAG_KEYWORD
)) == NULL
)
3130 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
3134 ippSetValueTag(job
->attrs
, &attr
, IPP_TAG_KEYWORD
);
3135 ippSetString(job
->attrs
, &attr
, 0, "no-hold");
3139 * Release the job and return...
3142 cupsdReleaseJob(job
);
3144 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, NULL
, job
, "Job authenticated by user");
3146 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Authenticated by \"%s\".", con
->username
);
3153 * 'cancel_all_jobs()' - Cancel all or selected print jobs.
3157 cancel_all_jobs(cupsd_client_t
*con
, /* I - Client connection */
3158 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3160 int i
; /* Looping var */
3161 http_status_t status
; /* Policy status */
3162 cups_ptype_t dtype
; /* Destination type */
3163 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3164 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
3165 hostname
[HTTP_MAX_URI
], /* Host portion of URI */
3166 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3167 int port
; /* Port portion of URI */
3168 ipp_attribute_t
*attr
; /* Attribute in request */
3169 const char *username
= NULL
; /* Username */
3170 cupsd_jobaction_t purge
= CUPSD_JOB_DEFAULT
;
3172 cupsd_printer_t
*printer
; /* Printer */
3173 ipp_attribute_t
*job_ids
; /* job-ids attribute */
3174 cupsd_job_t
*job
; /* Job */
3177 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_all_jobs(%p[%d], %s)", con
,
3178 con
->number
, uri
->values
[0].string
.text
);
3181 * Get the jobs to cancel/purge...
3184 switch (con
->request
->request
.op
.operation_id
)
3186 case IPP_PURGE_JOBS
:
3188 * Get the username (if any) for the jobs we want to cancel (only if
3189 * "my-jobs" is specified...
3192 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
3193 IPP_TAG_BOOLEAN
)) != NULL
&&
3194 attr
->values
[0].boolean
)
3196 if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3197 IPP_TAG_NAME
)) != NULL
)
3198 username
= attr
->values
[0].string
.text
;
3201 send_ipp_status(con
, IPP_BAD_REQUEST
,
3202 _("Missing requesting-user-name attribute."));
3208 * Look for the "purge-jobs" attribute...
3211 if ((attr
= ippFindAttribute(con
->request
, "purge-jobs",
3212 IPP_TAG_BOOLEAN
)) != NULL
)
3213 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
3215 purge
= CUPSD_JOB_PURGE
;
3218 case IPP_CANCEL_MY_JOBS
:
3219 if (con
->username
[0])
3220 username
= con
->username
;
3221 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3222 IPP_TAG_NAME
)) != NULL
)
3223 username
= attr
->values
[0].string
.text
;
3226 send_ipp_status(con
, IPP_BAD_REQUEST
,
3227 _("Missing requesting-user-name attribute."));
3235 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
3238 * See if we have a printer URI...
3241 if (strcmp(uri
->name
, "printer-uri"))
3243 send_ipp_status(con
, IPP_BAD_REQUEST
,
3244 _("The printer-uri attribute is required."));
3249 * And if the destination is valid...
3252 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3258 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
,
3259 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
3260 hostname
, sizeof(hostname
), &port
,
3261 resource
, sizeof(resource
));
3263 if ((!strncmp(resource
, "/printers/", 10) && resource
[10]) ||
3264 (!strncmp(resource
, "/classes/", 9) && resource
[9]))
3266 send_ipp_status(con
, IPP_NOT_FOUND
,
3267 _("The printer or class does not exist."));
3275 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
3277 send_http_error(con
, status
, NULL
);
3283 for (i
= 0; i
< job_ids
->num_values
; i
++)
3285 if ((job
= cupsdFindJob(job_ids
->values
[i
].integer
)) == NULL
)
3288 if (con
->request
->request
.op
.operation_id
== IPP_CANCEL_MY_JOBS
&&
3289 _cups_strcasecmp(job
->username
, username
))
3293 if (i
< job_ids
->num_values
)
3295 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3296 job_ids
->values
[i
].integer
);
3300 for (i
= 0; i
< job_ids
->num_values
; i
++)
3302 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
3304 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3305 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
3306 "Job canceled by user.");
3309 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
3310 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3316 * Cancel all jobs on all printers...
3319 cupsdCancelJobs(NULL
, username
, purge
);
3321 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs were %s by \"%s\".",
3322 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3332 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
3335 send_http_error(con
, status
, printer
);
3341 for (i
= 0; i
< job_ids
->num_values
; i
++)
3343 if ((job
= cupsdFindJob(job_ids
->values
[i
].integer
)) == NULL
||
3344 _cups_strcasecmp(job
->dest
, printer
->name
))
3347 if (con
->request
->request
.op
.operation_id
== IPP_CANCEL_MY_JOBS
&&
3348 _cups_strcasecmp(job
->username
, username
))
3352 if (i
< job_ids
->num_values
)
3354 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3355 job_ids
->values
[i
].integer
);
3359 for (i
= 0; i
< job_ids
->num_values
; i
++)
3361 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
3363 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3364 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
3365 "Job canceled by user.");
3368 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
3369 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3375 * Cancel all of the jobs on the named printer...
3378 cupsdCancelJobs(printer
->name
, username
, purge
);
3380 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs on \"%s\" were %s by \"%s\".",
3382 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3387 con
->response
->request
.status
.status_code
= IPP_OK
;
3394 * 'cancel_job()' - Cancel a print job.
3398 cancel_job(cupsd_client_t
*con
, /* I - Client connection */
3399 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3401 ipp_attribute_t
*attr
; /* Current attribute */
3402 int jobid
; /* Job ID */
3403 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3404 username
[HTTP_MAX_URI
], /* Username portion of URI */
3405 host
[HTTP_MAX_URI
], /* Host portion of URI */
3406 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3407 int port
; /* Port portion of URI */
3408 cupsd_job_t
*job
; /* Job information */
3409 cups_ptype_t dtype
; /* Destination type (printer/class) */
3410 cupsd_printer_t
*printer
; /* Printer data */
3411 cupsd_jobaction_t purge
; /* Purge the job? */
3414 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_job(%p[%d], %s)", con
,
3415 con
->number
, uri
->values
[0].string
.text
);
3418 * See if we have a job URI or a printer URI...
3421 if (!strcmp(uri
->name
, "printer-uri"))
3424 * Got a printer URI; see if we also have a job-id attribute...
3427 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3428 IPP_TAG_INTEGER
)) == NULL
)
3430 send_ipp_status(con
, IPP_BAD_REQUEST
,
3431 _("Got a printer-uri attribute but no job-id."));
3435 if ((jobid
= attr
->values
[0].integer
) == 0)
3438 * Find the current job on the specified printer...
3441 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3447 send_ipp_status(con
, IPP_NOT_FOUND
,
3448 _("The printer or class does not exist."));
3453 * See if there are any pending jobs...
3456 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3458 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3459 if (job
->state_value
<= IPP_JOB_PROCESSING
&&
3460 !_cups_strcasecmp(job
->dest
, printer
->name
))
3468 * No, try stopped jobs...
3471 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3473 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3474 if (job
->state_value
== IPP_JOB_STOPPED
&&
3475 !_cups_strcasecmp(job
->dest
, printer
->name
))
3482 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("No active jobs on %s."),
3492 * Got a job URI; parse it to get the job ID...
3495 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
3496 sizeof(scheme
), username
, sizeof(username
), host
,
3497 sizeof(host
), &port
, resource
, sizeof(resource
));
3499 if (strncmp(resource
, "/jobs/", 6))
3505 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
3506 uri
->values
[0].string
.text
);
3510 jobid
= atoi(resource
+ 6);
3514 * Look for the "purge-job" attribute...
3517 if ((attr
= ippFindAttribute(con
->request
, "purge-job",
3518 IPP_TAG_BOOLEAN
)) != NULL
)
3519 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
3521 purge
= CUPSD_JOB_DEFAULT
;
3524 * See if the job exists...
3527 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3530 * Nope - return a "not found" error...
3533 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
3538 * See if the job is owned by the requesting user...
3541 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3543 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3544 cupsdFindDest(job
->dest
));
3549 * See if the job is already completed, canceled, or aborted; if so,
3550 * we can't cancel...
3553 if (job
->state_value
>= IPP_JOB_CANCELED
&& purge
!= CUPSD_JOB_PURGE
)
3555 switch (job
->state_value
)
3557 case IPP_JOB_CANCELED
:
3558 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3559 _("Job #%d is already canceled - can\'t cancel."),
3563 case IPP_JOB_ABORTED
:
3564 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3565 _("Job #%d is already aborted - can\'t cancel."),
3570 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3571 _("Job #%d is already completed - can\'t cancel."),
3580 * Cancel the job and return...
3583 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3584 purge
== CUPSD_JOB_PURGE
? "Job purged by \"%s\"" :
3585 "Job canceled by \"%s\"",
3589 if (purge
== CUPSD_JOB_PURGE
)
3590 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Purged by \"%s\".", jobid
,
3593 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Canceled by \"%s\".", jobid
,
3596 con
->response
->request
.status
.status_code
= IPP_OK
;
3601 * 'cancel_subscription()' - Cancel a subscription.
3605 cancel_subscription(
3606 cupsd_client_t
*con
, /* I - Client connection */
3607 int sub_id
) /* I - Subscription ID */
3609 http_status_t status
; /* Policy status */
3610 cupsd_subscription_t
*sub
; /* Subscription */
3613 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3614 "cancel_subscription(con=%p[%d], sub_id=%d)",
3615 con
, con
->number
, sub_id
);
3618 * Is the subscription ID valid?
3621 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
3624 * Bad subscription ID...
3627 send_ipp_status(con
, IPP_NOT_FOUND
,
3628 _("Subscription #%d does not exist."), sub_id
);
3636 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
3638 con
, sub
->owner
)) != HTTP_OK
)
3640 send_http_error(con
, status
, sub
->dest
);
3645 * Cancel the subscription...
3648 cupsdDeleteSubscription(sub
, 1);
3650 con
->response
->request
.status
.status_code
= IPP_OK
;
3655 * 'check_rss_recipient()' - Check that we do not have a duplicate RSS feed URI.
3658 static int /* O - 1 if OK, 0 if not */
3659 check_rss_recipient(
3660 const char *recipient
) /* I - Recipient URI */
3662 cupsd_subscription_t
*sub
; /* Current subscription */
3665 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
);
3667 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
3671 * Compare the URIs up to the first ?...
3674 const char *r1
, *r2
;
3676 for (r1
= recipient
, r2
= sub
->recipient
;
3677 *r1
== *r2
&& *r1
&& *r1
!= '?' && *r2
&& *r2
!= '?';
3689 * 'check_quotas()' - Check quotas for a printer and user.
3692 static int /* O - 1 if OK, 0 if forbidden,
3693 -1 if limit reached */
3694 check_quotas(cupsd_client_t
*con
, /* I - Client connection */
3695 cupsd_printer_t
*p
) /* I - Printer or class */
3697 char username
[33], /* Username */
3698 *name
; /* Current user name */
3699 cupsd_quota_t
*q
; /* Quota data */
3700 #ifdef HAVE_MBR_UID_TO_UUID
3702 * Use Apple membership APIs which require that all names represent
3703 * valid user account or group records accessible by the server.
3706 uuid_t usr_uuid
; /* UUID for job requesting user */
3707 uuid_t usr2_uuid
; /* UUID for ACL user name entry */
3708 uuid_t grp_uuid
; /* UUID for ACL group name entry */
3709 int mbr_err
; /* Error from membership function */
3710 int is_member
; /* Is this user a member? */
3713 * Use standard POSIX APIs for checking users and groups...
3716 struct passwd
*pw
; /* User password data */
3717 #endif /* HAVE_MBR_UID_TO_UUID */
3720 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "check_quotas(%p[%d], %p[%s])",
3721 con
, con
->number
, p
, p
->name
);
3724 * Figure out who is printing...
3727 strlcpy(username
, get_username(con
), sizeof(username
));
3729 if ((name
= strchr(username
, '@')) != NULL
)
3730 *name
= '\0'; /* Strip @REALM */
3733 * Check global active job limits for printers and users...
3736 if (MaxJobsPerPrinter
)
3739 * Check if there are too many pending jobs on this printer...
3742 if (cupsdGetPrinterJobCount(p
->name
) >= MaxJobsPerPrinter
)
3744 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for printer \"%s\"...",
3753 * Check if there are too many pending jobs for this user...
3756 if (cupsdGetUserJobCount(username
) >= MaxJobsPerUser
)
3758 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for user \"%s\"...",
3765 * Check against users...
3768 if (cupsArrayCount(p
->users
) == 0 && p
->k_limit
== 0 && p
->page_limit
== 0)
3771 if (cupsArrayCount(p
->users
))
3773 #ifdef HAVE_MBR_UID_TO_UUID
3775 * Get UUID for job requesting user...
3778 if (mbr_user_name_to_uuid((char *)username
, usr_uuid
))
3784 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3785 "check_quotas: UUID lookup failed for user \"%s\"",
3787 cupsdLogMessage(CUPSD_LOG_INFO
,
3788 "Denying user \"%s\" access to printer \"%s\" "
3789 "(unknown user)...",
3795 * Get UID and GID of requesting user...
3798 pw
= getpwnam(username
);
3800 #endif /* HAVE_MBR_UID_TO_UUID */
3802 for (name
= (char *)cupsArrayFirst(p
->users
);
3804 name
= (char *)cupsArrayNext(p
->users
))
3808 * Check group membership...
3811 #ifdef HAVE_MBR_UID_TO_UUID
3814 if (uuid_parse(name
+ 2, grp_uuid
))
3815 uuid_clear(grp_uuid
);
3817 else if ((mbr_err
= mbr_group_name_to_uuid(name
+ 1, grp_uuid
)) != 0)
3820 * Invalid ACL entries are ignored for matching; just record a
3821 * warning in the log...
3824 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3825 "check_quotas: UUID lookup failed for ACL entry "
3826 "\"%s\" (err=%d)", name
, mbr_err
);
3827 cupsdLogMessage(CUPSD_LOG_WARN
,
3828 "Access control entry \"%s\" not a valid group name; "
3829 "entry ignored", name
);
3832 if ((mbr_err
= mbr_check_membership(usr_uuid
, grp_uuid
,
3836 * At this point, there should be no errors, but check anyways...
3839 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3840 "check_quotas: group \"%s\" membership check "
3841 "failed (err=%d)", name
+ 1, mbr_err
);
3846 * Stop if we found a match...
3853 if (cupsdCheckGroup(username
, pw
, name
+ 1))
3855 #endif /* HAVE_MBR_UID_TO_UUID */
3857 #ifdef HAVE_MBR_UID_TO_UUID
3862 if (uuid_parse(name
+ 1, usr2_uuid
))
3863 uuid_clear(usr2_uuid
);
3865 else if ((mbr_err
= mbr_user_name_to_uuid(name
, usr2_uuid
)) != 0)
3868 * Invalid ACL entries are ignored for matching; just record a
3869 * warning in the log...
3872 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3873 "check_quotas: UUID lookup failed for ACL entry "
3874 "\"%s\" (err=%d)", name
, mbr_err
);
3875 cupsdLogMessage(CUPSD_LOG_WARN
,
3876 "Access control entry \"%s\" not a valid user name; "
3877 "entry ignored", name
);
3880 if (!uuid_compare(usr_uuid
, usr2_uuid
))
3884 else if (!_cups_strcasecmp(username
, name
))
3886 #endif /* HAVE_MBR_UID_TO_UUID */
3888 if ((name
!= NULL
) == p
->deny_users
)
3890 cupsdLogMessage(CUPSD_LOG_INFO
,
3891 "Denying user \"%s\" access to printer \"%s\"...",
3901 if (p
->k_limit
|| p
->page_limit
)
3903 if ((q
= cupsdUpdateQuota(p
, username
, 0, 0)) == NULL
)
3905 cupsdLogMessage(CUPSD_LOG_ERROR
,
3906 "Unable to allocate quota data for user \"%s\"",
3911 if ((q
->k_count
>= p
->k_limit
&& p
->k_limit
) ||
3912 (q
->page_count
>= p
->page_limit
&& p
->page_limit
))
3914 cupsdLogMessage(CUPSD_LOG_INFO
, "User \"%s\" is over the quota limit...",
3921 * If we have gotten this far, we're done!
3929 * 'close_job()' - Close a multi-file job.
3933 close_job(cupsd_client_t
*con
, /* I - Client connection */
3934 ipp_attribute_t
*uri
) /* I - Printer URI */
3936 cupsd_job_t
*job
; /* Job */
3937 ipp_attribute_t
*attr
; /* Attribute */
3938 char job_uri
[HTTP_MAX_URI
],
3940 username
[256]; /* User name */
3943 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "close_job(%p[%d], %s)", con
,
3944 con
->number
, uri
->values
[0].string
.text
);
3947 * See if we have a job URI or a printer URI...
3950 if (strcmp(uri
->name
, "printer-uri"))
3953 * job-uri is not supported by Close-Job!
3956 send_ipp_status(con
, IPP_BAD_REQUEST
,
3957 _("Close-Job doesn't support the job-uri attribute."));
3962 * Got a printer URI; see if we also have a job-id attribute...
3965 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3966 IPP_TAG_INTEGER
)) == NULL
)
3968 send_ipp_status(con
, IPP_BAD_REQUEST
,
3969 _("Got a printer-uri attribute but no job-id."));
3973 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
3976 * Nope - return a "not found" error...
3979 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3980 attr
->values
[0].integer
);
3985 * See if the job is owned by the requesting user...
3988 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3990 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3991 cupsdFindDest(job
->dest
));
3996 * Add any ending sheet...
3999 if (cupsdTimeoutJob(job
))
4002 if (job
->state_value
== IPP_JOB_STOPPED
)
4004 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
4005 job
->state_value
= IPP_JOB_PENDING
;
4007 else if (job
->state_value
== IPP_JOB_HELD
)
4009 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
4010 IPP_TAG_KEYWORD
)) == NULL
)
4011 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
4013 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
4015 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
4016 job
->state_value
= IPP_JOB_PENDING
;
4021 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
4024 * Fill in the response info...
4027 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
4028 con
->clientname
, con
->clientport
, "/jobs/%d", job
->id
);
4029 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
4032 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
4034 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
4037 con
->response
->request
.status
.status_code
= IPP_OK
;
4040 * Start the job if necessary...
4048 * 'copy_attrs()' - Copy attributes from one request to another.
4052 copy_attrs(ipp_t
*to
, /* I - Destination request */
4053 ipp_t
*from
, /* I - Source request */
4054 cups_array_t
*ra
, /* I - Requested attributes */
4055 ipp_tag_t group
, /* I - Group to copy */
4056 int quickcopy
, /* I - Do a quick copy? */
4057 cups_array_t
*exclude
) /* I - Attributes to exclude? */
4059 ipp_attribute_t
*fromattr
; /* Source attribute */
4062 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4063 "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)",
4064 to
, from
, ra
, group
, quickcopy
);
4069 for (fromattr
= from
->attrs
; fromattr
; fromattr
= fromattr
->next
)
4072 * Filter attributes as needed...
4075 if ((group
!= IPP_TAG_ZERO
&& fromattr
->group_tag
!= group
&&
4076 fromattr
->group_tag
!= IPP_TAG_ZERO
) || !fromattr
->name
)
4079 if (!strcmp(fromattr
->name
, "document-password") ||
4080 !strcmp(fromattr
->name
, "job-authorization-uri") ||
4081 !strcmp(fromattr
->name
, "job-password") ||
4082 !strcmp(fromattr
->name
, "job-password-encryption") ||
4083 !strcmp(fromattr
->name
, "job-printer-uri"))
4087 (cupsArrayFind(exclude
, fromattr
->name
) ||
4088 cupsArrayFind(exclude
, "all")))
4091 * We need to exclude this attribute for security reasons; we require the
4092 * job-id attribute regardless of the security settings for IPP
4095 * The job-printer-uri attribute is handled by copy_job_attrs().
4097 * Subscription attribute security is handled by copy_subscription_attrs().
4100 if (strcmp(fromattr
->name
, "job-id"))
4104 if (!ra
|| cupsArrayFind(ra
, fromattr
->name
))
4107 * Don't send collection attributes by default to IPP/1.x clients
4108 * since many do not support collections. Also don't send
4109 * media-col-database unless specifically requested by the client.
4112 if (fromattr
->value_tag
== IPP_TAG_BEGIN_COLLECTION
&&
4114 (to
->request
.status
.version
[0] == 1 ||
4115 !strcmp(fromattr
->name
, "media-col-database")))
4118 ippCopyAttribute(to
, fromattr
, quickcopy
);
4125 * 'copy_banner()' - Copy a banner file to the requests directory for the
4129 static int /* O - Size of banner file in kbytes */
4130 copy_banner(cupsd_client_t
*con
, /* I - Client connection */
4131 cupsd_job_t
*job
, /* I - Job information */
4132 const char *name
) /* I - Name of banner */
4134 int i
; /* Looping var */
4135 int kbytes
; /* Size of banner file in kbytes */
4136 char filename
[1024]; /* Job filename */
4137 cupsd_banner_t
*banner
; /* Pointer to banner */
4138 cups_file_t
*in
; /* Input file */
4139 cups_file_t
*out
; /* Output file */
4140 int ch
; /* Character from file */
4141 char attrname
[255], /* Name of attribute */
4142 *s
; /* Pointer into name */
4143 ipp_attribute_t
*attr
; /* Attribute */
4146 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4147 "copy_banner(con=%p[%d], job=%p[%d], name=\"%s\")",
4148 con
, con
? con
->number
: -1, job
, job
->id
,
4149 name
? name
: "(null)");
4152 * Find the banner; return if not found or "none"...
4155 if (!name
|| !strcmp(name
, "none") ||
4156 (banner
= cupsdFindBanner(name
)) == NULL
)
4160 * Open the banner and job files...
4163 if (add_file(con
, job
, banner
->filetype
, 0))
4166 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
4168 if ((out
= cupsFileOpen(filename
, "w")) == NULL
)
4170 cupsdLogMessage(CUPSD_LOG_ERROR
,
4171 "Unable to create banner job file %s - %s",
4172 filename
, strerror(errno
));
4177 fchmod(cupsFileNumber(out
), 0640);
4178 fchown(cupsFileNumber(out
), RunUser
, Group
);
4181 * Try the localized banner file under the subdirectory...
4184 strlcpy(attrname
, job
->attrs
->attrs
->next
->values
[0].string
.text
,
4186 if (strlen(attrname
) > 2 && attrname
[2] == '-')
4189 * Convert ll-cc to ll_CC...
4193 attrname
[3] = (char)toupper(attrname
[3] & 255);
4194 attrname
[4] = (char)toupper(attrname
[4] & 255);
4197 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4200 if (access(filename
, 0) && strlen(attrname
) > 2)
4203 * Wasn't able to find "ll_CC" locale file; try the non-national
4204 * localization banner directory.
4209 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4213 if (access(filename
, 0))
4216 * Use the non-localized banner file.
4219 snprintf(filename
, sizeof(filename
), "%s/banners/%s", DataDir
, name
);
4222 if ((in
= cupsFileOpen(filename
, "r")) == NULL
)
4226 cupsdLogMessage(CUPSD_LOG_ERROR
,
4227 "Unable to open banner template file %s - %s",
4228 filename
, strerror(errno
));
4234 * Parse the file to the end...
4237 while ((ch
= cupsFileGetChar(in
)) != EOF
)
4241 * Get an attribute name...
4244 for (s
= attrname
; (ch
= cupsFileGetChar(in
)) != EOF
;)
4245 if (!isalpha(ch
& 255) && ch
!= '-' && ch
!= '?')
4247 else if (s
< (attrname
+ sizeof(attrname
) - 1))
4257 * Ignore { followed by stuff that is not an attribute name...
4260 cupsFilePrintf(out
, "{%s%c", attrname
, ch
);
4265 * See if it is defined...
4268 if (attrname
[0] == '?')
4273 if (!strcmp(s
, "printer-name"))
4275 cupsFilePuts(out
, job
->dest
);
4278 else if ((attr
= ippFindAttribute(job
->attrs
, s
, IPP_TAG_ZERO
)) == NULL
)
4281 * See if we have a leading question mark...
4284 if (attrname
[0] != '?')
4287 * Nope, write to file as-is; probably a PostScript procedure...
4290 cupsFilePrintf(out
, "{%s}", attrname
);
4297 * Output value(s)...
4300 for (i
= 0; i
< attr
->num_values
; i
++)
4303 cupsFilePutChar(out
, ',');
4305 switch (attr
->value_tag
)
4307 case IPP_TAG_INTEGER
:
4309 if (!strncmp(s
, "time-at-", 8))
4311 struct timeval tv
; /* Time value */
4313 tv
.tv_sec
= attr
->values
[i
].integer
;
4316 cupsFilePuts(out
, cupsdGetDateTime(&tv
, CUPSD_TIME_STANDARD
));
4319 cupsFilePrintf(out
, "%d", attr
->values
[i
].integer
);
4322 case IPP_TAG_BOOLEAN
:
4323 cupsFilePrintf(out
, "%d", attr
->values
[i
].boolean
);
4326 case IPP_TAG_NOVALUE
:
4327 cupsFilePuts(out
, "novalue");
4330 case IPP_TAG_RANGE
:
4331 cupsFilePrintf(out
, "%d-%d", attr
->values
[i
].range
.lower
,
4332 attr
->values
[i
].range
.upper
);
4335 case IPP_TAG_RESOLUTION
:
4336 cupsFilePrintf(out
, "%dx%d%s", attr
->values
[i
].resolution
.xres
,
4337 attr
->values
[i
].resolution
.yres
,
4338 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
4343 case IPP_TAG_STRING
:
4346 case IPP_TAG_KEYWORD
:
4347 case IPP_TAG_CHARSET
:
4348 case IPP_TAG_LANGUAGE
:
4349 if (!_cups_strcasecmp(banner
->filetype
->type
, "postscript"))
4352 * Need to quote strings for PS banners...
4357 for (p
= attr
->values
[i
].string
.text
; *p
; p
++)
4359 if (*p
== '(' || *p
== ')' || *p
== '\\')
4361 cupsFilePutChar(out
, '\\');
4362 cupsFilePutChar(out
, *p
);
4364 else if (*p
< 32 || *p
> 126)
4365 cupsFilePrintf(out
, "\\%03o", *p
& 255);
4367 cupsFilePutChar(out
, *p
);
4371 cupsFilePuts(out
, attr
->values
[i
].string
.text
);
4375 break; /* anti-compiler-warning-code */
4379 else if (ch
== '\\') /* Quoted char */
4381 ch
= cupsFileGetChar(in
);
4383 if (ch
!= '{') /* Only do special handling for \{ */
4384 cupsFilePutChar(out
, '\\');
4386 cupsFilePutChar(out
, ch
);
4389 cupsFilePutChar(out
, ch
);
4393 kbytes
= (cupsFileTell(out
) + 1023) / 1024;
4395 job
->koctets
+= kbytes
;
4397 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets", IPP_TAG_INTEGER
)) != NULL
)
4398 attr
->values
[0].integer
+= kbytes
;
4407 * 'copy_file()' - Copy a PPD file...
4410 static int /* O - 0 = success, -1 = error */
4411 copy_file(const char *from
, /* I - Source file */
4412 const char *to
, /* I - Destination file */
4413 mode_t mode
) /* I - Permissions */
4415 cups_file_t
*src
, /* Source file */
4416 *dst
; /* Destination file */
4417 int bytes
; /* Bytes to read/write */
4418 char buffer
[2048]; /* Copy buffer */
4421 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_file(\"%s\", \"%s\")", from
, to
);
4424 * Open the source and destination file for a copy...
4427 if ((src
= cupsFileOpen(from
, "rb")) == NULL
)
4430 if ((dst
= cupsdCreateConfFile(to
, mode
)) == NULL
)
4437 * Copy the source file to the destination...
4440 while ((bytes
= cupsFileRead(src
, buffer
, sizeof(buffer
))) > 0)
4441 if (cupsFileWrite(dst
, buffer
, (size_t)bytes
) < bytes
)
4449 * Close both files and return...
4454 return (cupsdCloseCreatedConfFile(dst
, to
));
4459 * 'copy_model()' - Copy a PPD model file, substituting default values
4463 static int /* O - 0 = success, -1 = error */
4464 copy_model(cupsd_client_t
*con
, /* I - Client connection */
4465 const char *from
, /* I - Source file */
4466 const char *to
) /* I - Destination file */
4468 fd_set input
; /* select() input set */
4469 struct timeval timeout
; /* select() timeout */
4470 int maxfd
; /* Max file descriptor for select() */
4471 char tempfile
[1024]; /* Temporary PPD file */
4472 int tempfd
; /* Temporary PPD file descriptor */
4473 int temppid
; /* Process ID of cups-driverd */
4474 int temppipe
[2]; /* Temporary pipes */
4475 char *argv
[4], /* Command-line arguments */
4476 *envp
[MAX_ENV
]; /* Environment */
4477 cups_file_t
*src
, /* Source file */
4478 *dst
; /* Destination file */
4479 ppd_file_t
*ppd
; /* PPD file */
4480 int bytes
, /* Bytes from pipe */
4481 total
; /* Total bytes from pipe */
4482 char buffer
[2048]; /* Copy buffer */
4483 int i
; /* Looping var */
4484 char option
[PPD_MAX_NAME
], /* Option name */
4485 choice
[PPD_MAX_NAME
]; /* Choice name */
4486 ppd_size_t
*size
; /* Default size */
4487 int num_defaults
; /* Number of default options */
4488 cups_option_t
*defaults
; /* Default options */
4489 char cups_protocol
[PPD_MAX_LINE
];
4490 /* cupsProtocol attribute */
4493 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_model(con=%p, from=\"%s\", to=\"%s\")", con
, from
, to
);
4496 * Run cups-driverd to get the PPD file...
4499 argv
[0] = "cups-driverd";
4501 argv
[2] = (char *)from
;
4504 cupsdLoadEnv(envp
, (int)(sizeof(envp
) / sizeof(envp
[0])));
4506 snprintf(buffer
, sizeof(buffer
), "%s/daemon/cups-driverd", ServerBin
);
4507 snprintf(tempfile
, sizeof(tempfile
), "%s/%d.ppd", TempDir
, con
->number
);
4508 tempfd
= open(tempfile
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
4509 if (tempfd
< 0 || cupsdOpenPipe(temppipe
))
4512 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4513 "copy_model: Running \"cups-driverd cat %s\"...", from
);
4515 if (!cupsdStartProcess(buffer
, argv
, envp
, -1, temppipe
[1], CGIPipes
[1],
4516 -1, -1, 0, DefaultProfile
, NULL
, &temppid
))
4527 * Wait up to 30 seconds for the PPD file to be copied...
4532 if (temppipe
[0] > CGIPipes
[0])
4533 maxfd
= temppipe
[0] + 1;
4535 maxfd
= CGIPipes
[0] + 1;
4540 * See if we have data ready...
4544 FD_SET(temppipe
[0], &input
);
4545 FD_SET(CGIPipes
[0], &input
);
4547 timeout
.tv_sec
= 30;
4548 timeout
.tv_usec
= 0;
4550 if ((i
= select(maxfd
, &input
, NULL
, NULL
, &timeout
)) < 0)
4560 * We have timed out...
4566 if (FD_ISSET(temppipe
[0], &input
))
4569 * Read the PPD file from the pipe, and write it to the PPD file.
4572 if ((bytes
= read(temppipe
[0], buffer
, sizeof(buffer
))) > 0)
4574 if (write(tempfd
, buffer
, (size_t)bytes
) < bytes
)
4583 if (FD_ISSET(CGIPipes
[0], &input
))
4593 * No data from cups-deviced...
4596 cupsdLogMessage(CUPSD_LOG_ERROR
, "copy_model: empty PPD file");
4602 * Open the source file for a copy...
4605 if ((src
= cupsFileOpen(tempfile
, "rb")) == NULL
)
4612 * Read the source file and see what page sizes are supported...
4615 if ((ppd
= _ppdOpen(src
, _PPD_LOCALIZATION_NONE
)) == NULL
)
4623 * Open the destination (if possible) and set the default options...
4628 cups_protocol
[0] = '\0';
4630 if ((dst
= cupsFileOpen(to
, "rb")) != NULL
)
4633 * Read all of the default lines from the old PPD...
4636 while (cupsFileGets(dst
, buffer
, sizeof(buffer
)))
4637 if (!strncmp(buffer
, "*Default", 8))
4640 * Add the default option...
4643 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
4644 choice
, sizeof(choice
)))
4646 ppd_option_t
*ppdo
; /* PPD option */
4650 * Only add the default if the default hasn't already been
4651 * set and the choice exists in the new PPD...
4654 if (!cupsGetOption(option
, num_defaults
, defaults
) &&
4655 (ppdo
= ppdFindOption(ppd
, option
)) != NULL
&&
4656 ppdFindChoice(ppdo
, choice
))
4657 num_defaults
= cupsAddOption(option
, choice
, num_defaults
,
4661 else if (!strncmp(buffer
, "*cupsProtocol:", 14))
4662 strlcpy(cups_protocol
, buffer
, sizeof(cups_protocol
));
4666 else if ((size
= ppdPageSize(ppd
, DefaultPaperSize
)) != NULL
)
4669 * Add the default media sizes...
4672 num_defaults
= cupsAddOption("PageSize", size
->name
,
4673 num_defaults
, &defaults
);
4674 num_defaults
= cupsAddOption("PageRegion", size
->name
,
4675 num_defaults
, &defaults
);
4676 num_defaults
= cupsAddOption("PaperDimension", size
->name
,
4677 num_defaults
, &defaults
);
4678 num_defaults
= cupsAddOption("ImageableArea", size
->name
,
4679 num_defaults
, &defaults
);
4685 * Open the destination file for a copy...
4688 if ((dst
= cupsdCreateConfFile(to
, ConfigFilePerm
)) == NULL
)
4690 cupsFreeOptions(num_defaults
, defaults
);
4697 * Copy the source file to the destination...
4700 cupsFileRewind(src
);
4702 while (cupsFileGets(src
, buffer
, sizeof(buffer
)))
4704 if (!strncmp(buffer
, "*Default", 8))
4707 * Check for an previous default option choice...
4710 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
4711 choice
, sizeof(choice
)))
4713 const char *val
; /* Default option value */
4716 if ((val
= cupsGetOption(option
, num_defaults
, defaults
)) != NULL
)
4719 * Substitute the previous choice...
4722 snprintf(buffer
, sizeof(buffer
), "*Default%s: %s", option
, val
);
4727 cupsFilePrintf(dst
, "%s\n", buffer
);
4730 if (cups_protocol
[0])
4731 cupsFilePrintf(dst
, "%s\n", cups_protocol
);
4733 cupsFreeOptions(num_defaults
, defaults
);
4736 * Close both files and return...
4743 return (cupsdCloseCreatedConfFile(dst
, to
));
4748 * 'copy_job_attrs()' - Copy job attributes.
4752 copy_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
4753 cupsd_job_t
*job
, /* I - Job */
4754 cups_array_t
*ra
, /* I - Requested attributes array */
4755 cups_array_t
*exclude
) /* I - Private attributes array */
4757 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
4761 * Send the requested attributes for each job...
4764 if (!cupsArrayFind(exclude
, "all"))
4766 if ((!exclude
|| !cupsArrayFind(exclude
, "number-of-documents")) &&
4767 (!ra
|| cupsArrayFind(ra
, "number-of-documents")))
4768 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4769 "number-of-documents", job
->num_files
);
4771 if ((!exclude
|| !cupsArrayFind(exclude
, "job-media-progress")) &&
4772 (!ra
|| cupsArrayFind(ra
, "job-media-progress")))
4773 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4774 "job-media-progress", job
->progress
);
4776 if ((!exclude
|| !cupsArrayFind(exclude
, "job-more-info")) &&
4777 (!ra
|| cupsArrayFind(ra
, "job-more-info")))
4779 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "http",
4780 NULL
, con
->clientname
, con
->clientport
, "/jobs/%d",
4782 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4783 "job-more-info", NULL
, job_uri
);
4786 if (job
->state_value
> IPP_JOB_PROCESSING
&&
4787 (!exclude
|| !cupsArrayFind(exclude
, "job-preserved")) &&
4788 (!ra
|| cupsArrayFind(ra
, "job-preserved")))
4789 ippAddBoolean(con
->response
, IPP_TAG_JOB
, "job-preserved",
4790 job
->num_files
> 0);
4792 if ((!exclude
|| !cupsArrayFind(exclude
, "job-printer-up-time")) &&
4793 (!ra
|| cupsArrayFind(ra
, "job-printer-up-time")))
4794 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4795 "job-printer-up-time", time(NULL
));
4798 if (!ra
|| cupsArrayFind(ra
, "job-printer-uri"))
4800 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
4801 con
->clientname
, con
->clientport
,
4802 (job
->dtype
& CUPS_PRINTER_CLASS
) ? "/classes/%s" :
4805 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4806 "job-printer-uri", NULL
, job_uri
);
4809 if (!ra
|| cupsArrayFind(ra
, "job-uri"))
4811 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
4812 con
->clientname
, con
->clientport
, "/jobs/%d",
4814 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4815 "job-uri", NULL
, job_uri
);
4820 copy_attrs(con
->response
, job
->attrs
, ra
, IPP_TAG_JOB
, 0, exclude
);
4825 * Generate attributes from the job structure...
4828 if (job
->completed_time
&& (!ra
|| cupsArrayFind(ra
, "date-time-at-completed")))
4829 ippAddDate(con
->response
, IPP_TAG_JOB
, "date-time-at-completed", ippTimeToDate(job
->completed_time
));
4831 if (job
->creation_time
&& (!ra
|| cupsArrayFind(ra
, "date-time-at-creation")))
4832 ippAddDate(con
->response
, IPP_TAG_JOB
, "date-time-at-creation", ippTimeToDate(job
->creation_time
));
4834 if (!ra
|| cupsArrayFind(ra
, "job-id"))
4835 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
4837 if (!ra
|| cupsArrayFind(ra
, "job-k-octets"))
4838 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-k-octets", job
->koctets
);
4840 if (job
->name
&& (!ra
|| cupsArrayFind(ra
, "job-name")))
4841 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_CONST_TAG(IPP_TAG_NAME
), "job-name", NULL
, job
->name
);
4843 if (job
->username
&& (!ra
|| cupsArrayFind(ra
, "job-originating-user-name")))
4844 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_CONST_TAG(IPP_TAG_NAME
), "job-originating-user-name", NULL
, job
->username
);
4846 if (!ra
|| cupsArrayFind(ra
, "job-state"))
4847 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state", (int)job
->state_value
);
4849 if (!ra
|| cupsArrayFind(ra
, "job-state-reasons"))
4851 switch (job
->state_value
)
4853 default : /* Should never get here for processing, pending, held, or stopped jobs since they don't get unloaded... */
4855 case IPP_JSTATE_ABORTED
:
4856 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons", NULL
, "job-aborted-by-system");
4858 case IPP_JSTATE_CANCELED
:
4859 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons", NULL
, "job-canceled-by-user");
4861 case IPP_JSTATE_COMPLETED
:
4862 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons", NULL
, "job-completed-successfully");
4867 if (job
->completed_time
&& (!ra
|| cupsArrayFind(ra
, "time-at-completed")))
4868 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-completed", (int)job
->completed_time
);
4870 if (job
->creation_time
&& (!ra
|| cupsArrayFind(ra
, "time-at-creation")))
4871 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation", (int)job
->creation_time
);
4877 * 'copy_printer_attrs()' - Copy printer attributes.
4882 cupsd_client_t
*con
, /* I - Client connection */
4883 cupsd_printer_t
*printer
, /* I - Printer */
4884 cups_array_t
*ra
) /* I - Requested attributes array */
4886 char printer_uri
[HTTP_MAX_URI
];
4888 char printer_icons
[HTTP_MAX_URI
];
4890 time_t curtime
; /* Current time */
4891 int i
; /* Looping var */
4895 * Copy the printer attributes to the response using requested-attributes
4896 * and document-format attributes that may be provided by the client.
4899 curtime
= time(NULL
);
4901 if (!ra
|| cupsArrayFind(ra
, "marker-change-time"))
4902 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4903 "marker-change-time", printer
->marker_time
);
4905 if (printer
->num_printers
> 0 &&
4906 (!ra
|| cupsArrayFind(ra
, "member-uris")))
4908 ipp_attribute_t
*member_uris
; /* member-uris attribute */
4909 cupsd_printer_t
*p2
; /* Printer in class */
4910 ipp_attribute_t
*p2_uri
; /* printer-uri-supported for class printer */
4913 if ((member_uris
= ippAddStrings(con
->response
, IPP_TAG_PRINTER
,
4914 IPP_TAG_URI
, "member-uris",
4915 printer
->num_printers
, NULL
,
4918 for (i
= 0; i
< printer
->num_printers
; i
++)
4920 p2
= printer
->printers
[i
];
4922 if ((p2_uri
= ippFindAttribute(p2
->attrs
, "printer-uri-supported",
4923 IPP_TAG_URI
)) != NULL
)
4924 member_uris
->values
[i
].string
.text
=
4925 _cupsStrRetain(p2_uri
->values
[0].string
.text
);
4928 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
,
4929 sizeof(printer_uri
), "ipp", NULL
, con
->clientname
,
4931 (p2
->type
& CUPS_PRINTER_CLASS
) ?
4932 "/classes/%s" : "/printers/%s", p2
->name
);
4933 member_uris
->values
[i
].string
.text
= _cupsStrAlloc(printer_uri
);
4939 if (printer
->alert
&& (!ra
|| cupsArrayFind(ra
, "printer-alert")))
4940 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_STRING
,
4941 "printer-alert", NULL
, printer
->alert
);
4943 if (printer
->alert_description
&&
4944 (!ra
|| cupsArrayFind(ra
, "printer-alert-description")))
4945 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4946 "printer-alert-description", NULL
,
4947 printer
->alert_description
);
4949 if (!ra
|| cupsArrayFind(ra
, "printer-config-change-date-time"))
4950 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-config-change-date-time", ippTimeToDate(printer
->config_time
));
4952 if (!ra
|| cupsArrayFind(ra
, "printer-config-change-time"))
4953 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4954 "printer-config-change-time", printer
->config_time
);
4956 if (!ra
|| cupsArrayFind(ra
, "printer-current-time"))
4957 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-current-time",
4958 ippTimeToDate(curtime
));
4960 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
4961 if (!ra
|| cupsArrayFind(ra
, "printer-dns-sd-name"))
4963 if (printer
->reg_name
)
4964 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4965 "printer-dns-sd-name", NULL
, printer
->reg_name
);
4967 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
4968 "printer-dns-sd-name", 0);
4970 #endif /* HAVE_DNSSD || HAVE_AVAHI */
4972 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy"))
4973 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4974 "printer-error-policy", NULL
, printer
->error_policy
);
4976 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy-supported"))
4978 static const char * const errors
[] =/* printer-error-policy-supported values */
4981 "retry-current-job",
4986 if (printer
->type
& CUPS_PRINTER_CLASS
)
4987 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
4988 "printer-error-policy-supported", NULL
, "retry-current-job");
4990 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
4991 "printer-error-policy-supported",
4992 sizeof(errors
) / sizeof(errors
[0]), NULL
, errors
);
4995 if (!ra
|| cupsArrayFind(ra
, "printer-icons"))
4997 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_icons
, sizeof(printer_icons
),
4998 "http", NULL
, con
->clientname
, con
->clientport
,
4999 "/icons/%s.png", printer
->name
);
5000 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-icons",
5001 NULL
, printer_icons
);
5002 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-icons=\"%s\"", printer_icons
);
5005 if (!ra
|| cupsArrayFind(ra
, "printer-is-accepting-jobs"))
5006 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs", (char)printer
->accepting
);
5008 if (!ra
|| cupsArrayFind(ra
, "printer-is-shared"))
5009 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-shared", (char)printer
->shared
);
5011 if (!ra
|| cupsArrayFind(ra
, "printer-is-temporary"))
5012 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-temporary", (char)printer
->temporary
);
5014 if (!ra
|| cupsArrayFind(ra
, "printer-more-info"))
5016 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5017 "http", NULL
, con
->clientname
, con
->clientport
,
5018 (printer
->type
& CUPS_PRINTER_CLASS
) ?
5019 "/classes/%s" : "/printers/%s", printer
->name
);
5020 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5021 "printer-more-info", NULL
, printer_uri
);
5024 if (!ra
|| cupsArrayFind(ra
, "printer-op-policy"))
5025 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5026 "printer-op-policy", NULL
, printer
->op_policy
);
5028 if (!ra
|| cupsArrayFind(ra
, "printer-state"))
5029 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
5032 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-date-time"))
5033 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-state-change-date-time", ippTimeToDate(printer
->state_time
));
5035 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-time"))
5036 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5037 "printer-state-change-time", printer
->state_time
);
5039 if (!ra
|| cupsArrayFind(ra
, "printer-state-message"))
5040 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5041 "printer-state-message", NULL
, printer
->state_message
);
5043 if (!ra
|| cupsArrayFind(ra
, "printer-state-reasons"))
5044 add_printer_state_reasons(con
, printer
);
5046 if (!ra
|| cupsArrayFind(ra
, "printer-type"))
5048 cups_ptype_t type
; /* printer-type value */
5051 * Add the CUPS-specific printer-type attribute...
5054 type
= printer
->type
;
5056 if (printer
== DefaultPrinter
)
5057 type
|= CUPS_PRINTER_DEFAULT
;
5059 if (!printer
->accepting
)
5060 type
|= CUPS_PRINTER_REJECTING
;
5062 if (!printer
->shared
)
5063 type
|= CUPS_PRINTER_NOT_SHARED
;
5065 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-type", (int)type
);
5068 if (!ra
|| cupsArrayFind(ra
, "printer-up-time"))
5069 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5070 "printer-up-time", curtime
);
5072 if (!ra
|| cupsArrayFind(ra
, "printer-uri-supported"))
5074 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5075 "ipp", NULL
, con
->clientname
, con
->clientport
,
5076 (printer
->type
& CUPS_PRINTER_CLASS
) ?
5077 "/classes/%s" : "/printers/%s", printer
->name
);
5078 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5079 "printer-uri-supported", NULL
, printer_uri
);
5080 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-uri-supported=\"%s\"",
5084 if (!ra
|| cupsArrayFind(ra
, "queued-job-count"))
5085 add_queued_job_count(con
, printer
);
5087 copy_attrs(con
->response
, printer
->attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
5088 if (printer
->ppd_attrs
)
5089 copy_attrs(con
->response
, printer
->ppd_attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
5090 copy_attrs(con
->response
, CommonData
, ra
, IPP_TAG_ZERO
, IPP_TAG_COPY
, NULL
);
5095 * 'copy_subscription_attrs()' - Copy subscription attributes.
5099 copy_subscription_attrs(
5100 cupsd_client_t
*con
, /* I - Client connection */
5101 cupsd_subscription_t
*sub
, /* I - Subscription */
5102 cups_array_t
*ra
, /* I - Requested attributes array */
5103 cups_array_t
*exclude
) /* I - Private attributes array */
5105 ipp_attribute_t
*attr
; /* Current attribute */
5106 char printer_uri
[HTTP_MAX_URI
];
5108 int count
; /* Number of events */
5109 unsigned mask
; /* Current event mask */
5110 const char *name
; /* Current event name */
5113 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5114 "copy_subscription_attrs(con=%p, sub=%p, ra=%p, exclude=%p)",
5115 con
, sub
, ra
, exclude
);
5118 * Copy the subscription attributes to the response using the
5119 * requested-attributes attribute that may be provided by the client.
5122 if (!exclude
|| !cupsArrayFind(exclude
, "all"))
5124 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-events")) &&
5125 (!ra
|| cupsArrayFind(ra
, "notify-events")))
5127 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_subscription_attrs: notify-events");
5129 if ((name
= cupsdEventName((cupsd_eventmask_t
)sub
->mask
)) != NULL
)
5132 * Simple event list...
5135 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
,
5136 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5137 "notify-events", NULL
, name
);
5142 * Complex event list...
5145 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5146 if (sub
->mask
& mask
)
5149 attr
= ippAddStrings(con
->response
, IPP_TAG_SUBSCRIPTION
,
5150 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5151 "notify-events", count
, NULL
, NULL
);
5153 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5154 if (sub
->mask
& mask
)
5156 attr
->values
[count
].string
.text
=
5157 (char *)cupsdEventName((cupsd_eventmask_t
)mask
);
5164 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-lease-duration")) &&
5165 (!sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-lease-duration"))))
5166 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5167 "notify-lease-duration", sub
->lease
);
5169 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-recipient-uri")) &&
5170 (sub
->recipient
&& (!ra
|| cupsArrayFind(ra
, "notify-recipient-uri"))))
5171 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5172 "notify-recipient-uri", NULL
, sub
->recipient
);
5173 else if ((!exclude
|| !cupsArrayFind(exclude
, "notify-pull-method")) &&
5174 (!ra
|| cupsArrayFind(ra
, "notify-pull-method")))
5175 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_KEYWORD
,
5176 "notify-pull-method", NULL
, "ippget");
5178 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-subscriber-user-name")) &&
5179 (!ra
|| cupsArrayFind(ra
, "notify-subscriber-user-name")))
5180 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_NAME
,
5181 "notify-subscriber-user-name", NULL
, sub
->owner
);
5183 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-time-interval")) &&
5184 (!ra
|| cupsArrayFind(ra
, "notify-time-interval")))
5185 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5186 "notify-time-interval", sub
->interval
);
5188 if (sub
->user_data_len
> 0 &&
5189 (!exclude
|| !cupsArrayFind(exclude
, "notify-user-data")) &&
5190 (!ra
|| cupsArrayFind(ra
, "notify-user-data")))
5191 ippAddOctetString(con
->response
, IPP_TAG_SUBSCRIPTION
, "notify-user-data",
5192 sub
->user_data
, sub
->user_data_len
);
5195 if (sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-job-id")))
5196 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5197 "notify-job-id", sub
->job
->id
);
5199 if (sub
->dest
&& (!ra
|| cupsArrayFind(ra
, "notify-printer-uri")))
5201 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5202 "ipp", NULL
, con
->clientname
, con
->clientport
,
5203 "/printers/%s", sub
->dest
->name
);
5204 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5205 "notify-printer-uri", NULL
, printer_uri
);
5208 if (!ra
|| cupsArrayFind(ra
, "notify-subscription-id"))
5209 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5210 "notify-subscription-id", sub
->id
);
5215 * 'create_job()' - Print a file to a printer or class.
5219 create_job(cupsd_client_t
*con
, /* I - Client connection */
5220 ipp_attribute_t
*uri
) /* I - Printer URI */
5222 int i
; /* Looping var */
5223 cupsd_printer_t
*printer
; /* Printer */
5224 cupsd_job_t
*job
; /* New job */
5225 static const char * const forbidden_attrs
[] =
5226 { /* List of forbidden attributes */
5230 "document-natural-language"
5234 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "create_job(%p[%d], %s)", con
,
5235 con
->number
, uri
->values
[0].string
.text
);
5238 * Is the destination valid?
5241 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
5247 send_ipp_status(con
, IPP_NOT_FOUND
,
5248 _("The printer or class does not exist."));
5253 * Check for invalid Create-Job attributes and log a warning or error depending
5254 * on whether cupsd is running in "strict conformance" mode...
5258 i
< (int)(sizeof(forbidden_attrs
) / sizeof(forbidden_attrs
[0]));
5260 if (ippFindAttribute(con
->request
, forbidden_attrs
[i
], IPP_TAG_ZERO
))
5262 if (StrictConformance
)
5264 send_ipp_status(con
, IPP_BAD_REQUEST
,
5265 _("The '%s' operation attribute cannot be supplied in a "
5266 "Create-Job request."), forbidden_attrs
[i
]);
5270 cupsdLogMessage(CUPSD_LOG_WARN
,
5271 "Unexpected '%s' operation attribute in a Create-Job "
5272 "request.", forbidden_attrs
[i
]);
5276 * Create the job object...
5279 if ((job
= add_job(con
, printer
, NULL
)) == NULL
)
5282 job
->pending_timeout
= 1;
5285 * Save and log the job...
5288 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
5289 job
->dest
, job
->username
);
5294 * 'create_local_bg_thread()' - Background thread for creating a local print queue.
5297 static void * /* O - Exit status */
5298 create_local_bg_thread(
5299 cupsd_printer_t
*printer
) /* I - Printer */
5301 cups_file_t
*from
, /* Source file */
5302 *to
; /* Destination file */
5303 char fromppd
[1024], /* Source PPD */
5304 toppd
[1024], /* Destination PPD */
5305 scheme
[32], /* URI scheme */
5306 userpass
[256], /* User:pass */
5307 host
[256], /* Hostname */
5308 resource
[1024], /* Resource path */
5309 line
[1024]; /* Line from PPD */
5310 int port
; /* Port number */
5311 http_encryption_t encryption
; /* Type of encryption to use */
5312 http_t
*http
; /* Connection to printer */
5313 ipp_t
*request
, /* Request to printer */
5314 *response
; /* Response from printer */
5315 ipp_attribute_t
*attr
; /* Attribute in response */
5319 * Try connecting to the printer...
5322 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s: Generating PPD file from \"%s\"...", printer
->name
, printer
->device_uri
);
5324 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
)
5326 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: Bad device URI \"%s\".", printer
->name
, printer
->device_uri
);
5330 if (!strcmp(scheme
, "ipps") || port
== 443)
5331 encryption
= HTTP_ENCRYPTION_ALWAYS
;
5333 encryption
= HTTP_ENCRYPTION_IF_REQUESTED
;
5335 if ((http
= httpConnect2(host
, port
, NULL
, AF_UNSPEC
, encryption
, 1, 30000, NULL
)) == NULL
)
5337 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: Unable to connect to %s:%d: %s", printer
->name
, host
, port
, cupsLastErrorString());
5342 * Query the printer for its capabilities...
5345 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s: Connected to %s:%d, sending Get-Printer-Attributes request...", printer
->name
, host
, port
);
5347 request
= ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES
);
5348 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
, printer
->device_uri
);
5349 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
, "requested-attributes", NULL
, "all");
5351 response
= cupsDoRequest(http
, request
, resource
);
5353 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s: Get-Printer-Attributes returned %s", printer
->name
, ippErrorString(cupsLastError()));
5355 // TODO: Grab printer icon file...
5359 * Write the PPD for the queue...
5362 if (_ppdCreateFromIPP(fromppd
, sizeof(fromppd
), response
))
5364 if ((!printer
->info
|| !*(printer
->info
)) && (attr
= ippFindAttribute(response
, "printer-info", IPP_TAG_TEXT
)) != NULL
)
5365 cupsdSetString(&printer
->info
, ippGetString(attr
, 0, NULL
));
5367 if ((!printer
->location
|| !*(printer
->location
)) && (attr
= ippFindAttribute(response
, "printer-location", IPP_TAG_TEXT
)) != NULL
)
5368 cupsdSetString(&printer
->location
, ippGetString(attr
, 0, NULL
));
5370 if ((!printer
->geo_location
|| !*(printer
->geo_location
)) && (attr
= ippFindAttribute(response
, "printer-geo-location", IPP_TAG_URI
)) != NULL
)
5371 cupsdSetString(&printer
->geo_location
, ippGetString(attr
, 0, NULL
));
5373 if ((from
= cupsFileOpen(fromppd
, "r")) == NULL
)
5375 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: Unable to read generated PPD: %s", printer
->name
, strerror(errno
));
5379 snprintf(toppd
, sizeof(toppd
), "%s/ppd/%s.ppd", ServerRoot
, printer
->name
);
5380 if ((to
= cupsdCreateConfFile(toppd
, ConfigFilePerm
)) == NULL
)
5382 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: Unable to create PPD for printer: %s", printer
->name
, strerror(errno
));
5383 cupsFileClose(from
);
5387 while (cupsFileGets(from
, line
, sizeof(line
)))
5388 cupsFilePrintf(to
, "%s\n", line
);
5390 cupsFileClose(from
);
5391 if (!cupsdCloseCreatedConfFile(to
, toppd
))
5393 printer
->config_time
= time(NULL
);
5394 printer
->state
= IPP_PSTATE_IDLE
;
5395 printer
->accepting
= 1;
5397 cupsdSetPrinterAttrs(printer
);
5399 cupsdAddEvent(CUPSD_EVENT_PRINTER_CONFIG
, printer
, NULL
, "Printer \"%s\" is now available.", printer
->name
);
5400 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" is now available.", printer
->name
);
5404 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: PPD creation failed: %s", printer
->name
, cupsLastErrorString());
5411 * 'create_local_printer()' - Create a local (temporary) print queue.
5415 create_local_printer(
5416 cupsd_client_t
*con
) /* I - Client connection */
5418 ipp_attribute_t
*device_uri
, /* device-uri attribute */
5419 *printer_geo_location
, /* printer-geo-location attribute */
5420 *printer_info
, /* printer-info attribute */
5421 *printer_location
, /* printer-location attribute */
5422 *printer_name
; /* printer-name attribute */
5423 cupsd_printer_t
*printer
; /* New printer */
5424 http_status_t status
; /* Policy status */
5425 char name
[128], /* Sanitized printer name */
5426 *nameptr
, /* Pointer into name */
5427 uri
[1024]; /* printer-uri-supported value */
5428 const char *ptr
; /* Pointer into attribute value */
5432 * Require local access to create a local printer...
5435 if (!httpAddrLocalhost(httpGetAddress(con
->http
)))
5437 send_ipp_status(con
, IPP_STATUS_ERROR_FORBIDDEN
, _("Only local users can create a local printer."));
5442 * Check any other policy limits...
5445 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5447 send_http_error(con
, status
, NULL
);
5452 * Grab needed attributes...
5455 if ((printer_name
= ippFindAttribute(con
->request
, "printer-name", IPP_TAG_ZERO
)) == NULL
|| ippGetGroupTag(printer_name
) != IPP_TAG_PRINTER
|| ippGetValueTag(printer_name
) != IPP_TAG_NAME
)
5458 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Missing required attribute \"%s\"."), "printer-name");
5459 else if (ippGetGroupTag(printer_name
) != IPP_TAG_PRINTER
)
5460 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Attribute \"%s\" is in the wrong group."), "printer-name");
5462 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Attribute \"%s\" is the wrong value type."), "printer-name");
5467 for (nameptr
= name
, ptr
= ippGetString(printer_name
, 0, NULL
); *ptr
&& nameptr
< (name
+ sizeof(name
) - 1); ptr
++)
5470 * Sanitize the printer name...
5473 if (_cups_isalnum(*ptr
))
5475 else if (nameptr
== name
|| nameptr
[-1] != '_')
5481 if ((device_uri
= ippFindAttribute(con
->request
, "device-uri", IPP_TAG_ZERO
)) == NULL
|| ippGetGroupTag(device_uri
) != IPP_TAG_PRINTER
|| ippGetValueTag(device_uri
) != IPP_TAG_URI
)
5484 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Missing required attribute \"%s\"."), "device-uri");
5485 else if (ippGetGroupTag(device_uri
) != IPP_TAG_PRINTER
)
5486 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Attribute \"%s\" is in the wrong group."), "device-uri");
5488 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Attribute \"%s\" is the wrong value type."), "device-uri");
5493 printer_geo_location
= ippFindAttribute(con
->request
, "printer-geo-location", IPP_TAG_URI
);
5494 printer_info
= ippFindAttribute(con
->request
, "printer-info", IPP_TAG_TEXT
);
5495 printer_location
= ippFindAttribute(con
->request
, "printer-location", IPP_TAG_TEXT
);
5498 * See if the printer already exists...
5501 if ((printer
= cupsdFindDest(name
)) != NULL
)
5503 send_ipp_status(con
, IPP_STATUS_ERROR_NOT_POSSIBLE
, _("Printer \"%s\" already exists."), name
);
5504 goto add_printer_attributes
;
5508 * Create the printer...
5511 if ((printer
= cupsdAddPrinter(name
)) == NULL
)
5513 send_ipp_status(con
, IPP_STATUS_ERROR_INTERNAL
, _("Unable to create printer."));
5517 printer
->shared
= 0;
5518 printer
->temporary
= 1;
5520 cupsdSetDeviceURI(printer
, ippGetString(device_uri
, 0, NULL
));
5522 if (printer_geo_location
)
5523 cupsdSetString(&printer
->geo_location
, ippGetString(printer_geo_location
, 0, NULL
));
5525 cupsdSetString(&printer
->info
, ippGetString(printer_info
, 0, NULL
));
5526 if (printer_location
)
5527 cupsdSetString(&printer
->location
, ippGetString(printer_location
, 0, NULL
));
5529 cupsdSetPrinterAttrs(printer
);
5532 * Run a background thread to create the PPD...
5535 _cupsThreadCreate((_cups_thread_func_t
)create_local_bg_thread
, printer
);
5538 * Return printer attributes...
5541 send_ipp_status(con
, IPP_STATUS_OK
, _("Local printer created."));
5543 add_printer_attributes
:
5545 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs", (char)printer
->accepting
);
5546 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state", printer
->state
);
5547 add_printer_state_reasons(con
, printer
);
5549 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), httpIsEncrypted(con
->http
) ? "ipps" : "ipp", NULL
, con
->clientname
, con
->clientport
, "/printers/%s", printer
->name
);
5550 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-uri-supported", NULL
, uri
);
5555 * 'create_requested_array()' - Create an array for the requested-attributes.
5558 static cups_array_t
* /* O - Array of attributes or NULL */
5559 create_requested_array(ipp_t
*request
) /* I - IPP request */
5561 cups_array_t
*ra
; /* Requested attributes array */
5565 * Create the array for standard attributes...
5568 ra
= ippCreateRequestedArray(request
);
5571 * Add CUPS defaults as needed...
5574 if (cupsArrayFind(ra
, "printer-defaults"))
5577 * Include user-set defaults...
5580 char *name
; /* Option name */
5582 cupsArrayRemove(ra
, "printer-defaults");
5584 for (name
= (char *)cupsArrayFirst(CommonDefaults
);
5586 name
= (char *)cupsArrayNext(CommonDefaults
))
5587 if (!cupsArrayFind(ra
, name
))
5588 cupsArrayAdd(ra
, name
);
5596 * 'create_subscriptions()' - Create one or more notification subscriptions.
5600 create_subscriptions(
5601 cupsd_client_t
*con
, /* I - Client connection */
5602 ipp_attribute_t
*uri
) /* I - Printer URI */
5604 http_status_t status
; /* Policy status */
5605 int i
; /* Looping var */
5606 ipp_attribute_t
*attr
; /* Current attribute */
5607 cups_ptype_t dtype
; /* Destination type (printer/class) */
5608 char scheme
[HTTP_MAX_URI
],
5609 /* Scheme portion of URI */
5610 userpass
[HTTP_MAX_URI
],
5611 /* Username portion of URI */
5613 /* Host portion of URI */
5614 resource
[HTTP_MAX_URI
];
5615 /* Resource portion of URI */
5616 int port
; /* Port portion of URI */
5617 cupsd_printer_t
*printer
; /* Printer/class */
5618 cupsd_job_t
*job
; /* Job */
5619 int jobid
; /* Job ID */
5620 cupsd_subscription_t
*sub
; /* Subscription object */
5621 const char *username
, /* requesting-user-name or
5622 authenticated username */
5623 *recipient
, /* notify-recipient-uri */
5624 *pullmethod
; /* notify-pull-method */
5625 ipp_attribute_t
*user_data
; /* notify-user-data */
5626 int interval
, /* notify-time-interval */
5627 lease
; /* notify-lease-duration */
5628 unsigned mask
; /* notify-events */
5629 ipp_attribute_t
*notify_events
,/* notify-events(-default) */
5630 *notify_lease
; /* notify-lease-duration(-default) */
5634 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
5636 if (attr
->group_tag
!= IPP_TAG_ZERO
)
5637 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "g%04x v%04x %s", attr
->group_tag
,
5638 attr
->value_tag
, attr
->name
);
5640 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "----SEP----");
5645 * Is the destination valid?
5648 cupsdLogMessage(CUPSD_LOG_DEBUG
, "create_subscriptions(con=%p(%d), uri=\"%s\")", con
, con
->number
, uri
->values
[0].string
.text
);
5650 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
5651 sizeof(scheme
), userpass
, sizeof(userpass
), host
,
5652 sizeof(host
), &port
, resource
, sizeof(resource
));
5654 if (!strcmp(resource
, "/"))
5656 dtype
= (cups_ptype_t
)0;
5659 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
5661 dtype
= (cups_ptype_t
)0;
5664 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
5666 dtype
= CUPS_PRINTER_CLASS
;
5669 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
5675 send_ipp_status(con
, IPP_NOT_FOUND
,
5676 _("The printer or class does not exist."));
5686 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
5689 send_http_error(con
, status
, printer
);
5693 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5695 send_http_error(con
, status
, NULL
);
5700 * Get the user that is requesting the subscription...
5703 username
= get_username(con
);
5706 * Find the first subscription group attribute; return if we have
5710 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
5711 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
5716 send_ipp_status(con
, IPP_BAD_REQUEST
,
5717 _("No subscription attributes in request."));
5722 * Process the subscription attributes in the request...
5725 con
->response
->request
.status
.status_code
= IPP_BAD_REQUEST
;
5733 lease
= DefaultLeaseDuration
;
5735 mask
= CUPSD_EVENT_NONE
;
5739 notify_events
= ippFindAttribute(printer
->attrs
, "notify-events-default",
5741 notify_lease
= ippFindAttribute(printer
->attrs
,
5742 "notify-lease-duration-default",
5746 lease
= notify_lease
->values
[0].integer
;
5750 notify_events
= NULL
;
5751 notify_lease
= NULL
;
5754 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
5756 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
5757 attr
->value_tag
== IPP_TAG_URI
)
5760 * Validate the recipient scheme against the ServerBin/notifier
5764 char notifier
[1024]; /* Notifier filename */
5767 recipient
= attr
->values
[0].string
.text
;
5769 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
5770 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
5771 host
, sizeof(host
), &port
,
5772 resource
, sizeof(resource
)) < HTTP_URI_OK
)
5774 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5775 _("Bad notify-recipient-uri \"%s\"."), recipient
);
5776 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5777 "notify-status-code", IPP_URI_SCHEME
);
5781 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
5783 if (access(notifier
, X_OK
))
5785 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5786 _("notify-recipient-uri URI \"%s\" uses unknown "
5787 "scheme."), recipient
);
5788 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5789 "notify-status-code", IPP_URI_SCHEME
);
5793 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
5795 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5796 _("notify-recipient-uri URI \"%s\" is already used."),
5798 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5799 "notify-status-code", IPP_ATTRIBUTES
);
5803 else if (!strcmp(attr
->name
, "notify-pull-method") &&
5804 attr
->value_tag
== IPP_TAG_KEYWORD
)
5806 pullmethod
= attr
->values
[0].string
.text
;
5808 if (strcmp(pullmethod
, "ippget"))
5810 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5811 _("Bad notify-pull-method \"%s\"."), pullmethod
);
5812 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5813 "notify-status-code", IPP_ATTRIBUTES
);
5817 else if (!strcmp(attr
->name
, "notify-charset") &&
5818 attr
->value_tag
== IPP_TAG_CHARSET
&&
5819 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
5820 strcmp(attr
->values
[0].string
.text
, "utf-8"))
5822 send_ipp_status(con
, IPP_CHARSET
,
5823 _("Character set \"%s\" not supported."),
5824 attr
->values
[0].string
.text
);
5827 else if (!strcmp(attr
->name
, "notify-natural-language") &&
5828 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
5829 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
5831 send_ipp_status(con
, IPP_CHARSET
,
5832 _("Language \"%s\" not supported."),
5833 attr
->values
[0].string
.text
);
5836 else if (!strcmp(attr
->name
, "notify-user-data") &&
5837 attr
->value_tag
== IPP_TAG_STRING
)
5839 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
5841 send_ipp_status(con
, IPP_REQUEST_VALUE
,
5842 _("The notify-user-data value is too large "
5843 "(%d > 63 octets)."),
5844 attr
->values
[0].unknown
.length
);
5850 else if (!strcmp(attr
->name
, "notify-events") &&
5851 attr
->value_tag
== IPP_TAG_KEYWORD
)
5852 notify_events
= attr
;
5853 else if (!strcmp(attr
->name
, "notify-lease-duration") &&
5854 attr
->value_tag
== IPP_TAG_INTEGER
)
5855 lease
= attr
->values
[0].integer
;
5856 else if (!strcmp(attr
->name
, "notify-time-interval") &&
5857 attr
->value_tag
== IPP_TAG_INTEGER
)
5858 interval
= attr
->values
[0].integer
;
5859 else if (!strcmp(attr
->name
, "notify-job-id") &&
5860 attr
->value_tag
== IPP_TAG_INTEGER
)
5861 jobid
= attr
->values
[0].integer
;
5868 for (i
= 0; i
< notify_events
->num_values
; i
++)
5869 mask
|= cupsdEventValue(notify_events
->values
[i
].string
.text
);
5873 cupsdLogMessage(CUPSD_LOG_DEBUG
, "recipient=\"%s\"", recipient
);
5875 cupsdLogMessage(CUPSD_LOG_DEBUG
, "pullmethod=\"%s\"", pullmethod
);
5876 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-lease-duration=%d", lease
);
5877 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-time-interval=%d", interval
);
5879 if (!recipient
&& !pullmethod
)
5882 if (mask
== CUPSD_EVENT_NONE
)
5885 mask
= CUPSD_EVENT_JOB_COMPLETED
;
5887 mask
= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
5890 send_ipp_status(con
, IPP_BAD_REQUEST
,
5891 _("notify-events not specified."));
5896 if (MaxLeaseDuration
&& (lease
== 0 || lease
> MaxLeaseDuration
))
5898 cupsdLogMessage(CUPSD_LOG_INFO
,
5899 "create_subscriptions: Limiting notify-lease-duration to "
5902 lease
= MaxLeaseDuration
;
5907 if ((job
= cupsdFindJob(jobid
)) == NULL
)
5909 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
5917 if ((sub
= cupsdAddSubscription(mask
, printer
, job
, recipient
, 0)) == NULL
)
5919 send_ipp_status(con
, IPP_TOO_MANY_SUBSCRIPTIONS
,
5920 _("There are too many subscriptions."));
5925 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription #%d for job %d.",
5928 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5929 "Added subscription #%d for printer \"%s\".",
5930 sub
->id
, printer
->name
);
5932 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription #%d for server.",
5935 sub
->interval
= interval
;
5937 sub
->expire
= lease
? time(NULL
) + lease
: 0;
5939 cupsdSetString(&sub
->owner
, username
);
5943 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
5944 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
5945 (size_t)sub
->user_data_len
);
5948 ippAddSeparator(con
->response
);
5949 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5950 "notify-subscription-id", sub
->id
);
5952 con
->response
->request
.status
.status_code
= IPP_OK
;
5958 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
5963 * 'delete_printer()' - Remove a printer or class from the system.
5967 delete_printer(cupsd_client_t
*con
, /* I - Client connection */
5968 ipp_attribute_t
*uri
) /* I - URI of printer or class */
5970 http_status_t status
; /* Policy status */
5971 cups_ptype_t dtype
; /* Destination type (printer/class) */
5972 cupsd_printer_t
*printer
; /* Printer/class */
5973 char filename
[1024]; /* Script/PPD filename */
5974 int temporary
; /* Temporary queue? */
5977 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "delete_printer(%p[%d], %s)", con
,
5978 con
->number
, uri
->values
[0].string
.text
);
5981 * Do we have a valid URI?
5984 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
5990 send_ipp_status(con
, IPP_NOT_FOUND
,
5991 _("The printer or class does not exist."));
5999 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6001 send_http_error(con
, status
, NULL
);
6006 * Remove old jobs...
6009 cupsdCancelJobs(printer
->name
, NULL
, 1);
6012 * Remove old subscriptions and send a "deleted printer" event...
6015 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED
, printer
, NULL
,
6016 "%s \"%s\" deleted by \"%s\".",
6017 (dtype
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
6018 printer
->name
, get_username(con
));
6020 cupsdExpireSubscriptions(printer
, NULL
);
6023 * Remove any old PPD or script files...
6026 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
6029 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd.O", ServerRoot
,
6033 snprintf(filename
, sizeof(filename
), "%s/%s.png", CacheDir
, printer
->name
);
6036 snprintf(filename
, sizeof(filename
), "%s/%s.data", CacheDir
, printer
->name
);
6040 * Unregister color profiles...
6043 cupsdUnregisterColor(printer
);
6045 temporary
= printer
->temporary
;
6047 if (dtype
& CUPS_PRINTER_CLASS
)
6049 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" deleted by \"%s\".",
6050 printer
->name
, get_username(con
));
6052 cupsdDeletePrinter(printer
, 0);
6054 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
6058 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" deleted by \"%s\".",
6059 printer
->name
, get_username(con
));
6061 if (cupsdDeletePrinter(printer
, 0) && !temporary
)
6062 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
6065 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
6069 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
6072 * Return with no errors...
6075 con
->response
->request
.status
.status_code
= IPP_OK
;
6080 * 'get_default()' - Get the default destination.
6084 get_default(cupsd_client_t
*con
) /* I - Client connection */
6086 http_status_t status
; /* Policy status */
6087 cups_array_t
*ra
; /* Requested attributes array */
6090 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_default(%p[%d])", con
, con
->number
);
6096 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6098 send_http_error(con
, status
, NULL
);
6104 ra
= create_requested_array(con
->request
);
6106 copy_printer_attrs(con
, DefaultPrinter
, ra
);
6108 cupsArrayDelete(ra
);
6110 con
->response
->request
.status
.status_code
= IPP_OK
;
6113 send_ipp_status(con
, IPP_NOT_FOUND
, _("No default printer."));
6118 * 'get_devices()' - Get the list of available devices on the local system.
6122 get_devices(cupsd_client_t
*con
) /* I - Client connection */
6124 http_status_t status
; /* Policy status */
6125 ipp_attribute_t
*limit
, /* limit attribute */
6126 *timeout
, /* timeout attribute */
6127 *requested
, /* requested-attributes attribute */
6128 *exclude
, /* exclude-schemes attribute */
6129 *include
; /* include-schemes attribute */
6130 char command
[1024], /* cups-deviced command */
6131 options
[2048], /* Options to pass to command */
6133 /* String for requested attributes */
6135 /* String for excluded schemes */
6137 /* String for included schemes */
6140 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_devices(%p[%d])", con
, con
->number
);
6146 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6148 send_http_error(con
, status
, NULL
);
6153 * Run cups-deviced command with the given options...
6156 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
6157 timeout
= ippFindAttribute(con
->request
, "timeout", IPP_TAG_INTEGER
);
6158 requested
= ippFindAttribute(con
->request
, "requested-attributes",
6160 exclude
= ippFindAttribute(con
->request
, "exclude-schemes", IPP_TAG_NAME
);
6161 include
= ippFindAttribute(con
->request
, "include-schemes", IPP_TAG_NAME
);
6164 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
6166 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
6169 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
6171 exclude_str
[0] = '\0';
6174 url_encode_attr(include
, include_str
, sizeof(include_str
));
6176 include_str
[0] = '\0';
6178 snprintf(command
, sizeof(command
), "%s/daemon/cups-deviced", ServerBin
);
6179 snprintf(options
, sizeof(options
),
6180 "%d+%d+%d+%d+%s%s%s%s%s",
6181 con
->request
->request
.op
.request_id
,
6182 limit
? limit
->values
[0].integer
: 0,
6183 timeout
? timeout
->values
[0].integer
: 15,
6186 exclude_str
[0] ? "%20" : "", exclude_str
,
6187 include_str
[0] ? "%20" : "", include_str
);
6189 if (cupsdSendCommand(con
, command
, options
, 1))
6192 * Command started successfully, don't send an IPP response here...
6195 ippDelete(con
->response
);
6196 con
->response
= NULL
;
6201 * Command failed, return "internal error" so the user knows something
6205 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
6206 _("cups-deviced failed to execute."));
6212 * 'get_document()' - Get a copy of a job file.
6216 get_document(cupsd_client_t
*con
, /* I - Client connection */
6217 ipp_attribute_t
*uri
) /* I - Job URI */
6219 http_status_t status
; /* Policy status */
6220 ipp_attribute_t
*attr
; /* Current attribute */
6221 int jobid
; /* Job ID */
6222 int docnum
; /* Document number */
6223 cupsd_job_t
*job
; /* Current job */
6224 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
6225 username
[HTTP_MAX_URI
], /* Username portion of URI */
6226 host
[HTTP_MAX_URI
], /* Host portion of URI */
6227 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6228 int port
; /* Port portion of URI */
6229 char filename
[1024], /* Filename for document */
6230 format
[1024]; /* Format for document */
6233 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_document(%p[%d], %s)", con
,
6234 con
->number
, uri
->values
[0].string
.text
);
6237 * See if we have a job URI or a printer URI...
6240 if (!strcmp(uri
->name
, "printer-uri"))
6243 * Got a printer URI; see if we also have a job-id attribute...
6246 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6247 IPP_TAG_INTEGER
)) == NULL
)
6249 send_ipp_status(con
, IPP_BAD_REQUEST
,
6250 _("Got a printer-uri attribute but no job-id."));
6254 jobid
= attr
->values
[0].integer
;
6259 * Got a job URI; parse it to get the job ID...
6262 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6263 sizeof(scheme
), username
, sizeof(username
), host
,
6264 sizeof(host
), &port
, resource
, sizeof(resource
));
6266 if (strncmp(resource
, "/jobs/", 6))
6272 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
6273 uri
->values
[0].string
.text
);
6277 jobid
= atoi(resource
+ 6);
6281 * See if the job exists...
6284 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6287 * Nope - return a "not found" error...
6290 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
6298 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
,
6299 job
->username
)) != HTTP_OK
)
6301 send_http_error(con
, status
, NULL
);
6306 * Get the document number...
6309 if ((attr
= ippFindAttribute(con
->request
, "document-number",
6310 IPP_TAG_INTEGER
)) == NULL
)
6312 send_ipp_status(con
, IPP_BAD_REQUEST
,
6313 _("Missing document-number attribute."));
6317 if ((docnum
= attr
->values
[0].integer
) < 1 || docnum
> job
->num_files
||
6318 attr
->num_values
> 1)
6320 send_ipp_status(con
, IPP_NOT_FOUND
,
6321 _("Document #%d does not exist in job #%d."), docnum
,
6326 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, jobid
,
6328 if ((con
->file
= open(filename
, O_RDONLY
)) == -1)
6330 cupsdLogMessage(CUPSD_LOG_ERROR
,
6331 "Unable to open document %d in job %d - %s", docnum
, jobid
,
6333 send_ipp_status(con
, IPP_NOT_FOUND
,
6334 _("Unable to open document #%d in job #%d."), docnum
,
6339 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
6343 snprintf(format
, sizeof(format
), "%s/%s", job
->filetypes
[docnum
- 1]->super
,
6344 job
->filetypes
[docnum
- 1]->type
);
6346 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format",
6348 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "document-number",
6350 if ((attr
= ippFindAttribute(job
->attrs
, "document-name",
6351 IPP_TAG_NAME
)) != NULL
)
6352 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name",
6353 NULL
, attr
->values
[0].string
.text
);
6358 * 'get_job_attrs()' - Get job attributes.
6362 get_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
6363 ipp_attribute_t
*uri
) /* I - Job URI */
6365 http_status_t status
; /* Policy status */
6366 ipp_attribute_t
*attr
; /* Current attribute */
6367 int jobid
; /* Job ID */
6368 cupsd_job_t
*job
; /* Current job */
6369 cupsd_printer_t
*printer
; /* Current printer */
6370 cupsd_policy_t
*policy
; /* Current security policy */
6371 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6372 username
[HTTP_MAX_URI
], /* Username portion of URI */
6373 host
[HTTP_MAX_URI
], /* Host portion of URI */
6374 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6375 int port
; /* Port portion of URI */
6376 cups_array_t
*ra
, /* Requested attributes array */
6377 *exclude
; /* Private attributes array */
6380 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_job_attrs(%p[%d], %s)", con
,
6381 con
->number
, uri
->values
[0].string
.text
);
6384 * See if we have a job URI or a printer URI...
6387 if (!strcmp(uri
->name
, "printer-uri"))
6390 * Got a printer URI; see if we also have a job-id attribute...
6393 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6394 IPP_TAG_INTEGER
)) == NULL
)
6396 send_ipp_status(con
, IPP_BAD_REQUEST
,
6397 _("Got a printer-uri attribute but no job-id."));
6401 jobid
= attr
->values
[0].integer
;
6406 * Got a job URI; parse it to get the job ID...
6409 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6410 sizeof(scheme
), username
, sizeof(username
), host
,
6411 sizeof(host
), &port
, resource
, sizeof(resource
));
6413 if (strncmp(resource
, "/jobs/", 6))
6419 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
6420 uri
->values
[0].string
.text
);
6424 jobid
= atoi(resource
+ 6);
6428 * See if the job exists...
6431 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6434 * Nope - return a "not found" error...
6437 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
6445 if ((printer
= job
->printer
) == NULL
)
6446 printer
= cupsdFindDest(job
->dest
);
6449 policy
= printer
->op_policy_ptr
;
6451 policy
= DefaultPolicyPtr
;
6453 if ((status
= cupsdCheckPolicy(policy
, con
, job
->username
)) != HTTP_OK
)
6455 send_http_error(con
, status
, NULL
);
6459 exclude
= cupsdGetPrivateAttrs(policy
, con
, printer
, job
->username
);
6462 * Copy attributes...
6467 ra
= create_requested_array(con
->request
);
6468 copy_job_attrs(con
, job
, ra
, exclude
);
6469 cupsArrayDelete(ra
);
6471 con
->response
->request
.status
.status_code
= IPP_OK
;
6476 * 'get_jobs()' - Get a list of jobs for the specified printer.
6480 get_jobs(cupsd_client_t
*con
, /* I - Client connection */
6481 ipp_attribute_t
*uri
) /* I - Printer URI */
6483 http_status_t status
; /* Policy status */
6484 ipp_attribute_t
*attr
; /* Current attribute */
6485 const char *dest
; /* Destination */
6486 cups_ptype_t dtype
; /* Destination type (printer/class) */
6487 cups_ptype_t dmask
; /* Destination type mask */
6488 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6489 username
[HTTP_MAX_URI
], /* Username portion of URI */
6490 host
[HTTP_MAX_URI
], /* Host portion of URI */
6491 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6492 int port
; /* Port portion of URI */
6493 int job_comparison
; /* Job comparison */
6494 ipp_jstate_t job_state
; /* job-state value */
6495 int first_job_id
= 1, /* First job ID */
6496 first_index
= 1, /* First index */
6497 limit
= 0, /* Maximum number of jobs to return */
6498 count
, /* Number of jobs that match */
6499 need_load_job
= 0; /* Do we need to load the job? */
6500 const char *job_attr
; /* Job attribute requested */
6501 ipp_attribute_t
*job_ids
; /* job-ids attribute */
6502 cupsd_job_t
*job
; /* Current job pointer */
6503 cupsd_printer_t
*printer
; /* Printer */
6504 cups_array_t
*list
; /* Which job list... */
6505 int delete_list
= 0; /* Delete the list afterwards? */
6506 cups_array_t
*ra
, /* Requested attributes array */
6507 *exclude
; /* Private attributes array */
6508 cupsd_policy_t
*policy
; /* Current policy */
6511 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs(%p[%d], %s)", con
, con
->number
,
6512 uri
->values
[0].string
.text
);
6515 * Is the destination valid?
6518 if (strcmp(uri
->name
, "printer-uri"))
6520 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No printer-uri in request."));
6524 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6525 sizeof(scheme
), username
, sizeof(username
), host
,
6526 sizeof(host
), &port
, resource
, sizeof(resource
));
6528 if (!strcmp(resource
, "/") || !strcmp(resource
, "/jobs"))
6531 dtype
= (cups_ptype_t
)0;
6532 dmask
= (cups_ptype_t
)0;
6535 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6538 dtype
= (cups_ptype_t
)0;
6539 dmask
= CUPS_PRINTER_CLASS
;
6542 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6545 dtype
= CUPS_PRINTER_CLASS
;
6546 dmask
= CUPS_PRINTER_CLASS
;
6549 else if ((dest
= cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
,
6556 send_ipp_status(con
, IPP_NOT_FOUND
,
6557 _("The printer or class does not exist."));
6562 dtype
&= CUPS_PRINTER_CLASS
;
6563 dmask
= CUPS_PRINTER_CLASS
;
6571 policy
= printer
->op_policy_ptr
;
6573 policy
= DefaultPolicyPtr
;
6575 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
6577 send_http_error(con
, status
, NULL
);
6581 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
6584 * See if the "which-jobs" attribute have been specified...
6587 if ((attr
= ippFindAttribute(con
->request
, "which-jobs",
6588 IPP_TAG_KEYWORD
)) != NULL
&& job_ids
)
6590 send_ipp_status(con
, IPP_CONFLICT
,
6591 _("The %s attribute cannot be provided with job-ids."),
6595 else if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "not-completed"))
6597 job_comparison
= -1;
6598 job_state
= IPP_JOB_STOPPED
;
6601 else if (!strcmp(attr
->values
[0].string
.text
, "completed"))
6604 job_state
= IPP_JOB_CANCELED
;
6605 list
= cupsdGetCompletedJobs(printer
);
6608 else if (!strcmp(attr
->values
[0].string
.text
, "aborted"))
6611 job_state
= IPP_JOB_ABORTED
;
6612 list
= cupsdGetCompletedJobs(printer
);
6615 else if (!strcmp(attr
->values
[0].string
.text
, "all"))
6618 job_state
= IPP_JOB_PENDING
;
6621 else if (!strcmp(attr
->values
[0].string
.text
, "canceled"))
6624 job_state
= IPP_JOB_CANCELED
;
6625 list
= cupsdGetCompletedJobs(printer
);
6628 else if (!strcmp(attr
->values
[0].string
.text
, "pending"))
6631 job_state
= IPP_JOB_PENDING
;
6634 else if (!strcmp(attr
->values
[0].string
.text
, "pending-held"))
6637 job_state
= IPP_JOB_HELD
;
6640 else if (!strcmp(attr
->values
[0].string
.text
, "processing"))
6643 job_state
= IPP_JOB_PROCESSING
;
6644 list
= PrintingJobs
;
6646 else if (!strcmp(attr
->values
[0].string
.text
, "processing-stopped"))
6649 job_state
= IPP_JOB_STOPPED
;
6654 send_ipp_status(con
, IPP_ATTRIBUTES
,
6655 _("The which-jobs value \"%s\" is not supported."),
6656 attr
->values
[0].string
.text
);
6657 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
6658 "which-jobs", NULL
, attr
->values
[0].string
.text
);
6663 * See if they want to limit the number of jobs reported...
6666 if ((attr
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
)) != NULL
)
6670 send_ipp_status(con
, IPP_CONFLICT
,
6671 _("The %s attribute cannot be provided with job-ids."),
6676 limit
= attr
->values
[0].integer
;
6679 if ((attr
= ippFindAttribute(con
->request
, "first-index", IPP_TAG_INTEGER
)) != NULL
)
6683 send_ipp_status(con
, IPP_CONFLICT
,
6684 _("The %s attribute cannot be provided with job-ids."),
6689 first_index
= attr
->values
[0].integer
;
6691 else if ((attr
= ippFindAttribute(con
->request
, "first-job-id", IPP_TAG_INTEGER
)) != NULL
)
6695 send_ipp_status(con
, IPP_CONFLICT
,
6696 _("The %s attribute cannot be provided with job-ids."),
6701 first_job_id
= attr
->values
[0].integer
;
6705 * See if we only want to see jobs for a specific user...
6708 if ((attr
= ippFindAttribute(con
->request
, "my-jobs", IPP_TAG_BOOLEAN
)) != NULL
&& job_ids
)
6710 send_ipp_status(con
, IPP_CONFLICT
,
6711 _("The %s attribute cannot be provided with job-ids."),
6715 else if (attr
&& attr
->values
[0].boolean
)
6716 strlcpy(username
, get_username(con
), sizeof(username
));
6720 ra
= create_requested_array(con
->request
);
6721 for (job_attr
= (char *)cupsArrayFirst(ra
); job_attr
; job_attr
= (char *)cupsArrayNext(ra
))
6722 if (strcmp(job_attr
, "job-id") &&
6723 strcmp(job_attr
, "job-k-octets") &&
6724 strcmp(job_attr
, "job-media-progress") &&
6725 strcmp(job_attr
, "job-more-info") &&
6726 strcmp(job_attr
, "job-name") &&
6727 strcmp(job_attr
, "job-originating-user-name") &&
6728 strcmp(job_attr
, "job-preserved") &&
6729 strcmp(job_attr
, "job-printer-up-time") &&
6730 strcmp(job_attr
, "job-printer-uri") &&
6731 strcmp(job_attr
, "job-state") &&
6732 strcmp(job_attr
, "job-state-reasons") &&
6733 strcmp(job_attr
, "job-uri") &&
6734 strcmp(job_attr
, "time-at-completed") &&
6735 strcmp(job_attr
, "time-at-creation") &&
6736 strcmp(job_attr
, "number-of-documents"))
6742 if (need_load_job
&& (limit
== 0 || limit
> 500) && (list
== Jobs
|| delete_list
))
6745 * Limit expensive Get-Jobs for job history to 500 jobs...
6748 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
, "limit", 500);
6751 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
, "limit", limit
);
6755 cupsdLogClient(con
, CUPSD_LOG_INFO
, "Limiting Get-Jobs response to %d jobs.", limit
);
6759 * OK, build a list of jobs for this printer...
6764 int i
; /* Looping var */
6766 for (i
= 0; i
< job_ids
->num_values
; i
++)
6768 if (!cupsdFindJob(job_ids
->values
[i
].integer
))
6772 if (i
< job_ids
->num_values
)
6774 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
6775 job_ids
->values
[i
].integer
);
6779 for (i
= 0; i
< job_ids
->num_values
; i
++)
6781 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
6783 if (need_load_job
&& !job
->attrs
)
6789 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d", job
->id
);
6795 ippAddSeparator(con
->response
);
6797 exclude
= cupsdGetPrivateAttrs(job
->printer
?
6798 job
->printer
->op_policy_ptr
:
6799 policy
, con
, job
->printer
,
6802 copy_job_attrs(con
, job
, ra
, exclude
);
6807 if (first_index
> 1)
6808 job
= (cupsd_job_t
*)cupsArrayIndex(list
, first_index
- 1);
6810 job
= (cupsd_job_t
*)cupsArrayFirst(list
);
6812 for (count
= 0; (limit
<= 0 || count
< limit
) && job
; job
= (cupsd_job_t
*)cupsArrayNext(list
))
6815 * Filter out jobs that don't match...
6818 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
6819 "get_jobs: job->id=%d, dest=\"%s\", username=\"%s\", "
6820 "state_value=%d, attrs=%p", job
->id
, job
->dest
,
6821 job
->username
, job
->state_value
, job
->attrs
);
6823 if (!job
->dest
|| !job
->username
)
6826 if (!job
->dest
|| !job
->username
)
6829 if ((dest
&& strcmp(job
->dest
, dest
)) &&
6830 (!job
->printer
|| !dest
|| strcmp(job
->printer
->name
, dest
)))
6832 if ((job
->dtype
& dmask
) != dtype
&&
6833 (!job
->printer
|| (job
->printer
->type
& dmask
) != dtype
))
6836 if ((job_comparison
< 0 && job
->state_value
> job_state
) ||
6837 (job_comparison
== 0 && job
->state_value
!= job_state
) ||
6838 (job_comparison
> 0 && job
->state_value
< job_state
))
6841 if (job
->id
< first_job_id
)
6844 if (need_load_job
&& !job
->attrs
)
6850 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d", job
->id
);
6855 if (username
[0] && _cups_strcasecmp(username
, job
->username
))
6859 ippAddSeparator(con
->response
);
6863 exclude
= cupsdGetPrivateAttrs(job
->printer
?
6864 job
->printer
->op_policy_ptr
:
6865 policy
, con
, job
->printer
,
6868 copy_job_attrs(con
, job
, ra
, exclude
);
6871 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: count=%d", count
);
6874 cupsArrayDelete(ra
);
6877 cupsArrayDelete(list
);
6879 con
->response
->request
.status
.status_code
= IPP_OK
;
6884 * 'get_notifications()' - Get events for a subscription.
6888 get_notifications(cupsd_client_t
*con
) /* I - Client connection */
6890 int i
, j
; /* Looping vars */
6891 http_status_t status
; /* Policy status */
6892 cupsd_subscription_t
*sub
; /* Subscription */
6893 ipp_attribute_t
*ids
, /* notify-subscription-ids */
6894 *sequences
; /* notify-sequence-numbers */
6895 int min_seq
; /* Minimum sequence number */
6896 int interval
; /* Poll interval */
6899 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_notifications(con=%p[%d])",
6903 * Get subscription attributes...
6906 ids
= ippFindAttribute(con
->request
, "notify-subscription-ids",
6908 sequences
= ippFindAttribute(con
->request
, "notify-sequence-numbers",
6913 send_ipp_status(con
, IPP_BAD_REQUEST
,
6914 _("Missing notify-subscription-ids attribute."));
6919 * Are the subscription IDs valid?
6922 for (i
= 0, interval
= 60; i
< ids
->num_values
; i
++)
6924 if ((sub
= cupsdFindSubscription(ids
->values
[i
].integer
)) == NULL
)
6927 * Bad subscription ID...
6930 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
6931 ids
->values
[i
].integer
);
6939 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
6941 con
, sub
->owner
)) != HTTP_OK
)
6943 send_http_error(con
, status
, sub
->dest
);
6948 * Check the subscription type and update the interval accordingly.
6951 if (sub
->job
&& sub
->job
->state_value
== IPP_JOB_PROCESSING
&&
6954 else if (sub
->job
&& sub
->job
->state_value
>= IPP_JOB_STOPPED
)
6956 else if (sub
->dest
&& sub
->dest
->state
== IPP_PRINTER_PROCESSING
&&
6962 * Tell the client to poll again in N seconds...
6966 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
6967 "notify-get-interval", interval
);
6969 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
6970 "printer-up-time", time(NULL
));
6973 * Copy the subscription event attributes to the response.
6976 con
->response
->request
.status
.status_code
=
6977 interval
? IPP_OK
: IPP_OK_EVENTS_COMPLETE
;
6979 for (i
= 0; i
< ids
->num_values
; i
++)
6982 * Get the subscription and sequence number...
6985 sub
= cupsdFindSubscription(ids
->values
[i
].integer
);
6987 if (sequences
&& i
< sequences
->num_values
)
6988 min_seq
= sequences
->values
[i
].integer
;
6993 * If we don't have any new events, nothing to do here...
6996 if (min_seq
> (sub
->first_event_id
+ cupsArrayCount(sub
->events
)))
7000 * Otherwise copy all of the new events...
7003 if (sub
->first_event_id
> min_seq
)
7006 j
= min_seq
- sub
->first_event_id
;
7008 for (; j
< cupsArrayCount(sub
->events
); j
++)
7010 ippAddSeparator(con
->response
);
7012 copy_attrs(con
->response
,
7013 ((cupsd_event_t
*)cupsArrayIndex(sub
->events
, j
))->attrs
, NULL
,
7014 IPP_TAG_EVENT_NOTIFICATION
, 0, NULL
);
7021 * 'get_ppd()' - Get a named PPD from the local system.
7025 get_ppd(cupsd_client_t
*con
, /* I - Client connection */
7026 ipp_attribute_t
*uri
) /* I - Printer URI or PPD name */
7028 http_status_t status
; /* Policy status */
7029 cupsd_printer_t
*dest
; /* Destination */
7030 cups_ptype_t dtype
; /* Destination type */
7033 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppd(%p[%d], %p[%s=%s])", con
,
7034 con
->number
, uri
, uri
->name
, uri
->values
[0].string
.text
);
7036 if (!strcmp(ippGetName(uri
), "ppd-name"))
7039 * Return a PPD file from cups-driverd...
7042 const char *ppd_name
= ippGetString(uri
, 0, NULL
);
7043 /* ppd-name value */
7044 char command
[1024], /* cups-driverd command */
7045 options
[1024], /* Options to pass to command */
7046 oppd_name
[1024]; /* Escaped ppd-name */
7052 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7054 send_http_error(con
, status
, NULL
);
7059 * Check ppd-name value...
7062 if (strstr(ppd_name
, "../"))
7064 send_ipp_status(con
, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES
, _("Invalid ppd-name value."));
7069 * Run cups-driverd command with the given options...
7072 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7073 url_encode_string(ppd_name
, oppd_name
, sizeof(oppd_name
));
7074 snprintf(options
, sizeof(options
), "get+%d+%s", ippGetRequestId(con
->request
), oppd_name
);
7076 if (cupsdSendCommand(con
, command
, options
, 0))
7079 * Command started successfully, don't send an IPP response here...
7082 ippDelete(con
->response
);
7083 con
->response
= NULL
;
7088 * Command failed, return "internal error" so the user knows something
7092 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("cups-driverd failed to execute."));
7095 else if (!strcmp(ippGetName(uri
), "printer-uri") && cupsdValidateDest(ippGetString(uri
, 0, NULL
), &dtype
, &dest
))
7097 int i
; /* Looping var */
7098 char filename
[1024]; /* PPD filename */
7104 if ((status
= cupsdCheckPolicy(dest
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7106 send_http_error(con
, status
, dest
);
7111 * See if we need the PPD for a class or remote printer...
7114 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
, dest
->name
);
7116 if ((dtype
& CUPS_PRINTER_REMOTE
) && access(filename
, 0))
7118 send_ipp_status(con
, IPP_STATUS_CUPS_SEE_OTHER
, _("See remote printer."));
7119 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
, dest
->uri
);
7122 else if (dtype
& CUPS_PRINTER_CLASS
)
7124 for (i
= 0; i
< dest
->num_printers
; i
++)
7125 if (!(dest
->printers
[i
]->type
& CUPS_PRINTER_CLASS
))
7127 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
, dest
->printers
[i
]->name
);
7129 if (!access(filename
, 0))
7133 if (i
< dest
->num_printers
)
7134 dest
= dest
->printers
[i
];
7137 send_ipp_status(con
, IPP_STATUS_CUPS_SEE_OTHER
, _("See remote printer."));
7138 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
, dest
->printers
[0]->uri
);
7144 * Found the printer with the PPD file, now see if there is one...
7147 if ((con
->file
= open(filename
, O_RDONLY
)) < 0)
7149 send_ipp_status(con
, IPP_STATUS_ERROR_NOT_FOUND
, _("The PPD file \"%s\" could not be opened: %s"), ippGetString(uri
, 0, NULL
), strerror(errno
));
7153 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
7157 ippSetStatusCode(con
->response
, IPP_STATUS_OK
);
7160 send_ipp_status(con
, IPP_STATUS_ERROR_NOT_FOUND
, _("The PPD file \"%s\" could not be found."), ippGetString(uri
, 0, NULL
));
7165 * 'get_ppds()' - Get the list of PPD files on the local system.
7169 get_ppds(cupsd_client_t
*con
) /* I - Client connection */
7171 http_status_t status
; /* Policy status */
7172 ipp_attribute_t
*limit
, /* Limit attribute */
7173 *device
, /* ppd-device-id attribute */
7174 *language
, /* ppd-natural-language attribute */
7175 *make
, /* ppd-make attribute */
7176 *model
, /* ppd-make-and-model attribute */
7177 *model_number
, /* ppd-model-number attribute */
7178 *product
, /* ppd-product attribute */
7179 *psversion
, /* ppd-psverion attribute */
7180 *type
, /* ppd-type attribute */
7181 *requested
, /* requested-attributes attribute */
7182 *exclude
, /* exclude-schemes attribute */
7183 *include
; /* include-schemes attribute */
7184 char command
[1024], /* cups-driverd command */
7185 options
[4096], /* Options to pass to command */
7186 device_str
[256],/* Escaped ppd-device-id string */
7188 /* Escaped ppd-natural-language */
7189 make_str
[256], /* Escaped ppd-make string */
7190 model_str
[256], /* Escaped ppd-make-and-model string */
7191 model_number_str
[256],
7192 /* ppd-model-number string */
7194 /* Escaped ppd-product string */
7196 /* Escaped ppd-psversion string */
7197 type_str
[256], /* Escaped ppd-type string */
7199 /* String for requested attributes */
7201 /* String for excluded schemes */
7203 /* String for included schemes */
7206 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppds(%p[%d])", con
, con
->number
);
7212 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7214 send_http_error(con
, status
, NULL
);
7219 * Run cups-driverd command with the given options...
7222 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
7223 device
= ippFindAttribute(con
->request
, "ppd-device-id", IPP_TAG_TEXT
);
7224 language
= ippFindAttribute(con
->request
, "ppd-natural-language",
7226 make
= ippFindAttribute(con
->request
, "ppd-make", IPP_TAG_TEXT
);
7227 model
= ippFindAttribute(con
->request
, "ppd-make-and-model",
7229 model_number
= ippFindAttribute(con
->request
, "ppd-model-number",
7231 product
= ippFindAttribute(con
->request
, "ppd-product", IPP_TAG_TEXT
);
7232 psversion
= ippFindAttribute(con
->request
, "ppd-psversion", IPP_TAG_TEXT
);
7233 type
= ippFindAttribute(con
->request
, "ppd-type", IPP_TAG_KEYWORD
);
7234 requested
= ippFindAttribute(con
->request
, "requested-attributes",
7236 exclude
= ippFindAttribute(con
->request
, "exclude-schemes",
7238 include
= ippFindAttribute(con
->request
, "include-schemes",
7242 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
7244 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
7247 url_encode_attr(device
, device_str
, sizeof(device_str
));
7249 device_str
[0] = '\0';
7252 url_encode_attr(language
, language_str
, sizeof(language_str
));
7254 language_str
[0] = '\0';
7257 url_encode_attr(make
, make_str
, sizeof(make_str
));
7262 url_encode_attr(model
, model_str
, sizeof(model_str
));
7264 model_str
[0] = '\0';
7267 snprintf(model_number_str
, sizeof(model_number_str
), "ppd-model-number=%d",
7268 model_number
->values
[0].integer
);
7270 model_number_str
[0] = '\0';
7273 url_encode_attr(product
, product_str
, sizeof(product_str
));
7275 product_str
[0] = '\0';
7278 url_encode_attr(psversion
, psversion_str
, sizeof(psversion_str
));
7280 psversion_str
[0] = '\0';
7283 url_encode_attr(type
, type_str
, sizeof(type_str
));
7288 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
7290 exclude_str
[0] = '\0';
7293 url_encode_attr(include
, include_str
, sizeof(include_str
));
7295 include_str
[0] = '\0';
7297 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7298 snprintf(options
, sizeof(options
),
7299 "list+%d+%d+%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
7300 con
->request
->request
.op
.request_id
,
7301 limit
? limit
->values
[0].integer
: 0,
7303 device
? "%20" : "", device_str
,
7304 language
? "%20" : "", language_str
,
7305 make
? "%20" : "", make_str
,
7306 model
? "%20" : "", model_str
,
7307 model_number
? "%20" : "", model_number_str
,
7308 product
? "%20" : "", product_str
,
7309 psversion
? "%20" : "", psversion_str
,
7310 type
? "%20" : "", type_str
,
7311 exclude_str
[0] ? "%20" : "", exclude_str
,
7312 include_str
[0] ? "%20" : "", include_str
);
7314 if (cupsdSendCommand(con
, command
, options
, 0))
7317 * Command started successfully, don't send an IPP response here...
7320 ippDelete(con
->response
);
7321 con
->response
= NULL
;
7326 * Command failed, return "internal error" so the user knows something
7330 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7331 _("cups-driverd failed to execute."));
7337 * 'get_printer_attrs()' - Get printer attributes.
7341 get_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
7342 ipp_attribute_t
*uri
) /* I - Printer URI */
7344 http_status_t status
; /* Policy status */
7345 cups_ptype_t dtype
; /* Destination type (printer/class) */
7346 cupsd_printer_t
*printer
; /* Printer/class */
7347 cups_array_t
*ra
; /* Requested attributes array */
7350 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_attrs(%p[%d], %s)", con
,
7351 con
->number
, uri
->values
[0].string
.text
);
7354 * Is the destination valid?
7357 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7363 send_ipp_status(con
, IPP_NOT_FOUND
,
7364 _("The printer or class does not exist."));
7372 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7374 send_http_error(con
, status
, printer
);
7379 * Send the attributes...
7382 ra
= create_requested_array(con
->request
);
7384 copy_printer_attrs(con
, printer
, ra
);
7386 cupsArrayDelete(ra
);
7388 con
->response
->request
.status
.status_code
= IPP_OK
;
7393 * 'get_printer_supported()' - Get printer supported values.
7397 get_printer_supported(
7398 cupsd_client_t
*con
, /* I - Client connection */
7399 ipp_attribute_t
*uri
) /* I - Printer URI */
7401 http_status_t status
; /* Policy status */
7402 cups_ptype_t dtype
; /* Destination type (printer/class) */
7403 cupsd_printer_t
*printer
; /* Printer/class */
7406 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_supported(%p[%d], %s)", con
,
7407 con
->number
, uri
->values
[0].string
.text
);
7410 * Is the destination valid?
7413 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7419 send_ipp_status(con
, IPP_NOT_FOUND
,
7420 _("The printer or class does not exist."));
7428 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7430 send_http_error(con
, status
, printer
);
7435 * Return a list of attributes that can be set via Set-Printer-Attributes.
7438 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7439 "printer-geo-location", 0);
7440 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7442 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7443 "printer-location", 0);
7444 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7445 "printer-organization", 0);
7446 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7447 "printer-organizational-unit", 0);
7449 con
->response
->request
.status
.status_code
= IPP_OK
;
7454 * 'get_printers()' - Get a list of printers or classes.
7458 get_printers(cupsd_client_t
*con
, /* I - Client connection */
7459 int type
) /* I - 0 or CUPS_PRINTER_CLASS */
7461 http_status_t status
; /* Policy status */
7462 ipp_attribute_t
*attr
; /* Current attribute */
7463 int limit
; /* Max number of printers to return */
7464 int count
; /* Number of printers that match */
7465 cupsd_printer_t
*printer
; /* Current printer pointer */
7466 cups_ptype_t printer_type
, /* printer-type attribute */
7467 printer_mask
; /* printer-type-mask attribute */
7468 char *location
; /* Location string */
7469 const char *username
; /* Current user */
7470 char *first_printer_name
; /* first-printer-name attribute */
7471 cups_array_t
*ra
; /* Requested attributes array */
7472 int local
; /* Local connection? */
7475 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printers(%p[%d], %x)", con
,
7482 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7484 send_http_error(con
, status
, NULL
);
7489 * Check for printers...
7492 if (!Printers
|| !cupsArrayCount(Printers
))
7494 send_ipp_status(con
, IPP_NOT_FOUND
, _("No destinations added."));
7499 * See if they want to limit the number of printers reported...
7502 if ((attr
= ippFindAttribute(con
->request
, "limit",
7503 IPP_TAG_INTEGER
)) != NULL
)
7504 limit
= attr
->values
[0].integer
;
7508 if ((attr
= ippFindAttribute(con
->request
, "first-printer-name",
7509 IPP_TAG_NAME
)) != NULL
)
7510 first_printer_name
= attr
->values
[0].string
.text
;
7512 first_printer_name
= NULL
;
7515 * Support filtering...
7518 if ((attr
= ippFindAttribute(con
->request
, "printer-type",
7519 IPP_TAG_ENUM
)) != NULL
)
7520 printer_type
= (cups_ptype_t
)attr
->values
[0].integer
;
7522 printer_type
= (cups_ptype_t
)0;
7524 if ((attr
= ippFindAttribute(con
->request
, "printer-type-mask",
7525 IPP_TAG_ENUM
)) != NULL
)
7526 printer_mask
= (cups_ptype_t
)attr
->values
[0].integer
;
7528 printer_mask
= (cups_ptype_t
)0;
7530 local
= httpAddrLocalhost(&(con
->clientaddr
));
7532 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
7533 IPP_TAG_TEXT
)) != NULL
)
7534 location
= attr
->values
[0].string
.text
;
7538 if (con
->username
[0])
7539 username
= con
->username
;
7540 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7541 IPP_TAG_NAME
)) != NULL
)
7542 username
= attr
->values
[0].string
.text
;
7546 ra
= create_requested_array(con
->request
);
7549 * OK, build a list of printers for this printer...
7552 if (first_printer_name
)
7554 if ((printer
= cupsdFindDest(first_printer_name
)) == NULL
)
7555 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7558 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7561 count
< limit
&& printer
;
7562 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
7564 if (!local
&& !printer
->shared
)
7567 if ((!type
|| (printer
->type
& CUPS_PRINTER_CLASS
) == type
) &&
7568 (printer
->type
& printer_mask
) == printer_type
&&
7570 (printer
->location
&& !_cups_strcasecmp(printer
->location
, location
))))
7573 * If a username is specified, see if it is allowed or denied
7577 if (cupsArrayCount(printer
->users
) && username
&&
7578 !user_allowed(printer
, username
))
7582 * Add the group separator as needed...
7586 ippAddSeparator(con
->response
);
7591 * Send the attributes...
7594 copy_printer_attrs(con
, printer
, ra
);
7598 cupsArrayDelete(ra
);
7600 con
->response
->request
.status
.status_code
= IPP_OK
;
7605 * 'get_subscription_attrs()' - Get subscription attributes.
7609 get_subscription_attrs(
7610 cupsd_client_t
*con
, /* I - Client connection */
7611 int sub_id
) /* I - Subscription ID */
7613 http_status_t status
; /* Policy status */
7614 cupsd_subscription_t
*sub
; /* Subscription */
7615 cupsd_policy_t
*policy
; /* Current security policy */
7616 cups_array_t
*ra
, /* Requested attributes array */
7617 *exclude
; /* Private attributes array */
7620 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7621 "get_subscription_attrs(con=%p[%d], sub_id=%d)",
7622 con
, con
->number
, sub_id
);
7625 * Expire subscriptions as needed...
7628 cupsdExpireSubscriptions(NULL
, NULL
);
7631 * Is the subscription ID valid?
7634 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
7637 * Bad subscription ID...
7640 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
7650 policy
= sub
->dest
->op_policy_ptr
;
7652 policy
= DefaultPolicyPtr
;
7654 if ((status
= cupsdCheckPolicy(policy
, con
, sub
->owner
)) != HTTP_OK
)
7656 send_http_error(con
, status
, sub
->dest
);
7660 exclude
= cupsdGetPrivateAttrs(policy
, con
, sub
->dest
, sub
->owner
);
7663 * Copy the subscription attributes to the response using the
7664 * requested-attributes attribute that may be provided by the client.
7667 ra
= create_requested_array(con
->request
);
7669 copy_subscription_attrs(con
, sub
, ra
, exclude
);
7671 cupsArrayDelete(ra
);
7673 con
->response
->request
.status
.status_code
= IPP_OK
;
7678 * 'get_subscriptions()' - Get subscriptions.
7682 get_subscriptions(cupsd_client_t
*con
, /* I - Client connection */
7683 ipp_attribute_t
*uri
) /* I - Printer/job URI */
7685 http_status_t status
; /* Policy status */
7686 int count
; /* Number of subscriptions */
7687 int limit
; /* Limit */
7688 cupsd_subscription_t
*sub
; /* Subscription */
7689 cups_array_t
*ra
; /* Requested attributes array */
7690 ipp_attribute_t
*attr
; /* Attribute */
7691 cups_ptype_t dtype
; /* Destination type (printer/class) */
7692 char scheme
[HTTP_MAX_URI
],
7693 /* Scheme portion of URI */
7694 username
[HTTP_MAX_URI
],
7695 /* Username portion of URI */
7697 /* Host portion of URI */
7698 resource
[HTTP_MAX_URI
];
7699 /* Resource portion of URI */
7700 int port
; /* Port portion of URI */
7701 cupsd_job_t
*job
; /* Job pointer */
7702 cupsd_printer_t
*printer
; /* Printer */
7703 cupsd_policy_t
*policy
; /* Policy */
7704 cups_array_t
*exclude
; /* Private attributes array */
7707 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7708 "get_subscriptions(con=%p[%d], uri=%s)",
7709 con
, con
->number
, uri
->values
[0].string
.text
);
7712 * Is the destination valid?
7715 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7716 sizeof(scheme
), username
, sizeof(username
), host
,
7717 sizeof(host
), &port
, resource
, sizeof(resource
));
7719 if (!strcmp(resource
, "/") ||
7720 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6) ||
7721 (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10) ||
7722 (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9))
7727 else if (!strncmp(resource
, "/jobs/", 6) && resource
[6])
7730 job
= cupsdFindJob(atoi(resource
+ 6));
7734 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
7735 atoi(resource
+ 6));
7739 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7745 send_ipp_status(con
, IPP_NOT_FOUND
,
7746 _("The printer or class does not exist."));
7749 else if ((attr
= ippFindAttribute(con
->request
, "notify-job-id",
7750 IPP_TAG_INTEGER
)) != NULL
)
7752 job
= cupsdFindJob(attr
->values
[0].integer
);
7756 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
7757 attr
->values
[0].integer
);
7769 policy
= printer
->op_policy_ptr
;
7771 policy
= DefaultPolicyPtr
;
7773 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
7775 send_http_error(con
, status
, printer
);
7780 * Expire subscriptions as needed...
7783 cupsdExpireSubscriptions(NULL
, NULL
);
7786 * Copy the subscription attributes to the response using the
7787 * requested-attributes attribute that may be provided by the client.
7790 ra
= create_requested_array(con
->request
);
7792 if ((attr
= ippFindAttribute(con
->request
, "limit",
7793 IPP_TAG_INTEGER
)) != NULL
)
7794 limit
= attr
->values
[0].integer
;
7799 * See if we only want to see subscriptions for a specific user...
7802 if ((attr
= ippFindAttribute(con
->request
, "my-subscriptions",
7803 IPP_TAG_BOOLEAN
)) != NULL
&&
7804 attr
->values
[0].boolean
)
7805 strlcpy(username
, get_username(con
), sizeof(username
));
7809 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
), count
= 0;
7811 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
7812 if ((!printer
|| sub
->dest
== printer
) && (!job
|| sub
->job
== job
) &&
7813 (!username
[0] || !_cups_strcasecmp(username
, sub
->owner
)))
7815 ippAddSeparator(con
->response
);
7817 exclude
= cupsdGetPrivateAttrs(sub
->dest
? sub
->dest
->op_policy_ptr
:
7818 policy
, con
, sub
->dest
,
7821 copy_subscription_attrs(con
, sub
, ra
, exclude
);
7824 if (limit
&& count
>= limit
)
7828 cupsArrayDelete(ra
);
7831 con
->response
->request
.status
.status_code
= IPP_OK
;
7833 send_ipp_status(con
, IPP_NOT_FOUND
, _("No subscriptions found."));
7838 * 'get_username()' - Get the username associated with a request.
7841 static const char * /* O - Username */
7842 get_username(cupsd_client_t
*con
) /* I - Connection */
7844 ipp_attribute_t
*attr
; /* Attribute */
7847 if (con
->username
[0])
7848 return (con
->username
);
7849 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7850 IPP_TAG_NAME
)) != NULL
)
7851 return (attr
->values
[0].string
.text
);
7853 return ("anonymous");
7858 * 'hold_job()' - Hold a print job.
7862 hold_job(cupsd_client_t
*con
, /* I - Client connection */
7863 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
7865 ipp_attribute_t
*attr
; /* Current job-hold-until */
7866 const char *when
; /* New value */
7867 int jobid
; /* Job ID */
7868 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
7869 username
[HTTP_MAX_URI
], /* Username portion of URI */
7870 host
[HTTP_MAX_URI
], /* Host portion of URI */
7871 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7872 int port
; /* Port portion of URI */
7873 cupsd_job_t
*job
; /* Job information */
7876 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_job(%p[%d], %s)", con
, con
->number
,
7877 uri
->values
[0].string
.text
);
7880 * See if we have a job URI or a printer URI...
7883 if (!strcmp(uri
->name
, "printer-uri"))
7886 * Got a printer URI; see if we also have a job-id attribute...
7889 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7890 IPP_TAG_INTEGER
)) == NULL
)
7892 send_ipp_status(con
, IPP_BAD_REQUEST
,
7893 _("Got a printer-uri attribute but no job-id."));
7897 jobid
= attr
->values
[0].integer
;
7902 * Got a job URI; parse it to get the job ID...
7905 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7906 sizeof(scheme
), username
, sizeof(username
), host
,
7907 sizeof(host
), &port
, resource
, sizeof(resource
));
7909 if (strncmp(resource
, "/jobs/", 6))
7915 send_ipp_status(con
, IPP_BAD_REQUEST
,
7916 _("Bad job-uri \"%s\"."),
7917 uri
->values
[0].string
.text
);
7921 jobid
= atoi(resource
+ 6);
7925 * See if the job exists...
7928 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7931 * Nope - return a "not found" error...
7934 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
7939 * See if the job is owned by the requesting user...
7942 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7944 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
7945 cupsdFindDest(job
->dest
));
7950 * See if the job is in a state that allows holding...
7953 if (job
->state_value
> IPP_JOB_STOPPED
)
7956 * Return a "not-possible" error...
7959 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
7960 _("Job #%d is finished and cannot be altered."),
7966 * Hold the job and return...
7969 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
7970 IPP_TAG_KEYWORD
)) == NULL
)
7971 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
7975 when
= attr
->values
[0].string
.text
;
7977 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
7978 "Job job-hold-until value changed by user.");
7981 when
= "indefinite";
7983 cupsdSetJobHoldUntil(job
, when
, 1);
7984 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
, "Job held by \"%s\".",
7987 con
->response
->request
.status
.status_code
= IPP_OK
;
7992 * 'hold_new_jobs()' - Hold pending/new jobs on a printer or class.
7996 hold_new_jobs(cupsd_client_t
*con
, /* I - Connection */
7997 ipp_attribute_t
*uri
) /* I - Printer URI */
7999 http_status_t status
; /* Policy status */
8000 cups_ptype_t dtype
; /* Destination type (printer/class) */
8001 cupsd_printer_t
*printer
; /* Printer data */
8004 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_new_jobs(%p[%d], %s)", con
,
8005 con
->number
, uri
->values
[0].string
.text
);
8008 * Is the destination valid?
8011 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8017 send_ipp_status(con
, IPP_NOT_FOUND
,
8018 _("The printer or class does not exist."));
8026 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8028 send_http_error(con
, status
, printer
);
8033 * Hold pending/new jobs sent to the printer...
8036 printer
->holding_new_jobs
= 1;
8038 cupsdSetPrinterReasons(printer
, "+hold-new-jobs");
8040 if (dtype
& CUPS_PRINTER_CLASS
)
8041 cupsdLogMessage(CUPSD_LOG_INFO
,
8042 "Class \"%s\" now holding pending/new jobs (\"%s\").",
8043 printer
->name
, get_username(con
));
8045 cupsdLogMessage(CUPSD_LOG_INFO
,
8046 "Printer \"%s\" now holding pending/new jobs (\"%s\").",
8047 printer
->name
, get_username(con
));
8050 * Everything was ok, so return OK status...
8053 con
->response
->request
.status
.status_code
= IPP_OK
;
8058 * 'move_job()' - Move a job to a new destination.
8062 move_job(cupsd_client_t
*con
, /* I - Client connection */
8063 ipp_attribute_t
*uri
) /* I - Job URI */
8065 http_status_t status
; /* Policy status */
8066 ipp_attribute_t
*attr
; /* Current attribute */
8067 int jobid
; /* Job ID */
8068 cupsd_job_t
*job
; /* Current job */
8069 const char *src
; /* Source printer/class */
8070 cups_ptype_t stype
, /* Source type (printer or class) */
8071 dtype
; /* Destination type (printer/class) */
8072 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
8073 username
[HTTP_MAX_URI
], /* Username portion of URI */
8074 host
[HTTP_MAX_URI
], /* Host portion of URI */
8075 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8076 int port
; /* Port portion of URI */
8077 cupsd_printer_t
*sprinter
, /* Source printer */
8078 *dprinter
; /* Destination printer */
8081 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "move_job(%p[%d], %s)", con
, con
->number
,
8082 uri
->values
[0].string
.text
);
8085 * Get the new printer or class...
8088 if ((attr
= ippFindAttribute(con
->request
, "job-printer-uri",
8089 IPP_TAG_URI
)) == NULL
)
8092 * Need job-printer-uri...
8095 send_ipp_status(con
, IPP_BAD_REQUEST
,
8096 _("job-printer-uri attribute missing."));
8100 if (!cupsdValidateDest(attr
->values
[0].string
.text
, &dtype
, &dprinter
))
8106 send_ipp_status(con
, IPP_NOT_FOUND
,
8107 _("The printer or class does not exist."));
8112 * See if we have a job URI or a printer URI...
8115 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8116 sizeof(scheme
), username
, sizeof(username
), host
,
8117 sizeof(host
), &port
, resource
, sizeof(resource
));
8119 if (!strcmp(uri
->name
, "printer-uri"))
8122 * Got a printer URI; see if we also have a job-id attribute...
8125 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8126 IPP_TAG_INTEGER
)) == NULL
)
8132 if ((src
= cupsdValidateDest(uri
->values
[0].string
.text
, &stype
,
8133 &sprinter
)) == NULL
)
8139 send_ipp_status(con
, IPP_NOT_FOUND
,
8140 _("The printer or class does not exist."));
8149 * Otherwise, just move a single job...
8152 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
8155 * Nope - return a "not found" error...
8158 send_ipp_status(con
, IPP_NOT_FOUND
,
8159 _("Job #%d does not exist."), attr
->values
[0].integer
);
8165 * Job found, initialize source pointers...
8176 * Got a job URI; parse it to get the job ID...
8179 if (strncmp(resource
, "/jobs/", 6))
8185 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
8186 uri
->values
[0].string
.text
);
8191 * See if the job exists...
8194 jobid
= atoi(resource
+ 6);
8196 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8199 * Nope - return a "not found" error...
8202 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
8208 * Job found, initialize source pointers...
8217 * Check the policy of the destination printer...
8220 if ((status
= cupsdCheckPolicy(dprinter
->op_policy_ptr
, con
,
8221 job
? job
->username
: NULL
)) != HTTP_OK
)
8223 send_http_error(con
, status
, dprinter
);
8228 * Now move the job or jobs...
8234 * See if the job has been completed...
8237 if (job
->state_value
> IPP_JOB_STOPPED
)
8240 * Return a "not-possible" error...
8243 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8244 _("Job #%d is finished and cannot be altered."),
8250 * See if the job is owned by the requesting user...
8253 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8255 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8256 cupsdFindDest(job
->dest
));
8261 * Move the job to a different printer or class...
8264 cupsdMoveJob(job
, dprinter
);
8269 * Got the source printer, now look through the jobs...
8272 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
8274 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
8277 * See if the job is pointing at the source printer or has not been
8281 if (_cups_strcasecmp(job
->dest
, src
) ||
8282 job
->state_value
> IPP_JOB_STOPPED
)
8286 * See if the job can be moved by the requesting user...
8289 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8293 * Move the job to a different printer or class...
8296 cupsdMoveJob(job
, dprinter
);
8301 * Start jobs if possible...
8307 * Return with "everything is OK" status...
8310 con
->response
->request
.status
.status_code
= IPP_OK
;
8315 * 'ppd_parse_line()' - Parse a PPD default line.
8318 static int /* O - 0 on success, -1 on failure */
8319 ppd_parse_line(const char *line
, /* I - Line */
8320 char *option
, /* O - Option name */
8321 int olen
, /* I - Size of option name */
8322 char *choice
, /* O - Choice name */
8323 int clen
) /* I - Size of choice name */
8326 * Verify this is a default option line...
8329 if (strncmp(line
, "*Default", 8))
8333 * Read the option name...
8336 for (line
+= 8, olen
--;
8337 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
8348 * Skip everything else up to the colon (:)...
8351 while (*line
&& *line
!= ':')
8360 * Now grab the option choice, skipping leading whitespace...
8363 while (isspace(*line
& 255))
8367 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
8378 * Return with no errors...
8386 * 'print_job()' - Print a file to a printer or class.
8390 print_job(cupsd_client_t
*con
, /* I - Client connection */
8391 ipp_attribute_t
*uri
) /* I - Printer URI */
8393 ipp_attribute_t
*attr
; /* Current attribute */
8394 ipp_attribute_t
*doc_name
; /* document-name attribute */
8395 ipp_attribute_t
*format
; /* Document-format attribute */
8396 const char *default_format
; /* document-format-default value */
8397 cupsd_job_t
*job
; /* New job */
8398 char filename
[1024]; /* Job filename */
8399 mime_type_t
*filetype
; /* Type of file */
8400 char super
[MIME_MAX_SUPER
], /* Supertype of file */
8401 type
[MIME_MAX_TYPE
], /* Subtype of file */
8402 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
8403 /* Textual name of mime type */
8404 cupsd_printer_t
*printer
; /* Printer data */
8405 struct stat fileinfo
; /* File information */
8406 int kbytes
; /* Size of file */
8407 int compression
; /* Document compression */
8410 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "print_job(%p[%d], %s)", con
, con
->number
,
8411 uri
->values
[0].string
.text
);
8414 * Validate print file attributes, for now just document-format and
8415 * compression (CUPS only supports "none" and "gzip")...
8418 compression
= CUPS_FILE_NONE
;
8420 if ((attr
= ippFindAttribute(con
->request
, "compression",
8421 IPP_TAG_KEYWORD
)) != NULL
)
8423 if (strcmp(attr
->values
[0].string
.text
, "none")
8425 && strcmp(attr
->values
[0].string
.text
, "gzip")
8426 #endif /* HAVE_LIBZ */
8429 send_ipp_status(con
, IPP_ATTRIBUTES
,
8430 _("Unsupported compression \"%s\"."),
8431 attr
->values
[0].string
.text
);
8432 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
8433 "compression", NULL
, attr
->values
[0].string
.text
);
8438 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
8439 compression
= CUPS_FILE_GZIP
;
8440 #endif /* HAVE_LIBZ */
8444 * Do we have a file to print?
8449 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file in print request."));
8454 * Is the destination valid?
8457 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
8463 send_ipp_status(con
, IPP_NOT_FOUND
,
8464 _("The printer or class does not exist."));
8469 * Is it a format we support?
8472 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
8474 ippSetName(con
->request
, &doc_name
, "document-name-supplied");
8476 if ((format
= ippFindAttribute(con
->request
, "document-format",
8477 IPP_TAG_MIMETYPE
)) != NULL
)
8480 * Grab format from client...
8483 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%255[^;]", super
,
8486 send_ipp_status(con
, IPP_BAD_REQUEST
,
8487 _("Bad document-format \"%s\"."),
8488 format
->values
[0].string
.text
);
8492 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format-supplied", NULL
, ippGetString(format
, 0, NULL
));
8494 else if ((default_format
= cupsGetOption("document-format",
8495 printer
->num_options
,
8496 printer
->options
)) != NULL
)
8499 * Use default document format...
8502 if (sscanf(default_format
, "%15[^/]/%255[^;]", super
, type
) != 2)
8504 send_ipp_status(con
, IPP_BAD_REQUEST
,
8505 _("Bad document-format \"%s\"."),
8516 strlcpy(super
, "application", sizeof(super
));
8517 strlcpy(type
, "octet-stream", sizeof(type
));
8520 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
8523 * Auto-type the file...
8526 cupsdLogMessage(CUPSD_LOG_DEBUG
, "[Job ???] Auto-typing file...");
8529 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
8530 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
8534 filetype
= mimeType(MimeDatabase
, super
, type
);
8536 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job ???] Request file type is %s/%s.",
8537 filetype
->super
, filetype
->type
);
8539 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
, filetype
->type
);
8540 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format-detected", NULL
, mimetype
);
8543 filetype
= mimeType(MimeDatabase
, super
, type
);
8547 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
8550 * Replace the document-format attribute value with the auto-typed or
8554 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
8558 ippSetString(con
->request
, &format
, 0, mimetype
);
8560 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
8561 "document-format", NULL
, mimetype
);
8565 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
8566 _("Unsupported document-format \"%s\"."),
8567 format
? format
->values
[0].string
.text
:
8568 "application/octet-stream");
8569 cupsdLogMessage(CUPSD_LOG_INFO
,
8570 "Hint: Do you have the raw file printing rules enabled?");
8573 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
8574 "document-format", NULL
, format
->values
[0].string
.text
);
8580 * Read any embedded job ticket info from PS files...
8583 if (!_cups_strcasecmp(filetype
->super
, "application") &&
8584 (!_cups_strcasecmp(filetype
->type
, "postscript") ||
8585 !_cups_strcasecmp(filetype
->type
, "pdf")))
8586 read_job_ticket(con
);
8589 * Create the job object...
8592 if ((job
= add_job(con
, printer
, filetype
)) == NULL
)
8596 * Update quota data...
8599 if (stat(con
->filename
, &fileinfo
))
8602 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
8604 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
8606 job
->koctets
+= kbytes
;
8608 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets", IPP_TAG_INTEGER
)) != NULL
)
8609 attr
->values
[0].integer
+= kbytes
;
8612 * Add the job file...
8615 if (add_file(con
, job
, filetype
, compression
))
8618 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
, job
->num_files
);
8619 if (rename(con
->filename
, filename
))
8621 cupsdLogJob(job
, CUPSD_LOG_ERROR
, "Unable to rename job document file \"%s\": %s", filename
, strerror(errno
));
8623 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to rename job document file."));
8627 cupsdClearString(&con
->filename
);
8630 * See if we need to add the ending sheet...
8633 if (cupsdTimeoutJob(job
))
8637 * Log and save the job...
8640 cupsdLogJob(job
, CUPSD_LOG_INFO
,
8641 "File of type %s/%s queued by \"%s\".",
8642 filetype
->super
, filetype
->type
, job
->username
);
8643 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "hold_until=%d", (int)job
->hold_until
);
8644 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
8645 job
->dest
, job
->username
);
8648 * Start the job if possible...
8656 * 'read_job_ticket()' - Read a job ticket embedded in a print file.
8658 * This function only gets called when printing a single PDF or PostScript
8659 * file using the Print-Job operation. It doesn't work for Create-Job +
8660 * Send-File, since the job attributes need to be set at job creation
8661 * time for banners to work. The embedded job ticket stuff is here
8662 * primarily to allow the Windows printer driver for CUPS to pass in JCL
8663 * options and IPP attributes which otherwise would be lost.
8665 * The format of a job ticket is simple:
8667 * %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
8669 * %cupsJobTicket: attr1=value1
8670 * %cupsJobTicket: attr2=value2
8672 * %cupsJobTicket: attrN=valueN
8674 * Job ticket lines must appear immediately after the first line that
8675 * specifies PostScript (%!PS-Adobe-3.0) or PDF (%PDF) format, and CUPS
8676 * stops looking for job ticket info when it finds a line that does not begin
8677 * with "%cupsJobTicket:".
8679 * The maximum length of a job ticket line, including the prefix, is
8680 * 255 characters to conform with the Adobe DSC.
8682 * Read-only attributes are rejected with a notice to the error log in
8683 * case a malicious user tries anything. Since the job ticket is read
8684 * prior to attribute validation in print_job(), job ticket attributes
8685 * will go through the same validation as IPP attributes...
8689 read_job_ticket(cupsd_client_t
*con
) /* I - Client connection */
8691 cups_file_t
*fp
; /* File to read from */
8692 char line
[256]; /* Line data */
8693 int num_options
; /* Number of options */
8694 cups_option_t
*options
; /* Options */
8695 ipp_t
*ticket
; /* New attributes */
8696 ipp_attribute_t
*attr
, /* Current attribute */
8697 *attr2
, /* Job attribute */
8698 *prev2
; /* Previous job attribute */
8702 * First open the print file...
8705 if ((fp
= cupsFileOpen(con
->filename
, "rb")) == NULL
)
8707 cupsdLogMessage(CUPSD_LOG_ERROR
,
8708 "Unable to open print file for job ticket - %s",
8714 * Skip the first line...
8717 if (cupsFileGets(fp
, line
, sizeof(line
)) == NULL
)
8719 cupsdLogMessage(CUPSD_LOG_ERROR
,
8720 "Unable to read from print file for job ticket - %s",
8726 if (strncmp(line
, "%!PS-Adobe-", 11) && strncmp(line
, "%PDF-", 5))
8729 * Not a DSC-compliant file, so no job ticket info will be available...
8737 * Read job ticket info from the file...
8743 while (cupsFileGets(fp
, line
, sizeof(line
)))
8746 * Stop at the first non-ticket line...
8749 if (strncmp(line
, "%cupsJobTicket:", 15))
8753 * Add the options to the option array...
8756 num_options
= cupsParseOptions(line
+ 15, num_options
, &options
);
8760 * Done with the file; see if we have any options...
8765 if (num_options
== 0)
8769 * OK, convert the options to an attribute list, and apply them to
8774 cupsEncodeOptions(ticket
, num_options
, options
);
8777 * See what the user wants to change.
8780 for (attr
= ticket
->attrs
; attr
; attr
= attr
->next
)
8782 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
8785 if (!strncmp(attr
->name
, "date-time-at-", 13) ||
8786 !strcmp(attr
->name
, "job-impressions-completed") ||
8787 !strcmp(attr
->name
, "job-media-sheets-completed") ||
8788 !strncmp(attr
->name
, "job-k-octets", 12) ||
8789 !strcmp(attr
->name
, "job-id") ||
8790 !strcmp(attr
->name
, "job-originating-host-name") ||
8791 !strcmp(attr
->name
, "job-originating-user-name") ||
8792 !strcmp(attr
->name
, "job-pages-completed") ||
8793 !strcmp(attr
->name
, "job-printer-uri") ||
8794 !strncmp(attr
->name
, "job-state", 9) ||
8795 !strcmp(attr
->name
, "job-uri") ||
8796 !strncmp(attr
->name
, "time-at-", 8))
8797 continue; /* Read-only attrs */
8799 if ((attr2
= ippFindAttribute(con
->request
, attr
->name
,
8800 IPP_TAG_ZERO
)) != NULL
)
8803 * Some other value; first free the old value...
8806 if (con
->request
->attrs
== attr2
)
8808 con
->request
->attrs
= attr2
->next
;
8813 for (prev2
= con
->request
->attrs
; prev2
; prev2
= prev2
->next
)
8814 if (prev2
->next
== attr2
)
8816 prev2
->next
= attr2
->next
;
8821 if (con
->request
->last
== attr2
)
8822 con
->request
->last
= prev2
;
8824 ippDeleteAttribute(NULL
, attr2
);
8828 * Add new option by copying it...
8831 ippCopyAttribute(con
->request
, attr
, 0);
8835 * Then free the attribute list and option array...
8839 cupsFreeOptions(num_options
, options
);
8844 * 'reject_jobs()' - Reject print jobs to a printer.
8848 reject_jobs(cupsd_client_t
*con
, /* I - Client connection */
8849 ipp_attribute_t
*uri
) /* I - Printer or class URI */
8851 http_status_t status
; /* Policy status */
8852 cups_ptype_t dtype
; /* Destination type (printer/class) */
8853 cupsd_printer_t
*printer
; /* Printer data */
8854 ipp_attribute_t
*attr
; /* printer-state-message text */
8857 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "reject_jobs(%p[%d], %s)", con
,
8858 con
->number
, uri
->values
[0].string
.text
);
8861 * Is the destination valid?
8864 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8870 send_ipp_status(con
, IPP_NOT_FOUND
,
8871 _("The printer or class does not exist."));
8879 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8881 send_http_error(con
, status
, printer
);
8886 * Reject jobs sent to the printer...
8889 printer
->accepting
= 0;
8891 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
8892 IPP_TAG_TEXT
)) == NULL
)
8893 strlcpy(printer
->state_message
, "Rejecting Jobs",
8894 sizeof(printer
->state_message
));
8896 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
8897 sizeof(printer
->state_message
));
8899 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
8900 "No longer accepting jobs.");
8902 if (dtype
& CUPS_PRINTER_CLASS
)
8904 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
8906 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" rejecting jobs (\"%s\").",
8907 printer
->name
, get_username(con
));
8911 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
8913 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" rejecting jobs (\"%s\").",
8914 printer
->name
, get_username(con
));
8918 * Everything was ok, so return OK status...
8921 con
->response
->request
.status
.status_code
= IPP_OK
;
8926 * 'release_held_new_jobs()' - Release pending/new jobs on a printer or class.
8930 release_held_new_jobs(
8931 cupsd_client_t
*con
, /* I - Connection */
8932 ipp_attribute_t
*uri
) /* I - Printer URI */
8934 http_status_t status
; /* Policy status */
8935 cups_ptype_t dtype
; /* Destination type (printer/class) */
8936 cupsd_printer_t
*printer
; /* Printer data */
8939 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_held_new_jobs(%p[%d], %s)", con
,
8940 con
->number
, uri
->values
[0].string
.text
);
8943 * Is the destination valid?
8946 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8952 send_ipp_status(con
, IPP_NOT_FOUND
,
8953 _("The printer or class does not exist."));
8961 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8963 send_http_error(con
, status
, printer
);
8968 * Hold pending/new jobs sent to the printer...
8971 printer
->holding_new_jobs
= 0;
8973 cupsdSetPrinterReasons(printer
, "-hold-new-jobs");
8975 if (dtype
& CUPS_PRINTER_CLASS
)
8976 cupsdLogMessage(CUPSD_LOG_INFO
,
8977 "Class \"%s\" now printing pending/new jobs (\"%s\").",
8978 printer
->name
, get_username(con
));
8980 cupsdLogMessage(CUPSD_LOG_INFO
,
8981 "Printer \"%s\" now printing pending/new jobs (\"%s\").",
8982 printer
->name
, get_username(con
));
8987 * Everything was ok, so return OK status...
8990 con
->response
->request
.status
.status_code
= IPP_OK
;
8995 * 'release_job()' - Release a held print job.
8999 release_job(cupsd_client_t
*con
, /* I - Client connection */
9000 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9002 ipp_attribute_t
*attr
; /* Current attribute */
9003 int jobid
; /* Job ID */
9004 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9005 username
[HTTP_MAX_URI
], /* Username portion of URI */
9006 host
[HTTP_MAX_URI
], /* Host portion of URI */
9007 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9008 int port
; /* Port portion of URI */
9009 cupsd_job_t
*job
; /* Job information */
9012 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_job(%p[%d], %s)", con
,
9013 con
->number
, uri
->values
[0].string
.text
);
9016 * See if we have a job URI or a printer URI...
9019 if (!strcmp(uri
->name
, "printer-uri"))
9022 * Got a printer URI; see if we also have a job-id attribute...
9025 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9026 IPP_TAG_INTEGER
)) == NULL
)
9028 send_ipp_status(con
, IPP_BAD_REQUEST
,
9029 _("Got a printer-uri attribute but no job-id."));
9033 jobid
= attr
->values
[0].integer
;
9038 * Got a job URI; parse it to get the job ID...
9041 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9042 sizeof(scheme
), username
, sizeof(username
), host
,
9043 sizeof(host
), &port
, resource
, sizeof(resource
));
9045 if (strncmp(resource
, "/jobs/", 6))
9051 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9052 uri
->values
[0].string
.text
);
9056 jobid
= atoi(resource
+ 6);
9060 * See if the job exists...
9063 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9066 * Nope - return a "not found" error...
9069 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9074 * See if job is "held"...
9077 if (job
->state_value
!= IPP_JOB_HELD
)
9080 * Nope - return a "not possible" error...
9083 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not held."), jobid
);
9088 * See if the job is owned by the requesting user...
9091 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9093 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9094 cupsdFindDest(job
->dest
));
9099 * Reset the job-hold-until value to "no-hold"...
9102 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9103 IPP_TAG_KEYWORD
)) == NULL
)
9104 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9108 ippSetValueTag(job
->attrs
, &attr
, IPP_TAG_KEYWORD
);
9109 ippSetString(job
->attrs
, &attr
, 0, "no-hold");
9111 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
9112 "Job job-hold-until value changed by user.");
9113 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
9117 * Release the job and return...
9120 cupsdReleaseJob(job
);
9122 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
9123 "Job released by user.");
9125 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Released by \"%s\".", username
);
9127 con
->response
->request
.status
.status_code
= IPP_OK
;
9134 * 'renew_subscription()' - Renew an existing subscription...
9139 cupsd_client_t
*con
, /* I - Client connection */
9140 int sub_id
) /* I - Subscription ID */
9142 http_status_t status
; /* Policy status */
9143 cupsd_subscription_t
*sub
; /* Subscription */
9144 ipp_attribute_t
*lease
; /* notify-lease-duration */
9147 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
9148 "renew_subscription(con=%p[%d], sub_id=%d)",
9149 con
, con
->number
, sub_id
);
9152 * Is the subscription ID valid?
9155 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
9158 * Bad subscription ID...
9161 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
9169 * Job subscriptions cannot be renewed...
9172 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9173 _("Job subscriptions cannot be renewed."));
9181 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
9183 con
, sub
->owner
)) != HTTP_OK
)
9185 send_http_error(con
, status
, sub
->dest
);
9190 * Renew the subscription...
9193 lease
= ippFindAttribute(con
->request
, "notify-lease-duration",
9196 sub
->lease
= lease
? lease
->values
[0].integer
: DefaultLeaseDuration
;
9198 if (MaxLeaseDuration
&& (sub
->lease
== 0 || sub
->lease
> MaxLeaseDuration
))
9200 cupsdLogMessage(CUPSD_LOG_INFO
,
9201 "renew_subscription: Limiting notify-lease-duration to "
9204 sub
->lease
= MaxLeaseDuration
;
9207 sub
->expire
= sub
->lease
? time(NULL
) + sub
->lease
: 0;
9209 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
9211 con
->response
->request
.status
.status_code
= IPP_OK
;
9213 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
9214 "notify-lease-duration", sub
->lease
);
9219 * 'restart_job()' - Restart an old print job.
9223 restart_job(cupsd_client_t
*con
, /* I - Client connection */
9224 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9226 ipp_attribute_t
*attr
; /* Current attribute */
9227 int jobid
; /* Job ID */
9228 cupsd_job_t
*job
; /* Job information */
9229 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9230 username
[HTTP_MAX_URI
], /* Username portion of URI */
9231 host
[HTTP_MAX_URI
], /* Host portion of URI */
9232 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9233 int port
; /* Port portion of URI */
9236 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "restart_job(%p[%d], %s)", con
,
9237 con
->number
, uri
->values
[0].string
.text
);
9240 * See if we have a job URI or a printer URI...
9243 if (!strcmp(uri
->name
, "printer-uri"))
9246 * Got a printer URI; see if we also have a job-id attribute...
9249 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9250 IPP_TAG_INTEGER
)) == NULL
)
9252 send_ipp_status(con
, IPP_BAD_REQUEST
,
9253 _("Got a printer-uri attribute but no job-id."));
9257 jobid
= attr
->values
[0].integer
;
9262 * Got a job URI; parse it to get the job ID...
9265 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9266 sizeof(scheme
), username
, sizeof(username
), host
,
9267 sizeof(host
), &port
, resource
, sizeof(resource
));
9269 if (strncmp(resource
, "/jobs/", 6))
9275 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9276 uri
->values
[0].string
.text
);
9280 jobid
= atoi(resource
+ 6);
9284 * See if the job exists...
9287 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9290 * Nope - return a "not found" error...
9293 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9298 * See if job is in any of the "completed" states...
9301 if (job
->state_value
<= IPP_JOB_PROCESSING
)
9304 * Nope - return a "not possible" error...
9307 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not complete."),
9313 * See if we have retained the job files...
9318 if (!job
->attrs
|| job
->num_files
== 0)
9321 * Nope - return a "not possible" error...
9324 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9325 _("Job #%d cannot be restarted - no files."), jobid
);
9330 * See if the job is owned by the requesting user...
9333 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9335 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9336 cupsdFindDest(job
->dest
));
9341 * See if the job-hold-until attribute is specified...
9344 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
9345 IPP_TAG_KEYWORD
)) == NULL
)
9346 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
9348 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
9351 * Return the job to a held state...
9354 cupsdLogJob(job
, CUPSD_LOG_DEBUG
,
9355 "Restarted by \"%s\" with job-hold-until=%s.",
9356 username
, attr
->values
[0].string
.text
);
9357 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
9359 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
,
9360 NULL
, job
, "Job restarted by user with job-hold-until=%s",
9361 attr
->values
[0].string
.text
);
9366 * Restart the job...
9369 cupsdRestartJob(job
);
9373 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Restarted by \"%s\".", username
);
9375 con
->response
->request
.status
.status_code
= IPP_OK
;
9380 * 'save_auth_info()' - Save authentication information for a job.
9385 cupsd_client_t
*con
, /* I - Client connection */
9386 cupsd_job_t
*job
, /* I - Job */
9387 ipp_attribute_t
*auth_info
) /* I - auth-info attribute, if any */
9389 int i
; /* Looping var */
9390 char filename
[1024]; /* Job authentication filename */
9391 cups_file_t
*fp
; /* Job authentication file */
9392 char line
[65536]; /* Line for file */
9393 cupsd_printer_t
*dest
; /* Destination printer/class */
9397 * This function saves the in-memory authentication information for
9398 * a job so that it can be used to authenticate with a remote host.
9399 * The information is stored in a file that is readable only by the
9400 * root user. The fields are Base-64 encoded, each on a separate line,
9401 * followed by random number (up to 1024) of newlines to limit the
9402 * amount of information that is exposed.
9404 * Because of the potential for exposing of authentication information,
9405 * this functionality is only enabled when running cupsd as root.
9407 * This caching only works for the Basic and BasicDigest authentication
9408 * types. Digest authentication cannot be cached this way, and in
9409 * the future Kerberos authentication may make all of this obsolete.
9411 * Authentication information is saved whenever an authenticated
9412 * Print-Job, Create-Job, or CUPS-Authenticate-Job operation is
9415 * This information is deleted after a job is completed or canceled,
9416 * so reprints may require subsequent re-authentication.
9422 if ((dest
= cupsdFindDest(job
->dest
)) == NULL
)
9426 * Create the authentication file and change permissions...
9429 snprintf(filename
, sizeof(filename
), "%s/a%05d", RequestRoot
, job
->id
);
9430 if ((fp
= cupsFileOpen(filename
, "w")) == NULL
)
9432 cupsdLogMessage(CUPSD_LOG_ERROR
,
9433 "Unable to save authentication info to \"%s\" - %s",
9434 filename
, strerror(errno
));
9438 fchown(cupsFileNumber(fp
), 0, 0);
9439 fchmod(cupsFileNumber(fp
), 0400);
9441 cupsFilePuts(fp
, "CUPSD-AUTH-V3\n");
9444 i
< (int)(sizeof(job
->auth_env
) / sizeof(job
->auth_env
[0]));
9446 cupsdClearString(job
->auth_env
+ i
);
9448 if (auth_info
&& auth_info
->num_values
== dest
->num_auth_info_required
)
9451 * Write 1 to 3 auth values...
9455 i
< auth_info
->num_values
&&
9456 i
< (int)(sizeof(job
->auth_env
) / sizeof(job
->auth_env
[0]));
9459 if (strcmp(dest
->auth_info_required
[i
], "negotiate"))
9461 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[i
].string
.text
, (int)strlen(auth_info
->values
[i
].string
.text
));
9462 cupsFilePutConf(fp
, dest
->auth_info_required
[i
], line
);
9465 cupsFilePutConf(fp
, dest
->auth_info_required
[i
],
9466 auth_info
->values
[i
].string
.text
);
9468 if (!strcmp(dest
->auth_info_required
[i
], "username"))
9469 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_USERNAME=%s",
9470 auth_info
->values
[i
].string
.text
);
9471 else if (!strcmp(dest
->auth_info_required
[i
], "domain"))
9472 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_DOMAIN=%s",
9473 auth_info
->values
[i
].string
.text
);
9474 else if (!strcmp(dest
->auth_info_required
[i
], "password"))
9475 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_PASSWORD=%s",
9476 auth_info
->values
[i
].string
.text
);
9477 else if (!strcmp(dest
->auth_info_required
[i
], "negotiate"))
9478 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_NEGOTIATE=%s",
9479 auth_info
->values
[i
].string
.text
);
9484 else if (auth_info
&& auth_info
->num_values
== 2 &&
9485 dest
->num_auth_info_required
== 1 &&
9486 !strcmp(dest
->auth_info_required
[0], "negotiate"))
9489 * Allow fallback to username+password for Kerberized queues...
9492 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[0].string
.text
, (int)strlen(auth_info
->values
[0].string
.text
));
9493 cupsFilePutConf(fp
, "username", line
);
9495 cupsdSetStringf(job
->auth_env
+ 0, "AUTH_USERNAME=%s",
9496 auth_info
->values
[0].string
.text
);
9498 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[1].string
.text
, (int)strlen(auth_info
->values
[1].string
.text
));
9499 cupsFilePutConf(fp
, "password", line
);
9501 cupsdSetStringf(job
->auth_env
+ 1, "AUTH_PASSWORD=%s",
9502 auth_info
->values
[1].string
.text
);
9504 else if (con
->username
[0])
9507 * Write the authenticated username...
9510 httpEncode64_2(line
, sizeof(line
), con
->username
, (int)strlen(con
->username
));
9511 cupsFilePutConf(fp
, "username", line
);
9513 cupsdSetStringf(job
->auth_env
+ 0, "AUTH_USERNAME=%s", con
->username
);
9516 * Write the authenticated password...
9519 httpEncode64_2(line
, sizeof(line
), con
->password
, (int)strlen(con
->password
));
9520 cupsFilePutConf(fp
, "password", line
);
9522 cupsdSetStringf(job
->auth_env
+ 1, "AUTH_PASSWORD=%s", con
->password
);
9526 if (con
->gss_uid
> 0)
9528 cupsFilePrintf(fp
, "uid %d\n", (int)con
->gss_uid
);
9529 cupsdSetStringf(&job
->auth_uid
, "AUTH_UID=%d", (int)con
->gss_uid
);
9531 #endif /* HAVE_GSSAPI */
9534 * Write a random number of newlines to the end of the file...
9537 for (i
= (CUPS_RAND() % 1024); i
>= 0; i
--)
9538 cupsFilePutChar(fp
, '\n');
9541 * Close the file and return...
9549 * 'send_document()' - Send a file to a printer or class.
9553 send_document(cupsd_client_t
*con
, /* I - Client connection */
9554 ipp_attribute_t
*uri
) /* I - Printer URI */
9556 ipp_attribute_t
*attr
; /* Current attribute */
9557 ipp_attribute_t
*format
; /* Request's document-format attribute */
9558 ipp_attribute_t
*jformat
; /* Job's document-format attribute */
9559 const char *default_format
;/* document-format-default value */
9560 int jobid
; /* Job ID number */
9561 cupsd_job_t
*job
; /* Current job */
9562 char job_uri
[HTTP_MAX_URI
],
9564 scheme
[HTTP_MAX_URI
],
9565 /* Method portion of URI */
9566 username
[HTTP_MAX_URI
],
9567 /* Username portion of URI */
9569 /* Host portion of URI */
9570 resource
[HTTP_MAX_URI
];
9571 /* Resource portion of URI */
9572 int port
; /* Port portion of URI */
9573 mime_type_t
*filetype
; /* Type of file */
9574 char super
[MIME_MAX_SUPER
],
9575 /* Supertype of file */
9576 type
[MIME_MAX_TYPE
],
9577 /* Subtype of file */
9578 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
9579 /* Textual name of mime type */
9580 char filename
[1024]; /* Job filename */
9581 cupsd_printer_t
*printer
; /* Current printer */
9582 struct stat fileinfo
; /* File information */
9583 int kbytes
; /* Size of file */
9584 int compression
; /* Type of compression */
9585 int start_job
; /* Start the job? */
9588 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "send_document(%p[%d], %s)", con
,
9589 con
->number
, uri
->values
[0].string
.text
);
9592 * See if we have a job URI or a printer URI...
9595 if (!strcmp(uri
->name
, "printer-uri"))
9598 * Got a printer URI; see if we also have a job-id attribute...
9601 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9602 IPP_TAG_INTEGER
)) == NULL
)
9604 send_ipp_status(con
, IPP_BAD_REQUEST
,
9605 _("Got a printer-uri attribute but no job-id."));
9609 jobid
= attr
->values
[0].integer
;
9614 * Got a job URI; parse it to get the job ID...
9617 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9618 sizeof(scheme
), username
, sizeof(username
), host
,
9619 sizeof(host
), &port
, resource
, sizeof(resource
));
9621 if (strncmp(resource
, "/jobs/", 6))
9627 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9628 uri
->values
[0].string
.text
);
9632 jobid
= atoi(resource
+ 6);
9636 * See if the job exists...
9639 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9642 * Nope - return a "not found" error...
9645 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9649 printer
= cupsdFindDest(job
->dest
);
9652 * See if the job is owned by the requesting user...
9655 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9657 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9658 cupsdFindDest(job
->dest
));
9663 * OK, see if the client is sending the document compressed - CUPS
9664 * only supports "none" and "gzip".
9667 compression
= CUPS_FILE_NONE
;
9669 if ((attr
= ippFindAttribute(con
->request
, "compression",
9670 IPP_TAG_KEYWORD
)) != NULL
)
9672 if (strcmp(attr
->values
[0].string
.text
, "none")
9674 && strcmp(attr
->values
[0].string
.text
, "gzip")
9675 #endif /* HAVE_LIBZ */
9678 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Unsupported compression \"%s\"."),
9679 attr
->values
[0].string
.text
);
9680 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
9681 "compression", NULL
, attr
->values
[0].string
.text
);
9686 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
9687 compression
= CUPS_FILE_GZIP
;
9688 #endif /* HAVE_LIBZ */
9692 * Do we have a file to print?
9695 if ((attr
= ippFindAttribute(con
->request
, "last-document",
9696 IPP_TAG_BOOLEAN
)) == NULL
)
9698 send_ipp_status(con
, IPP_BAD_REQUEST
,
9699 _("Missing last-document attribute in request."));
9706 * Check for an empty request with "last-document" set to true, which is
9707 * used to close an "open" job by RFC 2911, section 3.3.2.
9710 if (job
->num_files
> 0 && attr
->values
[0].boolean
)
9713 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file in print request."));
9718 * Is it a format we support?
9723 if ((format
= ippFindAttribute(con
->request
, "document-format",
9724 IPP_TAG_MIMETYPE
)) != NULL
)
9727 * Grab format from client...
9730 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%255[^;]",
9733 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"."),
9734 format
->values
[0].string
.text
);
9738 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format-supplied", NULL
, ippGetString(format
, 0, NULL
));
9740 else if ((default_format
= cupsGetOption("document-format",
9741 printer
->num_options
,
9742 printer
->options
)) != NULL
)
9745 * Use default document format...
9748 if (sscanf(default_format
, "%15[^/]/%255[^;]", super
, type
) != 2)
9750 send_ipp_status(con
, IPP_BAD_REQUEST
,
9751 _("Bad document-format-default \"%s\"."), default_format
);
9758 * No document format attribute? Auto-type it!
9761 strlcpy(super
, "application", sizeof(super
));
9762 strlcpy(type
, "octet-stream", sizeof(type
));
9765 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
9768 * Auto-type the file...
9771 ipp_attribute_t
*doc_name
; /* document-name attribute */
9774 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Auto-typing file...");
9776 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
9777 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
9778 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
9782 filetype
= mimeType(MimeDatabase
, super
, type
);
9785 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Request file type is %s/%s.",
9786 filetype
->super
, filetype
->type
);
9788 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
, filetype
->type
);
9789 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format-detected", NULL
, mimetype
);
9792 filetype
= mimeType(MimeDatabase
, super
, type
);
9797 * Replace the document-format attribute value with the auto-typed or
9801 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9804 if ((jformat
= ippFindAttribute(job
->attrs
, "document-format",
9805 IPP_TAG_MIMETYPE
)) != NULL
)
9806 ippSetString(job
->attrs
, &jformat
, 0, mimetype
);
9808 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
9809 "document-format", NULL
, mimetype
);
9813 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9814 _("Unsupported document-format \"%s/%s\"."), super
, type
);
9815 cupsdLogMessage(CUPSD_LOG_INFO
,
9816 "Hint: Do you have the raw file printing rules enabled?");
9819 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9820 "document-format", NULL
, format
->values
[0].string
.text
);
9825 if (printer
->filetypes
&& !cupsArrayFind(printer
->filetypes
, filetype
))
9827 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9830 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9831 _("Unsupported document-format \"%s\"."), mimetype
);
9833 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9834 "document-format", NULL
, mimetype
);
9840 * Add the file to the job...
9843 if (add_file(con
, job
, filetype
, compression
))
9846 if ((attr
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
)) != NULL
)
9847 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name-supplied", NULL
, ippGetString(attr
, 0, NULL
));
9849 if (stat(con
->filename
, &fileinfo
))
9852 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
9854 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
9856 job
->koctets
+= kbytes
;
9858 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets", IPP_TAG_INTEGER
)) != NULL
)
9859 attr
->values
[0].integer
+= kbytes
;
9861 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
, job
->num_files
);
9862 if (rename(con
->filename
, filename
))
9864 cupsdLogJob(job
, CUPSD_LOG_ERROR
, "Unable to rename job document file \"%s\": %s", filename
, strerror(errno
));
9866 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to rename job document file."));
9870 cupsdClearString(&con
->filename
);
9872 cupsdLogJob(job
, CUPSD_LOG_INFO
, "File of type %s/%s queued by \"%s\".",
9873 filetype
->super
, filetype
->type
, job
->username
);
9876 * Start the job if this is the last document...
9881 if ((attr
= ippFindAttribute(con
->request
, "last-document",
9882 IPP_TAG_BOOLEAN
)) != NULL
&&
9883 attr
->values
[0].boolean
)
9886 * See if we need to add the ending sheet...
9889 if (cupsdTimeoutJob(job
))
9892 if (job
->state_value
== IPP_JOB_STOPPED
)
9894 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9895 job
->state_value
= IPP_JOB_PENDING
;
9897 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
9899 else if (job
->state_value
== IPP_JOB_HELD
)
9901 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9902 IPP_TAG_KEYWORD
)) == NULL
)
9903 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9905 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9907 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9908 job
->state_value
= IPP_JOB_PENDING
;
9910 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
9913 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-hold-until-specified");
9917 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
9923 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9924 IPP_TAG_KEYWORD
)) == NULL
)
9925 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9927 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9929 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
9930 job
->state_value
= IPP_JOB_HELD
;
9931 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
9933 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-incoming");
9936 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
9943 * Fill in the response info...
9946 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
9947 con
->clientname
, con
->clientport
, "/jobs/%d", jobid
);
9948 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
9951 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", jobid
);
9953 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
9955 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons",
9956 NULL
, job
->reasons
->values
[0].string
.text
);
9958 con
->response
->request
.status
.status_code
= IPP_OK
;
9961 * Start the job if necessary...
9970 * 'send_http_error()' - Send a HTTP error back to the IPP client.
9975 cupsd_client_t
*con
, /* I - Client connection */
9976 http_status_t status
, /* I - HTTP status code */
9977 cupsd_printer_t
*printer
) /* I - Printer, if any */
9979 ipp_attribute_t
*uri
; /* Request URI, if any */
9982 if ((uri
= ippFindAttribute(con
->request
, "printer-uri",
9983 IPP_TAG_URI
)) == NULL
)
9984 uri
= ippFindAttribute(con
->request
, "job-uri", IPP_TAG_URI
);
9986 cupsdLogMessage(status
== HTTP_FORBIDDEN
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
9987 "[Client %d] Returning HTTP %s for %s (%s) from %s",
9988 con
->number
, httpStatus(status
),
9990 ippOpString(con
->request
->request
.op
.operation_id
) :
9992 uri
? uri
->values
[0].string
.text
: "no URI",
9993 con
->http
->hostname
);
9997 int auth_type
; /* Type of authentication required */
10000 auth_type
= CUPSD_AUTH_NONE
;
10002 if (status
== HTTP_UNAUTHORIZED
&&
10003 printer
->num_auth_info_required
> 0 &&
10004 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
10006 (con
->request
->request
.op
.operation_id
== IPP_PRINT_JOB
||
10007 con
->request
->request
.op
.operation_id
== IPP_CREATE_JOB
||
10008 con
->request
->request
.op
.operation_id
== CUPS_AUTHENTICATE_JOB
))
10011 * Creating and authenticating jobs requires Kerberos...
10014 auth_type
= CUPSD_AUTH_NEGOTIATE
;
10019 * Use policy/location-defined authentication requirements...
10022 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
10023 cupsd_location_t
*auth
; /* Pointer to authentication element */
10026 if (printer
->type
& CUPS_PRINTER_CLASS
)
10027 snprintf(resource
, sizeof(resource
), "/classes/%s", printer
->name
);
10029 snprintf(resource
, sizeof(resource
), "/printers/%s", printer
->name
);
10031 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
10032 auth
->type
== CUPSD_AUTH_NONE
)
10033 auth
= cupsdFindPolicyOp(printer
->op_policy_ptr
,
10035 con
->request
->request
.op
.operation_id
:
10040 if (auth
->type
== CUPSD_AUTH_DEFAULT
)
10041 auth_type
= cupsdDefaultAuthType();
10043 auth_type
= auth
->type
;
10047 cupsdSendError(con
, status
, auth_type
);
10050 cupsdSendError(con
, status
, CUPSD_AUTH_NONE
);
10052 ippDelete(con
->response
);
10053 con
->response
= NULL
;
10060 * 'send_ipp_status()' - Send a status back to the IPP client.
10064 send_ipp_status(cupsd_client_t
*con
, /* I - Client connection */
10065 ipp_status_t status
, /* I - IPP status code */
10066 const char *message
,/* I - Status message */
10067 ...) /* I - Additional args as needed */
10069 va_list ap
; /* Pointer to additional args */
10070 char formatted
[1024]; /* Formatted errror message */
10073 va_start(ap
, message
);
10074 vsnprintf(formatted
, sizeof(formatted
),
10075 _cupsLangString(con
->language
, message
), ap
);
10078 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s: %s",
10079 ippOpString(con
->request
->request
.op
.operation_id
),
10080 ippErrorString(status
), formatted
);
10082 con
->response
->request
.status
.status_code
= status
;
10084 if (ippFindAttribute(con
->response
, "attributes-charset",
10085 IPP_TAG_ZERO
) == NULL
)
10086 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
10087 "attributes-charset", NULL
, "utf-8");
10089 if (ippFindAttribute(con
->response
, "attributes-natural-language",
10090 IPP_TAG_ZERO
) == NULL
)
10091 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
10092 "attributes-natural-language", NULL
, DefaultLanguage
);
10094 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
10095 "status-message", NULL
, formatted
);
10100 * 'set_default()' - Set the default destination...
10104 set_default(cupsd_client_t
*con
, /* I - Client connection */
10105 ipp_attribute_t
*uri
) /* I - Printer URI */
10107 http_status_t status
; /* Policy status */
10108 cups_ptype_t dtype
; /* Destination type (printer/class) */
10109 cupsd_printer_t
*printer
, /* Printer */
10110 *oldprinter
; /* Old default printer */
10113 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_default(%p[%d], %s)", con
,
10114 con
->number
, uri
->values
[0].string
.text
);
10117 * Is the destination valid?
10120 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10126 send_ipp_status(con
, IPP_NOT_FOUND
,
10127 _("The printer or class does not exist."));
10135 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
10137 send_http_error(con
, status
, NULL
);
10142 * Set it as the default...
10145 oldprinter
= DefaultPrinter
;
10146 DefaultPrinter
= printer
;
10149 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, oldprinter
, NULL
,
10150 "%s is no longer the default printer.", oldprinter
->name
);
10152 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
10153 "%s is now the default printer.", printer
->name
);
10155 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
| CUPSD_DIRTY_CLASSES
|
10156 CUPSD_DIRTY_PRINTCAP
);
10158 cupsdLogMessage(CUPSD_LOG_INFO
,
10159 "Default destination set to \"%s\" by \"%s\".",
10160 printer
->name
, get_username(con
));
10163 * Everything was ok, so return OK status...
10166 con
->response
->request
.status
.status_code
= IPP_OK
;
10171 * 'set_job_attrs()' - Set job attributes.
10175 set_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
10176 ipp_attribute_t
*uri
) /* I - Job URI */
10178 ipp_attribute_t
*attr
, /* Current attribute */
10179 *attr2
; /* Job attribute */
10180 int jobid
; /* Job ID */
10181 cupsd_job_t
*job
; /* Current job */
10182 char scheme
[HTTP_MAX_URI
],
10183 /* Method portion of URI */
10184 username
[HTTP_MAX_URI
],
10185 /* Username portion of URI */
10186 host
[HTTP_MAX_URI
],
10187 /* Host portion of URI */
10188 resource
[HTTP_MAX_URI
];
10189 /* Resource portion of URI */
10190 int port
; /* Port portion of URI */
10191 int event
; /* Events? */
10192 int check_jobs
; /* Check jobs? */
10195 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_job_attrs(%p[%d], %s)", con
,
10196 con
->number
, uri
->values
[0].string
.text
);
10199 * Start with "everything is OK" status...
10202 con
->response
->request
.status
.status_code
= IPP_OK
;
10205 * See if we have a job URI or a printer URI...
10208 if (!strcmp(uri
->name
, "printer-uri"))
10211 * Got a printer URI; see if we also have a job-id attribute...
10214 if ((attr
= ippFindAttribute(con
->request
, "job-id",
10215 IPP_TAG_INTEGER
)) == NULL
)
10217 send_ipp_status(con
, IPP_BAD_REQUEST
,
10218 _("Got a printer-uri attribute but no job-id."));
10222 jobid
= attr
->values
[0].integer
;
10227 * Got a job URI; parse it to get the job ID...
10230 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
10231 sizeof(scheme
), username
, sizeof(username
), host
,
10232 sizeof(host
), &port
, resource
, sizeof(resource
));
10234 if (strncmp(resource
, "/jobs/", 6))
10240 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
10241 uri
->values
[0].string
.text
);
10245 jobid
= atoi(resource
+ 6);
10249 * See if the job exists...
10252 if ((job
= cupsdFindJob(jobid
)) == NULL
)
10255 * Nope - return a "not found" error...
10258 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
10263 * See if the job has been completed...
10266 if (job
->state_value
> IPP_JOB_STOPPED
)
10269 * Return a "not-possible" error...
10272 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10273 _("Job #%d is finished and cannot be altered."), jobid
);
10278 * See if the job is owned by the requesting user...
10281 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10283 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
10284 cupsdFindDest(job
->dest
));
10289 * See what the user wants to change.
10297 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10299 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
10302 if (!strcmp(attr
->name
, "attributes-charset") ||
10303 !strcmp(attr
->name
, "attributes-natural-language") ||
10304 !strncmp(attr
->name
, "date-time-at-", 13) ||
10305 !strncmp(attr
->name
, "document-compression", 20) ||
10306 !strncmp(attr
->name
, "document-format", 15) ||
10307 !strcmp(attr
->name
, "job-detailed-status-messages") ||
10308 !strcmp(attr
->name
, "job-document-access-errors") ||
10309 !strcmp(attr
->name
, "job-id") ||
10310 !strcmp(attr
->name
, "job-impressions-completed") ||
10311 !strcmp(attr
->name
, "job-k-octets-completed") ||
10312 !strcmp(attr
->name
, "job-media-sheets-completed") ||
10313 !strcmp(attr
->name
, "job-originating-host-name") ||
10314 !strcmp(attr
->name
, "job-originating-user-name") ||
10315 !strcmp(attr
->name
, "job-pages-completed") ||
10316 !strcmp(attr
->name
, "job-printer-up-time") ||
10317 !strcmp(attr
->name
, "job-printer-uri") ||
10318 !strcmp(attr
->name
, "job-sheets") ||
10319 !strcmp(attr
->name
, "job-state-message") ||
10320 !strcmp(attr
->name
, "job-state-reasons") ||
10321 !strcmp(attr
->name
, "job-uri") ||
10322 !strcmp(attr
->name
, "number-of-documents") ||
10323 !strcmp(attr
->name
, "number-of-intervening-jobs") ||
10324 !strcmp(attr
->name
, "output-device-assigned") ||
10325 !strncmp(attr
->name
, "time-at-", 8))
10331 send_ipp_status(con
, IPP_ATTRIBUTES_NOT_SETTABLE
,
10332 _("%s cannot be changed."), attr
->name
);
10334 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
10335 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
10339 if (!strcmp(attr
->name
, "job-priority"))
10342 * Change the job priority...
10345 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10347 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-priority value."));
10349 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
10350 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
10352 else if (job
->state_value
>= IPP_JOB_PROCESSING
)
10354 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10355 _("Job is completed and cannot be changed."));
10358 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10360 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-priority to %d",
10361 attr
->values
[0].integer
);
10362 cupsdSetJobPriority(job
, attr
->values
[0].integer
);
10365 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
|
10366 CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
;
10369 else if (!strcmp(attr
->name
, "job-state"))
10372 * Change the job state...
10375 if (attr
->value_tag
!= IPP_TAG_ENUM
)
10377 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-state value."));
10379 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
10380 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
10384 switch (attr
->values
[0].integer
)
10386 case IPP_JOB_PENDING
:
10387 case IPP_JOB_HELD
:
10388 if (job
->state_value
> IPP_JOB_HELD
)
10390 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10391 _("Job state cannot be changed."));
10394 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10396 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10397 attr
->values
[0].integer
);
10398 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
, CUPSD_JOB_DEFAULT
, "Job state changed by \"%s\"", username
);
10403 case IPP_JOB_PROCESSING
:
10404 case IPP_JOB_STOPPED
:
10405 if (job
->state_value
!= attr
->values
[0].integer
)
10407 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10408 _("Job state cannot be changed."));
10413 case IPP_JOB_CANCELED
:
10414 case IPP_JOB_ABORTED
:
10415 case IPP_JOB_COMPLETED
:
10416 if (job
->state_value
> IPP_JOB_PROCESSING
)
10418 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10419 _("Job state cannot be changed."));
10422 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10424 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10425 attr
->values
[0].integer
);
10426 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
,
10428 "Job state changed by \"%s\"", username
);
10435 else if (con
->response
->request
.status
.status_code
!= IPP_OK
)
10437 else if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10438 IPP_TAG_ZERO
)) != NULL
)
10441 * Some other value; first free the old value...
10444 if (job
->attrs
->prev
)
10445 job
->attrs
->prev
->next
= attr2
->next
;
10447 job
->attrs
->attrs
= attr2
->next
;
10449 if (job
->attrs
->last
== attr2
)
10450 job
->attrs
->last
= job
->attrs
->prev
;
10452 ippDeleteAttribute(NULL
, attr2
);
10455 * Then copy the attribute...
10458 ippCopyAttribute(job
->attrs
, attr
, 0);
10461 * See if the job-name or job-hold-until is being changed.
10464 if (!strcmp(attr
->name
, "job-hold-until"))
10466 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-hold-until to %s",
10467 attr
->values
[0].string
.text
);
10468 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
10470 if (!strcmp(attr
->values
[0].string
.text
, "no-hold"))
10472 cupsdReleaseJob(job
);
10476 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
,
10477 "Job held by \"%s\".", username
);
10479 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
;
10482 else if (attr
->value_tag
== IPP_TAG_DELETEATTR
)
10485 * Delete the attribute...
10488 if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10489 IPP_TAG_ZERO
)) != NULL
)
10491 if (job
->attrs
->prev
)
10492 job
->attrs
->prev
->next
= attr2
->next
;
10494 job
->attrs
->attrs
= attr2
->next
;
10496 if (attr2
== job
->attrs
->last
)
10497 job
->attrs
->last
= job
->attrs
->prev
;
10499 ippDeleteAttribute(NULL
, attr2
);
10501 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10507 * Add new option by copying it...
10510 ippCopyAttribute(job
->attrs
, attr
, 0);
10512 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10521 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10524 * Send events as needed...
10527 if (event
& CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
)
10528 cupsdAddEvent(CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
,
10529 cupsdFindDest(job
->dest
), job
,
10530 "Job priority changed by user.");
10532 if (event
& CUPSD_EVENT_JOB_STATE
)
10533 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
10534 job
->state_value
== IPP_JOB_HELD
?
10535 "Job held by user." : "Job restarted by user.");
10537 if (event
& CUPSD_EVENT_JOB_CONFIG_CHANGED
)
10538 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
10539 "Job options changed by user.");
10542 * Start jobs if possible...
10551 * 'set_printer_attrs()' - Set printer attributes.
10555 set_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
10556 ipp_attribute_t
*uri
) /* I - Printer */
10558 http_status_t status
; /* Policy status */
10559 cups_ptype_t dtype
; /* Destination type (printer/class) */
10560 cupsd_printer_t
*printer
; /* Printer/class */
10561 ipp_attribute_t
*attr
; /* Printer attribute */
10562 int changed
= 0; /* Was anything changed? */
10565 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_attrs(%p[%d], %s)", con
,
10566 con
->number
, uri
->values
[0].string
.text
);
10569 * Is the destination valid?
10572 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10578 send_ipp_status(con
, IPP_NOT_FOUND
,
10579 _("The printer or class does not exist."));
10587 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10589 send_http_error(con
, status
, printer
);
10594 * Return a list of attributes that can be set via Set-Printer-Attributes.
10597 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
10598 IPP_TAG_TEXT
)) != NULL
)
10600 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
10604 if ((attr
= ippFindAttribute(con
->request
, "printer-geo-location", IPP_TAG_URI
)) != NULL
&& !strncmp(attr
->values
[0].string
.text
, "geo:", 4))
10606 cupsdSetString(&printer
->geo_location
, attr
->values
[0].string
.text
);
10610 if ((attr
= ippFindAttribute(con
->request
, "printer-organization", IPP_TAG_TEXT
)) != NULL
)
10612 cupsdSetString(&printer
->organization
, attr
->values
[0].string
.text
);
10616 if ((attr
= ippFindAttribute(con
->request
, "printer-organizational-unit", IPP_TAG_TEXT
)) != NULL
)
10618 cupsdSetString(&printer
->organizational_unit
, attr
->values
[0].string
.text
);
10622 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
10623 IPP_TAG_TEXT
)) != NULL
)
10625 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
10630 * Update the printer attributes and return...
10635 printer
->config_time
= time(NULL
);
10637 cupsdSetPrinterAttrs(printer
);
10638 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
10640 cupsdAddEvent(CUPSD_EVENT_PRINTER_CONFIG
, printer
, NULL
,
10641 "Printer \"%s\" description or location changed by \"%s\".",
10642 printer
->name
, get_username(con
));
10644 cupsdLogMessage(CUPSD_LOG_INFO
,
10645 "Printer \"%s\" description or location changed by \"%s\".",
10646 printer
->name
, get_username(con
));
10649 con
->response
->request
.status
.status_code
= IPP_OK
;
10654 * 'set_printer_defaults()' - Set printer default options from a request.
10657 static int /* O - 1 on success, 0 on failure */
10658 set_printer_defaults(
10659 cupsd_client_t
*con
, /* I - Client connection */
10660 cupsd_printer_t
*printer
) /* I - Printer */
10662 int i
; /* Looping var */
10663 ipp_attribute_t
*attr
; /* Current attribute */
10664 size_t namelen
; /* Length of attribute name */
10665 char name
[256], /* New attribute name */
10666 value
[256]; /* String version of integer attrs */
10669 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10672 * Skip non-printer attributes...
10675 if (attr
->group_tag
!= IPP_TAG_PRINTER
|| !attr
->name
)
10678 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_defaults: %s", attr
->name
);
10680 if (!strcmp(attr
->name
, "job-sheets-default"))
10683 * Only allow keywords and names...
10686 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10690 * Only allow job-sheets-default to be set when running without a
10691 * system high classification level...
10694 if (Classification
)
10697 cupsdSetString(&printer
->job_sheets
[0], attr
->values
[0].string
.text
);
10699 if (attr
->num_values
> 1)
10700 cupsdSetString(&printer
->job_sheets
[1], attr
->values
[1].string
.text
);
10702 cupsdSetString(&printer
->job_sheets
[1], "none");
10704 else if (!strcmp(attr
->name
, "requesting-user-name-allowed"))
10706 cupsdFreeStrings(&(printer
->users
));
10708 printer
->deny_users
= 0;
10710 if (attr
->value_tag
== IPP_TAG_NAME
&&
10711 (attr
->num_values
> 1 ||
10712 strcmp(attr
->values
[0].string
.text
, "all")))
10714 for (i
= 0; i
< attr
->num_values
; i
++)
10715 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
10718 else if (!strcmp(attr
->name
, "requesting-user-name-denied"))
10720 cupsdFreeStrings(&(printer
->users
));
10722 printer
->deny_users
= 1;
10724 if (attr
->value_tag
== IPP_TAG_NAME
&&
10725 (attr
->num_values
> 1 ||
10726 strcmp(attr
->values
[0].string
.text
, "none")))
10728 for (i
= 0; i
< attr
->num_values
; i
++)
10729 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
10732 else if (!strcmp(attr
->name
, "job-quota-period"))
10734 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10737 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-quota-period to %d...",
10738 attr
->values
[0].integer
);
10739 cupsdFreeQuotas(printer
);
10741 printer
->quota_period
= attr
->values
[0].integer
;
10743 else if (!strcmp(attr
->name
, "job-k-limit"))
10745 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10748 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-k-limit to %d...",
10749 attr
->values
[0].integer
);
10750 cupsdFreeQuotas(printer
);
10752 printer
->k_limit
= attr
->values
[0].integer
;
10754 else if (!strcmp(attr
->name
, "job-page-limit"))
10756 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10759 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-page-limit to %d...",
10760 attr
->values
[0].integer
);
10761 cupsdFreeQuotas(printer
);
10763 printer
->page_limit
= attr
->values
[0].integer
;
10765 else if (!strcmp(attr
->name
, "printer-op-policy"))
10767 cupsd_policy_t
*p
; /* Policy */
10770 if (attr
->value_tag
!= IPP_TAG_NAME
)
10773 if ((p
= cupsdFindPolicy(attr
->values
[0].string
.text
)) != NULL
)
10775 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10776 "Setting printer-op-policy to \"%s\"...",
10777 attr
->values
[0].string
.text
);
10778 cupsdSetString(&printer
->op_policy
, attr
->values
[0].string
.text
);
10779 printer
->op_policy_ptr
= p
;
10783 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10784 _("Unknown printer-op-policy \"%s\"."),
10785 attr
->values
[0].string
.text
);
10789 else if (!strcmp(attr
->name
, "printer-error-policy"))
10791 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10794 if (strcmp(attr
->values
[0].string
.text
, "retry-current-job") &&
10795 ((printer
->type
& CUPS_PRINTER_CLASS
) ||
10796 (strcmp(attr
->values
[0].string
.text
, "abort-job") &&
10797 strcmp(attr
->values
[0].string
.text
, "retry-job") &&
10798 strcmp(attr
->values
[0].string
.text
, "stop-printer"))))
10800 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10801 _("Unknown printer-error-policy \"%s\"."),
10802 attr
->values
[0].string
.text
);
10806 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10807 "Setting printer-error-policy to \"%s\"...",
10808 attr
->values
[0].string
.text
);
10809 cupsdSetString(&printer
->error_policy
, attr
->values
[0].string
.text
);
10813 * Skip any other non-default attributes...
10816 namelen
= strlen(attr
->name
);
10817 if (namelen
< 9 || strcmp(attr
->name
+ namelen
- 8, "-default") ||
10818 namelen
> (sizeof(name
) - 1) || attr
->num_values
!= 1)
10822 * OK, anything else must be a user-defined default...
10825 strlcpy(name
, attr
->name
, sizeof(name
));
10826 name
[namelen
- 8] = '\0'; /* Strip "-default" */
10828 switch (attr
->value_tag
)
10830 case IPP_TAG_DELETEATTR
:
10831 printer
->num_options
= cupsRemoveOption(name
,
10832 printer
->num_options
,
10833 &(printer
->options
));
10834 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10835 "Deleting %s", attr
->name
);
10838 case IPP_TAG_NAME
:
10839 case IPP_TAG_TEXT
:
10840 case IPP_TAG_KEYWORD
:
10842 printer
->num_options
= cupsAddOption(name
,
10843 attr
->values
[0].string
.text
,
10844 printer
->num_options
,
10845 &(printer
->options
));
10846 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10847 "Setting %s to \"%s\"...", attr
->name
,
10848 attr
->values
[0].string
.text
);
10851 case IPP_TAG_BOOLEAN
:
10852 printer
->num_options
= cupsAddOption(name
,
10853 attr
->values
[0].boolean
?
10855 printer
->num_options
,
10856 &(printer
->options
));
10857 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10858 "Setting %s to %s...", attr
->name
,
10859 attr
->values
[0].boolean
? "true" : "false");
10862 case IPP_TAG_INTEGER
:
10863 case IPP_TAG_ENUM
:
10864 sprintf(value
, "%d", attr
->values
[0].integer
);
10865 printer
->num_options
= cupsAddOption(name
, value
,
10866 printer
->num_options
,
10867 &(printer
->options
));
10868 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10869 "Setting %s to %s...", attr
->name
, value
);
10872 case IPP_TAG_RANGE
:
10873 sprintf(value
, "%d-%d", attr
->values
[0].range
.lower
,
10874 attr
->values
[0].range
.upper
);
10875 printer
->num_options
= cupsAddOption(name
, value
,
10876 printer
->num_options
,
10877 &(printer
->options
));
10878 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10879 "Setting %s to %s...", attr
->name
, value
);
10882 case IPP_TAG_RESOLUTION
:
10883 sprintf(value
, "%dx%d%s", attr
->values
[0].resolution
.xres
,
10884 attr
->values
[0].resolution
.yres
,
10885 attr
->values
[0].resolution
.units
== IPP_RES_PER_INCH
?
10887 printer
->num_options
= cupsAddOption(name
, value
,
10888 printer
->num_options
,
10889 &(printer
->options
));
10890 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10891 "Setting %s to %s...", attr
->name
, value
);
10895 /* Do nothing for other values */
10905 * 'start_printer()' - Start a printer.
10909 start_printer(cupsd_client_t
*con
, /* I - Client connection */
10910 ipp_attribute_t
*uri
) /* I - Printer URI */
10912 int i
; /* Temporary variable */
10913 http_status_t status
; /* Policy status */
10914 cups_ptype_t dtype
; /* Destination type (printer/class) */
10915 cupsd_printer_t
*printer
; /* Printer data */
10918 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_printer(%p[%d], %s)", con
,
10919 con
->number
, uri
->values
[0].string
.text
);
10922 * Is the destination valid?
10925 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10931 send_ipp_status(con
, IPP_NOT_FOUND
,
10932 _("The printer or class does not exist."));
10940 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10942 send_http_error(con
, status
, printer
);
10947 * Start the printer...
10950 printer
->state_message
[0] = '\0';
10952 cupsdStartPrinter(printer
, 1);
10954 if (dtype
& CUPS_PRINTER_CLASS
)
10955 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" started by \"%s\".",
10956 printer
->name
, get_username(con
));
10958 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" started by \"%s\".",
10959 printer
->name
, get_username(con
));
10967 if ((i
= check_quotas(con
, printer
)) < 0)
10969 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
10974 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
10979 * Everything was ok, so return OK status...
10982 con
->response
->request
.status
.status_code
= IPP_OK
;
10987 * 'stop_printer()' - Stop a printer.
10991 stop_printer(cupsd_client_t
*con
, /* I - Client connection */
10992 ipp_attribute_t
*uri
) /* I - Printer URI */
10994 http_status_t status
; /* Policy status */
10995 cups_ptype_t dtype
; /* Destination type (printer/class) */
10996 cupsd_printer_t
*printer
; /* Printer data */
10997 ipp_attribute_t
*attr
; /* printer-state-message attribute */
11000 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "stop_printer(%p[%d], %s)", con
,
11001 con
->number
, uri
->values
[0].string
.text
);
11004 * Is the destination valid?
11007 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11013 send_ipp_status(con
, IPP_NOT_FOUND
,
11014 _("The printer or class does not exist."));
11022 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11024 send_http_error(con
, status
, printer
);
11029 * Stop the printer...
11032 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
11033 IPP_TAG_TEXT
)) == NULL
)
11034 strlcpy(printer
->state_message
, "Paused", sizeof(printer
->state_message
));
11037 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
11038 sizeof(printer
->state_message
));
11041 cupsdStopPrinter(printer
, 1);
11043 if (dtype
& CUPS_PRINTER_CLASS
)
11044 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" stopped by \"%s\".",
11045 printer
->name
, get_username(con
));
11047 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" stopped by \"%s\".",
11048 printer
->name
, get_username(con
));
11051 * Everything was ok, so return OK status...
11054 con
->response
->request
.status
.status_code
= IPP_OK
;
11059 * 'url_encode_attr()' - URL-encode a string attribute.
11063 url_encode_attr(ipp_attribute_t
*attr
, /* I - Attribute */
11064 char *buffer
,/* I - String buffer */
11065 size_t bufsize
)/* I - Size of buffer */
11067 int i
; /* Looping var */
11068 char *bufptr
, /* Pointer into buffer */
11069 *bufend
; /* End of buffer */
11072 strlcpy(buffer
, attr
->name
, bufsize
);
11073 bufptr
= buffer
+ strlen(buffer
);
11074 bufend
= buffer
+ bufsize
- 1;
11076 for (i
= 0; i
< attr
->num_values
; i
++)
11078 if (bufptr
>= bufend
)
11086 if (bufptr
>= bufend
)
11091 bufptr
= url_encode_string(attr
->values
[i
].string
.text
, bufptr
, (size_t)(bufend
- bufptr
+ 1));
11093 if (bufptr
>= bufend
)
11104 * 'url_encode_string()' - URL-encode a string.
11107 static char * /* O - End of string */
11108 url_encode_string(const char *s
, /* I - String */
11109 char *buffer
, /* I - String buffer */
11110 size_t bufsize
) /* I - Size of buffer */
11112 char *bufptr
, /* Pointer into buffer */
11113 *bufend
; /* End of buffer */
11114 static const char *hex
= "0123456789ABCDEF";
11119 bufend
= buffer
+ bufsize
- 1;
11121 while (*s
&& bufptr
< bufend
)
11123 if (*s
== ' ' || *s
== '%' || *s
== '+')
11125 if (bufptr
>= (bufend
- 2))
11129 *bufptr
++ = hex
[(*s
>> 4) & 15];
11130 *bufptr
++ = hex
[*s
& 15];
11134 else if (*s
== '\'' || *s
== '\\')
11136 if (bufptr
>= (bufend
- 1))
11153 * 'user_allowed()' - See if a user is allowed to print to a queue.
11156 static int /* O - 0 if not allowed, 1 if allowed */
11157 user_allowed(cupsd_printer_t
*p
, /* I - Printer or class */
11158 const char *username
) /* I - Username */
11160 struct passwd
*pw
; /* User password data */
11161 char baseuser
[256], /* Base username */
11162 *baseptr
, /* Pointer to "@" in base username */
11163 *name
; /* Current user name */
11166 if (cupsArrayCount(p
->users
) == 0)
11169 if (!strcmp(username
, "root"))
11172 if (strchr(username
, '@'))
11175 * Strip @REALM for username check...
11178 strlcpy(baseuser
, username
, sizeof(baseuser
));
11180 if ((baseptr
= strchr(baseuser
, '@')) != NULL
)
11183 username
= baseuser
;
11186 pw
= getpwnam(username
);
11189 for (name
= (char *)cupsArrayFirst(p
->users
);
11191 name
= (char *)cupsArrayNext(p
->users
))
11193 if (name
[0] == '@')
11196 * Check group membership...
11199 if (cupsdCheckGroup(username
, pw
, name
+ 1))
11202 else if (name
[0] == '#')
11208 if (cupsdCheckGroup(username
, pw
, name
))
11211 else if (!_cups_strcasecmp(username
, name
))
11215 return ((name
!= NULL
) != p
->deny_users
);
11220 * 'validate_job()' - Validate printer options and destination.
11224 validate_job(cupsd_client_t
*con
, /* I - Client connection */
11225 ipp_attribute_t
*uri
) /* I - Printer URI */
11227 http_status_t status
; /* Policy status */
11228 ipp_attribute_t
*attr
; /* Current attribute */
11230 ipp_attribute_t
*auth_info
; /* auth-info attribute */
11231 #endif /* HAVE_SSL */
11232 ipp_attribute_t
*format
, /* Document-format attribute */
11233 *name
; /* Job-name attribute */
11234 cups_ptype_t dtype
; /* Destination type (printer/class) */
11235 char super
[MIME_MAX_SUPER
],
11236 /* Supertype of file */
11237 type
[MIME_MAX_TYPE
];
11238 /* Subtype of file */
11239 cupsd_printer_t
*printer
; /* Printer */
11242 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_job(%p[%d], %s)", con
,
11243 con
->number
, uri
->values
[0].string
.text
);
11246 * OK, see if the client is sending the document compressed - CUPS
11247 * doesn't support compression yet...
11250 if ((attr
= ippFindAttribute(con
->request
, "compression",
11251 IPP_TAG_KEYWORD
)) != NULL
)
11253 if (strcmp(attr
->values
[0].string
.text
, "none")
11255 && strcmp(attr
->values
[0].string
.text
, "gzip")
11256 #endif /* HAVE_LIBZ */
11259 send_ipp_status(con
, IPP_ATTRIBUTES
,
11260 _("Unsupported 'compression' value \"%s\"."),
11261 attr
->values
[0].string
.text
);
11262 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
11263 "compression", NULL
, attr
->values
[0].string
.text
);
11269 * Is it a format we support?
11272 if ((format
= ippFindAttribute(con
->request
, "document-format",
11273 IPP_TAG_MIMETYPE
)) != NULL
)
11275 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%255[^;]",
11278 send_ipp_status(con
, IPP_BAD_REQUEST
,
11279 _("Bad 'document-format' value \"%s\"."),
11280 format
->values
[0].string
.text
);
11284 if ((strcmp(super
, "application") || strcmp(type
, "octet-stream")) &&
11285 !mimeType(MimeDatabase
, super
, type
))
11287 cupsdLogMessage(CUPSD_LOG_INFO
,
11288 "Hint: Do you have the raw file printing rules enabled?");
11289 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
11290 _("Unsupported 'document-format' value \"%s\"."),
11291 format
->values
[0].string
.text
);
11292 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
11293 "document-format", NULL
, format
->values
[0].string
.text
);
11299 * Is the job-name valid?
11302 if ((name
= ippFindAttribute(con
->request
, "job-name", IPP_TAG_ZERO
)) != NULL
)
11304 int bad_name
= 0; /* Is the job-name value bad? */
11306 if ((name
->value_tag
!= IPP_TAG_NAME
&& name
->value_tag
!= IPP_TAG_NAMELANG
) ||
11307 name
->num_values
!= 1)
11314 * Validate that job-name conforms to RFC 5198 (Network Unicode) and
11315 * IPP Everywhere requirements for "name" values...
11318 const unsigned char *nameptr
; /* Pointer into "job-name" attribute */
11320 for (nameptr
= (unsigned char *)name
->values
[0].string
.text
;
11324 if (*nameptr
< ' ' && *nameptr
!= '\t')
11326 else if (*nameptr
== 0x7f)
11328 else if ((*nameptr
& 0xe0) == 0xc0)
11330 if ((nameptr
[1] & 0xc0) != 0x80)
11335 else if ((*nameptr
& 0xf0) == 0xe0)
11337 if ((nameptr
[1] & 0xc0) != 0x80 ||
11338 (nameptr
[2] & 0xc0) != 0x80)
11343 else if ((*nameptr
& 0xf8) == 0xf0)
11345 if ((nameptr
[1] & 0xc0) != 0x80 ||
11346 (nameptr
[2] & 0xc0) != 0x80 ||
11347 (nameptr
[3] & 0xc0) != 0x80)
11352 else if (*nameptr
& 0x80)
11362 if (StrictConformance
)
11364 send_ipp_status(con
, IPP_ATTRIBUTES
,
11365 _("Unsupported 'job-name' value."));
11366 ippCopyAttribute(con
->response
, name
, 0);
11371 cupsdLogMessage(CUPSD_LOG_WARN
,
11372 "Unsupported 'job-name' value, deleting from request.");
11373 ippDeleteAttribute(con
->request
, name
);
11379 * Is the destination valid?
11382 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11388 send_ipp_status(con
, IPP_NOT_FOUND
,
11389 _("The printer or class does not exist."));
11398 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
11399 #endif /* HAVE_SSL */
11401 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11403 send_http_error(con
, status
, printer
);
11406 else if (printer
->num_auth_info_required
== 1 &&
11407 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
11410 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
11414 else if (auth_info
&& !con
->http
->tls
&&
11415 !httpAddrLocalhost(con
->http
->hostaddr
))
11418 * Require encryption of auth-info over non-local connections...
11421 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
11424 #endif /* HAVE_SSL */
11427 * Everything was ok, so return OK status...
11430 con
->response
->request
.status
.status_code
= IPP_OK
;
11435 * 'validate_name()' - Make sure the printer name only contains valid chars.
11438 static int /* O - 0 if name is no good, 1 if good */
11439 validate_name(const char *name
) /* I - Name to check */
11441 const char *ptr
; /* Pointer into name */
11445 * Scan the whole name...
11448 for (ptr
= name
; *ptr
; ptr
++)
11449 if ((*ptr
> 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
11453 * All the characters are good; validate the length, too...
11456 return ((ptr
- name
) < 128);
11461 * 'validate_user()' - Validate the user for the request.
11464 static int /* O - 1 if permitted, 0 otherwise */
11465 validate_user(cupsd_job_t
*job
, /* I - Job */
11466 cupsd_client_t
*con
, /* I - Client connection */
11467 const char *owner
, /* I - Owner of job/resource */
11468 char *username
, /* O - Authenticated username */
11469 size_t userlen
) /* I - Length of username */
11471 cupsd_printer_t
*printer
; /* Printer for job */
11474 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
);
11477 * Validate input...
11480 if (!con
|| !owner
|| !username
|| userlen
<= 0)
11484 * Get the best authenticated username that is available.
11487 strlcpy(username
, get_username(con
), userlen
);
11490 * Check the username against the owner...
11493 printer
= cupsdFindDest(job
->dest
);
11495 return (cupsdCheckPolicy(printer
? printer
->op_policy_ptr
: DefaultPolicyPtr
,
11496 con
, owner
) == HTTP_OK
);