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
,
156 "cupsdProcessIPPRequest(%p[%d]): operation_id = %04x",
157 con
, con
->number
, con
->request
->request
.op
.operation_id
);
160 * First build an empty response message for this request...
163 con
->response
= ippNew();
165 con
->response
->request
.status
.version
[0] =
166 con
->request
->request
.op
.version
[0];
167 con
->response
->request
.status
.version
[1] =
168 con
->request
->request
.op
.version
[1];
169 con
->response
->request
.status
.request_id
=
170 con
->request
->request
.op
.request_id
;
173 * Then validate the request header and required attributes...
176 if (con
->request
->request
.any
.version
[0] != 1 &&
177 con
->request
->request
.any
.version
[0] != 2)
180 * Return an error, since we only support IPP 1.x and 2.x.
183 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
184 "%04X %s Bad request version number %d.%d",
185 IPP_VERSION_NOT_SUPPORTED
, con
->http
->hostname
,
186 con
->request
->request
.any
.version
[0],
187 con
->request
->request
.any
.version
[1]);
189 send_ipp_status(con
, IPP_VERSION_NOT_SUPPORTED
,
190 _("Bad request version number %d.%d."),
191 con
->request
->request
.any
.version
[0],
192 con
->request
->request
.any
.version
[1]);
194 else if (con
->request
->request
.any
.request_id
< 1)
197 * Return an error, since request IDs must be between 1 and 2^31-1
200 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
201 "%04X %s Bad request ID %d",
202 IPP_BAD_REQUEST
, con
->http
->hostname
,
203 con
->request
->request
.any
.request_id
);
205 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad request ID %d."),
206 con
->request
->request
.any
.request_id
);
208 else if (!con
->request
->attrs
)
210 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
211 "%04X %s No attributes in request",
212 IPP_BAD_REQUEST
, con
->http
->hostname
);
214 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No attributes in request."));
219 * Make sure that the attributes are provided in the correct order and
220 * don't repeat groups...
223 for (attr
= con
->request
->attrs
, group
= attr
->group_tag
;
226 if (attr
->group_tag
< group
&& attr
->group_tag
!= IPP_TAG_ZERO
)
229 * Out of order; return an error...
232 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
233 "%04X %s Attribute groups are out of order",
234 IPP_BAD_REQUEST
, con
->http
->hostname
);
236 send_ipp_status(con
, IPP_BAD_REQUEST
,
237 _("Attribute groups are out of order (%x < %x)."),
238 attr
->group_tag
, group
);
242 group
= attr
->group_tag
;
247 * Then make sure that the first three attributes are:
250 * attributes-natural-language
251 * printer-uri/job-uri
254 attr
= con
->request
->attrs
;
255 if (attr
&& attr
->name
&&
256 !strcmp(attr
->name
, "attributes-charset") &&
257 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_CHARSET
)
265 if (attr
&& attr
->name
&&
266 !strcmp(attr
->name
, "attributes-natural-language") &&
267 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_LANGUAGE
)
272 * Reset language for this request if different from Accept-Language.
275 if (!con
->language
||
276 strcmp(attr
->values
[0].string
.text
, con
->language
->language
))
278 cupsLangFree(con
->language
);
279 con
->language
= cupsLangGet(attr
->values
[0].string
.text
);
285 if ((attr
= ippFindAttribute(con
->request
, "printer-uri",
286 IPP_TAG_URI
)) != NULL
)
288 else if ((attr
= ippFindAttribute(con
->request
, "job-uri",
289 IPP_TAG_URI
)) != NULL
)
291 else if (con
->request
->request
.op
.operation_id
== CUPS_GET_PPD
)
292 uri
= ippFindAttribute(con
->request
, "ppd-name", IPP_TAG_NAME
);
297 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
298 "attributes-charset", NULL
,
299 charset
->values
[0].string
.text
);
301 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
302 "attributes-charset", NULL
, "utf-8");
305 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
306 "attributes-natural-language", NULL
,
307 language
->values
[0].string
.text
);
309 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
310 "attributes-natural-language", NULL
, DefaultLanguage
);
313 _cups_strcasecmp(charset
->values
[0].string
.text
, "us-ascii") &&
314 _cups_strcasecmp(charset
->values
[0].string
.text
, "utf-8"))
317 * Bad character set...
320 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unsupported character set \"%s\"",
321 charset
->values
[0].string
.text
);
322 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
323 "%04X %s Unsupported attributes-charset value \"%s\"",
324 IPP_CHARSET
, con
->http
->hostname
,
325 charset
->values
[0].string
.text
);
326 send_ipp_status(con
, IPP_BAD_REQUEST
,
327 _("Unsupported character set \"%s\"."),
328 charset
->values
[0].string
.text
);
330 else if (!charset
|| !language
||
332 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEFAULT
&&
333 con
->request
->request
.op
.operation_id
!= CUPS_GET_PRINTERS
&&
334 con
->request
->request
.op
.operation_id
!= CUPS_GET_CLASSES
&&
335 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEVICES
&&
336 con
->request
->request
.op
.operation_id
!= CUPS_GET_PPDS
))
339 * Return an error, since attributes-charset,
340 * attributes-natural-language, and printer-uri/job-uri are required
341 * for all operations.
346 cupsdLogMessage(CUPSD_LOG_ERROR
,
347 "Missing attributes-charset attribute");
349 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
350 "%04X %s Missing attributes-charset attribute",
351 IPP_BAD_REQUEST
, con
->http
->hostname
);
356 cupsdLogMessage(CUPSD_LOG_ERROR
,
357 "Missing attributes-natural-language attribute");
359 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
360 "%04X %s Missing attributes-natural-language attribute",
361 IPP_BAD_REQUEST
, con
->http
->hostname
);
366 cupsdLogMessage(CUPSD_LOG_ERROR
,
367 "Missing printer-uri, job-uri, or ppd-name "
370 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
371 "%04X %s Missing printer-uri, job-uri, or ppd-name "
372 "attribute", IPP_BAD_REQUEST
, con
->http
->hostname
);
375 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Request attributes follow...");
377 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
378 cupsdLogMessage(CUPSD_LOG_DEBUG
,
379 "attr \"%s\": group_tag = %x, value_tag = %x",
380 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
383 cupsdLogMessage(CUPSD_LOG_DEBUG
, "End of attributes...");
385 send_ipp_status(con
, IPP_BAD_REQUEST
,
386 _("Missing required attributes."));
391 * OK, all the checks pass so far; make sure requesting-user-name is
392 * not "root" from a remote host...
395 if ((username
= ippFindAttribute(con
->request
, "requesting-user-name",
396 IPP_TAG_NAME
)) != NULL
)
399 * Check for root user...
402 if (!strcmp(username
->values
[0].string
.text
, "root") &&
403 _cups_strcasecmp(con
->http
->hostname
, "localhost") &&
404 strcmp(con
->username
, "root"))
407 * Remote unauthenticated user masquerading as local root...
410 ippSetString(con
->request
, &username
, 0, RemoteRoot
);
414 if ((attr
= ippFindAttribute(con
->request
, "notify-subscription-id",
415 IPP_TAG_INTEGER
)) != NULL
)
416 sub_id
= attr
->values
[0].integer
;
421 * Then try processing the operation...
425 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s",
426 ippOpString(con
->request
->request
.op
.operation_id
),
427 uri
->values
[0].string
.text
);
429 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s",
430 ippOpString(con
->request
->request
.op
.operation_id
));
432 switch (con
->request
->request
.op
.operation_id
)
434 case IPP_OP_PRINT_JOB
:
438 case IPP_OP_VALIDATE_JOB
:
439 validate_job(con
, uri
);
442 case IPP_OP_CREATE_JOB
:
443 create_job(con
, uri
);
446 case IPP_OP_SEND_DOCUMENT
:
447 send_document(con
, uri
);
450 case IPP_OP_CANCEL_JOB
:
451 cancel_job(con
, uri
);
454 case IPP_OP_GET_JOB_ATTRIBUTES
:
455 get_job_attrs(con
, uri
);
458 case IPP_OP_GET_JOBS
:
462 case IPP_OP_GET_PRINTER_ATTRIBUTES
:
463 get_printer_attrs(con
, uri
);
466 case IPP_OP_GET_PRINTER_SUPPORTED_VALUES
:
467 get_printer_supported(con
, uri
);
470 case IPP_OP_HOLD_JOB
:
474 case IPP_OP_RELEASE_JOB
:
475 release_job(con
, uri
);
478 case IPP_OP_RESTART_JOB
:
479 restart_job(con
, uri
);
482 case IPP_OP_PAUSE_PRINTER
:
483 stop_printer(con
, uri
);
486 case IPP_OP_RESUME_PRINTER
:
487 start_printer(con
, uri
);
490 case IPP_OP_PURGE_JOBS
:
491 case IPP_OP_CANCEL_JOBS
:
492 case IPP_OP_CANCEL_MY_JOBS
:
493 cancel_all_jobs(con
, uri
);
496 case IPP_OP_SET_JOB_ATTRIBUTES
:
497 set_job_attrs(con
, uri
);
500 case IPP_OP_SET_PRINTER_ATTRIBUTES
:
501 set_printer_attrs(con
, uri
);
504 case IPP_OP_HOLD_NEW_JOBS
:
505 hold_new_jobs(con
, uri
);
508 case IPP_OP_RELEASE_HELD_NEW_JOBS
:
509 release_held_new_jobs(con
, uri
);
512 case IPP_OP_CLOSE_JOB
:
516 case IPP_OP_CUPS_GET_DEFAULT
:
520 case IPP_OP_CUPS_GET_PRINTERS
:
521 get_printers(con
, 0);
524 case IPP_OP_CUPS_GET_CLASSES
:
525 get_printers(con
, CUPS_PRINTER_CLASS
);
528 case IPP_OP_CUPS_ADD_MODIFY_PRINTER
:
529 add_printer(con
, uri
);
532 case IPP_OP_CUPS_DELETE_PRINTER
:
533 delete_printer(con
, uri
);
536 case IPP_OP_CUPS_ADD_MODIFY_CLASS
:
540 case IPP_OP_CUPS_DELETE_CLASS
:
541 delete_printer(con
, uri
);
544 case IPP_OP_CUPS_ACCEPT_JOBS
:
545 case IPP_OP_ENABLE_PRINTER
:
546 accept_jobs(con
, uri
);
549 case IPP_OP_CUPS_REJECT_JOBS
:
550 case IPP_OP_DISABLE_PRINTER
:
551 reject_jobs(con
, uri
);
554 case IPP_OP_CUPS_SET_DEFAULT
:
555 set_default(con
, uri
);
558 case IPP_OP_CUPS_GET_DEVICES
:
562 case IPP_OP_CUPS_GET_DOCUMENT
:
563 get_document(con
, uri
);
566 case IPP_OP_CUPS_GET_PPD
:
570 case IPP_OP_CUPS_GET_PPDS
:
574 case IPP_OP_CUPS_MOVE_JOB
:
578 case IPP_OP_CUPS_AUTHENTICATE_JOB
:
579 authenticate_job(con
, uri
);
582 case IPP_OP_CREATE_PRINTER_SUBSCRIPTIONS
:
583 case IPP_OP_CREATE_JOB_SUBSCRIPTIONS
:
584 create_subscriptions(con
, uri
);
587 case IPP_OP_GET_SUBSCRIPTION_ATTRIBUTES
:
588 get_subscription_attrs(con
, sub_id
);
591 case IPP_OP_GET_SUBSCRIPTIONS
:
592 get_subscriptions(con
, uri
);
595 case IPP_OP_RENEW_SUBSCRIPTION
:
596 renew_subscription(con
, sub_id
);
599 case IPP_OP_CANCEL_SUBSCRIPTION
:
600 cancel_subscription(con
, sub_id
);
603 case IPP_OP_GET_NOTIFICATIONS
:
604 get_notifications(con
);
607 case IPP_OP_CUPS_CREATE_LOCAL_PRINTER
:
608 create_local_printer(con
);
612 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
613 "%04X %s Operation %04X (%s) not supported",
614 IPP_OPERATION_NOT_SUPPORTED
, con
->http
->hostname
,
615 con
->request
->request
.op
.operation_id
,
616 ippOpString(con
->request
->request
.op
.operation_id
));
618 send_ipp_status(con
, IPP_OPERATION_NOT_SUPPORTED
,
619 _("%s not supported."),
621 con
->request
->request
.op
.operation_id
));
631 * Sending data from the scheduler...
634 cupsdLogMessage(con
->response
->request
.status
.status_code
635 >= IPP_BAD_REQUEST
&&
636 con
->response
->request
.status
.status_code
637 != IPP_NOT_FOUND
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
638 "[Client %d] Returning IPP %s for %s (%s) from %s",
640 ippErrorString(con
->response
->request
.status
.status_code
),
641 ippOpString(con
->request
->request
.op
.operation_id
),
642 uri
? uri
->values
[0].string
.text
: "no URI",
643 con
->http
->hostname
);
645 httpClearFields(con
->http
);
647 #ifdef CUPSD_USE_CHUNKING
649 * Because older versions of CUPS (1.1.17 and older) and some IPP
650 * clients do not implement chunking properly, we cannot use
651 * chunking by default. This may become the default in future
652 * CUPS releases, or we might add a configuration directive for
656 if (con
->http
->version
== HTTP_1_1
)
658 cupsdLogMessage(CUPSD_LOG_DEBUG
,
659 "[Client %d] Transfer-Encoding: chunked",
662 cupsdSetLength(con
->http
, 0);
665 #endif /* CUPSD_USE_CHUNKING */
667 size_t length
; /* Length of response */
670 length
= ippLength(con
->response
);
672 if (con
->file
>= 0 && !con
->pipe_pid
)
674 struct stat fileinfo
; /* File information */
676 if (!fstat(con
->file
, &fileinfo
))
677 length
+= (size_t)fileinfo
.st_size
;
680 cupsdLogMessage(CUPSD_LOG_DEBUG
,
681 "[Client %d] Content-Length: " CUPS_LLFMT
,
682 con
->number
, CUPS_LLCAST length
);
683 httpSetLength(con
->http
, length
);
686 if (cupsdSendHeader(con
, HTTP_OK
, "application/ipp", CUPSD_AUTH_NONE
))
689 * Tell the caller the response header was sent successfully...
692 cupsdAddSelect(httpGetFd(con
->http
), (cupsd_selfunc_t
)cupsdReadClient
,
693 (cupsd_selfunc_t
)cupsdWriteClient
, con
);
700 * Tell the caller the response header could not be sent...
709 * Sending data from a subprocess like cups-deviced; tell the caller
710 * everything is A-OK so far...
719 * 'cupsdTimeoutJob()' - Timeout a job waiting on job files.
722 int /* O - 0 on success, -1 on error */
723 cupsdTimeoutJob(cupsd_job_t
*job
) /* I - Job to timeout */
725 cupsd_printer_t
*printer
; /* Destination printer or class */
726 ipp_attribute_t
*attr
; /* job-sheets attribute */
727 int kbytes
; /* Kilobytes in banner */
730 job
->pending_timeout
= 0;
733 * See if we need to add the ending sheet...
736 if (!cupsdLoadJob(job
))
739 printer
= cupsdFindDest(job
->dest
);
740 attr
= ippFindAttribute(job
->attrs
, "job-sheets", IPP_TAG_NAME
);
742 if (printer
&& !(printer
->type
& CUPS_PRINTER_REMOTE
) &&
743 attr
&& attr
->num_values
> 1)
749 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding end banner page \"%s\".",
750 attr
->values
[1].string
.text
);
752 if ((kbytes
= copy_banner(NULL
, job
, attr
->values
[1].string
.text
)) < 0)
755 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
763 * 'accept_jobs()' - Accept print jobs to a printer.
767 accept_jobs(cupsd_client_t
*con
, /* I - Client connection */
768 ipp_attribute_t
*uri
) /* I - Printer or class URI */
770 http_status_t status
; /* Policy status */
771 cups_ptype_t dtype
; /* Destination type (printer/class) */
772 cupsd_printer_t
*printer
; /* Printer data */
775 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "accept_jobs(%p[%d], %s)", con
,
776 con
->number
, uri
->values
[0].string
.text
);
779 * Is the destination valid?
782 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
788 send_ipp_status(con
, IPP_NOT_FOUND
,
789 _("The printer or class does not exist."));
797 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
799 send_http_error(con
, status
, printer
);
804 * Accept jobs sent to the printer...
807 printer
->accepting
= 1;
808 printer
->state_message
[0] = '\0';
810 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
811 "Now accepting jobs.");
813 if (dtype
& CUPS_PRINTER_CLASS
)
815 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
817 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" now accepting jobs (\"%s\").",
818 printer
->name
, get_username(con
));
822 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
824 cupsdLogMessage(CUPSD_LOG_INFO
,
825 "Printer \"%s\" now accepting jobs (\"%s\").",
826 printer
->name
, get_username(con
));
830 * Everything was ok, so return OK status...
833 con
->response
->request
.status
.status_code
= IPP_OK
;
838 * 'add_class()' - Add a class to the system.
842 add_class(cupsd_client_t
*con
, /* I - Client connection */
843 ipp_attribute_t
*uri
) /* I - URI of class */
845 http_status_t status
; /* Policy status */
846 int i
; /* Looping var */
847 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
848 username
[HTTP_MAX_URI
], /* Username portion of URI */
849 host
[HTTP_MAX_URI
], /* Host portion of URI */
850 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
851 int port
; /* Port portion of URI */
852 cupsd_printer_t
*pclass
, /* Class */
853 *member
; /* Member printer/class */
854 cups_ptype_t dtype
; /* Destination type */
855 ipp_attribute_t
*attr
; /* Printer attribute */
856 int modify
; /* Non-zero if we just modified */
857 int need_restart_job
; /* Need to restart job? */
860 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_class(%p[%d], %s)", con
,
861 con
->number
, uri
->values
[0].string
.text
);
864 * Do we have a valid URI?
867 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
868 sizeof(scheme
), username
, sizeof(username
), host
,
869 sizeof(host
), &port
, resource
, sizeof(resource
));
872 if (strncmp(resource
, "/classes/", 9) || strlen(resource
) == 9)
875 * No, return an error...
878 send_ipp_status(con
, IPP_BAD_REQUEST
,
879 _("The printer-uri must be of the form "
880 "\"ipp://HOSTNAME/classes/CLASSNAME\"."));
885 * Do we have a valid printer name?
888 if (!validate_name(resource
+ 9))
891 * No, return an error...
894 send_ipp_status(con
, IPP_BAD_REQUEST
,
895 _("The printer-uri \"%s\" contains invalid characters."),
896 uri
->values
[0].string
.text
);
901 * See if the class already exists; if not, create a new class...
904 if ((pclass
= cupsdFindClass(resource
+ 9)) == NULL
)
907 * Class doesn't exist; see if we have a printer of the same name...
910 if ((pclass
= cupsdFindPrinter(resource
+ 9)) != NULL
)
913 * Yes, return an error...
916 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
917 _("A printer named \"%s\" already exists."),
923 * No, check the default policy and then add the class...
926 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
928 send_http_error(con
, status
, NULL
);
932 pclass
= cupsdAddClass(resource
+ 9);
935 else if ((status
= cupsdCheckPolicy(pclass
->op_policy_ptr
, con
,
938 send_http_error(con
, status
, pclass
);
945 * Look for attributes and copy them over as needed...
948 need_restart_job
= 0;
950 if ((attr
= ippFindAttribute(con
->request
, "printer-location", IPP_TAG_TEXT
)) != NULL
)
951 cupsdSetString(&pclass
->location
, attr
->values
[0].string
.text
);
953 if ((attr
= ippFindAttribute(con
->request
, "printer-geo-location", IPP_TAG_URI
)) != NULL
&& !strncmp(attr
->values
[0].string
.text
, "geo:", 4))
954 cupsdSetString(&pclass
->geo_location
, attr
->values
[0].string
.text
);
956 if ((attr
= ippFindAttribute(con
->request
, "printer-organization", IPP_TAG_TEXT
)) != NULL
)
957 cupsdSetString(&pclass
->organization
, attr
->values
[0].string
.text
);
959 if ((attr
= ippFindAttribute(con
->request
, "printer-organizational-unit", IPP_TAG_TEXT
)) != NULL
)
960 cupsdSetString(&pclass
->organizational_unit
, attr
->values
[0].string
.text
);
962 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
963 IPP_TAG_TEXT
)) != NULL
)
964 cupsdSetString(&pclass
->info
, attr
->values
[0].string
.text
);
966 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
967 IPP_TAG_BOOLEAN
)) != NULL
&&
968 attr
->values
[0].boolean
!= pclass
->accepting
)
970 cupsdLogMessage(CUPSD_LOG_INFO
,
971 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
972 pclass
->name
, attr
->values
[0].boolean
, pclass
->accepting
);
974 pclass
->accepting
= attr
->values
[0].boolean
;
976 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s accepting jobs.",
977 pclass
->accepting
? "Now" : "No longer");
980 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared", IPP_TAG_BOOLEAN
)) != NULL
)
982 if (pclass
->type
& CUPS_PRINTER_REMOTE
)
985 * Cannot re-share remote printers.
988 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Cannot change printer-is-shared for remote queues."));
990 cupsdDeletePrinter(pclass
, 0);
995 if (pclass
->shared
&& !ippGetBoolean(attr
, 0))
996 cupsdDeregisterPrinter(pclass
, 1);
998 cupsdLogMessage(CUPSD_LOG_INFO
,
999 "Setting %s printer-is-shared to %d (was %d.)",
1000 pclass
->name
, attr
->values
[0].boolean
, pclass
->shared
);
1002 pclass
->shared
= ippGetBoolean(attr
, 0);
1005 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
1006 IPP_TAG_ENUM
)) != NULL
)
1008 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
1009 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
1011 send_ipp_status(con
, IPP_BAD_REQUEST
,
1012 _("Attempt to set %s printer-state to bad value %d."),
1013 pclass
->name
, attr
->values
[0].integer
);
1015 cupsdDeletePrinter(pclass
, 0);
1020 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
1021 pclass
->name
, attr
->values
[0].integer
, pclass
->state
);
1023 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
1024 cupsdStopPrinter(pclass
, 0);
1027 cupsdSetPrinterState(pclass
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
1028 need_restart_job
= 1;
1031 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
1032 IPP_TAG_TEXT
)) != NULL
)
1034 strlcpy(pclass
->state_message
, attr
->values
[0].string
.text
,
1035 sizeof(pclass
->state_message
));
1037 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s",
1038 pclass
->state_message
);
1040 if ((attr
= ippFindAttribute(con
->request
, "member-uris",
1041 IPP_TAG_URI
)) != NULL
)
1044 * Clear the printer array as needed...
1047 need_restart_job
= 1;
1049 if (pclass
->num_printers
> 0)
1051 free(pclass
->printers
);
1052 pclass
->num_printers
= 0;
1056 * Add each printer or class that is listed...
1059 for (i
= 0; i
< attr
->num_values
; i
++)
1062 * Search for the printer or class URI...
1065 if (!cupsdValidateDest(attr
->values
[i
].string
.text
, &dtype
, &member
))
1071 send_ipp_status(con
, IPP_NOT_FOUND
,
1072 _("The printer or class does not exist."));
1074 cupsdDeletePrinter(pclass
, 0);
1078 else if (dtype
& CUPS_PRINTER_CLASS
)
1080 send_ipp_status(con
, IPP_BAD_REQUEST
,
1081 _("Nested classes are not allowed."));
1083 cupsdDeletePrinter(pclass
, 0);
1089 * Add it to the class...
1092 cupsdAddPrinterToClass(pclass
, member
);
1096 if (!set_printer_defaults(con
, pclass
))
1099 cupsdDeletePrinter(pclass
, 0);
1104 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
1105 IPP_TAG_KEYWORD
)) != NULL
)
1106 cupsdSetAuthInfoRequired(pclass
, NULL
, attr
);
1108 pclass
->config_time
= time(NULL
);
1111 * Update the printer class attributes and return...
1114 cupsdSetPrinterAttrs(pclass
);
1115 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
1117 if (need_restart_job
&& pclass
->job
)
1120 * Reset the current job to a "pending" status...
1123 cupsdSetJobState(pclass
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
1124 "Job restarted because the class was modified.");
1127 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1131 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
1132 pclass
, NULL
, "Class \"%s\" modified by \"%s\".",
1133 pclass
->name
, get_username(con
));
1135 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" modified by \"%s\".",
1136 pclass
->name
, get_username(con
));
1140 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
1141 pclass
, NULL
, "New class \"%s\" added by \"%s\".",
1142 pclass
->name
, get_username(con
));
1144 cupsdLogMessage(CUPSD_LOG_INFO
, "New class \"%s\" added by \"%s\".",
1145 pclass
->name
, get_username(con
));
1148 con
->response
->request
.status
.status_code
= IPP_OK
;
1153 * 'add_file()' - Add a file to a job.
1156 static int /* O - 0 on success, -1 on error */
1157 add_file(cupsd_client_t
*con
, /* I - Connection to client */
1158 cupsd_job_t
*job
, /* I - Job to add to */
1159 mime_type_t
*filetype
, /* I - Type of file */
1160 int compression
) /* I - Compression */
1162 mime_type_t
**filetypes
; /* New filetypes array... */
1163 int *compressions
; /* New compressions array... */
1166 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1167 "add_file(con=%p[%d], job=%d, filetype=%s/%s, "
1168 "compression=%d)", con
, con
? con
->number
: -1, job
->id
,
1169 filetype
->super
, filetype
->type
, compression
);
1172 * Add the file to the job...
1175 if (job
->num_files
== 0)
1177 compressions
= (int *)malloc(sizeof(int));
1178 filetypes
= (mime_type_t
**)malloc(sizeof(mime_type_t
*));
1182 compressions
= (int *)realloc(job
->compressions
,
1183 (size_t)(job
->num_files
+ 1) * sizeof(int));
1184 filetypes
= (mime_type_t
**)realloc(job
->filetypes
,
1185 (size_t)(job
->num_files
+ 1) *
1186 sizeof(mime_type_t
*));
1190 job
->compressions
= compressions
;
1193 job
->filetypes
= filetypes
;
1195 if (!compressions
|| !filetypes
)
1197 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1198 "Job aborted because the scheduler ran out of memory.");
1201 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1202 _("Unable to allocate memory for file types."));
1207 job
->compressions
[job
->num_files
] = compression
;
1208 job
->filetypes
[job
->num_files
] = filetype
;
1213 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1220 * 'add_job()' - Add a job to a print queue.
1223 static cupsd_job_t
* /* O - Job object */
1224 add_job(cupsd_client_t
*con
, /* I - Client connection */
1225 cupsd_printer_t
*printer
, /* I - Destination printer */
1226 mime_type_t
*filetype
) /* I - First print file type, if any */
1228 http_status_t status
; /* Policy status */
1229 ipp_attribute_t
*attr
, /* Current attribute */
1230 *auth_info
; /* auth-info attribute */
1231 const char *mandatory
; /* Current mandatory job attribute */
1232 const char *val
; /* Default option value */
1233 int priority
; /* Job priority */
1234 cupsd_job_t
*job
; /* Current job */
1235 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
1236 int kbytes
; /* Size of print file */
1237 int i
; /* Looping var */
1238 int lowerpagerange
; /* Page range bound */
1239 int exact
; /* Did we have an exact match? */
1240 ipp_attribute_t
*media_col
, /* media-col attribute */
1241 *media_margin
; /* media-*-margin attribute */
1242 ipp_t
*unsup_col
; /* media-col in unsupported response */
1243 static const char * const readonly
[] =/* List of read-only attributes */
1245 "date-time-at-completed",
1246 "date-time-at-creation",
1247 "date-time-at-processing",
1248 "job-detailed-status-messages",
1249 "job-document-access-errors",
1251 "job-impressions-completed",
1252 "job-k-octets-completed",
1253 "job-media-sheets-completed",
1254 "job-pages-completed",
1255 "job-printer-up-time",
1258 "job-state-message",
1259 "job-state-reasons",
1261 "number-of-documents",
1262 "number-of-intervening-jobs",
1263 "output-device-assigned",
1264 "time-at-completed",
1266 "time-at-processing"
1270 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job(%p[%d], %p(%s), %p(%s/%s))",
1271 con
, con
->number
, printer
, printer
->name
,
1272 filetype
, filetype
? filetype
->super
: "none",
1273 filetype
? filetype
->type
: "none");
1276 * Check remote printing to non-shared printer...
1279 if (!printer
->shared
&&
1280 _cups_strcasecmp(con
->http
->hostname
, "localhost") &&
1281 _cups_strcasecmp(con
->http
->hostname
, ServerName
))
1283 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
1284 _("The printer or class is not shared."));
1292 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
1294 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
1296 send_http_error(con
, status
, printer
);
1299 else if (printer
->num_auth_info_required
== 1 &&
1300 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
1303 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
1307 else if (auth_info
&& !con
->http
->tls
&&
1308 !httpAddrLocalhost(con
->http
->hostaddr
))
1311 * Require encryption of auth-info over non-local connections...
1314 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
1317 #endif /* HAVE_SSL */
1320 * See if the printer is accepting jobs...
1323 if (!printer
->accepting
)
1325 send_ipp_status(con
, IPP_NOT_ACCEPTING
,
1326 _("Destination \"%s\" is not accepting jobs."),
1332 * Validate job template attributes; for now just document-format,
1333 * copies, job-sheets, number-up, page-ranges, mandatory attributes, and
1337 for (i
= 0; i
< (int)(sizeof(readonly
) / sizeof(readonly
[0])); i
++)
1339 if ((attr
= ippFindAttribute(con
->request
, readonly
[i
], IPP_TAG_ZERO
)) != NULL
)
1341 ippDeleteAttribute(con
->request
, attr
);
1343 if (StrictConformance
)
1345 send_ipp_status(con
, IPP_BAD_REQUEST
, _("The '%s' Job Status attribute cannot be supplied in a job creation request."), readonly
[i
]);
1349 cupsdLogMessage(CUPSD_LOG_INFO
, "Unexpected '%s' Job Status attribute in a job creation request.", readonly
[i
]);
1355 for (mandatory
= (char *)cupsArrayFirst(printer
->pc
->mandatory
);
1357 mandatory
= (char *)cupsArrayNext(printer
->pc
->mandatory
))
1359 if (!ippFindAttribute(con
->request
, mandatory
, IPP_TAG_ZERO
))
1362 * Missing a required attribute...
1365 send_ipp_status(con
, IPP_CONFLICT
,
1366 _("The \"%s\" attribute is required for print jobs."),
1373 if (filetype
&& printer
->filetypes
&&
1374 !cupsArrayFind(printer
->filetypes
, filetype
))
1376 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
1377 /* MIME media type string */
1380 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
1383 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
1384 _("Unsupported format \"%s\"."), mimetype
);
1386 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
1387 "document-format", NULL
, mimetype
);
1392 if ((attr
= ippFindAttribute(con
->request
, "copies",
1393 IPP_TAG_INTEGER
)) != NULL
)
1395 if (attr
->values
[0].integer
< 1 || attr
->values
[0].integer
> MaxCopies
)
1397 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad copies value %d."),
1398 attr
->values
[0].integer
);
1399 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1400 "copies", attr
->values
[0].integer
);
1405 if ((attr
= ippFindAttribute(con
->request
, "job-sheets",
1406 IPP_TAG_ZERO
)) != NULL
)
1408 if (attr
->value_tag
!= IPP_TAG_KEYWORD
&&
1409 attr
->value_tag
!= IPP_TAG_NAME
)
1411 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value type."));
1415 if (attr
->num_values
> 2)
1417 send_ipp_status(con
, IPP_BAD_REQUEST
,
1418 _("Too many job-sheets values (%d > 2)."),
1423 for (i
= 0; i
< attr
->num_values
; i
++)
1424 if (strcmp(attr
->values
[i
].string
.text
, "none") &&
1425 !cupsdFindBanner(attr
->values
[i
].string
.text
))
1427 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value \"%s\"."),
1428 attr
->values
[i
].string
.text
);
1433 if ((attr
= ippFindAttribute(con
->request
, "number-up",
1434 IPP_TAG_INTEGER
)) != NULL
)
1436 if (attr
->values
[0].integer
!= 1 &&
1437 attr
->values
[0].integer
!= 2 &&
1438 attr
->values
[0].integer
!= 4 &&
1439 attr
->values
[0].integer
!= 6 &&
1440 attr
->values
[0].integer
!= 9 &&
1441 attr
->values
[0].integer
!= 16)
1443 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad number-up value %d."),
1444 attr
->values
[0].integer
);
1445 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1446 "number-up", attr
->values
[0].integer
);
1451 if ((attr
= ippFindAttribute(con
->request
, "page-ranges",
1452 IPP_TAG_RANGE
)) != NULL
)
1454 for (i
= 0, lowerpagerange
= 1; i
< attr
->num_values
; i
++)
1456 if (attr
->values
[i
].range
.lower
< lowerpagerange
||
1457 attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
1459 send_ipp_status(con
, IPP_BAD_REQUEST
,
1460 _("Bad page-ranges values %d-%d."),
1461 attr
->values
[i
].range
.lower
,
1462 attr
->values
[i
].range
.upper
);
1466 lowerpagerange
= attr
->values
[i
].range
.upper
+ 1;
1471 * Do media selection as needed...
1474 if (!ippFindAttribute(con
->request
, "PageRegion", IPP_TAG_ZERO
) &&
1475 !ippFindAttribute(con
->request
, "PageSize", IPP_TAG_ZERO
) &&
1476 _ppdCacheGetPageSize(printer
->pc
, con
->request
, NULL
, &exact
))
1479 (media_col
= ippFindAttribute(con
->request
, "media-col",
1480 IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
1482 send_ipp_status(con
, IPP_OK_SUBST
, _("Unsupported margins."));
1484 unsup_col
= ippNew();
1485 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1486 "media-bottom-margin",
1487 IPP_TAG_INTEGER
)) != NULL
)
1488 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1489 "media-bottom-margin", media_margin
->values
[0].integer
);
1491 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1492 "media-left-margin",
1493 IPP_TAG_INTEGER
)) != NULL
)
1494 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1495 "media-left-margin", media_margin
->values
[0].integer
);
1497 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1498 "media-right-margin",
1499 IPP_TAG_INTEGER
)) != NULL
)
1500 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1501 "media-right-margin", media_margin
->values
[0].integer
);
1503 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1505 IPP_TAG_INTEGER
)) != NULL
)
1506 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1507 "media-top-margin", media_margin
->values
[0].integer
);
1509 ippAddCollection(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, "media-col",
1511 ippDelete(unsup_col
);
1516 * Make sure we aren't over our limit...
1519 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1522 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1524 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Too many active jobs."));
1528 if ((i
= check_quotas(con
, printer
)) < 0)
1530 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
1535 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
1540 * Create the job and set things up...
1543 if ((attr
= ippFindAttribute(con
->request
, "job-priority",
1544 IPP_TAG_INTEGER
)) != NULL
)
1545 priority
= attr
->values
[0].integer
;
1548 if ((val
= cupsGetOption("job-priority", printer
->num_options
,
1549 printer
->options
)) != NULL
)
1550 priority
= atoi(val
);
1554 ippAddInteger(con
->request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-priority",
1558 if ((attr
= ippFindAttribute(con
->request
, "job-name", IPP_TAG_ZERO
)) == NULL
)
1559 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
, "Untitled");
1560 else if ((attr
->value_tag
!= IPP_TAG_NAME
&&
1561 attr
->value_tag
!= IPP_TAG_NAMELANG
) ||
1562 attr
->num_values
!= 1)
1564 send_ipp_status(con
, IPP_ATTRIBUTES
,
1565 _("Bad job-name value: Wrong type or count."));
1566 if ((attr
= ippCopyAttribute(con
->response
, attr
, 0)) != NULL
)
1567 attr
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
1570 else if (!ippValidateAttribute(attr
))
1572 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad job-name value: %s"),
1573 cupsLastErrorString());
1574 if ((attr
= ippCopyAttribute(con
->response
, attr
, 0)) != NULL
)
1575 attr
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
1579 if ((job
= cupsdAddJob(priority
, printer
->name
)) == NULL
)
1581 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1582 _("Unable to add job for destination \"%s\"."),
1587 job
->dtype
= printer
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
1588 job
->attrs
= con
->request
;
1590 con
->request
= ippNewRequest(job
->attrs
->request
.op
.operation_id
);
1592 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1595 apply_printer_defaults(printer
, job
);
1597 attr
= ippFindAttribute(job
->attrs
, "requesting-user-name", IPP_TAG_NAME
);
1599 if (con
->username
[0])
1601 cupsdSetString(&job
->username
, con
->username
);
1604 ippSetString(job
->attrs
, &attr
, 0, con
->username
);
1608 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1609 "add_job: requesting-user-name=\"%s\"",
1610 attr
->values
[0].string
.text
);
1612 cupsdSetString(&job
->username
, attr
->values
[0].string
.text
);
1615 cupsdSetString(&job
->username
, "anonymous");
1618 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1619 "job-originating-user-name", NULL
, job
->username
);
1622 ippSetGroupTag(job
->attrs
, &attr
, IPP_TAG_JOB
);
1623 ippSetName(job
->attrs
, &attr
, "job-originating-user-name");
1626 if (con
->username
[0] || auth_info
)
1628 save_auth_info(con
, job
, auth_info
);
1631 * Remove the auth-info attribute from the attribute data...
1635 ippDeleteAttribute(job
->attrs
, auth_info
);
1638 if ((attr
= ippFindAttribute(con
->request
, "job-name", IPP_TAG_NAME
)) != NULL
)
1639 cupsdSetString(&(job
->name
), attr
->values
[0].string
.text
);
1641 if ((attr
= ippFindAttribute(job
->attrs
, "job-originating-host-name",
1642 IPP_TAG_ZERO
)) != NULL
)
1645 * Request contains a job-originating-host-name attribute; validate it...
1648 if (attr
->value_tag
!= IPP_TAG_NAME
||
1649 attr
->num_values
!= 1 ||
1650 strcmp(con
->http
->hostname
, "localhost"))
1653 * Can't override the value if we aren't connected via localhost.
1654 * Also, we can only have 1 value and it must be a name value.
1657 ippDeleteAttribute(job
->attrs
, attr
);
1658 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-originating-host-name", NULL
, con
->http
->hostname
);
1661 ippSetGroupTag(job
->attrs
, &attr
, IPP_TAG_JOB
);
1666 * No job-originating-host-name attribute, so use the hostname from
1670 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1671 "job-originating-host-name", NULL
, con
->http
->hostname
);
1674 ippAddOutOfBand(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NOVALUE
, "date-time-at-completed");
1675 ippAddDate(job
->attrs
, IPP_TAG_JOB
, "date-time-at-creation", ippTimeToDate(time(NULL
)));
1676 ippAddOutOfBand(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NOVALUE
, "date-time-at-processing");
1677 ippAddOutOfBand(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NOVALUE
, "time-at-completed");
1678 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation", time(NULL
));
1679 ippAddOutOfBand(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NOVALUE
, "time-at-processing");
1682 * Add remaining job attributes...
1685 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1686 job
->state
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_ENUM
,
1687 "job-state", IPP_JOB_STOPPED
);
1688 job
->state_value
= (ipp_jstate_t
)job
->state
->values
[0].integer
;
1689 job
->reasons
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1690 "job-state-reasons", NULL
, "job-incoming");
1691 job
->impressions
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-impressions-completed", 0);
1692 job
->sheets
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1693 "job-media-sheets-completed", 0);
1694 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-printer-uri", NULL
,
1697 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets", IPP_TAG_INTEGER
)) != NULL
)
1698 attr
->values
[0].integer
= 0;
1700 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-k-octets", 0);
1702 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
1703 IPP_TAG_KEYWORD
)) == NULL
)
1704 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
1707 if ((val
= cupsGetOption("job-hold-until", printer
->num_options
,
1708 printer
->options
)) == NULL
)
1711 attr
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1712 "job-hold-until", NULL
, val
);
1715 if (printer
->holding_new_jobs
)
1718 * Hold all new jobs on this printer...
1721 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
1722 cupsdSetJobHoldUntil(job
, ippGetString(attr
, 0, NULL
), 0);
1724 cupsdSetJobHoldUntil(job
, "indefinite", 0);
1726 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1727 job
->state_value
= IPP_JOB_HELD
;
1729 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-held-on-create");
1731 else if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
1734 * Hold job until specified time...
1737 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
1739 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1740 job
->state_value
= IPP_JOB_HELD
;
1742 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-hold-until-specified");
1744 else if (job
->attrs
->request
.op
.operation_id
== IPP_CREATE_JOB
)
1746 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
1747 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1748 job
->state_value
= IPP_JOB_HELD
;
1752 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1753 job
->state_value
= IPP_JOB_PENDING
;
1755 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
1758 if (!(printer
->type
& CUPS_PRINTER_REMOTE
) || Classification
)
1761 * Add job sheets options...
1764 if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1765 IPP_TAG_ZERO
)) == NULL
)
1767 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1768 "Adding default job-sheets values \"%s,%s\"...",
1769 printer
->job_sheets
[0], printer
->job_sheets
[1]);
1771 attr
= ippAddStrings(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-sheets",
1773 ippSetString(job
->attrs
, &attr
, 0, printer
->job_sheets
[0]);
1774 ippSetString(job
->attrs
, &attr
, 1, printer
->job_sheets
[1]);
1777 job
->job_sheets
= attr
;
1780 * Enforce classification level if set...
1785 cupsdLogMessage(CUPSD_LOG_INFO
,
1786 "Classification=\"%s\", ClassifyOverride=%d",
1787 Classification
? Classification
: "(null)",
1790 if (ClassifyOverride
)
1792 if (!strcmp(attr
->values
[0].string
.text
, "none") &&
1793 (attr
->num_values
== 1 ||
1794 !strcmp(attr
->values
[1].string
.text
, "none")))
1797 * Force the leading banner to have the classification on it...
1800 ippSetString(job
->attrs
, &attr
, 0, Classification
);
1802 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1803 "job-sheets=\"%s,none\", "
1804 "job-originating-user-name=\"%s\"",
1805 Classification
, job
->username
);
1807 else if (attr
->num_values
== 2 &&
1808 strcmp(attr
->values
[0].string
.text
,
1809 attr
->values
[1].string
.text
) &&
1810 strcmp(attr
->values
[0].string
.text
, "none") &&
1811 strcmp(attr
->values
[1].string
.text
, "none"))
1814 * Can't put two different security markings on the same document!
1817 ippSetString(job
->attrs
, &attr
, 1, attr
->values
[0].string
.text
);
1819 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1820 "job-sheets=\"%s,%s\", "
1821 "job-originating-user-name=\"%s\"",
1822 attr
->values
[0].string
.text
,
1823 attr
->values
[1].string
.text
, job
->username
);
1825 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1826 strcmp(attr
->values
[0].string
.text
, "none") &&
1827 (attr
->num_values
== 1 ||
1828 (strcmp(attr
->values
[1].string
.text
, Classification
) &&
1829 strcmp(attr
->values
[1].string
.text
, "none"))))
1831 if (attr
->num_values
== 1)
1832 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1833 "CLASSIFICATION OVERRIDDEN "
1834 "job-sheets=\"%s\", "
1835 "job-originating-user-name=\"%s\"",
1836 attr
->values
[0].string
.text
, job
->username
);
1838 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1839 "CLASSIFICATION OVERRIDDEN "
1840 "job-sheets=\"%s,%s\",fffff "
1841 "job-originating-user-name=\"%s\"",
1842 attr
->values
[0].string
.text
,
1843 attr
->values
[1].string
.text
, job
->username
);
1846 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1847 (attr
->num_values
== 1 ||
1848 strcmp(attr
->values
[1].string
.text
, Classification
)))
1851 * Force the banner to have the classification on it...
1854 if (attr
->num_values
> 1 &&
1855 !strcmp(attr
->values
[0].string
.text
, attr
->values
[1].string
.text
))
1857 ippSetString(job
->attrs
, &attr
, 0, Classification
);
1858 ippSetString(job
->attrs
, &attr
, 1, Classification
);
1862 if (attr
->num_values
== 1 ||
1863 strcmp(attr
->values
[0].string
.text
, "none"))
1864 ippSetString(job
->attrs
, &attr
, 0, Classification
);
1866 if (attr
->num_values
> 1 &&
1867 strcmp(attr
->values
[1].string
.text
, "none"))
1868 ippSetString(job
->attrs
, &attr
, 1, Classification
);
1871 if (attr
->num_values
> 1)
1872 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1873 "CLASSIFICATION FORCED "
1874 "job-sheets=\"%s,%s\", "
1875 "job-originating-user-name=\"%s\"",
1876 attr
->values
[0].string
.text
,
1877 attr
->values
[1].string
.text
, job
->username
);
1879 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1880 "CLASSIFICATION FORCED "
1881 "job-sheets=\"%s\", "
1882 "job-originating-user-name=\"%s\"",
1883 Classification
, job
->username
);
1888 * See if we need to add the starting sheet...
1891 if (!(printer
->type
& CUPS_PRINTER_REMOTE
))
1893 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding start banner page \"%s\".",
1894 attr
->values
[0].string
.text
);
1896 if ((kbytes
= copy_banner(con
, job
, attr
->values
[0].string
.text
)) < 0)
1898 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1899 "Aborting job because the start banner could not be "
1904 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
1907 else if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1908 IPP_TAG_ZERO
)) != NULL
)
1909 job
->job_sheets
= attr
;
1912 * Fill in the response info...
1915 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
1916 con
->clientname
, con
->clientport
, "/jobs/%d", job
->id
);
1917 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
1920 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1922 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
1924 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_TEXT
, "job-state-message", NULL
, "");
1925 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons",
1926 NULL
, job
->reasons
->values
[0].string
.text
);
1928 con
->response
->request
.status
.status_code
= IPP_OK
;
1931 * Add any job subscriptions...
1934 add_job_subscriptions(con
, job
);
1937 * Set all but the first two attributes to the job attributes group...
1940 for (attr
= job
->attrs
->attrs
->next
->next
; attr
; attr
= attr
->next
)
1941 attr
->group_tag
= IPP_TAG_JOB
;
1944 * Fire the "job created" event...
1947 cupsdAddEvent(CUPSD_EVENT_JOB_CREATED
, printer
, job
, "Job created.");
1950 * Return the new job...
1958 * 'add_job_subscriptions()' - Add any subscriptions for a job.
1962 add_job_subscriptions(
1963 cupsd_client_t
*con
, /* I - Client connection */
1964 cupsd_job_t
*job
) /* I - Newly created job */
1966 int i
; /* Looping var */
1967 ipp_attribute_t
*prev
, /* Previous attribute */
1968 *next
, /* Next attribute */
1969 *attr
; /* Current attribute */
1970 cupsd_subscription_t
*sub
; /* Subscription object */
1971 const char *recipient
, /* notify-recipient-uri */
1972 *pullmethod
; /* notify-pull-method */
1973 ipp_attribute_t
*user_data
; /* notify-user-data */
1974 int interval
; /* notify-time-interval */
1975 unsigned mask
; /* notify-events */
1979 * Find the first subscription group attribute; return if we have
1983 for (attr
= job
->attrs
->attrs
; attr
; attr
= attr
->next
)
1984 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
1991 * Process the subscription attributes in the request...
2000 mask
= CUPSD_EVENT_NONE
;
2002 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
2004 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
2005 attr
->value_tag
== IPP_TAG_URI
)
2008 * Validate the recipient scheme against the ServerBin/notifier
2012 char notifier
[1024], /* Notifier filename */
2013 scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
2014 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
2015 host
[HTTP_MAX_URI
], /* Host portion of URI */
2016 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2017 int port
; /* Port portion of URI */
2020 recipient
= attr
->values
[0].string
.text
;
2022 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
2023 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
2024 host
, sizeof(host
), &port
,
2025 resource
, sizeof(resource
)) < HTTP_URI_OK
)
2027 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2028 _("Bad notify-recipient-uri \"%s\"."), recipient
);
2029 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2030 "notify-status-code", IPP_URI_SCHEME
);
2034 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
2036 if (access(notifier
, X_OK
))
2038 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2039 _("notify-recipient-uri URI \"%s\" uses unknown "
2040 "scheme."), recipient
);
2041 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2042 "notify-status-code", IPP_URI_SCHEME
);
2046 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
2048 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2049 _("notify-recipient-uri URI \"%s\" is already used."),
2051 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2052 "notify-status-code", IPP_ATTRIBUTES
);
2056 else if (!strcmp(attr
->name
, "notify-pull-method") &&
2057 attr
->value_tag
== IPP_TAG_KEYWORD
)
2059 pullmethod
= attr
->values
[0].string
.text
;
2061 if (strcmp(pullmethod
, "ippget"))
2063 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2064 _("Bad notify-pull-method \"%s\"."), pullmethod
);
2065 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2066 "notify-status-code", IPP_ATTRIBUTES
);
2070 else if (!strcmp(attr
->name
, "notify-charset") &&
2071 attr
->value_tag
== IPP_TAG_CHARSET
&&
2072 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
2073 strcmp(attr
->values
[0].string
.text
, "utf-8"))
2075 send_ipp_status(con
, IPP_CHARSET
,
2076 _("Character set \"%s\" not supported."),
2077 attr
->values
[0].string
.text
);
2080 else if (!strcmp(attr
->name
, "notify-natural-language") &&
2081 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
2082 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
2084 send_ipp_status(con
, IPP_CHARSET
,
2085 _("Language \"%s\" not supported."),
2086 attr
->values
[0].string
.text
);
2089 else if (!strcmp(attr
->name
, "notify-user-data") &&
2090 attr
->value_tag
== IPP_TAG_STRING
)
2092 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
2094 send_ipp_status(con
, IPP_REQUEST_VALUE
,
2095 _("The notify-user-data value is too large "
2096 "(%d > 63 octets)."),
2097 attr
->values
[0].unknown
.length
);
2103 else if (!strcmp(attr
->name
, "notify-events") &&
2104 attr
->value_tag
== IPP_TAG_KEYWORD
)
2106 for (i
= 0; i
< attr
->num_values
; i
++)
2107 mask
|= cupsdEventValue(attr
->values
[i
].string
.text
);
2109 else if (!strcmp(attr
->name
, "notify-lease-duration"))
2111 send_ipp_status(con
, IPP_BAD_REQUEST
,
2112 _("The notify-lease-duration attribute cannot be "
2113 "used with job subscriptions."));
2116 else if (!strcmp(attr
->name
, "notify-time-interval") &&
2117 attr
->value_tag
== IPP_TAG_INTEGER
)
2118 interval
= attr
->values
[0].integer
;
2123 if (!recipient
&& !pullmethod
)
2126 if (mask
== CUPSD_EVENT_NONE
)
2127 mask
= CUPSD_EVENT_JOB_COMPLETED
;
2129 if ((sub
= cupsdAddSubscription(mask
, cupsdFindDest(job
->dest
), job
,
2130 recipient
, 0)) != NULL
)
2132 sub
->interval
= interval
;
2134 cupsdSetString(&sub
->owner
, job
->username
);
2138 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
2139 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
2140 (size_t)sub
->user_data_len
);
2143 ippAddSeparator(con
->response
);
2144 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
2145 "notify-subscription-id", sub
->id
);
2147 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
2155 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
2158 * Remove all of the subscription attributes from the job request...
2160 * TODO: Optimize this since subscription groups have to come at the
2161 * end of the request...
2164 for (attr
= job
->attrs
->attrs
, prev
= NULL
; attr
; attr
= next
)
2168 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
||
2169 attr
->group_tag
== IPP_TAG_ZERO
)
2172 * Free and remove this attribute...
2175 ippDeleteAttribute(NULL
, attr
);
2180 job
->attrs
->attrs
= next
;
2186 job
->attrs
->last
= prev
;
2187 job
->attrs
->current
= prev
;
2192 * 'add_job_uuid()' - Add job-uuid attribute to a job.
2194 * See RFC 4122 for the definition of UUIDs and the format.
2198 add_job_uuid(cupsd_job_t
*job
) /* I - Job */
2200 char uuid
[64]; /* job-uuid string */
2204 * Add a job-uuid attribute if none exists...
2207 if (!ippFindAttribute(job
->attrs
, "job-uuid", IPP_TAG_URI
))
2208 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uuid", NULL
,
2209 httpAssembleUUID(ServerName
, RemotePort
, job
->dest
, job
->id
,
2210 uuid
, sizeof(uuid
)));
2215 * 'add_printer()' - Add a printer to the system.
2219 add_printer(cupsd_client_t
*con
, /* I - Client connection */
2220 ipp_attribute_t
*uri
) /* I - URI of printer */
2222 http_status_t status
; /* Policy status */
2223 int i
; /* Looping var */
2224 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
2225 username
[HTTP_MAX_URI
], /* Username portion of URI */
2226 host
[HTTP_MAX_URI
], /* Host portion of URI */
2227 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2228 int port
; /* Port portion of URI */
2229 cupsd_printer_t
*printer
; /* Printer/class */
2230 ipp_attribute_t
*attr
; /* Printer attribute */
2231 cups_file_t
*fp
; /* Script/PPD file */
2232 char line
[1024]; /* Line from file... */
2233 char srcfile
[1024], /* Source Script/PPD file */
2234 dstfile
[1024]; /* Destination Script/PPD file */
2235 int modify
; /* Non-zero if we are modifying */
2236 int changed_driver
, /* Changed the PPD? */
2237 need_restart_job
, /* Need to restart job? */
2238 set_device_uri
, /* Did we set the device URI? */
2239 set_port_monitor
; /* Did we set the port monitor? */
2242 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer(%p[%d], %s)", con
,
2243 con
->number
, uri
->values
[0].string
.text
);
2246 * Do we have a valid URI?
2249 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
2250 sizeof(scheme
), username
, sizeof(username
), host
,
2251 sizeof(host
), &port
, resource
, sizeof(resource
));
2253 if (strncmp(resource
, "/printers/", 10) || strlen(resource
) == 10)
2256 * No, return an error...
2259 send_ipp_status(con
, IPP_BAD_REQUEST
,
2260 _("The printer-uri must be of the form "
2261 "\"ipp://HOSTNAME/printers/PRINTERNAME\"."));
2266 * Do we have a valid printer name?
2269 if (!validate_name(resource
+ 10))
2272 * No, return an error...
2275 send_ipp_status(con
, IPP_BAD_REQUEST
,
2276 _("The printer-uri \"%s\" contains invalid characters."),
2277 uri
->values
[0].string
.text
);
2282 * See if the printer already exists; if not, create a new printer...
2285 if ((printer
= cupsdFindPrinter(resource
+ 10)) == NULL
)
2288 * Printer doesn't exist; see if we have a class of the same name...
2291 if ((printer
= cupsdFindClass(resource
+ 10)) != NULL
)
2294 * Yes, return an error...
2297 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2298 _("A class named \"%s\" already exists."),
2304 * No, check the default policy then add the printer...
2307 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2309 send_http_error(con
, status
, NULL
);
2313 printer
= cupsdAddPrinter(resource
+ 10);
2316 else if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
2319 send_http_error(con
, status
, printer
);
2326 * Look for attributes and copy them over as needed...
2330 need_restart_job
= 0;
2332 if ((attr
= ippFindAttribute(con
->request
, "printer-is-temporary", IPP_TAG_BOOLEAN
)) != NULL
)
2333 printer
->temporary
= ippGetBoolean(attr
, 0);
2335 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
2336 IPP_TAG_TEXT
)) != NULL
)
2337 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
2339 if ((attr
= ippFindAttribute(con
->request
, "printer-geo-location", IPP_TAG_URI
)) != NULL
&& !strncmp(attr
->values
[0].string
.text
, "geo:", 4))
2340 cupsdSetString(&printer
->geo_location
, attr
->values
[0].string
.text
);
2342 if ((attr
= ippFindAttribute(con
->request
, "printer-organization", IPP_TAG_TEXT
)) != NULL
)
2343 cupsdSetString(&printer
->organization
, attr
->values
[0].string
.text
);
2345 if ((attr
= ippFindAttribute(con
->request
, "printer-organizational-unit", IPP_TAG_TEXT
)) != NULL
)
2346 cupsdSetString(&printer
->organizational_unit
, attr
->values
[0].string
.text
);
2348 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
2349 IPP_TAG_TEXT
)) != NULL
)
2350 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
2354 if ((attr
= ippFindAttribute(con
->request
, "device-uri",
2355 IPP_TAG_URI
)) != NULL
)
2358 * Do we have a valid device URI?
2361 http_uri_status_t uri_status
; /* URI separation status */
2362 char old_device_uri
[1024];
2363 /* Old device URI */
2365 need_restart_job
= 1;
2367 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
,
2368 attr
->values
[0].string
.text
,
2369 scheme
, sizeof(scheme
),
2370 username
, sizeof(username
),
2371 host
, sizeof(host
), &port
,
2372 resource
, sizeof(resource
));
2374 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s device-uri: %s", printer
->name
, httpURIStatusString(uri_status
));
2376 if (uri_status
< HTTP_URI_OK
)
2378 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri \"%s\"."),
2379 attr
->values
[0].string
.text
);
2381 cupsdDeletePrinter(printer
, 0);
2386 if (!strcmp(scheme
, "file"))
2389 * See if the administrator has enabled file devices...
2392 if (!FileDevice
&& strcmp(resource
, "/dev/null"))
2395 * File devices are disabled and the URL is not file:/dev/null...
2398 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2399 _("File device URIs have been disabled. "
2400 "To enable, see the FileDevice directive in "
2401 "\"%s/cups-files.conf\"."),
2404 cupsdDeletePrinter(printer
, 0);
2412 * See if the backend exists and is executable...
2415 snprintf(srcfile
, sizeof(srcfile
), "%s/backend/%s", ServerBin
, scheme
);
2416 if (access(srcfile
, X_OK
))
2419 * Could not find device in list!
2422 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2423 _("Bad device-uri scheme \"%s\"."), scheme
);
2425 cupsdDeletePrinter(printer
, 0);
2431 if (printer
->sanitized_device_uri
)
2432 strlcpy(old_device_uri
, printer
->sanitized_device_uri
,
2433 sizeof(old_device_uri
));
2435 old_device_uri
[0] = '\0';
2437 cupsdSetDeviceURI(printer
, attr
->values
[0].string
.text
);
2439 cupsdLogMessage(CUPSD_LOG_INFO
,
2440 "Setting %s device-uri to \"%s\" (was \"%s\".)",
2441 printer
->name
, printer
->sanitized_device_uri
,
2447 set_port_monitor
= 0;
2449 if ((attr
= ippFindAttribute(con
->request
, "port-monitor",
2450 IPP_TAG_NAME
)) != NULL
)
2452 ipp_attribute_t
*supported
; /* port-monitor-supported attribute */
2455 need_restart_job
= 1;
2457 supported
= ippFindAttribute(printer
->ppd_attrs
, "port-monitor-supported",
2461 for (i
= 0; i
< supported
->num_values
; i
++)
2462 if (!strcmp(supported
->values
[i
].string
.text
,
2463 attr
->values
[0].string
.text
))
2467 if (!supported
|| i
>= supported
->num_values
)
2469 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad port-monitor \"%s\"."),
2470 attr
->values
[0].string
.text
);
2472 cupsdDeletePrinter(printer
, 0);
2477 cupsdLogMessage(CUPSD_LOG_INFO
,
2478 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2479 printer
->name
, attr
->values
[0].string
.text
,
2480 printer
->port_monitor
? printer
->port_monitor
: "none");
2482 if (strcmp(attr
->values
[0].string
.text
, "none"))
2483 cupsdSetString(&printer
->port_monitor
, attr
->values
[0].string
.text
);
2485 cupsdClearString(&printer
->port_monitor
);
2487 set_port_monitor
= 1;
2490 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
2491 IPP_TAG_BOOLEAN
)) != NULL
&&
2492 attr
->values
[0].boolean
!= printer
->accepting
)
2494 cupsdLogMessage(CUPSD_LOG_INFO
,
2495 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
2496 printer
->name
, attr
->values
[0].boolean
, printer
->accepting
);
2498 printer
->accepting
= attr
->values
[0].boolean
;
2500 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2501 "%s accepting jobs.",
2502 printer
->accepting
? "Now" : "No longer");
2505 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared", IPP_TAG_BOOLEAN
)) != NULL
)
2507 if (ippGetBoolean(attr
, 0) &&
2508 printer
->num_auth_info_required
== 1 &&
2509 !strcmp(printer
->auth_info_required
[0], "negotiate"))
2511 send_ipp_status(con
, IPP_BAD_REQUEST
,
2512 _("Cannot share a remote Kerberized printer."));
2514 cupsdDeletePrinter(printer
, 0);
2519 if (printer
->type
& CUPS_PRINTER_REMOTE
)
2522 * Cannot re-share remote printers.
2525 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Cannot change printer-is-shared for remote queues."));
2527 cupsdDeletePrinter(printer
, 0);
2532 if (printer
->shared
&& !ippGetBoolean(attr
, 0))
2533 cupsdDeregisterPrinter(printer
, 1);
2535 cupsdLogMessage(CUPSD_LOG_INFO
,
2536 "Setting %s printer-is-shared to %d (was %d.)",
2537 printer
->name
, attr
->values
[0].boolean
, printer
->shared
);
2539 printer
->shared
= ippGetBoolean(attr
, 0);
2540 if (printer
->shared
&& printer
->temporary
)
2541 printer
->temporary
= 0;
2544 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
2545 IPP_TAG_ENUM
)) != NULL
)
2547 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
2548 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
2550 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad printer-state value %d."),
2551 attr
->values
[0].integer
);
2553 cupsdDeletePrinter(printer
, 0);
2558 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
2559 printer
->name
, attr
->values
[0].integer
, printer
->state
);
2561 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
2562 cupsdStopPrinter(printer
, 0);
2565 need_restart_job
= 1;
2566 cupsdSetPrinterState(printer
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
2570 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
2571 IPP_TAG_TEXT
)) != NULL
)
2573 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
2574 sizeof(printer
->state_message
));
2576 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
, "%s",
2577 printer
->state_message
);
2580 if ((attr
= ippFindAttribute(con
->request
, "printer-state-reasons",
2581 IPP_TAG_KEYWORD
)) != NULL
)
2583 if (attr
->num_values
>
2584 (int)(sizeof(printer
->reasons
) / sizeof(printer
->reasons
[0])))
2586 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2587 _("Too many printer-state-reasons values (%d > %d)."),
2589 (int)(sizeof(printer
->reasons
) /
2590 sizeof(printer
->reasons
[0])));
2592 cupsdDeletePrinter(printer
, 0);
2597 for (i
= 0; i
< printer
->num_reasons
; i
++)
2598 _cupsStrFree(printer
->reasons
[i
]);
2600 printer
->num_reasons
= 0;
2601 for (i
= 0; i
< attr
->num_values
; i
++)
2603 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
2606 printer
->reasons
[printer
->num_reasons
] =
2607 _cupsStrRetain(attr
->values
[i
].string
.text
);
2608 printer
->num_reasons
++;
2610 if (!strcmp(attr
->values
[i
].string
.text
, "paused") &&
2611 printer
->state
!= IPP_PRINTER_STOPPED
)
2613 cupsdLogMessage(CUPSD_LOG_INFO
,
2614 "Setting %s printer-state to %d (was %d.)",
2615 printer
->name
, IPP_PRINTER_STOPPED
, printer
->state
);
2616 cupsdStopPrinter(printer
, 0);
2620 if (PrintcapFormat
== PRINTCAP_PLIST
)
2621 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2623 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2624 "Printer \"%s\" state changed.", printer
->name
);
2627 if (!set_printer_defaults(con
, printer
))
2630 cupsdDeletePrinter(printer
, 0);
2635 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
2636 IPP_TAG_KEYWORD
)) != NULL
)
2637 cupsdSetAuthInfoRequired(printer
, NULL
, attr
);
2640 * See if we have all required attributes...
2643 if (!printer
->device_uri
)
2644 cupsdSetString(&printer
->device_uri
, "file:///dev/null");
2647 * See if we have a PPD file attached to the request...
2652 need_restart_job
= 1;
2655 strlcpy(srcfile
, con
->filename
, sizeof(srcfile
));
2657 if ((fp
= cupsFileOpen(srcfile
, "rb")))
2660 * Yes; get the first line from it...
2664 cupsFileGets(fp
, line
, sizeof(line
));
2668 * Then see what kind of file it is...
2671 if (strncmp(line
, "*PPD-Adobe", 10))
2673 send_ipp_status(con
, IPP_STATUS_ERROR_DOCUMENT_FORMAT_NOT_SUPPORTED
, _("Bad PPD file."));
2675 cupsdDeletePrinter(printer
, 0);
2680 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2684 * The new file is a PPD file, so move the file over to the ppd
2688 if (copy_file(srcfile
, dstfile
, ConfigFilePerm
))
2690 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file - %s"), strerror(errno
));
2692 cupsdDeletePrinter(printer
, 0);
2697 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Copied PPD file successfully");
2700 else if ((attr
= ippFindAttribute(con
->request
, "ppd-name", IPP_TAG_NAME
)) != NULL
)
2702 const char *ppd_name
= ippGetString(attr
, 0, NULL
);
2703 /* ppd-name value */
2705 need_restart_job
= 1;
2708 if (!strcmp(ppd_name
, "raw"))
2711 * Raw driver, remove any existing PPD file.
2714 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
, printer
->name
);
2717 else if (strstr(ppd_name
, "../"))
2719 send_ipp_status(con
, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES
, _("Invalid ppd-name value."));
2721 cupsdDeletePrinter(printer
, 0);
2731 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
, printer
->name
);
2733 if (copy_model(con
, ppd_name
, dstfile
))
2735 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file."));
2737 cupsdDeletePrinter(printer
, 0);
2742 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Copied PPD file successfully");
2749 * If we changed the PPD, then remove the printer's cache file and clear the
2750 * printer-state-reasons...
2753 char cache_name
[1024]; /* Cache filename for printer attrs */
2755 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.data", CacheDir
, printer
->name
);
2758 cupsdSetPrinterReasons(printer
, "none");
2761 * (Re)register color profiles...
2764 cupsdRegisterColor(printer
);
2768 * If we set the device URI but not the port monitor, check which port
2769 * monitor to use by default...
2772 if (set_device_uri
&& !set_port_monitor
)
2774 ppd_file_t
*ppd
; /* PPD file */
2775 ppd_attr_t
*ppdattr
; /* cupsPortMonitor attribute */
2778 httpSeparateURI(HTTP_URI_CODING_ALL
, printer
->device_uri
, scheme
,
2779 sizeof(scheme
), username
, sizeof(username
), host
,
2780 sizeof(host
), &port
, resource
, sizeof(resource
));
2782 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
,
2784 if ((ppd
= _ppdOpenFile(srcfile
, _PPD_LOCALIZATION_NONE
)) != NULL
)
2786 for (ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2788 ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
2789 if (!strcmp(scheme
, ppdattr
->spec
))
2791 cupsdLogMessage(CUPSD_LOG_INFO
,
2792 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2793 printer
->name
, ppdattr
->value
,
2794 printer
->port_monitor
? printer
->port_monitor
2797 if (strcmp(ppdattr
->value
, "none"))
2798 cupsdSetString(&printer
->port_monitor
, ppdattr
->value
);
2800 cupsdClearString(&printer
->port_monitor
);
2809 printer
->config_time
= time(NULL
);
2812 * Update the printer attributes and return...
2815 cupsdSetPrinterAttrs(printer
);
2816 if (!printer
->temporary
)
2817 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2819 if (need_restart_job
&& printer
->job
)
2822 * Restart the current job...
2825 cupsdSetJobState(printer
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
2826 "Job restarted because the printer was modified.");
2829 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2833 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
2834 printer
, NULL
, "Printer \"%s\" modified by \"%s\".",
2835 printer
->name
, get_username(con
));
2837 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" modified by \"%s\".",
2838 printer
->name
, get_username(con
));
2842 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
2843 printer
, NULL
, "New printer \"%s\" added by \"%s\".",
2844 printer
->name
, get_username(con
));
2846 cupsdLogMessage(CUPSD_LOG_INFO
, "New printer \"%s\" added by \"%s\".",
2847 printer
->name
, get_username(con
));
2850 con
->response
->request
.status
.status_code
= IPP_OK
;
2855 * 'add_printer_state_reasons()' - Add the "printer-state-reasons" attribute
2856 * based upon the printer state...
2860 add_printer_state_reasons(
2861 cupsd_client_t
*con
, /* I - Client connection */
2862 cupsd_printer_t
*p
) /* I - Printer info */
2864 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2865 "add_printer_state_reasons(%p[%d], %p[%s])",
2866 con
, con
->number
, p
, p
->name
);
2868 if (p
->num_reasons
== 0)
2869 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2870 "printer-state-reasons", NULL
, "none");
2872 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2873 "printer-state-reasons", p
->num_reasons
, NULL
,
2874 (const char * const *)p
->reasons
);
2879 * 'add_queued_job_count()' - Add the "queued-job-count" attribute for
2880 * the specified printer or class.
2884 add_queued_job_count(
2885 cupsd_client_t
*con
, /* I - Client connection */
2886 cupsd_printer_t
*p
) /* I - Printer or class */
2888 int count
; /* Number of jobs on destination */
2891 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_queued_job_count(%p[%d], %p[%s])",
2892 con
, con
->number
, p
, p
->name
);
2894 count
= cupsdGetPrinterJobCount(p
->name
);
2896 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2897 "queued-job-count", count
);
2902 * 'apply_printer_defaults()' - Apply printer default options to a job.
2906 apply_printer_defaults(
2907 cupsd_printer_t
*printer
, /* I - Printer */
2908 cupsd_job_t
*job
) /* I - Job */
2910 int i
, /* Looping var */
2911 num_options
; /* Number of default options */
2912 cups_option_t
*options
, /* Default options */
2913 *option
; /* Current option */
2917 * Collect all of the default options and add the missing ones to the
2921 for (i
= printer
->num_options
, num_options
= 0, options
= NULL
,
2922 option
= printer
->options
;
2925 if (!ippFindAttribute(job
->attrs
, option
->name
, IPP_TAG_ZERO
))
2927 num_options
= cupsAddOption(option
->name
, option
->value
, num_options
,
2932 * Encode these options as attributes in the job object...
2935 cupsEncodeOptions2(job
->attrs
, num_options
, options
, IPP_TAG_JOB
);
2936 cupsFreeOptions(num_options
, options
);
2941 * 'authenticate_job()' - Set job authentication info.
2945 authenticate_job(cupsd_client_t
*con
, /* I - Client connection */
2946 ipp_attribute_t
*uri
) /* I - Job URI */
2948 ipp_attribute_t
*attr
, /* job-id attribute */
2949 *auth_info
; /* auth-info attribute */
2950 int jobid
; /* Job ID */
2951 cupsd_job_t
*job
; /* Current job */
2952 char scheme
[HTTP_MAX_URI
],
2953 /* Method portion of URI */
2954 username
[HTTP_MAX_URI
],
2955 /* Username portion of URI */
2957 /* Host portion of URI */
2958 resource
[HTTP_MAX_URI
];
2959 /* Resource portion of URI */
2960 int port
; /* Port portion of URI */
2963 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "authenticate_job(%p[%d], %s)",
2964 con
, con
->number
, uri
->values
[0].string
.text
);
2967 * Start with "everything is OK" status...
2970 con
->response
->request
.status
.status_code
= IPP_OK
;
2973 * See if we have a job URI or a printer URI...
2976 if (!strcmp(uri
->name
, "printer-uri"))
2979 * Got a printer URI; see if we also have a job-id attribute...
2982 if ((attr
= ippFindAttribute(con
->request
, "job-id",
2983 IPP_TAG_INTEGER
)) == NULL
)
2985 send_ipp_status(con
, IPP_BAD_REQUEST
,
2986 _("Got a printer-uri attribute but no job-id."));
2990 jobid
= attr
->values
[0].integer
;
2995 * Got a job URI; parse it to get the job ID...
2998 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
2999 sizeof(scheme
), username
, sizeof(username
), host
,
3000 sizeof(host
), &port
, resource
, sizeof(resource
));
3002 if (strncmp(resource
, "/jobs/", 6))
3008 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
3009 uri
->values
[0].string
.text
);
3013 jobid
= atoi(resource
+ 6);
3017 * See if the job exists...
3020 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3023 * Nope - return a "not found" error...
3026 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
3031 * See if the job has been completed...
3034 if (job
->state_value
!= IPP_JOB_HELD
)
3037 * Return a "not-possible" error...
3040 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3041 _("Job #%d is not held for authentication."),
3047 * See if we have already authenticated...
3050 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
3052 if (!con
->username
[0] && !auth_info
)
3054 cupsd_printer_t
*printer
; /* Job destination */
3057 * No auth data. If we need to authenticate via Kerberos, send a
3058 * HTTP auth challenge, otherwise just return an IPP error...
3061 printer
= cupsdFindDest(job
->dest
);
3063 if (printer
&& printer
->num_auth_info_required
> 0 &&
3064 !strcmp(printer
->auth_info_required
[0], "negotiate"))
3065 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
3067 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
3068 _("No authentication information provided."));
3073 * See if the job is owned by the requesting user...
3076 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3078 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3079 cupsdFindDest(job
->dest
));
3084 * Save the authentication information for this job...
3087 save_auth_info(con
, job
, auth_info
);
3090 * Reset the job-hold-until value to "no-hold"...
3093 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
3094 IPP_TAG_KEYWORD
)) == NULL
)
3095 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
3099 ippSetValueTag(job
->attrs
, &attr
, IPP_TAG_KEYWORD
);
3100 ippSetString(job
->attrs
, &attr
, 0, "no-hold");
3104 * Release the job and return...
3107 cupsdReleaseJob(job
);
3109 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, NULL
, job
, "Job authenticated by user");
3111 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Authenticated by \"%s\".", con
->username
);
3118 * 'cancel_all_jobs()' - Cancel all or selected print jobs.
3122 cancel_all_jobs(cupsd_client_t
*con
, /* I - Client connection */
3123 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3125 int i
; /* Looping var */
3126 http_status_t status
; /* Policy status */
3127 cups_ptype_t dtype
; /* Destination type */
3128 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3129 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
3130 hostname
[HTTP_MAX_URI
], /* Host portion of URI */
3131 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3132 int port
; /* Port portion of URI */
3133 ipp_attribute_t
*attr
; /* Attribute in request */
3134 const char *username
= NULL
; /* Username */
3135 cupsd_jobaction_t purge
= CUPSD_JOB_DEFAULT
;
3137 cupsd_printer_t
*printer
; /* Printer */
3138 ipp_attribute_t
*job_ids
; /* job-ids attribute */
3139 cupsd_job_t
*job
; /* Job */
3142 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_all_jobs(%p[%d], %s)", con
,
3143 con
->number
, uri
->values
[0].string
.text
);
3146 * Get the jobs to cancel/purge...
3149 switch (con
->request
->request
.op
.operation_id
)
3151 case IPP_PURGE_JOBS
:
3153 * Get the username (if any) for the jobs we want to cancel (only if
3154 * "my-jobs" is specified...
3157 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
3158 IPP_TAG_BOOLEAN
)) != NULL
&&
3159 attr
->values
[0].boolean
)
3161 if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3162 IPP_TAG_NAME
)) != NULL
)
3163 username
= attr
->values
[0].string
.text
;
3166 send_ipp_status(con
, IPP_BAD_REQUEST
,
3167 _("Missing requesting-user-name attribute."));
3173 * Look for the "purge-jobs" attribute...
3176 if ((attr
= ippFindAttribute(con
->request
, "purge-jobs",
3177 IPP_TAG_BOOLEAN
)) != NULL
)
3178 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
3180 purge
= CUPSD_JOB_PURGE
;
3183 case IPP_CANCEL_MY_JOBS
:
3184 if (con
->username
[0])
3185 username
= con
->username
;
3186 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3187 IPP_TAG_NAME
)) != NULL
)
3188 username
= attr
->values
[0].string
.text
;
3191 send_ipp_status(con
, IPP_BAD_REQUEST
,
3192 _("Missing requesting-user-name attribute."));
3200 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
3203 * See if we have a printer URI...
3206 if (strcmp(uri
->name
, "printer-uri"))
3208 send_ipp_status(con
, IPP_BAD_REQUEST
,
3209 _("The printer-uri attribute is required."));
3214 * And if the destination is valid...
3217 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3223 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
,
3224 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
3225 hostname
, sizeof(hostname
), &port
,
3226 resource
, sizeof(resource
));
3228 if ((!strncmp(resource
, "/printers/", 10) && resource
[10]) ||
3229 (!strncmp(resource
, "/classes/", 9) && resource
[9]))
3231 send_ipp_status(con
, IPP_NOT_FOUND
,
3232 _("The printer or class does not exist."));
3240 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
3242 send_http_error(con
, status
, NULL
);
3248 for (i
= 0; i
< job_ids
->num_values
; i
++)
3250 if ((job
= cupsdFindJob(job_ids
->values
[i
].integer
)) == NULL
)
3253 if (con
->request
->request
.op
.operation_id
== IPP_CANCEL_MY_JOBS
&&
3254 _cups_strcasecmp(job
->username
, username
))
3258 if (i
< job_ids
->num_values
)
3260 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3261 job_ids
->values
[i
].integer
);
3265 for (i
= 0; i
< job_ids
->num_values
; i
++)
3267 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
3269 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3270 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
3271 "Job canceled by user.");
3274 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
3275 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3281 * Cancel all jobs on all printers...
3284 cupsdCancelJobs(NULL
, username
, purge
);
3286 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs were %s by \"%s\".",
3287 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3297 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
3300 send_http_error(con
, status
, printer
);
3306 for (i
= 0; i
< job_ids
->num_values
; i
++)
3308 if ((job
= cupsdFindJob(job_ids
->values
[i
].integer
)) == NULL
||
3309 _cups_strcasecmp(job
->dest
, printer
->name
))
3312 if (con
->request
->request
.op
.operation_id
== IPP_CANCEL_MY_JOBS
&&
3313 _cups_strcasecmp(job
->username
, username
))
3317 if (i
< job_ids
->num_values
)
3319 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3320 job_ids
->values
[i
].integer
);
3324 for (i
= 0; i
< job_ids
->num_values
; i
++)
3326 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
3328 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3329 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
3330 "Job canceled by user.");
3333 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
3334 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3340 * Cancel all of the jobs on the named printer...
3343 cupsdCancelJobs(printer
->name
, username
, purge
);
3345 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs on \"%s\" were %s by \"%s\".",
3347 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3352 con
->response
->request
.status
.status_code
= IPP_OK
;
3359 * 'cancel_job()' - Cancel a print job.
3363 cancel_job(cupsd_client_t
*con
, /* I - Client connection */
3364 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3366 ipp_attribute_t
*attr
; /* Current attribute */
3367 int jobid
; /* Job ID */
3368 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3369 username
[HTTP_MAX_URI
], /* Username portion of URI */
3370 host
[HTTP_MAX_URI
], /* Host portion of URI */
3371 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3372 int port
; /* Port portion of URI */
3373 cupsd_job_t
*job
; /* Job information */
3374 cups_ptype_t dtype
; /* Destination type (printer/class) */
3375 cupsd_printer_t
*printer
; /* Printer data */
3376 cupsd_jobaction_t purge
; /* Purge the job? */
3379 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_job(%p[%d], %s)", con
,
3380 con
->number
, uri
->values
[0].string
.text
);
3383 * See if we have a job URI or a printer URI...
3386 if (!strcmp(uri
->name
, "printer-uri"))
3389 * Got a printer URI; see if we also have a job-id attribute...
3392 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3393 IPP_TAG_INTEGER
)) == NULL
)
3395 send_ipp_status(con
, IPP_BAD_REQUEST
,
3396 _("Got a printer-uri attribute but no job-id."));
3400 if ((jobid
= attr
->values
[0].integer
) == 0)
3403 * Find the current job on the specified printer...
3406 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3412 send_ipp_status(con
, IPP_NOT_FOUND
,
3413 _("The printer or class does not exist."));
3418 * See if there are any pending jobs...
3421 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3423 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3424 if (job
->state_value
<= IPP_JOB_PROCESSING
&&
3425 !_cups_strcasecmp(job
->dest
, printer
->name
))
3433 * No, try stopped jobs...
3436 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3438 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3439 if (job
->state_value
== IPP_JOB_STOPPED
&&
3440 !_cups_strcasecmp(job
->dest
, printer
->name
))
3447 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("No active jobs on %s."),
3457 * Got a job URI; parse it to get the job ID...
3460 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
3461 sizeof(scheme
), username
, sizeof(username
), host
,
3462 sizeof(host
), &port
, resource
, sizeof(resource
));
3464 if (strncmp(resource
, "/jobs/", 6))
3470 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
3471 uri
->values
[0].string
.text
);
3475 jobid
= atoi(resource
+ 6);
3479 * Look for the "purge-job" attribute...
3482 if ((attr
= ippFindAttribute(con
->request
, "purge-job",
3483 IPP_TAG_BOOLEAN
)) != NULL
)
3484 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
3486 purge
= CUPSD_JOB_DEFAULT
;
3489 * See if the job exists...
3492 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3495 * Nope - return a "not found" error...
3498 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
3503 * See if the job is owned by the requesting user...
3506 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3508 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3509 cupsdFindDest(job
->dest
));
3514 * See if the job is already completed, canceled, or aborted; if so,
3515 * we can't cancel...
3518 if (job
->state_value
>= IPP_JOB_CANCELED
&& purge
!= CUPSD_JOB_PURGE
)
3520 switch (job
->state_value
)
3522 case IPP_JOB_CANCELED
:
3523 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3524 _("Job #%d is already canceled - can\'t cancel."),
3528 case IPP_JOB_ABORTED
:
3529 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3530 _("Job #%d is already aborted - can\'t cancel."),
3535 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3536 _("Job #%d is already completed - can\'t cancel."),
3545 * Cancel the job and return...
3548 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3549 purge
== CUPSD_JOB_PURGE
? "Job purged by \"%s\"" :
3550 "Job canceled by \"%s\"",
3554 if (purge
== CUPSD_JOB_PURGE
)
3555 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Purged by \"%s\".", jobid
,
3558 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Canceled by \"%s\".", jobid
,
3561 con
->response
->request
.status
.status_code
= IPP_OK
;
3566 * 'cancel_subscription()' - Cancel a subscription.
3570 cancel_subscription(
3571 cupsd_client_t
*con
, /* I - Client connection */
3572 int sub_id
) /* I - Subscription ID */
3574 http_status_t status
; /* Policy status */
3575 cupsd_subscription_t
*sub
; /* Subscription */
3578 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3579 "cancel_subscription(con=%p[%d], sub_id=%d)",
3580 con
, con
->number
, sub_id
);
3583 * Is the subscription ID valid?
3586 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
3589 * Bad subscription ID...
3592 send_ipp_status(con
, IPP_NOT_FOUND
,
3593 _("Subscription #%d does not exist."), sub_id
);
3601 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
3603 con
, sub
->owner
)) != HTTP_OK
)
3605 send_http_error(con
, status
, sub
->dest
);
3610 * Cancel the subscription...
3613 cupsdDeleteSubscription(sub
, 1);
3615 con
->response
->request
.status
.status_code
= IPP_OK
;
3620 * 'check_rss_recipient()' - Check that we do not have a duplicate RSS feed URI.
3623 static int /* O - 1 if OK, 0 if not */
3624 check_rss_recipient(
3625 const char *recipient
) /* I - Recipient URI */
3627 cupsd_subscription_t
*sub
; /* Current subscription */
3630 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
);
3632 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
3636 * Compare the URIs up to the first ?...
3639 const char *r1
, *r2
;
3641 for (r1
= recipient
, r2
= sub
->recipient
;
3642 *r1
== *r2
&& *r1
&& *r1
!= '?' && *r2
&& *r2
!= '?';
3654 * 'check_quotas()' - Check quotas for a printer and user.
3657 static int /* O - 1 if OK, 0 if forbidden,
3658 -1 if limit reached */
3659 check_quotas(cupsd_client_t
*con
, /* I - Client connection */
3660 cupsd_printer_t
*p
) /* I - Printer or class */
3662 char username
[33], /* Username */
3663 *name
; /* Current user name */
3664 cupsd_quota_t
*q
; /* Quota data */
3665 #ifdef HAVE_MBR_UID_TO_UUID
3667 * Use Apple membership APIs which require that all names represent
3668 * valid user account or group records accessible by the server.
3671 uuid_t usr_uuid
; /* UUID for job requesting user */
3672 uuid_t usr2_uuid
; /* UUID for ACL user name entry */
3673 uuid_t grp_uuid
; /* UUID for ACL group name entry */
3674 int mbr_err
; /* Error from membership function */
3675 int is_member
; /* Is this user a member? */
3678 * Use standard POSIX APIs for checking users and groups...
3681 struct passwd
*pw
; /* User password data */
3682 #endif /* HAVE_MBR_UID_TO_UUID */
3685 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "check_quotas(%p[%d], %p[%s])",
3686 con
, con
->number
, p
, p
->name
);
3689 * Figure out who is printing...
3692 strlcpy(username
, get_username(con
), sizeof(username
));
3694 if ((name
= strchr(username
, '@')) != NULL
)
3695 *name
= '\0'; /* Strip @REALM */
3698 * Check global active job limits for printers and users...
3701 if (MaxJobsPerPrinter
)
3704 * Check if there are too many pending jobs on this printer...
3707 if (cupsdGetPrinterJobCount(p
->name
) >= MaxJobsPerPrinter
)
3709 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for printer \"%s\"...",
3718 * Check if there are too many pending jobs for this user...
3721 if (cupsdGetUserJobCount(username
) >= MaxJobsPerUser
)
3723 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for user \"%s\"...",
3730 * Check against users...
3733 if (cupsArrayCount(p
->users
) == 0 && p
->k_limit
== 0 && p
->page_limit
== 0)
3736 if (cupsArrayCount(p
->users
))
3738 #ifdef HAVE_MBR_UID_TO_UUID
3740 * Get UUID for job requesting user...
3743 if (mbr_user_name_to_uuid((char *)username
, usr_uuid
))
3749 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3750 "check_quotas: UUID lookup failed for user \"%s\"",
3752 cupsdLogMessage(CUPSD_LOG_INFO
,
3753 "Denying user \"%s\" access to printer \"%s\" "
3754 "(unknown user)...",
3760 * Get UID and GID of requesting user...
3763 pw
= getpwnam(username
);
3765 #endif /* HAVE_MBR_UID_TO_UUID */
3767 for (name
= (char *)cupsArrayFirst(p
->users
);
3769 name
= (char *)cupsArrayNext(p
->users
))
3773 * Check group membership...
3776 #ifdef HAVE_MBR_UID_TO_UUID
3779 if (uuid_parse(name
+ 2, grp_uuid
))
3780 uuid_clear(grp_uuid
);
3782 else if ((mbr_err
= mbr_group_name_to_uuid(name
+ 1, grp_uuid
)) != 0)
3785 * Invalid ACL entries are ignored for matching; just record a
3786 * warning in the log...
3789 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3790 "check_quotas: UUID lookup failed for ACL entry "
3791 "\"%s\" (err=%d)", name
, mbr_err
);
3792 cupsdLogMessage(CUPSD_LOG_WARN
,
3793 "Access control entry \"%s\" not a valid group name; "
3794 "entry ignored", name
);
3797 if ((mbr_err
= mbr_check_membership(usr_uuid
, grp_uuid
,
3801 * At this point, there should be no errors, but check anyways...
3804 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3805 "check_quotas: group \"%s\" membership check "
3806 "failed (err=%d)", name
+ 1, mbr_err
);
3811 * Stop if we found a match...
3818 if (cupsdCheckGroup(username
, pw
, name
+ 1))
3820 #endif /* HAVE_MBR_UID_TO_UUID */
3822 #ifdef HAVE_MBR_UID_TO_UUID
3827 if (uuid_parse(name
+ 1, usr2_uuid
))
3828 uuid_clear(usr2_uuid
);
3830 else if ((mbr_err
= mbr_user_name_to_uuid(name
, usr2_uuid
)) != 0)
3833 * Invalid ACL entries are ignored for matching; just record a
3834 * warning in the log...
3837 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3838 "check_quotas: UUID lookup failed for ACL entry "
3839 "\"%s\" (err=%d)", name
, mbr_err
);
3840 cupsdLogMessage(CUPSD_LOG_WARN
,
3841 "Access control entry \"%s\" not a valid user name; "
3842 "entry ignored", name
);
3845 if (!uuid_compare(usr_uuid
, usr2_uuid
))
3849 else if (!_cups_strcasecmp(username
, name
))
3851 #endif /* HAVE_MBR_UID_TO_UUID */
3853 if ((name
!= NULL
) == p
->deny_users
)
3855 cupsdLogMessage(CUPSD_LOG_INFO
,
3856 "Denying user \"%s\" access to printer \"%s\"...",
3866 if (p
->k_limit
|| p
->page_limit
)
3868 if ((q
= cupsdUpdateQuota(p
, username
, 0, 0)) == NULL
)
3870 cupsdLogMessage(CUPSD_LOG_ERROR
,
3871 "Unable to allocate quota data for user \"%s\"",
3876 if ((q
->k_count
>= p
->k_limit
&& p
->k_limit
) ||
3877 (q
->page_count
>= p
->page_limit
&& p
->page_limit
))
3879 cupsdLogMessage(CUPSD_LOG_INFO
, "User \"%s\" is over the quota limit...",
3886 * If we have gotten this far, we're done!
3894 * 'close_job()' - Close a multi-file job.
3898 close_job(cupsd_client_t
*con
, /* I - Client connection */
3899 ipp_attribute_t
*uri
) /* I - Printer URI */
3901 cupsd_job_t
*job
; /* Job */
3902 ipp_attribute_t
*attr
; /* Attribute */
3903 char job_uri
[HTTP_MAX_URI
],
3905 username
[256]; /* User name */
3908 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "close_job(%p[%d], %s)", con
,
3909 con
->number
, uri
->values
[0].string
.text
);
3912 * See if we have a job URI or a printer URI...
3915 if (strcmp(uri
->name
, "printer-uri"))
3918 * job-uri is not supported by Close-Job!
3921 send_ipp_status(con
, IPP_BAD_REQUEST
,
3922 _("Close-Job doesn't support the job-uri attribute."));
3927 * Got a printer URI; see if we also have a job-id attribute...
3930 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3931 IPP_TAG_INTEGER
)) == NULL
)
3933 send_ipp_status(con
, IPP_BAD_REQUEST
,
3934 _("Got a printer-uri attribute but no job-id."));
3938 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
3941 * Nope - return a "not found" error...
3944 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3945 attr
->values
[0].integer
);
3950 * See if the job is owned by the requesting user...
3953 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3955 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3956 cupsdFindDest(job
->dest
));
3961 * Add any ending sheet...
3964 if (cupsdTimeoutJob(job
))
3967 if (job
->state_value
== IPP_JOB_STOPPED
)
3969 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
3970 job
->state_value
= IPP_JOB_PENDING
;
3972 else if (job
->state_value
== IPP_JOB_HELD
)
3974 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
3975 IPP_TAG_KEYWORD
)) == NULL
)
3976 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
3978 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
3980 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
3981 job
->state_value
= IPP_JOB_PENDING
;
3986 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
3989 * Fill in the response info...
3992 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
3993 con
->clientname
, con
->clientport
, "/jobs/%d", job
->id
);
3994 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
3997 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
3999 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
4002 con
->response
->request
.status
.status_code
= IPP_OK
;
4005 * Start the job if necessary...
4013 * 'copy_attrs()' - Copy attributes from one request to another.
4017 copy_attrs(ipp_t
*to
, /* I - Destination request */
4018 ipp_t
*from
, /* I - Source request */
4019 cups_array_t
*ra
, /* I - Requested attributes */
4020 ipp_tag_t group
, /* I - Group to copy */
4021 int quickcopy
, /* I - Do a quick copy? */
4022 cups_array_t
*exclude
) /* I - Attributes to exclude? */
4024 ipp_attribute_t
*fromattr
; /* Source attribute */
4027 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4028 "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)",
4029 to
, from
, ra
, group
, quickcopy
);
4034 for (fromattr
= from
->attrs
; fromattr
; fromattr
= fromattr
->next
)
4037 * Filter attributes as needed...
4040 if ((group
!= IPP_TAG_ZERO
&& fromattr
->group_tag
!= group
&&
4041 fromattr
->group_tag
!= IPP_TAG_ZERO
) || !fromattr
->name
)
4044 if (!strcmp(fromattr
->name
, "document-password") ||
4045 !strcmp(fromattr
->name
, "job-authorization-uri") ||
4046 !strcmp(fromattr
->name
, "job-password") ||
4047 !strcmp(fromattr
->name
, "job-password-encryption") ||
4048 !strcmp(fromattr
->name
, "job-printer-uri"))
4052 (cupsArrayFind(exclude
, fromattr
->name
) ||
4053 cupsArrayFind(exclude
, "all")))
4056 * We need to exclude this attribute for security reasons; we require the
4057 * job-id attribute regardless of the security settings for IPP
4060 * The job-printer-uri attribute is handled by copy_job_attrs().
4062 * Subscription attribute security is handled by copy_subscription_attrs().
4065 if (strcmp(fromattr
->name
, "job-id"))
4069 if (!ra
|| cupsArrayFind(ra
, fromattr
->name
))
4072 * Don't send collection attributes by default to IPP/1.x clients
4073 * since many do not support collections. Also don't send
4074 * media-col-database unless specifically requested by the client.
4077 if (fromattr
->value_tag
== IPP_TAG_BEGIN_COLLECTION
&&
4079 (to
->request
.status
.version
[0] == 1 ||
4080 !strcmp(fromattr
->name
, "media-col-database")))
4083 ippCopyAttribute(to
, fromattr
, quickcopy
);
4090 * 'copy_banner()' - Copy a banner file to the requests directory for the
4094 static int /* O - Size of banner file in kbytes */
4095 copy_banner(cupsd_client_t
*con
, /* I - Client connection */
4096 cupsd_job_t
*job
, /* I - Job information */
4097 const char *name
) /* I - Name of banner */
4099 int i
; /* Looping var */
4100 int kbytes
; /* Size of banner file in kbytes */
4101 char filename
[1024]; /* Job filename */
4102 cupsd_banner_t
*banner
; /* Pointer to banner */
4103 cups_file_t
*in
; /* Input file */
4104 cups_file_t
*out
; /* Output file */
4105 int ch
; /* Character from file */
4106 char attrname
[255], /* Name of attribute */
4107 *s
; /* Pointer into name */
4108 ipp_attribute_t
*attr
; /* Attribute */
4111 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4112 "copy_banner(con=%p[%d], job=%p[%d], name=\"%s\")",
4113 con
, con
? con
->number
: -1, job
, job
->id
,
4114 name
? name
: "(null)");
4117 * Find the banner; return if not found or "none"...
4120 if (!name
|| !strcmp(name
, "none") ||
4121 (banner
= cupsdFindBanner(name
)) == NULL
)
4125 * Open the banner and job files...
4128 if (add_file(con
, job
, banner
->filetype
, 0))
4131 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
4133 if ((out
= cupsFileOpen(filename
, "w")) == NULL
)
4135 cupsdLogMessage(CUPSD_LOG_ERROR
,
4136 "Unable to create banner job file %s - %s",
4137 filename
, strerror(errno
));
4142 fchmod(cupsFileNumber(out
), 0640);
4143 fchown(cupsFileNumber(out
), RunUser
, Group
);
4146 * Try the localized banner file under the subdirectory...
4149 strlcpy(attrname
, job
->attrs
->attrs
->next
->values
[0].string
.text
,
4151 if (strlen(attrname
) > 2 && attrname
[2] == '-')
4154 * Convert ll-cc to ll_CC...
4158 attrname
[3] = (char)toupper(attrname
[3] & 255);
4159 attrname
[4] = (char)toupper(attrname
[4] & 255);
4162 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4165 if (access(filename
, 0) && strlen(attrname
) > 2)
4168 * Wasn't able to find "ll_CC" locale file; try the non-national
4169 * localization banner directory.
4174 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4178 if (access(filename
, 0))
4181 * Use the non-localized banner file.
4184 snprintf(filename
, sizeof(filename
), "%s/banners/%s", DataDir
, name
);
4187 if ((in
= cupsFileOpen(filename
, "r")) == NULL
)
4191 cupsdLogMessage(CUPSD_LOG_ERROR
,
4192 "Unable to open banner template file %s - %s",
4193 filename
, strerror(errno
));
4199 * Parse the file to the end...
4202 while ((ch
= cupsFileGetChar(in
)) != EOF
)
4206 * Get an attribute name...
4209 for (s
= attrname
; (ch
= cupsFileGetChar(in
)) != EOF
;)
4210 if (!isalpha(ch
& 255) && ch
!= '-' && ch
!= '?')
4212 else if (s
< (attrname
+ sizeof(attrname
) - 1))
4222 * Ignore { followed by stuff that is not an attribute name...
4225 cupsFilePrintf(out
, "{%s%c", attrname
, ch
);
4230 * See if it is defined...
4233 if (attrname
[0] == '?')
4238 if (!strcmp(s
, "printer-name"))
4240 cupsFilePuts(out
, job
->dest
);
4243 else if ((attr
= ippFindAttribute(job
->attrs
, s
, IPP_TAG_ZERO
)) == NULL
)
4246 * See if we have a leading question mark...
4249 if (attrname
[0] != '?')
4252 * Nope, write to file as-is; probably a PostScript procedure...
4255 cupsFilePrintf(out
, "{%s}", attrname
);
4262 * Output value(s)...
4265 for (i
= 0; i
< attr
->num_values
; i
++)
4268 cupsFilePutChar(out
, ',');
4270 switch (attr
->value_tag
)
4272 case IPP_TAG_INTEGER
:
4274 if (!strncmp(s
, "time-at-", 8))
4276 struct timeval tv
; /* Time value */
4278 tv
.tv_sec
= attr
->values
[i
].integer
;
4281 cupsFilePuts(out
, cupsdGetDateTime(&tv
, CUPSD_TIME_STANDARD
));
4284 cupsFilePrintf(out
, "%d", attr
->values
[i
].integer
);
4287 case IPP_TAG_BOOLEAN
:
4288 cupsFilePrintf(out
, "%d", attr
->values
[i
].boolean
);
4291 case IPP_TAG_NOVALUE
:
4292 cupsFilePuts(out
, "novalue");
4295 case IPP_TAG_RANGE
:
4296 cupsFilePrintf(out
, "%d-%d", attr
->values
[i
].range
.lower
,
4297 attr
->values
[i
].range
.upper
);
4300 case IPP_TAG_RESOLUTION
:
4301 cupsFilePrintf(out
, "%dx%d%s", attr
->values
[i
].resolution
.xres
,
4302 attr
->values
[i
].resolution
.yres
,
4303 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
4308 case IPP_TAG_STRING
:
4311 case IPP_TAG_KEYWORD
:
4312 case IPP_TAG_CHARSET
:
4313 case IPP_TAG_LANGUAGE
:
4314 if (!_cups_strcasecmp(banner
->filetype
->type
, "postscript"))
4317 * Need to quote strings for PS banners...
4322 for (p
= attr
->values
[i
].string
.text
; *p
; p
++)
4324 if (*p
== '(' || *p
== ')' || *p
== '\\')
4326 cupsFilePutChar(out
, '\\');
4327 cupsFilePutChar(out
, *p
);
4329 else if (*p
< 32 || *p
> 126)
4330 cupsFilePrintf(out
, "\\%03o", *p
& 255);
4332 cupsFilePutChar(out
, *p
);
4336 cupsFilePuts(out
, attr
->values
[i
].string
.text
);
4340 break; /* anti-compiler-warning-code */
4344 else if (ch
== '\\') /* Quoted char */
4346 ch
= cupsFileGetChar(in
);
4348 if (ch
!= '{') /* Only do special handling for \{ */
4349 cupsFilePutChar(out
, '\\');
4351 cupsFilePutChar(out
, ch
);
4354 cupsFilePutChar(out
, ch
);
4358 kbytes
= (cupsFileTell(out
) + 1023) / 1024;
4360 job
->koctets
+= kbytes
;
4362 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets", IPP_TAG_INTEGER
)) != NULL
)
4363 attr
->values
[0].integer
+= kbytes
;
4372 * 'copy_file()' - Copy a PPD file...
4375 static int /* O - 0 = success, -1 = error */
4376 copy_file(const char *from
, /* I - Source file */
4377 const char *to
, /* I - Destination file */
4378 mode_t mode
) /* I - Permissions */
4380 cups_file_t
*src
, /* Source file */
4381 *dst
; /* Destination file */
4382 int bytes
; /* Bytes to read/write */
4383 char buffer
[2048]; /* Copy buffer */
4386 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_file(\"%s\", \"%s\")", from
, to
);
4389 * Open the source and destination file for a copy...
4392 if ((src
= cupsFileOpen(from
, "rb")) == NULL
)
4395 if ((dst
= cupsdCreateConfFile(to
, mode
)) == NULL
)
4402 * Copy the source file to the destination...
4405 while ((bytes
= cupsFileRead(src
, buffer
, sizeof(buffer
))) > 0)
4406 if (cupsFileWrite(dst
, buffer
, (size_t)bytes
) < bytes
)
4414 * Close both files and return...
4419 return (cupsdCloseCreatedConfFile(dst
, to
));
4424 * 'copy_model()' - Copy a PPD model file, substituting default values
4428 static int /* O - 0 = success, -1 = error */
4429 copy_model(cupsd_client_t
*con
, /* I - Client connection */
4430 const char *from
, /* I - Source file */
4431 const char *to
) /* I - Destination file */
4433 fd_set input
; /* select() input set */
4434 struct timeval timeout
; /* select() timeout */
4435 int maxfd
; /* Max file descriptor for select() */
4436 char tempfile
[1024]; /* Temporary PPD file */
4437 int tempfd
; /* Temporary PPD file descriptor */
4438 int temppid
; /* Process ID of cups-driverd */
4439 int temppipe
[2]; /* Temporary pipes */
4440 char *argv
[4], /* Command-line arguments */
4441 *envp
[MAX_ENV
]; /* Environment */
4442 cups_file_t
*src
, /* Source file */
4443 *dst
; /* Destination file */
4444 ppd_file_t
*ppd
; /* PPD file */
4445 int bytes
, /* Bytes from pipe */
4446 total
; /* Total bytes from pipe */
4447 char buffer
[2048]; /* Copy buffer */
4448 int i
; /* Looping var */
4449 char option
[PPD_MAX_NAME
], /* Option name */
4450 choice
[PPD_MAX_NAME
]; /* Choice name */
4451 ppd_size_t
*size
; /* Default size */
4452 int num_defaults
; /* Number of default options */
4453 cups_option_t
*defaults
; /* Default options */
4454 char cups_protocol
[PPD_MAX_LINE
];
4455 /* cupsProtocol attribute */
4458 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_model(con=%p, from=\"%s\", to=\"%s\")", con
, from
, to
);
4461 * Run cups-driverd to get the PPD file...
4464 argv
[0] = "cups-driverd";
4466 argv
[2] = (char *)from
;
4469 cupsdLoadEnv(envp
, (int)(sizeof(envp
) / sizeof(envp
[0])));
4471 snprintf(buffer
, sizeof(buffer
), "%s/daemon/cups-driverd", ServerBin
);
4472 snprintf(tempfile
, sizeof(tempfile
), "%s/%d.ppd", TempDir
, con
->number
);
4473 tempfd
= open(tempfile
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
4474 if (tempfd
< 0 || cupsdOpenPipe(temppipe
))
4477 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4478 "copy_model: Running \"cups-driverd cat %s\"...", from
);
4480 if (!cupsdStartProcess(buffer
, argv
, envp
, -1, temppipe
[1], CGIPipes
[1],
4481 -1, -1, 0, DefaultProfile
, NULL
, &temppid
))
4492 * Wait up to 30 seconds for the PPD file to be copied...
4497 if (temppipe
[0] > CGIPipes
[0])
4498 maxfd
= temppipe
[0] + 1;
4500 maxfd
= CGIPipes
[0] + 1;
4505 * See if we have data ready...
4509 FD_SET(temppipe
[0], &input
);
4510 FD_SET(CGIPipes
[0], &input
);
4512 timeout
.tv_sec
= 30;
4513 timeout
.tv_usec
= 0;
4515 if ((i
= select(maxfd
, &input
, NULL
, NULL
, &timeout
)) < 0)
4525 * We have timed out...
4531 if (FD_ISSET(temppipe
[0], &input
))
4534 * Read the PPD file from the pipe, and write it to the PPD file.
4537 if ((bytes
= read(temppipe
[0], buffer
, sizeof(buffer
))) > 0)
4539 if (write(tempfd
, buffer
, (size_t)bytes
) < bytes
)
4548 if (FD_ISSET(CGIPipes
[0], &input
))
4558 * No data from cups-deviced...
4561 cupsdLogMessage(CUPSD_LOG_ERROR
, "copy_model: empty PPD file");
4567 * Open the source file for a copy...
4570 if ((src
= cupsFileOpen(tempfile
, "rb")) == NULL
)
4577 * Read the source file and see what page sizes are supported...
4580 if ((ppd
= _ppdOpen(src
, _PPD_LOCALIZATION_NONE
)) == NULL
)
4588 * Open the destination (if possible) and set the default options...
4593 cups_protocol
[0] = '\0';
4595 if ((dst
= cupsFileOpen(to
, "rb")) != NULL
)
4598 * Read all of the default lines from the old PPD...
4601 while (cupsFileGets(dst
, buffer
, sizeof(buffer
)))
4602 if (!strncmp(buffer
, "*Default", 8))
4605 * Add the default option...
4608 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
4609 choice
, sizeof(choice
)))
4611 ppd_option_t
*ppdo
; /* PPD option */
4615 * Only add the default if the default hasn't already been
4616 * set and the choice exists in the new PPD...
4619 if (!cupsGetOption(option
, num_defaults
, defaults
) &&
4620 (ppdo
= ppdFindOption(ppd
, option
)) != NULL
&&
4621 ppdFindChoice(ppdo
, choice
))
4622 num_defaults
= cupsAddOption(option
, choice
, num_defaults
,
4626 else if (!strncmp(buffer
, "*cupsProtocol:", 14))
4627 strlcpy(cups_protocol
, buffer
, sizeof(cups_protocol
));
4631 else if ((size
= ppdPageSize(ppd
, DefaultPaperSize
)) != NULL
)
4634 * Add the default media sizes...
4637 num_defaults
= cupsAddOption("PageSize", size
->name
,
4638 num_defaults
, &defaults
);
4639 num_defaults
= cupsAddOption("PageRegion", size
->name
,
4640 num_defaults
, &defaults
);
4641 num_defaults
= cupsAddOption("PaperDimension", size
->name
,
4642 num_defaults
, &defaults
);
4643 num_defaults
= cupsAddOption("ImageableArea", size
->name
,
4644 num_defaults
, &defaults
);
4650 * Open the destination file for a copy...
4653 if ((dst
= cupsdCreateConfFile(to
, ConfigFilePerm
)) == NULL
)
4655 cupsFreeOptions(num_defaults
, defaults
);
4662 * Copy the source file to the destination...
4665 cupsFileRewind(src
);
4667 while (cupsFileGets(src
, buffer
, sizeof(buffer
)))
4669 if (!strncmp(buffer
, "*Default", 8))
4672 * Check for an previous default option choice...
4675 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
4676 choice
, sizeof(choice
)))
4678 const char *val
; /* Default option value */
4681 if ((val
= cupsGetOption(option
, num_defaults
, defaults
)) != NULL
)
4684 * Substitute the previous choice...
4687 snprintf(buffer
, sizeof(buffer
), "*Default%s: %s", option
, val
);
4692 cupsFilePrintf(dst
, "%s\n", buffer
);
4695 if (cups_protocol
[0])
4696 cupsFilePrintf(dst
, "%s\n", cups_protocol
);
4698 cupsFreeOptions(num_defaults
, defaults
);
4701 * Close both files and return...
4708 return (cupsdCloseCreatedConfFile(dst
, to
));
4713 * 'copy_job_attrs()' - Copy job attributes.
4717 copy_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
4718 cupsd_job_t
*job
, /* I - Job */
4719 cups_array_t
*ra
, /* I - Requested attributes array */
4720 cups_array_t
*exclude
) /* I - Private attributes array */
4722 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
4726 * Send the requested attributes for each job...
4729 if (!cupsArrayFind(exclude
, "all"))
4731 if ((!exclude
|| !cupsArrayFind(exclude
, "number-of-documents")) &&
4732 (!ra
|| cupsArrayFind(ra
, "number-of-documents")))
4733 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4734 "number-of-documents", job
->num_files
);
4736 if ((!exclude
|| !cupsArrayFind(exclude
, "job-media-progress")) &&
4737 (!ra
|| cupsArrayFind(ra
, "job-media-progress")))
4738 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4739 "job-media-progress", job
->progress
);
4741 if ((!exclude
|| !cupsArrayFind(exclude
, "job-more-info")) &&
4742 (!ra
|| cupsArrayFind(ra
, "job-more-info")))
4744 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "http",
4745 NULL
, con
->clientname
, con
->clientport
, "/jobs/%d",
4747 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4748 "job-more-info", NULL
, job_uri
);
4751 if (job
->state_value
> IPP_JOB_PROCESSING
&&
4752 (!exclude
|| !cupsArrayFind(exclude
, "job-preserved")) &&
4753 (!ra
|| cupsArrayFind(ra
, "job-preserved")))
4754 ippAddBoolean(con
->response
, IPP_TAG_JOB
, "job-preserved",
4755 job
->num_files
> 0);
4757 if ((!exclude
|| !cupsArrayFind(exclude
, "job-printer-up-time")) &&
4758 (!ra
|| cupsArrayFind(ra
, "job-printer-up-time")))
4759 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4760 "job-printer-up-time", time(NULL
));
4763 if (!ra
|| cupsArrayFind(ra
, "job-printer-uri"))
4765 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
4766 con
->clientname
, con
->clientport
,
4767 (job
->dtype
& CUPS_PRINTER_CLASS
) ? "/classes/%s" :
4770 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4771 "job-printer-uri", NULL
, job_uri
);
4774 if (!ra
|| cupsArrayFind(ra
, "job-uri"))
4776 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
4777 con
->clientname
, con
->clientport
, "/jobs/%d",
4779 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4780 "job-uri", NULL
, job_uri
);
4785 copy_attrs(con
->response
, job
->attrs
, ra
, IPP_TAG_JOB
, 0, exclude
);
4790 * Generate attributes from the job structure...
4793 if (job
->completed_time
&& (!ra
|| cupsArrayFind(ra
, "date-time-at-completed")))
4794 ippAddDate(con
->response
, IPP_TAG_JOB
, "date-time-at-completed", ippTimeToDate(job
->completed_time
));
4796 if (job
->creation_time
&& (!ra
|| cupsArrayFind(ra
, "date-time-at-creation")))
4797 ippAddDate(con
->response
, IPP_TAG_JOB
, "date-time-at-creation", ippTimeToDate(job
->creation_time
));
4799 if (!ra
|| cupsArrayFind(ra
, "job-id"))
4800 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
4802 if (!ra
|| cupsArrayFind(ra
, "job-k-octets"))
4803 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-k-octets", job
->koctets
);
4805 if (job
->name
&& (!ra
|| cupsArrayFind(ra
, "job-name")))
4806 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_CONST_TAG(IPP_TAG_NAME
), "job-name", NULL
, job
->name
);
4808 if (job
->username
&& (!ra
|| cupsArrayFind(ra
, "job-originating-user-name")))
4809 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_CONST_TAG(IPP_TAG_NAME
), "job-originating-user-name", NULL
, job
->username
);
4811 if (!ra
|| cupsArrayFind(ra
, "job-state"))
4812 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state", (int)job
->state_value
);
4814 if (!ra
|| cupsArrayFind(ra
, "job-state-reasons"))
4816 switch (job
->state_value
)
4818 default : /* Should never get here for processing, pending, held, or stopped jobs since they don't get unloaded... */
4820 case IPP_JSTATE_ABORTED
:
4821 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons", NULL
, "job-aborted-by-system");
4823 case IPP_JSTATE_CANCELED
:
4824 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons", NULL
, "job-canceled-by-user");
4826 case IPP_JSTATE_COMPLETED
:
4827 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons", NULL
, "job-completed-successfully");
4832 if (job
->completed_time
&& (!ra
|| cupsArrayFind(ra
, "time-at-completed")))
4833 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-completed", (int)job
->completed_time
);
4835 if (job
->creation_time
&& (!ra
|| cupsArrayFind(ra
, "time-at-creation")))
4836 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation", (int)job
->creation_time
);
4842 * 'copy_printer_attrs()' - Copy printer attributes.
4847 cupsd_client_t
*con
, /* I - Client connection */
4848 cupsd_printer_t
*printer
, /* I - Printer */
4849 cups_array_t
*ra
) /* I - Requested attributes array */
4851 char printer_uri
[HTTP_MAX_URI
];
4853 char printer_icons
[HTTP_MAX_URI
];
4855 time_t curtime
; /* Current time */
4856 int i
; /* Looping var */
4860 * Copy the printer attributes to the response using requested-attributes
4861 * and document-format attributes that may be provided by the client.
4864 curtime
= time(NULL
);
4866 if (!ra
|| cupsArrayFind(ra
, "marker-change-time"))
4867 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4868 "marker-change-time", printer
->marker_time
);
4870 if (printer
->num_printers
> 0 &&
4871 (!ra
|| cupsArrayFind(ra
, "member-uris")))
4873 ipp_attribute_t
*member_uris
; /* member-uris attribute */
4874 cupsd_printer_t
*p2
; /* Printer in class */
4875 ipp_attribute_t
*p2_uri
; /* printer-uri-supported for class printer */
4878 if ((member_uris
= ippAddStrings(con
->response
, IPP_TAG_PRINTER
,
4879 IPP_TAG_URI
, "member-uris",
4880 printer
->num_printers
, NULL
,
4883 for (i
= 0; i
< printer
->num_printers
; i
++)
4885 p2
= printer
->printers
[i
];
4887 if ((p2_uri
= ippFindAttribute(p2
->attrs
, "printer-uri-supported",
4888 IPP_TAG_URI
)) != NULL
)
4889 member_uris
->values
[i
].string
.text
=
4890 _cupsStrRetain(p2_uri
->values
[0].string
.text
);
4893 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
,
4894 sizeof(printer_uri
), "ipp", NULL
, con
->clientname
,
4896 (p2
->type
& CUPS_PRINTER_CLASS
) ?
4897 "/classes/%s" : "/printers/%s", p2
->name
);
4898 member_uris
->values
[i
].string
.text
= _cupsStrAlloc(printer_uri
);
4904 if (printer
->alert
&& (!ra
|| cupsArrayFind(ra
, "printer-alert")))
4905 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_STRING
,
4906 "printer-alert", NULL
, printer
->alert
);
4908 if (printer
->alert_description
&&
4909 (!ra
|| cupsArrayFind(ra
, "printer-alert-description")))
4910 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4911 "printer-alert-description", NULL
,
4912 printer
->alert_description
);
4914 if (!ra
|| cupsArrayFind(ra
, "printer-config-change-date-time"))
4915 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-config-change-date-time", ippTimeToDate(printer
->config_time
));
4917 if (!ra
|| cupsArrayFind(ra
, "printer-config-change-time"))
4918 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4919 "printer-config-change-time", printer
->config_time
);
4921 if (!ra
|| cupsArrayFind(ra
, "printer-current-time"))
4922 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-current-time",
4923 ippTimeToDate(curtime
));
4925 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
4926 if (!ra
|| cupsArrayFind(ra
, "printer-dns-sd-name"))
4928 if (printer
->reg_name
)
4929 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4930 "printer-dns-sd-name", NULL
, printer
->reg_name
);
4932 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
4933 "printer-dns-sd-name", 0);
4935 #endif /* HAVE_DNSSD || HAVE_AVAHI */
4937 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy"))
4938 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4939 "printer-error-policy", NULL
, printer
->error_policy
);
4941 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy-supported"))
4943 static const char * const errors
[] =/* printer-error-policy-supported values */
4946 "retry-current-job",
4951 if (printer
->type
& CUPS_PRINTER_CLASS
)
4952 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
4953 "printer-error-policy-supported", NULL
, "retry-current-job");
4955 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
4956 "printer-error-policy-supported",
4957 sizeof(errors
) / sizeof(errors
[0]), NULL
, errors
);
4960 if (!ra
|| cupsArrayFind(ra
, "printer-icons"))
4962 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_icons
, sizeof(printer_icons
),
4963 "http", NULL
, con
->clientname
, con
->clientport
,
4964 "/icons/%s.png", printer
->name
);
4965 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-icons",
4966 NULL
, printer_icons
);
4967 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-icons=\"%s\"", printer_icons
);
4970 if (!ra
|| cupsArrayFind(ra
, "printer-is-accepting-jobs"))
4971 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs", (char)printer
->accepting
);
4973 if (!ra
|| cupsArrayFind(ra
, "printer-is-shared"))
4974 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-shared", (char)printer
->shared
);
4976 if (!ra
|| cupsArrayFind(ra
, "printer-is-temporary"))
4977 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-temporary", (char)printer
->temporary
);
4979 if (!ra
|| cupsArrayFind(ra
, "printer-more-info"))
4981 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
4982 "http", NULL
, con
->clientname
, con
->clientport
,
4983 (printer
->type
& CUPS_PRINTER_CLASS
) ?
4984 "/classes/%s" : "/printers/%s", printer
->name
);
4985 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
4986 "printer-more-info", NULL
, printer_uri
);
4989 if (!ra
|| cupsArrayFind(ra
, "printer-op-policy"))
4990 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4991 "printer-op-policy", NULL
, printer
->op_policy
);
4993 if (!ra
|| cupsArrayFind(ra
, "printer-state"))
4994 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
4997 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-date-time"))
4998 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-state-change-date-time", ippTimeToDate(printer
->state_time
));
5000 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-time"))
5001 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5002 "printer-state-change-time", printer
->state_time
);
5004 if (!ra
|| cupsArrayFind(ra
, "printer-state-message"))
5005 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5006 "printer-state-message", NULL
, printer
->state_message
);
5008 if (!ra
|| cupsArrayFind(ra
, "printer-state-reasons"))
5009 add_printer_state_reasons(con
, printer
);
5011 if (!ra
|| cupsArrayFind(ra
, "printer-type"))
5013 cups_ptype_t type
; /* printer-type value */
5016 * Add the CUPS-specific printer-type attribute...
5019 type
= printer
->type
;
5021 if (printer
== DefaultPrinter
)
5022 type
|= CUPS_PRINTER_DEFAULT
;
5024 if (!printer
->accepting
)
5025 type
|= CUPS_PRINTER_REJECTING
;
5027 if (!printer
->shared
)
5028 type
|= CUPS_PRINTER_NOT_SHARED
;
5030 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-type", (int)type
);
5033 if (!ra
|| cupsArrayFind(ra
, "printer-up-time"))
5034 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5035 "printer-up-time", curtime
);
5037 if (!ra
|| cupsArrayFind(ra
, "printer-uri-supported"))
5039 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5040 "ipp", NULL
, con
->clientname
, con
->clientport
,
5041 (printer
->type
& CUPS_PRINTER_CLASS
) ?
5042 "/classes/%s" : "/printers/%s", printer
->name
);
5043 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5044 "printer-uri-supported", NULL
, printer_uri
);
5045 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-uri-supported=\"%s\"",
5049 if (!ra
|| cupsArrayFind(ra
, "queued-job-count"))
5050 add_queued_job_count(con
, printer
);
5052 copy_attrs(con
->response
, printer
->attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
5053 if (printer
->ppd_attrs
)
5054 copy_attrs(con
->response
, printer
->ppd_attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
5055 copy_attrs(con
->response
, CommonData
, ra
, IPP_TAG_ZERO
, IPP_TAG_COPY
, NULL
);
5060 * 'copy_subscription_attrs()' - Copy subscription attributes.
5064 copy_subscription_attrs(
5065 cupsd_client_t
*con
, /* I - Client connection */
5066 cupsd_subscription_t
*sub
, /* I - Subscription */
5067 cups_array_t
*ra
, /* I - Requested attributes array */
5068 cups_array_t
*exclude
) /* I - Private attributes array */
5070 ipp_attribute_t
*attr
; /* Current attribute */
5071 char printer_uri
[HTTP_MAX_URI
];
5073 int count
; /* Number of events */
5074 unsigned mask
; /* Current event mask */
5075 const char *name
; /* Current event name */
5078 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5079 "copy_subscription_attrs(con=%p, sub=%p, ra=%p, exclude=%p)",
5080 con
, sub
, ra
, exclude
);
5083 * Copy the subscription attributes to the response using the
5084 * requested-attributes attribute that may be provided by the client.
5087 if (!exclude
|| !cupsArrayFind(exclude
, "all"))
5089 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-events")) &&
5090 (!ra
|| cupsArrayFind(ra
, "notify-events")))
5092 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_subscription_attrs: notify-events");
5094 if ((name
= cupsdEventName((cupsd_eventmask_t
)sub
->mask
)) != NULL
)
5097 * Simple event list...
5100 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
,
5101 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5102 "notify-events", NULL
, name
);
5107 * Complex event list...
5110 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5111 if (sub
->mask
& mask
)
5114 attr
= ippAddStrings(con
->response
, IPP_TAG_SUBSCRIPTION
,
5115 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5116 "notify-events", count
, NULL
, NULL
);
5118 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5119 if (sub
->mask
& mask
)
5121 attr
->values
[count
].string
.text
=
5122 (char *)cupsdEventName((cupsd_eventmask_t
)mask
);
5129 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-lease-duration")) &&
5130 (!sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-lease-duration"))))
5131 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5132 "notify-lease-duration", sub
->lease
);
5134 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-recipient-uri")) &&
5135 (sub
->recipient
&& (!ra
|| cupsArrayFind(ra
, "notify-recipient-uri"))))
5136 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5137 "notify-recipient-uri", NULL
, sub
->recipient
);
5138 else if ((!exclude
|| !cupsArrayFind(exclude
, "notify-pull-method")) &&
5139 (!ra
|| cupsArrayFind(ra
, "notify-pull-method")))
5140 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_KEYWORD
,
5141 "notify-pull-method", NULL
, "ippget");
5143 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-subscriber-user-name")) &&
5144 (!ra
|| cupsArrayFind(ra
, "notify-subscriber-user-name")))
5145 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_NAME
,
5146 "notify-subscriber-user-name", NULL
, sub
->owner
);
5148 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-time-interval")) &&
5149 (!ra
|| cupsArrayFind(ra
, "notify-time-interval")))
5150 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5151 "notify-time-interval", sub
->interval
);
5153 if (sub
->user_data_len
> 0 &&
5154 (!exclude
|| !cupsArrayFind(exclude
, "notify-user-data")) &&
5155 (!ra
|| cupsArrayFind(ra
, "notify-user-data")))
5156 ippAddOctetString(con
->response
, IPP_TAG_SUBSCRIPTION
, "notify-user-data",
5157 sub
->user_data
, sub
->user_data_len
);
5160 if (sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-job-id")))
5161 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5162 "notify-job-id", sub
->job
->id
);
5164 if (sub
->dest
&& (!ra
|| cupsArrayFind(ra
, "notify-printer-uri")))
5166 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5167 "ipp", NULL
, con
->clientname
, con
->clientport
,
5168 "/printers/%s", sub
->dest
->name
);
5169 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5170 "notify-printer-uri", NULL
, printer_uri
);
5173 if (!ra
|| cupsArrayFind(ra
, "notify-subscription-id"))
5174 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5175 "notify-subscription-id", sub
->id
);
5180 * 'create_job()' - Print a file to a printer or class.
5184 create_job(cupsd_client_t
*con
, /* I - Client connection */
5185 ipp_attribute_t
*uri
) /* I - Printer URI */
5187 int i
; /* Looping var */
5188 cupsd_printer_t
*printer
; /* Printer */
5189 cupsd_job_t
*job
; /* New job */
5190 static const char * const forbidden_attrs
[] =
5191 { /* List of forbidden attributes */
5195 "document-natural-language"
5199 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "create_job(%p[%d], %s)", con
,
5200 con
->number
, uri
->values
[0].string
.text
);
5203 * Is the destination valid?
5206 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
5212 send_ipp_status(con
, IPP_NOT_FOUND
,
5213 _("The printer or class does not exist."));
5218 * Check for invalid Create-Job attributes and log a warning or error depending
5219 * on whether cupsd is running in "strict conformance" mode...
5223 i
< (int)(sizeof(forbidden_attrs
) / sizeof(forbidden_attrs
[0]));
5225 if (ippFindAttribute(con
->request
, forbidden_attrs
[i
], IPP_TAG_ZERO
))
5227 if (StrictConformance
)
5229 send_ipp_status(con
, IPP_BAD_REQUEST
,
5230 _("The '%s' operation attribute cannot be supplied in a "
5231 "Create-Job request."), forbidden_attrs
[i
]);
5235 cupsdLogMessage(CUPSD_LOG_WARN
,
5236 "Unexpected '%s' operation attribute in a Create-Job "
5237 "request.", forbidden_attrs
[i
]);
5241 * Create the job object...
5244 if ((job
= add_job(con
, printer
, NULL
)) == NULL
)
5247 job
->pending_timeout
= 1;
5250 * Save and log the job...
5253 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
5254 job
->dest
, job
->username
);
5259 * 'create_local_bg_thread()' - Background thread for creating a local print queue.
5262 static void * /* O - Exit status */
5263 create_local_bg_thread(
5264 cupsd_printer_t
*printer
) /* I - Printer */
5266 cups_file_t
*from
, /* Source file */
5267 *to
; /* Destination file */
5268 char fromppd
[1024], /* Source PPD */
5269 toppd
[1024], /* Destination PPD */
5270 scheme
[32], /* URI scheme */
5271 userpass
[256], /* User:pass */
5272 host
[256], /* Hostname */
5273 resource
[1024], /* Resource path */
5274 line
[1024]; /* Line from PPD */
5275 int port
; /* Port number */
5276 http_encryption_t encryption
; /* Type of encryption to use */
5277 http_t
*http
; /* Connection to printer */
5278 ipp_t
*request
, /* Request to printer */
5279 *response
; /* Response from printer */
5280 ipp_attribute_t
*attr
; /* Attribute in response */
5284 * Try connecting to the printer...
5287 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s: Generating PPD file from \"%s\"...", printer
->name
, printer
->device_uri
);
5289 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
)
5291 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: Bad device URI \"%s\".", printer
->name
, printer
->device_uri
);
5295 if (!strcmp(scheme
, "ipps") || port
== 443)
5296 encryption
= HTTP_ENCRYPTION_ALWAYS
;
5298 encryption
= HTTP_ENCRYPTION_IF_REQUESTED
;
5300 if ((http
= httpConnect2(host
, port
, NULL
, AF_UNSPEC
, encryption
, 1, 30000, NULL
)) == NULL
)
5302 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: Unable to connect to %s:%d: %s", printer
->name
, host
, port
, cupsLastErrorString());
5307 * Query the printer for its capabilities...
5310 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s: Connected to %s:%d, sending Get-Printer-Attributes request...", printer
->name
, host
, port
);
5312 request
= ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES
);
5313 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
, printer
->device_uri
);
5314 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
, "requested-attributes", NULL
, "all");
5316 response
= cupsDoRequest(http
, request
, resource
);
5318 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s: Get-Printer-Attributes returned %s", printer
->name
, ippErrorString(cupsLastError()));
5320 // TODO: Grab printer icon file...
5324 * Write the PPD for the queue...
5327 if (_ppdCreateFromIPP(fromppd
, sizeof(fromppd
), response
))
5329 if ((!printer
->info
|| !*(printer
->info
)) && (attr
= ippFindAttribute(response
, "printer-info", IPP_TAG_TEXT
)) != NULL
)
5330 cupsdSetString(&printer
->info
, ippGetString(attr
, 0, NULL
));
5332 if ((!printer
->location
|| !*(printer
->location
)) && (attr
= ippFindAttribute(response
, "printer-location", IPP_TAG_TEXT
)) != NULL
)
5333 cupsdSetString(&printer
->location
, ippGetString(attr
, 0, NULL
));
5335 if ((!printer
->geo_location
|| !*(printer
->geo_location
)) && (attr
= ippFindAttribute(response
, "printer-geo-location", IPP_TAG_URI
)) != NULL
)
5336 cupsdSetString(&printer
->geo_location
, ippGetString(attr
, 0, NULL
));
5338 if ((from
= cupsFileOpen(fromppd
, "r")) == NULL
)
5340 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: Unable to read generated PPD: %s", printer
->name
, strerror(errno
));
5344 snprintf(toppd
, sizeof(toppd
), "%s/ppd/%s.ppd", ServerRoot
, printer
->name
);
5345 if ((to
= cupsdCreateConfFile(toppd
, ConfigFilePerm
)) == NULL
)
5347 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: Unable to create PPD for printer: %s", printer
->name
, strerror(errno
));
5348 cupsFileClose(from
);
5352 while (cupsFileGets(from
, line
, sizeof(line
)))
5353 cupsFilePrintf(to
, "%s\n", line
);
5355 cupsFileClose(from
);
5356 if (!cupsdCloseCreatedConfFile(to
, toppd
))
5358 printer
->config_time
= time(NULL
);
5359 printer
->state
= IPP_PSTATE_IDLE
;
5360 printer
->accepting
= 1;
5362 cupsdSetPrinterAttrs(printer
);
5364 cupsdAddEvent(CUPSD_EVENT_PRINTER_CONFIG
, printer
, NULL
, "Printer \"%s\" is now available.", printer
->name
);
5365 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" is now available.", printer
->name
);
5369 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: PPD creation failed: %s", printer
->name
, cupsLastErrorString());
5376 * 'create_local_printer()' - Create a local (temporary) print queue.
5380 create_local_printer(
5381 cupsd_client_t
*con
) /* I - Client connection */
5383 ipp_attribute_t
*device_uri
, /* device-uri attribute */
5384 *printer_geo_location
, /* printer-geo-location attribute */
5385 *printer_info
, /* printer-info attribute */
5386 *printer_location
, /* printer-location attribute */
5387 *printer_name
; /* printer-name attribute */
5388 cupsd_printer_t
*printer
; /* New printer */
5389 http_status_t status
; /* Policy status */
5390 char name
[128], /* Sanitized printer name */
5391 *nameptr
, /* Pointer into name */
5392 uri
[1024]; /* printer-uri-supported value */
5393 const char *ptr
; /* Pointer into attribute value */
5397 * Require local access to create a local printer...
5400 if (!httpAddrLocalhost(httpGetAddress(con
->http
)))
5402 send_ipp_status(con
, IPP_STATUS_ERROR_FORBIDDEN
, _("Only local users can create a local printer."));
5407 * Check any other policy limits...
5410 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5412 send_http_error(con
, status
, NULL
);
5417 * Grab needed attributes...
5420 if ((printer_name
= ippFindAttribute(con
->request
, "printer-name", IPP_TAG_ZERO
)) == NULL
|| ippGetGroupTag(printer_name
) != IPP_TAG_PRINTER
|| ippGetValueTag(printer_name
) != IPP_TAG_NAME
)
5423 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Missing required attribute \"%s\"."), "printer-name");
5424 else if (ippGetGroupTag(printer_name
) != IPP_TAG_PRINTER
)
5425 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Attribute \"%s\" is in the wrong group."), "printer-name");
5427 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Attribute \"%s\" is the wrong value type."), "printer-name");
5432 for (nameptr
= name
, ptr
= ippGetString(printer_name
, 0, NULL
); *ptr
&& nameptr
< (name
+ sizeof(name
) - 1); ptr
++)
5435 * Sanitize the printer name...
5438 if (_cups_isalnum(*ptr
))
5440 else if (nameptr
== name
|| nameptr
[-1] != '_')
5446 if ((device_uri
= ippFindAttribute(con
->request
, "device-uri", IPP_TAG_ZERO
)) == NULL
|| ippGetGroupTag(device_uri
) != IPP_TAG_PRINTER
|| ippGetValueTag(device_uri
) != IPP_TAG_URI
)
5449 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Missing required attribute \"%s\"."), "device-uri");
5450 else if (ippGetGroupTag(device_uri
) != IPP_TAG_PRINTER
)
5451 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Attribute \"%s\" is in the wrong group."), "device-uri");
5453 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Attribute \"%s\" is the wrong value type."), "device-uri");
5458 printer_geo_location
= ippFindAttribute(con
->request
, "printer-geo-location", IPP_TAG_URI
);
5459 printer_info
= ippFindAttribute(con
->request
, "printer-info", IPP_TAG_TEXT
);
5460 printer_location
= ippFindAttribute(con
->request
, "printer-location", IPP_TAG_TEXT
);
5463 * See if the printer already exists...
5466 if ((printer
= cupsdFindDest(name
)) != NULL
)
5468 send_ipp_status(con
, IPP_STATUS_ERROR_NOT_POSSIBLE
, _("Printer \"%s\" already exists."), name
);
5469 goto add_printer_attributes
;
5473 * Create the printer...
5476 if ((printer
= cupsdAddPrinter(name
)) == NULL
)
5478 send_ipp_status(con
, IPP_STATUS_ERROR_INTERNAL
, _("Unable to create printer."));
5482 printer
->shared
= 0;
5483 printer
->temporary
= 1;
5485 cupsdSetDeviceURI(printer
, ippGetString(device_uri
, 0, NULL
));
5487 if (printer_geo_location
)
5488 cupsdSetString(&printer
->geo_location
, ippGetString(printer_geo_location
, 0, NULL
));
5490 cupsdSetString(&printer
->info
, ippGetString(printer_info
, 0, NULL
));
5491 if (printer_location
)
5492 cupsdSetString(&printer
->location
, ippGetString(printer_location
, 0, NULL
));
5494 cupsdSetPrinterAttrs(printer
);
5497 * Run a background thread to create the PPD...
5500 _cupsThreadCreate((_cups_thread_func_t
)create_local_bg_thread
, printer
);
5503 * Return printer attributes...
5506 send_ipp_status(con
, IPP_STATUS_OK
, _("Local printer created."));
5508 add_printer_attributes
:
5510 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs", (char)printer
->accepting
);
5511 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state", printer
->state
);
5512 add_printer_state_reasons(con
, printer
);
5514 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), httpIsEncrypted(con
->http
) ? "ipps" : "ipp", NULL
, con
->clientname
, con
->clientport
, "/printers/%s", printer
->name
);
5515 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-uri-supported", NULL
, uri
);
5520 * 'create_requested_array()' - Create an array for the requested-attributes.
5523 static cups_array_t
* /* O - Array of attributes or NULL */
5524 create_requested_array(ipp_t
*request
) /* I - IPP request */
5526 cups_array_t
*ra
; /* Requested attributes array */
5530 * Create the array for standard attributes...
5533 ra
= ippCreateRequestedArray(request
);
5536 * Add CUPS defaults as needed...
5539 if (cupsArrayFind(ra
, "printer-defaults"))
5542 * Include user-set defaults...
5545 char *name
; /* Option name */
5547 cupsArrayRemove(ra
, "printer-defaults");
5549 for (name
= (char *)cupsArrayFirst(CommonDefaults
);
5551 name
= (char *)cupsArrayNext(CommonDefaults
))
5552 if (!cupsArrayFind(ra
, name
))
5553 cupsArrayAdd(ra
, name
);
5561 * 'create_subscriptions()' - Create one or more notification subscriptions.
5565 create_subscriptions(
5566 cupsd_client_t
*con
, /* I - Client connection */
5567 ipp_attribute_t
*uri
) /* I - Printer URI */
5569 http_status_t status
; /* Policy status */
5570 int i
; /* Looping var */
5571 ipp_attribute_t
*attr
; /* Current attribute */
5572 cups_ptype_t dtype
; /* Destination type (printer/class) */
5573 char scheme
[HTTP_MAX_URI
],
5574 /* Scheme portion of URI */
5575 userpass
[HTTP_MAX_URI
],
5576 /* Username portion of URI */
5578 /* Host portion of URI */
5579 resource
[HTTP_MAX_URI
];
5580 /* Resource portion of URI */
5581 int port
; /* Port portion of URI */
5582 cupsd_printer_t
*printer
; /* Printer/class */
5583 cupsd_job_t
*job
; /* Job */
5584 int jobid
; /* Job ID */
5585 cupsd_subscription_t
*sub
; /* Subscription object */
5586 const char *username
, /* requesting-user-name or
5587 authenticated username */
5588 *recipient
, /* notify-recipient-uri */
5589 *pullmethod
; /* notify-pull-method */
5590 ipp_attribute_t
*user_data
; /* notify-user-data */
5591 int interval
, /* notify-time-interval */
5592 lease
; /* notify-lease-duration */
5593 unsigned mask
; /* notify-events */
5594 ipp_attribute_t
*notify_events
,/* notify-events(-default) */
5595 *notify_lease
; /* notify-lease-duration(-default) */
5599 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
5601 if (attr
->group_tag
!= IPP_TAG_ZERO
)
5602 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "g%04x v%04x %s", attr
->group_tag
,
5603 attr
->value_tag
, attr
->name
);
5605 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "----SEP----");
5610 * Is the destination valid?
5613 cupsdLogMessage(CUPSD_LOG_DEBUG
, "create_subscriptions(con=%p(%d), uri=\"%s\")", con
, con
->number
, uri
->values
[0].string
.text
);
5615 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
5616 sizeof(scheme
), userpass
, sizeof(userpass
), host
,
5617 sizeof(host
), &port
, resource
, sizeof(resource
));
5619 if (!strcmp(resource
, "/"))
5621 dtype
= (cups_ptype_t
)0;
5624 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
5626 dtype
= (cups_ptype_t
)0;
5629 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
5631 dtype
= CUPS_PRINTER_CLASS
;
5634 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
5640 send_ipp_status(con
, IPP_NOT_FOUND
,
5641 _("The printer or class does not exist."));
5651 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
5654 send_http_error(con
, status
, printer
);
5658 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5660 send_http_error(con
, status
, NULL
);
5665 * Get the user that is requesting the subscription...
5668 username
= get_username(con
);
5671 * Find the first subscription group attribute; return if we have
5675 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
5676 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
5681 send_ipp_status(con
, IPP_BAD_REQUEST
,
5682 _("No subscription attributes in request."));
5687 * Process the subscription attributes in the request...
5690 con
->response
->request
.status
.status_code
= IPP_BAD_REQUEST
;
5698 lease
= DefaultLeaseDuration
;
5700 mask
= CUPSD_EVENT_NONE
;
5704 notify_events
= ippFindAttribute(printer
->attrs
, "notify-events-default",
5706 notify_lease
= ippFindAttribute(printer
->attrs
,
5707 "notify-lease-duration-default",
5711 lease
= notify_lease
->values
[0].integer
;
5715 notify_events
= NULL
;
5716 notify_lease
= NULL
;
5719 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
5721 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
5722 attr
->value_tag
== IPP_TAG_URI
)
5725 * Validate the recipient scheme against the ServerBin/notifier
5729 char notifier
[1024]; /* Notifier filename */
5732 recipient
= attr
->values
[0].string
.text
;
5734 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
5735 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
5736 host
, sizeof(host
), &port
,
5737 resource
, sizeof(resource
)) < HTTP_URI_OK
)
5739 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5740 _("Bad notify-recipient-uri \"%s\"."), recipient
);
5741 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5742 "notify-status-code", IPP_URI_SCHEME
);
5746 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
5748 if (access(notifier
, X_OK
))
5750 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5751 _("notify-recipient-uri URI \"%s\" uses unknown "
5752 "scheme."), recipient
);
5753 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5754 "notify-status-code", IPP_URI_SCHEME
);
5758 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
5760 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5761 _("notify-recipient-uri URI \"%s\" is already used."),
5763 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5764 "notify-status-code", IPP_ATTRIBUTES
);
5768 else if (!strcmp(attr
->name
, "notify-pull-method") &&
5769 attr
->value_tag
== IPP_TAG_KEYWORD
)
5771 pullmethod
= attr
->values
[0].string
.text
;
5773 if (strcmp(pullmethod
, "ippget"))
5775 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5776 _("Bad notify-pull-method \"%s\"."), pullmethod
);
5777 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5778 "notify-status-code", IPP_ATTRIBUTES
);
5782 else if (!strcmp(attr
->name
, "notify-charset") &&
5783 attr
->value_tag
== IPP_TAG_CHARSET
&&
5784 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
5785 strcmp(attr
->values
[0].string
.text
, "utf-8"))
5787 send_ipp_status(con
, IPP_CHARSET
,
5788 _("Character set \"%s\" not supported."),
5789 attr
->values
[0].string
.text
);
5792 else if (!strcmp(attr
->name
, "notify-natural-language") &&
5793 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
5794 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
5796 send_ipp_status(con
, IPP_CHARSET
,
5797 _("Language \"%s\" not supported."),
5798 attr
->values
[0].string
.text
);
5801 else if (!strcmp(attr
->name
, "notify-user-data") &&
5802 attr
->value_tag
== IPP_TAG_STRING
)
5804 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
5806 send_ipp_status(con
, IPP_REQUEST_VALUE
,
5807 _("The notify-user-data value is too large "
5808 "(%d > 63 octets)."),
5809 attr
->values
[0].unknown
.length
);
5815 else if (!strcmp(attr
->name
, "notify-events") &&
5816 attr
->value_tag
== IPP_TAG_KEYWORD
)
5817 notify_events
= attr
;
5818 else if (!strcmp(attr
->name
, "notify-lease-duration") &&
5819 attr
->value_tag
== IPP_TAG_INTEGER
)
5820 lease
= attr
->values
[0].integer
;
5821 else if (!strcmp(attr
->name
, "notify-time-interval") &&
5822 attr
->value_tag
== IPP_TAG_INTEGER
)
5823 interval
= attr
->values
[0].integer
;
5824 else if (!strcmp(attr
->name
, "notify-job-id") &&
5825 attr
->value_tag
== IPP_TAG_INTEGER
)
5826 jobid
= attr
->values
[0].integer
;
5833 for (i
= 0; i
< notify_events
->num_values
; i
++)
5834 mask
|= cupsdEventValue(notify_events
->values
[i
].string
.text
);
5838 cupsdLogMessage(CUPSD_LOG_DEBUG
, "recipient=\"%s\"", recipient
);
5840 cupsdLogMessage(CUPSD_LOG_DEBUG
, "pullmethod=\"%s\"", pullmethod
);
5841 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-lease-duration=%d", lease
);
5842 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-time-interval=%d", interval
);
5844 if (!recipient
&& !pullmethod
)
5847 if (mask
== CUPSD_EVENT_NONE
)
5850 mask
= CUPSD_EVENT_JOB_COMPLETED
;
5852 mask
= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
5855 send_ipp_status(con
, IPP_BAD_REQUEST
,
5856 _("notify-events not specified."));
5861 if (MaxLeaseDuration
&& (lease
== 0 || lease
> MaxLeaseDuration
))
5863 cupsdLogMessage(CUPSD_LOG_INFO
,
5864 "create_subscriptions: Limiting notify-lease-duration to "
5867 lease
= MaxLeaseDuration
;
5872 if ((job
= cupsdFindJob(jobid
)) == NULL
)
5874 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
5882 if ((sub
= cupsdAddSubscription(mask
, printer
, job
, recipient
, 0)) == NULL
)
5884 send_ipp_status(con
, IPP_TOO_MANY_SUBSCRIPTIONS
,
5885 _("There are too many subscriptions."));
5890 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription #%d for job %d.",
5893 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5894 "Added subscription #%d for printer \"%s\".",
5895 sub
->id
, printer
->name
);
5897 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription #%d for server.",
5900 sub
->interval
= interval
;
5902 sub
->expire
= lease
? time(NULL
) + lease
: 0;
5904 cupsdSetString(&sub
->owner
, username
);
5908 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
5909 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
5910 (size_t)sub
->user_data_len
);
5913 ippAddSeparator(con
->response
);
5914 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5915 "notify-subscription-id", sub
->id
);
5917 con
->response
->request
.status
.status_code
= IPP_OK
;
5923 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
5928 * 'delete_printer()' - Remove a printer or class from the system.
5932 delete_printer(cupsd_client_t
*con
, /* I - Client connection */
5933 ipp_attribute_t
*uri
) /* I - URI of printer or class */
5935 http_status_t status
; /* Policy status */
5936 cups_ptype_t dtype
; /* Destination type (printer/class) */
5937 cupsd_printer_t
*printer
; /* Printer/class */
5938 char filename
[1024]; /* Script/PPD filename */
5939 int temporary
; /* Temporary queue? */
5942 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "delete_printer(%p[%d], %s)", con
,
5943 con
->number
, uri
->values
[0].string
.text
);
5946 * Do we have a valid URI?
5949 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
5955 send_ipp_status(con
, IPP_NOT_FOUND
,
5956 _("The printer or class does not exist."));
5964 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5966 send_http_error(con
, status
, NULL
);
5971 * Remove old jobs...
5974 cupsdCancelJobs(printer
->name
, NULL
, 1);
5977 * Remove old subscriptions and send a "deleted printer" event...
5980 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED
, printer
, NULL
,
5981 "%s \"%s\" deleted by \"%s\".",
5982 (dtype
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
5983 printer
->name
, get_username(con
));
5985 cupsdExpireSubscriptions(printer
, NULL
);
5988 * Remove any old PPD or script files...
5991 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
5994 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd.O", ServerRoot
,
5998 snprintf(filename
, sizeof(filename
), "%s/%s.png", CacheDir
, printer
->name
);
6001 snprintf(filename
, sizeof(filename
), "%s/%s.data", CacheDir
, printer
->name
);
6005 * Unregister color profiles...
6008 cupsdUnregisterColor(printer
);
6010 temporary
= printer
->temporary
;
6012 if (dtype
& CUPS_PRINTER_CLASS
)
6014 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" deleted by \"%s\".",
6015 printer
->name
, get_username(con
));
6017 cupsdDeletePrinter(printer
, 0);
6019 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
6023 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" deleted by \"%s\".",
6024 printer
->name
, get_username(con
));
6026 if (cupsdDeletePrinter(printer
, 0) && !temporary
)
6027 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
6030 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
6034 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
6037 * Return with no errors...
6040 con
->response
->request
.status
.status_code
= IPP_OK
;
6045 * 'get_default()' - Get the default destination.
6049 get_default(cupsd_client_t
*con
) /* I - Client connection */
6051 http_status_t status
; /* Policy status */
6052 cups_array_t
*ra
; /* Requested attributes array */
6055 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_default(%p[%d])", con
, con
->number
);
6061 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6063 send_http_error(con
, status
, NULL
);
6069 ra
= create_requested_array(con
->request
);
6071 copy_printer_attrs(con
, DefaultPrinter
, ra
);
6073 cupsArrayDelete(ra
);
6075 con
->response
->request
.status
.status_code
= IPP_OK
;
6078 send_ipp_status(con
, IPP_NOT_FOUND
, _("No default printer."));
6083 * 'get_devices()' - Get the list of available devices on the local system.
6087 get_devices(cupsd_client_t
*con
) /* I - Client connection */
6089 http_status_t status
; /* Policy status */
6090 ipp_attribute_t
*limit
, /* limit attribute */
6091 *timeout
, /* timeout attribute */
6092 *requested
, /* requested-attributes attribute */
6093 *exclude
, /* exclude-schemes attribute */
6094 *include
; /* include-schemes attribute */
6095 char command
[1024], /* cups-deviced command */
6096 options
[2048], /* Options to pass to command */
6098 /* String for requested attributes */
6100 /* String for excluded schemes */
6102 /* String for included schemes */
6105 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_devices(%p[%d])", con
, con
->number
);
6111 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6113 send_http_error(con
, status
, NULL
);
6118 * Run cups-deviced command with the given options...
6121 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
6122 timeout
= ippFindAttribute(con
->request
, "timeout", IPP_TAG_INTEGER
);
6123 requested
= ippFindAttribute(con
->request
, "requested-attributes",
6125 exclude
= ippFindAttribute(con
->request
, "exclude-schemes", IPP_TAG_NAME
);
6126 include
= ippFindAttribute(con
->request
, "include-schemes", IPP_TAG_NAME
);
6129 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
6131 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
6134 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
6136 exclude_str
[0] = '\0';
6139 url_encode_attr(include
, include_str
, sizeof(include_str
));
6141 include_str
[0] = '\0';
6143 snprintf(command
, sizeof(command
), "%s/daemon/cups-deviced", ServerBin
);
6144 snprintf(options
, sizeof(options
),
6145 "%d+%d+%d+%d+%s%s%s%s%s",
6146 con
->request
->request
.op
.request_id
,
6147 limit
? limit
->values
[0].integer
: 0,
6148 timeout
? timeout
->values
[0].integer
: 15,
6151 exclude_str
[0] ? "%20" : "", exclude_str
,
6152 include_str
[0] ? "%20" : "", include_str
);
6154 if (cupsdSendCommand(con
, command
, options
, 1))
6157 * Command started successfully, don't send an IPP response here...
6160 ippDelete(con
->response
);
6161 con
->response
= NULL
;
6166 * Command failed, return "internal error" so the user knows something
6170 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
6171 _("cups-deviced failed to execute."));
6177 * 'get_document()' - Get a copy of a job file.
6181 get_document(cupsd_client_t
*con
, /* I - Client connection */
6182 ipp_attribute_t
*uri
) /* I - Job URI */
6184 http_status_t status
; /* Policy status */
6185 ipp_attribute_t
*attr
; /* Current attribute */
6186 int jobid
; /* Job ID */
6187 int docnum
; /* Document number */
6188 cupsd_job_t
*job
; /* Current job */
6189 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
6190 username
[HTTP_MAX_URI
], /* Username portion of URI */
6191 host
[HTTP_MAX_URI
], /* Host portion of URI */
6192 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6193 int port
; /* Port portion of URI */
6194 char filename
[1024], /* Filename for document */
6195 format
[1024]; /* Format for document */
6198 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_document(%p[%d], %s)", con
,
6199 con
->number
, uri
->values
[0].string
.text
);
6202 * See if we have a job URI or a printer URI...
6205 if (!strcmp(uri
->name
, "printer-uri"))
6208 * Got a printer URI; see if we also have a job-id attribute...
6211 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6212 IPP_TAG_INTEGER
)) == NULL
)
6214 send_ipp_status(con
, IPP_BAD_REQUEST
,
6215 _("Got a printer-uri attribute but no job-id."));
6219 jobid
= attr
->values
[0].integer
;
6224 * Got a job URI; parse it to get the job ID...
6227 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6228 sizeof(scheme
), username
, sizeof(username
), host
,
6229 sizeof(host
), &port
, resource
, sizeof(resource
));
6231 if (strncmp(resource
, "/jobs/", 6))
6237 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
6238 uri
->values
[0].string
.text
);
6242 jobid
= atoi(resource
+ 6);
6246 * See if the job exists...
6249 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6252 * Nope - return a "not found" error...
6255 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
6263 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
,
6264 job
->username
)) != HTTP_OK
)
6266 send_http_error(con
, status
, NULL
);
6271 * Get the document number...
6274 if ((attr
= ippFindAttribute(con
->request
, "document-number",
6275 IPP_TAG_INTEGER
)) == NULL
)
6277 send_ipp_status(con
, IPP_BAD_REQUEST
,
6278 _("Missing document-number attribute."));
6282 if ((docnum
= attr
->values
[0].integer
) < 1 || docnum
> job
->num_files
||
6283 attr
->num_values
> 1)
6285 send_ipp_status(con
, IPP_NOT_FOUND
,
6286 _("Document #%d does not exist in job #%d."), docnum
,
6291 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, jobid
,
6293 if ((con
->file
= open(filename
, O_RDONLY
)) == -1)
6295 cupsdLogMessage(CUPSD_LOG_ERROR
,
6296 "Unable to open document %d in job %d - %s", docnum
, jobid
,
6298 send_ipp_status(con
, IPP_NOT_FOUND
,
6299 _("Unable to open document #%d in job #%d."), docnum
,
6304 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
6308 snprintf(format
, sizeof(format
), "%s/%s", job
->filetypes
[docnum
- 1]->super
,
6309 job
->filetypes
[docnum
- 1]->type
);
6311 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format",
6313 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "document-number",
6315 if ((attr
= ippFindAttribute(job
->attrs
, "document-name",
6316 IPP_TAG_NAME
)) != NULL
)
6317 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name",
6318 NULL
, attr
->values
[0].string
.text
);
6323 * 'get_job_attrs()' - Get job attributes.
6327 get_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
6328 ipp_attribute_t
*uri
) /* I - Job URI */
6330 http_status_t status
; /* Policy status */
6331 ipp_attribute_t
*attr
; /* Current attribute */
6332 int jobid
; /* Job ID */
6333 cupsd_job_t
*job
; /* Current job */
6334 cupsd_printer_t
*printer
; /* Current printer */
6335 cupsd_policy_t
*policy
; /* Current security policy */
6336 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6337 username
[HTTP_MAX_URI
], /* Username portion of URI */
6338 host
[HTTP_MAX_URI
], /* Host portion of URI */
6339 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6340 int port
; /* Port portion of URI */
6341 cups_array_t
*ra
, /* Requested attributes array */
6342 *exclude
; /* Private attributes array */
6345 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_job_attrs(%p[%d], %s)", con
,
6346 con
->number
, uri
->values
[0].string
.text
);
6349 * See if we have a job URI or a printer URI...
6352 if (!strcmp(uri
->name
, "printer-uri"))
6355 * Got a printer URI; see if we also have a job-id attribute...
6358 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6359 IPP_TAG_INTEGER
)) == NULL
)
6361 send_ipp_status(con
, IPP_BAD_REQUEST
,
6362 _("Got a printer-uri attribute but no job-id."));
6366 jobid
= attr
->values
[0].integer
;
6371 * Got a job URI; parse it to get the job ID...
6374 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6375 sizeof(scheme
), username
, sizeof(username
), host
,
6376 sizeof(host
), &port
, resource
, sizeof(resource
));
6378 if (strncmp(resource
, "/jobs/", 6))
6384 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
6385 uri
->values
[0].string
.text
);
6389 jobid
= atoi(resource
+ 6);
6393 * See if the job exists...
6396 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6399 * Nope - return a "not found" error...
6402 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
6410 if ((printer
= job
->printer
) == NULL
)
6411 printer
= cupsdFindDest(job
->dest
);
6414 policy
= printer
->op_policy_ptr
;
6416 policy
= DefaultPolicyPtr
;
6418 if ((status
= cupsdCheckPolicy(policy
, con
, job
->username
)) != HTTP_OK
)
6420 send_http_error(con
, status
, NULL
);
6424 exclude
= cupsdGetPrivateAttrs(policy
, con
, printer
, job
->username
);
6427 * Copy attributes...
6432 ra
= create_requested_array(con
->request
);
6433 copy_job_attrs(con
, job
, ra
, exclude
);
6434 cupsArrayDelete(ra
);
6436 con
->response
->request
.status
.status_code
= IPP_OK
;
6441 * 'get_jobs()' - Get a list of jobs for the specified printer.
6445 get_jobs(cupsd_client_t
*con
, /* I - Client connection */
6446 ipp_attribute_t
*uri
) /* I - Printer URI */
6448 http_status_t status
; /* Policy status */
6449 ipp_attribute_t
*attr
; /* Current attribute */
6450 const char *dest
; /* Destination */
6451 cups_ptype_t dtype
; /* Destination type (printer/class) */
6452 cups_ptype_t dmask
; /* Destination type mask */
6453 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6454 username
[HTTP_MAX_URI
], /* Username portion of URI */
6455 host
[HTTP_MAX_URI
], /* Host portion of URI */
6456 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6457 int port
; /* Port portion of URI */
6458 int job_comparison
; /* Job comparison */
6459 ipp_jstate_t job_state
; /* job-state value */
6460 int first_job_id
= 1, /* First job ID */
6461 first_index
= 1, /* First index */
6462 limit
= 0, /* Maximum number of jobs to return */
6463 count
, /* Number of jobs that match */
6464 need_load_job
= 0; /* Do we need to load the job? */
6465 const char *job_attr
; /* Job attribute requested */
6466 ipp_attribute_t
*job_ids
; /* job-ids attribute */
6467 cupsd_job_t
*job
; /* Current job pointer */
6468 cupsd_printer_t
*printer
; /* Printer */
6469 cups_array_t
*list
; /* Which job list... */
6470 int delete_list
= 0; /* Delete the list afterwards? */
6471 cups_array_t
*ra
, /* Requested attributes array */
6472 *exclude
; /* Private attributes array */
6473 cupsd_policy_t
*policy
; /* Current policy */
6476 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs(%p[%d], %s)", con
, con
->number
,
6477 uri
->values
[0].string
.text
);
6480 * Is the destination valid?
6483 if (strcmp(uri
->name
, "printer-uri"))
6485 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No printer-uri in request."));
6489 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6490 sizeof(scheme
), username
, sizeof(username
), host
,
6491 sizeof(host
), &port
, resource
, sizeof(resource
));
6493 if (!strcmp(resource
, "/") || !strcmp(resource
, "/jobs"))
6496 dtype
= (cups_ptype_t
)0;
6497 dmask
= (cups_ptype_t
)0;
6500 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6503 dtype
= (cups_ptype_t
)0;
6504 dmask
= CUPS_PRINTER_CLASS
;
6507 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6510 dtype
= CUPS_PRINTER_CLASS
;
6511 dmask
= CUPS_PRINTER_CLASS
;
6514 else if ((dest
= cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
,
6521 send_ipp_status(con
, IPP_NOT_FOUND
,
6522 _("The printer or class does not exist."));
6527 dtype
&= CUPS_PRINTER_CLASS
;
6528 dmask
= CUPS_PRINTER_CLASS
;
6536 policy
= printer
->op_policy_ptr
;
6538 policy
= DefaultPolicyPtr
;
6540 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
6542 send_http_error(con
, status
, NULL
);
6546 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
6549 * See if the "which-jobs" attribute have been specified...
6552 if ((attr
= ippFindAttribute(con
->request
, "which-jobs",
6553 IPP_TAG_KEYWORD
)) != NULL
&& job_ids
)
6555 send_ipp_status(con
, IPP_CONFLICT
,
6556 _("The %s attribute cannot be provided with job-ids."),
6560 else if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "not-completed"))
6562 job_comparison
= -1;
6563 job_state
= IPP_JOB_STOPPED
;
6566 else if (!strcmp(attr
->values
[0].string
.text
, "completed"))
6569 job_state
= IPP_JOB_CANCELED
;
6570 list
= cupsdGetCompletedJobs(printer
);
6573 else if (!strcmp(attr
->values
[0].string
.text
, "aborted"))
6576 job_state
= IPP_JOB_ABORTED
;
6577 list
= cupsdGetCompletedJobs(printer
);
6580 else if (!strcmp(attr
->values
[0].string
.text
, "all"))
6583 job_state
= IPP_JOB_PENDING
;
6586 else if (!strcmp(attr
->values
[0].string
.text
, "canceled"))
6589 job_state
= IPP_JOB_CANCELED
;
6590 list
= cupsdGetCompletedJobs(printer
);
6593 else if (!strcmp(attr
->values
[0].string
.text
, "pending"))
6596 job_state
= IPP_JOB_PENDING
;
6599 else if (!strcmp(attr
->values
[0].string
.text
, "pending-held"))
6602 job_state
= IPP_JOB_HELD
;
6605 else if (!strcmp(attr
->values
[0].string
.text
, "processing"))
6608 job_state
= IPP_JOB_PROCESSING
;
6609 list
= PrintingJobs
;
6611 else if (!strcmp(attr
->values
[0].string
.text
, "processing-stopped"))
6614 job_state
= IPP_JOB_STOPPED
;
6619 send_ipp_status(con
, IPP_ATTRIBUTES
,
6620 _("The which-jobs value \"%s\" is not supported."),
6621 attr
->values
[0].string
.text
);
6622 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
6623 "which-jobs", NULL
, attr
->values
[0].string
.text
);
6628 * See if they want to limit the number of jobs reported...
6631 if ((attr
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
)) != NULL
)
6635 send_ipp_status(con
, IPP_CONFLICT
,
6636 _("The %s attribute cannot be provided with job-ids."),
6641 limit
= attr
->values
[0].integer
;
6644 if ((attr
= ippFindAttribute(con
->request
, "first-index", IPP_TAG_INTEGER
)) != NULL
)
6648 send_ipp_status(con
, IPP_CONFLICT
,
6649 _("The %s attribute cannot be provided with job-ids."),
6654 first_index
= attr
->values
[0].integer
;
6656 else if ((attr
= ippFindAttribute(con
->request
, "first-job-id", IPP_TAG_INTEGER
)) != NULL
)
6660 send_ipp_status(con
, IPP_CONFLICT
,
6661 _("The %s attribute cannot be provided with job-ids."),
6666 first_job_id
= attr
->values
[0].integer
;
6670 * See if we only want to see jobs for a specific user...
6673 if ((attr
= ippFindAttribute(con
->request
, "my-jobs", IPP_TAG_BOOLEAN
)) != NULL
&& job_ids
)
6675 send_ipp_status(con
, IPP_CONFLICT
,
6676 _("The %s attribute cannot be provided with job-ids."),
6680 else if (attr
&& attr
->values
[0].boolean
)
6681 strlcpy(username
, get_username(con
), sizeof(username
));
6685 ra
= create_requested_array(con
->request
);
6686 for (job_attr
= (char *)cupsArrayFirst(ra
); job_attr
; job_attr
= (char *)cupsArrayNext(ra
))
6687 if (strcmp(job_attr
, "job-id") &&
6688 strcmp(job_attr
, "job-k-octets") &&
6689 strcmp(job_attr
, "job-media-progress") &&
6690 strcmp(job_attr
, "job-more-info") &&
6691 strcmp(job_attr
, "job-name") &&
6692 strcmp(job_attr
, "job-originating-user-name") &&
6693 strcmp(job_attr
, "job-preserved") &&
6694 strcmp(job_attr
, "job-printer-up-time") &&
6695 strcmp(job_attr
, "job-printer-uri") &&
6696 strcmp(job_attr
, "job-state") &&
6697 strcmp(job_attr
, "job-state-reasons") &&
6698 strcmp(job_attr
, "job-uri") &&
6699 strcmp(job_attr
, "time-at-completed") &&
6700 strcmp(job_attr
, "time-at-creation") &&
6701 strcmp(job_attr
, "number-of-documents"))
6707 if (need_load_job
&& (limit
== 0 || limit
> 500) && (list
== Jobs
|| delete_list
))
6710 * Limit expensive Get-Jobs for job history to 500 jobs...
6713 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
, "limit", 500);
6716 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
, "limit", limit
);
6720 cupsdLogClient(con
, CUPSD_LOG_INFO
, "Limiting Get-Jobs response to %d jobs.", limit
);
6724 * OK, build a list of jobs for this printer...
6729 int i
; /* Looping var */
6731 for (i
= 0; i
< job_ids
->num_values
; i
++)
6733 if (!cupsdFindJob(job_ids
->values
[i
].integer
))
6737 if (i
< job_ids
->num_values
)
6739 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
6740 job_ids
->values
[i
].integer
);
6744 for (i
= 0; i
< job_ids
->num_values
; i
++)
6746 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
6748 if (need_load_job
&& !job
->attrs
)
6754 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d", job
->id
);
6760 ippAddSeparator(con
->response
);
6762 exclude
= cupsdGetPrivateAttrs(job
->printer
?
6763 job
->printer
->op_policy_ptr
:
6764 policy
, con
, job
->printer
,
6767 copy_job_attrs(con
, job
, ra
, exclude
);
6772 if (first_index
> 1)
6773 job
= (cupsd_job_t
*)cupsArrayIndex(list
, first_index
- 1);
6775 job
= (cupsd_job_t
*)cupsArrayFirst(list
);
6777 for (count
= 0; (limit
<= 0 || count
< limit
) && job
; job
= (cupsd_job_t
*)cupsArrayNext(list
))
6780 * Filter out jobs that don't match...
6783 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
6784 "get_jobs: job->id=%d, dest=\"%s\", username=\"%s\", "
6785 "state_value=%d, attrs=%p", job
->id
, job
->dest
,
6786 job
->username
, job
->state_value
, job
->attrs
);
6788 if (!job
->dest
|| !job
->username
)
6791 if (!job
->dest
|| !job
->username
)
6794 if ((dest
&& strcmp(job
->dest
, dest
)) &&
6795 (!job
->printer
|| !dest
|| strcmp(job
->printer
->name
, dest
)))
6797 if ((job
->dtype
& dmask
) != dtype
&&
6798 (!job
->printer
|| (job
->printer
->type
& dmask
) != dtype
))
6801 if ((job_comparison
< 0 && job
->state_value
> job_state
) ||
6802 (job_comparison
== 0 && job
->state_value
!= job_state
) ||
6803 (job_comparison
> 0 && job
->state_value
< job_state
))
6806 if (job
->id
< first_job_id
)
6809 if (need_load_job
&& !job
->attrs
)
6815 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d", job
->id
);
6820 if (username
[0] && _cups_strcasecmp(username
, job
->username
))
6824 ippAddSeparator(con
->response
);
6828 exclude
= cupsdGetPrivateAttrs(job
->printer
?
6829 job
->printer
->op_policy_ptr
:
6830 policy
, con
, job
->printer
,
6833 copy_job_attrs(con
, job
, ra
, exclude
);
6836 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: count=%d", count
);
6839 cupsArrayDelete(ra
);
6842 cupsArrayDelete(list
);
6844 con
->response
->request
.status
.status_code
= IPP_OK
;
6849 * 'get_notifications()' - Get events for a subscription.
6853 get_notifications(cupsd_client_t
*con
) /* I - Client connection */
6855 int i
, j
; /* Looping vars */
6856 http_status_t status
; /* Policy status */
6857 cupsd_subscription_t
*sub
; /* Subscription */
6858 ipp_attribute_t
*ids
, /* notify-subscription-ids */
6859 *sequences
; /* notify-sequence-numbers */
6860 int min_seq
; /* Minimum sequence number */
6861 int interval
; /* Poll interval */
6864 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_notifications(con=%p[%d])",
6868 * Get subscription attributes...
6871 ids
= ippFindAttribute(con
->request
, "notify-subscription-ids",
6873 sequences
= ippFindAttribute(con
->request
, "notify-sequence-numbers",
6878 send_ipp_status(con
, IPP_BAD_REQUEST
,
6879 _("Missing notify-subscription-ids attribute."));
6884 * Are the subscription IDs valid?
6887 for (i
= 0, interval
= 60; i
< ids
->num_values
; i
++)
6889 if ((sub
= cupsdFindSubscription(ids
->values
[i
].integer
)) == NULL
)
6892 * Bad subscription ID...
6895 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
6896 ids
->values
[i
].integer
);
6904 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
6906 con
, sub
->owner
)) != HTTP_OK
)
6908 send_http_error(con
, status
, sub
->dest
);
6913 * Check the subscription type and update the interval accordingly.
6916 if (sub
->job
&& sub
->job
->state_value
== IPP_JOB_PROCESSING
&&
6919 else if (sub
->job
&& sub
->job
->state_value
>= IPP_JOB_STOPPED
)
6921 else if (sub
->dest
&& sub
->dest
->state
== IPP_PRINTER_PROCESSING
&&
6927 * Tell the client to poll again in N seconds...
6931 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
6932 "notify-get-interval", interval
);
6934 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
6935 "printer-up-time", time(NULL
));
6938 * Copy the subscription event attributes to the response.
6941 con
->response
->request
.status
.status_code
=
6942 interval
? IPP_OK
: IPP_OK_EVENTS_COMPLETE
;
6944 for (i
= 0; i
< ids
->num_values
; i
++)
6947 * Get the subscription and sequence number...
6950 sub
= cupsdFindSubscription(ids
->values
[i
].integer
);
6952 if (sequences
&& i
< sequences
->num_values
)
6953 min_seq
= sequences
->values
[i
].integer
;
6958 * If we don't have any new events, nothing to do here...
6961 if (min_seq
> (sub
->first_event_id
+ cupsArrayCount(sub
->events
)))
6965 * Otherwise copy all of the new events...
6968 if (sub
->first_event_id
> min_seq
)
6971 j
= min_seq
- sub
->first_event_id
;
6973 for (; j
< cupsArrayCount(sub
->events
); j
++)
6975 ippAddSeparator(con
->response
);
6977 copy_attrs(con
->response
,
6978 ((cupsd_event_t
*)cupsArrayIndex(sub
->events
, j
))->attrs
, NULL
,
6979 IPP_TAG_EVENT_NOTIFICATION
, 0, NULL
);
6986 * 'get_ppd()' - Get a named PPD from the local system.
6990 get_ppd(cupsd_client_t
*con
, /* I - Client connection */
6991 ipp_attribute_t
*uri
) /* I - Printer URI or PPD name */
6993 http_status_t status
; /* Policy status */
6994 cupsd_printer_t
*dest
; /* Destination */
6995 cups_ptype_t dtype
; /* Destination type */
6998 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppd(%p[%d], %p[%s=%s])", con
,
6999 con
->number
, uri
, uri
->name
, uri
->values
[0].string
.text
);
7001 if (!strcmp(ippGetName(uri
), "ppd-name"))
7004 * Return a PPD file from cups-driverd...
7007 const char *ppd_name
= ippGetString(uri
, 0, NULL
);
7008 /* ppd-name value */
7009 char command
[1024], /* cups-driverd command */
7010 options
[1024], /* Options to pass to command */
7011 oppd_name
[1024]; /* Escaped ppd-name */
7017 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7019 send_http_error(con
, status
, NULL
);
7024 * Check ppd-name value...
7027 if (strstr(ppd_name
, "../"))
7029 send_ipp_status(con
, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES
, _("Invalid ppd-name value."));
7034 * Run cups-driverd command with the given options...
7037 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7038 url_encode_string(ppd_name
, oppd_name
, sizeof(oppd_name
));
7039 snprintf(options
, sizeof(options
), "get+%d+%s", ippGetRequestId(con
->request
), oppd_name
);
7041 if (cupsdSendCommand(con
, command
, options
, 0))
7044 * Command started successfully, don't send an IPP response here...
7047 ippDelete(con
->response
);
7048 con
->response
= NULL
;
7053 * Command failed, return "internal error" so the user knows something
7057 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("cups-driverd failed to execute."));
7060 else if (!strcmp(ippGetName(uri
), "printer-uri") && cupsdValidateDest(ippGetString(uri
, 0, NULL
), &dtype
, &dest
))
7062 int i
; /* Looping var */
7063 char filename
[1024]; /* PPD filename */
7069 if ((status
= cupsdCheckPolicy(dest
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7071 send_http_error(con
, status
, dest
);
7076 * See if we need the PPD for a class or remote printer...
7079 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
, dest
->name
);
7081 if ((dtype
& CUPS_PRINTER_REMOTE
) && access(filename
, 0))
7083 send_ipp_status(con
, IPP_STATUS_CUPS_SEE_OTHER
, _("See remote printer."));
7084 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
, dest
->uri
);
7087 else if (dtype
& CUPS_PRINTER_CLASS
)
7089 for (i
= 0; i
< dest
->num_printers
; i
++)
7090 if (!(dest
->printers
[i
]->type
& CUPS_PRINTER_CLASS
))
7092 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
, dest
->printers
[i
]->name
);
7094 if (!access(filename
, 0))
7098 if (i
< dest
->num_printers
)
7099 dest
= dest
->printers
[i
];
7102 send_ipp_status(con
, IPP_STATUS_CUPS_SEE_OTHER
, _("See remote printer."));
7103 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
, dest
->printers
[0]->uri
);
7109 * Found the printer with the PPD file, now see if there is one...
7112 if ((con
->file
= open(filename
, O_RDONLY
)) < 0)
7114 send_ipp_status(con
, IPP_STATUS_ERROR_NOT_FOUND
, _("The PPD file \"%s\" could not be opened: %s"), ippGetString(uri
, 0, NULL
), strerror(errno
));
7118 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
7122 ippSetStatusCode(con
->response
, IPP_STATUS_OK
);
7125 send_ipp_status(con
, IPP_STATUS_ERROR_NOT_FOUND
, _("The PPD file \"%s\" could not be found."), ippGetString(uri
, 0, NULL
));
7130 * 'get_ppds()' - Get the list of PPD files on the local system.
7134 get_ppds(cupsd_client_t
*con
) /* I - Client connection */
7136 http_status_t status
; /* Policy status */
7137 ipp_attribute_t
*limit
, /* Limit attribute */
7138 *device
, /* ppd-device-id attribute */
7139 *language
, /* ppd-natural-language attribute */
7140 *make
, /* ppd-make attribute */
7141 *model
, /* ppd-make-and-model attribute */
7142 *model_number
, /* ppd-model-number attribute */
7143 *product
, /* ppd-product attribute */
7144 *psversion
, /* ppd-psverion attribute */
7145 *type
, /* ppd-type attribute */
7146 *requested
, /* requested-attributes attribute */
7147 *exclude
, /* exclude-schemes attribute */
7148 *include
; /* include-schemes attribute */
7149 char command
[1024], /* cups-driverd command */
7150 options
[4096], /* Options to pass to command */
7151 device_str
[256],/* Escaped ppd-device-id string */
7153 /* Escaped ppd-natural-language */
7154 make_str
[256], /* Escaped ppd-make string */
7155 model_str
[256], /* Escaped ppd-make-and-model string */
7156 model_number_str
[256],
7157 /* ppd-model-number string */
7159 /* Escaped ppd-product string */
7161 /* Escaped ppd-psversion string */
7162 type_str
[256], /* Escaped ppd-type string */
7164 /* String for requested attributes */
7166 /* String for excluded schemes */
7168 /* String for included schemes */
7171 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppds(%p[%d])", con
, con
->number
);
7177 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7179 send_http_error(con
, status
, NULL
);
7184 * Run cups-driverd command with the given options...
7187 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
7188 device
= ippFindAttribute(con
->request
, "ppd-device-id", IPP_TAG_TEXT
);
7189 language
= ippFindAttribute(con
->request
, "ppd-natural-language",
7191 make
= ippFindAttribute(con
->request
, "ppd-make", IPP_TAG_TEXT
);
7192 model
= ippFindAttribute(con
->request
, "ppd-make-and-model",
7194 model_number
= ippFindAttribute(con
->request
, "ppd-model-number",
7196 product
= ippFindAttribute(con
->request
, "ppd-product", IPP_TAG_TEXT
);
7197 psversion
= ippFindAttribute(con
->request
, "ppd-psversion", IPP_TAG_TEXT
);
7198 type
= ippFindAttribute(con
->request
, "ppd-type", IPP_TAG_KEYWORD
);
7199 requested
= ippFindAttribute(con
->request
, "requested-attributes",
7201 exclude
= ippFindAttribute(con
->request
, "exclude-schemes",
7203 include
= ippFindAttribute(con
->request
, "include-schemes",
7207 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
7209 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
7212 url_encode_attr(device
, device_str
, sizeof(device_str
));
7214 device_str
[0] = '\0';
7217 url_encode_attr(language
, language_str
, sizeof(language_str
));
7219 language_str
[0] = '\0';
7222 url_encode_attr(make
, make_str
, sizeof(make_str
));
7227 url_encode_attr(model
, model_str
, sizeof(model_str
));
7229 model_str
[0] = '\0';
7232 snprintf(model_number_str
, sizeof(model_number_str
), "ppd-model-number=%d",
7233 model_number
->values
[0].integer
);
7235 model_number_str
[0] = '\0';
7238 url_encode_attr(product
, product_str
, sizeof(product_str
));
7240 product_str
[0] = '\0';
7243 url_encode_attr(psversion
, psversion_str
, sizeof(psversion_str
));
7245 psversion_str
[0] = '\0';
7248 url_encode_attr(type
, type_str
, sizeof(type_str
));
7253 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
7255 exclude_str
[0] = '\0';
7258 url_encode_attr(include
, include_str
, sizeof(include_str
));
7260 include_str
[0] = '\0';
7262 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7263 snprintf(options
, sizeof(options
),
7264 "list+%d+%d+%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
7265 con
->request
->request
.op
.request_id
,
7266 limit
? limit
->values
[0].integer
: 0,
7268 device
? "%20" : "", device_str
,
7269 language
? "%20" : "", language_str
,
7270 make
? "%20" : "", make_str
,
7271 model
? "%20" : "", model_str
,
7272 model_number
? "%20" : "", model_number_str
,
7273 product
? "%20" : "", product_str
,
7274 psversion
? "%20" : "", psversion_str
,
7275 type
? "%20" : "", type_str
,
7276 exclude_str
[0] ? "%20" : "", exclude_str
,
7277 include_str
[0] ? "%20" : "", include_str
);
7279 if (cupsdSendCommand(con
, command
, options
, 0))
7282 * Command started successfully, don't send an IPP response here...
7285 ippDelete(con
->response
);
7286 con
->response
= NULL
;
7291 * Command failed, return "internal error" so the user knows something
7295 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7296 _("cups-driverd failed to execute."));
7302 * 'get_printer_attrs()' - Get printer attributes.
7306 get_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
7307 ipp_attribute_t
*uri
) /* I - Printer URI */
7309 http_status_t status
; /* Policy status */
7310 cups_ptype_t dtype
; /* Destination type (printer/class) */
7311 cupsd_printer_t
*printer
; /* Printer/class */
7312 cups_array_t
*ra
; /* Requested attributes array */
7315 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_attrs(%p[%d], %s)", con
,
7316 con
->number
, uri
->values
[0].string
.text
);
7319 * Is the destination valid?
7322 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7328 send_ipp_status(con
, IPP_NOT_FOUND
,
7329 _("The printer or class does not exist."));
7337 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7339 send_http_error(con
, status
, printer
);
7344 * Send the attributes...
7347 ra
= create_requested_array(con
->request
);
7349 copy_printer_attrs(con
, printer
, ra
);
7351 cupsArrayDelete(ra
);
7353 con
->response
->request
.status
.status_code
= IPP_OK
;
7358 * 'get_printer_supported()' - Get printer supported values.
7362 get_printer_supported(
7363 cupsd_client_t
*con
, /* I - Client connection */
7364 ipp_attribute_t
*uri
) /* I - Printer URI */
7366 http_status_t status
; /* Policy status */
7367 cups_ptype_t dtype
; /* Destination type (printer/class) */
7368 cupsd_printer_t
*printer
; /* Printer/class */
7371 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_supported(%p[%d], %s)", con
,
7372 con
->number
, uri
->values
[0].string
.text
);
7375 * Is the destination valid?
7378 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7384 send_ipp_status(con
, IPP_NOT_FOUND
,
7385 _("The printer or class does not exist."));
7393 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7395 send_http_error(con
, status
, printer
);
7400 * Return a list of attributes that can be set via Set-Printer-Attributes.
7403 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7404 "printer-geo-location", 0);
7405 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7407 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7408 "printer-location", 0);
7409 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7410 "printer-organization", 0);
7411 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7412 "printer-organizational-unit", 0);
7414 con
->response
->request
.status
.status_code
= IPP_OK
;
7419 * 'get_printers()' - Get a list of printers or classes.
7423 get_printers(cupsd_client_t
*con
, /* I - Client connection */
7424 int type
) /* I - 0 or CUPS_PRINTER_CLASS */
7426 http_status_t status
; /* Policy status */
7427 ipp_attribute_t
*attr
; /* Current attribute */
7428 int limit
; /* Max number of printers to return */
7429 int count
; /* Number of printers that match */
7430 cupsd_printer_t
*printer
; /* Current printer pointer */
7431 cups_ptype_t printer_type
, /* printer-type attribute */
7432 printer_mask
; /* printer-type-mask attribute */
7433 char *location
; /* Location string */
7434 const char *username
; /* Current user */
7435 char *first_printer_name
; /* first-printer-name attribute */
7436 cups_array_t
*ra
; /* Requested attributes array */
7437 int local
; /* Local connection? */
7440 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printers(%p[%d], %x)", con
,
7447 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7449 send_http_error(con
, status
, NULL
);
7454 * Check for printers...
7457 if (!Printers
|| !cupsArrayCount(Printers
))
7459 send_ipp_status(con
, IPP_NOT_FOUND
, _("No destinations added."));
7464 * See if they want to limit the number of printers reported...
7467 if ((attr
= ippFindAttribute(con
->request
, "limit",
7468 IPP_TAG_INTEGER
)) != NULL
)
7469 limit
= attr
->values
[0].integer
;
7473 if ((attr
= ippFindAttribute(con
->request
, "first-printer-name",
7474 IPP_TAG_NAME
)) != NULL
)
7475 first_printer_name
= attr
->values
[0].string
.text
;
7477 first_printer_name
= NULL
;
7480 * Support filtering...
7483 if ((attr
= ippFindAttribute(con
->request
, "printer-type",
7484 IPP_TAG_ENUM
)) != NULL
)
7485 printer_type
= (cups_ptype_t
)attr
->values
[0].integer
;
7487 printer_type
= (cups_ptype_t
)0;
7489 if ((attr
= ippFindAttribute(con
->request
, "printer-type-mask",
7490 IPP_TAG_ENUM
)) != NULL
)
7491 printer_mask
= (cups_ptype_t
)attr
->values
[0].integer
;
7493 printer_mask
= (cups_ptype_t
)0;
7495 local
= httpAddrLocalhost(&(con
->clientaddr
));
7497 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
7498 IPP_TAG_TEXT
)) != NULL
)
7499 location
= attr
->values
[0].string
.text
;
7503 if (con
->username
[0])
7504 username
= con
->username
;
7505 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7506 IPP_TAG_NAME
)) != NULL
)
7507 username
= attr
->values
[0].string
.text
;
7511 ra
= create_requested_array(con
->request
);
7514 * OK, build a list of printers for this printer...
7517 if (first_printer_name
)
7519 if ((printer
= cupsdFindDest(first_printer_name
)) == NULL
)
7520 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7523 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7526 count
< limit
&& printer
;
7527 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
7529 if (!local
&& !printer
->shared
)
7532 if ((!type
|| (printer
->type
& CUPS_PRINTER_CLASS
) == type
) &&
7533 (printer
->type
& printer_mask
) == printer_type
&&
7535 (printer
->location
&& !_cups_strcasecmp(printer
->location
, location
))))
7538 * If a username is specified, see if it is allowed or denied
7542 if (cupsArrayCount(printer
->users
) && username
&&
7543 !user_allowed(printer
, username
))
7547 * Add the group separator as needed...
7551 ippAddSeparator(con
->response
);
7556 * Send the attributes...
7559 copy_printer_attrs(con
, printer
, ra
);
7563 cupsArrayDelete(ra
);
7565 con
->response
->request
.status
.status_code
= IPP_OK
;
7570 * 'get_subscription_attrs()' - Get subscription attributes.
7574 get_subscription_attrs(
7575 cupsd_client_t
*con
, /* I - Client connection */
7576 int sub_id
) /* I - Subscription ID */
7578 http_status_t status
; /* Policy status */
7579 cupsd_subscription_t
*sub
; /* Subscription */
7580 cupsd_policy_t
*policy
; /* Current security policy */
7581 cups_array_t
*ra
, /* Requested attributes array */
7582 *exclude
; /* Private attributes array */
7585 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7586 "get_subscription_attrs(con=%p[%d], sub_id=%d)",
7587 con
, con
->number
, sub_id
);
7590 * Expire subscriptions as needed...
7593 cupsdExpireSubscriptions(NULL
, NULL
);
7596 * Is the subscription ID valid?
7599 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
7602 * Bad subscription ID...
7605 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
7615 policy
= sub
->dest
->op_policy_ptr
;
7617 policy
= DefaultPolicyPtr
;
7619 if ((status
= cupsdCheckPolicy(policy
, con
, sub
->owner
)) != HTTP_OK
)
7621 send_http_error(con
, status
, sub
->dest
);
7625 exclude
= cupsdGetPrivateAttrs(policy
, con
, sub
->dest
, sub
->owner
);
7628 * Copy the subscription attributes to the response using the
7629 * requested-attributes attribute that may be provided by the client.
7632 ra
= create_requested_array(con
->request
);
7634 copy_subscription_attrs(con
, sub
, ra
, exclude
);
7636 cupsArrayDelete(ra
);
7638 con
->response
->request
.status
.status_code
= IPP_OK
;
7643 * 'get_subscriptions()' - Get subscriptions.
7647 get_subscriptions(cupsd_client_t
*con
, /* I - Client connection */
7648 ipp_attribute_t
*uri
) /* I - Printer/job URI */
7650 http_status_t status
; /* Policy status */
7651 int count
; /* Number of subscriptions */
7652 int limit
; /* Limit */
7653 cupsd_subscription_t
*sub
; /* Subscription */
7654 cups_array_t
*ra
; /* Requested attributes array */
7655 ipp_attribute_t
*attr
; /* Attribute */
7656 cups_ptype_t dtype
; /* Destination type (printer/class) */
7657 char scheme
[HTTP_MAX_URI
],
7658 /* Scheme portion of URI */
7659 username
[HTTP_MAX_URI
],
7660 /* Username portion of URI */
7662 /* Host portion of URI */
7663 resource
[HTTP_MAX_URI
];
7664 /* Resource portion of URI */
7665 int port
; /* Port portion of URI */
7666 cupsd_job_t
*job
; /* Job pointer */
7667 cupsd_printer_t
*printer
; /* Printer */
7668 cupsd_policy_t
*policy
; /* Policy */
7669 cups_array_t
*exclude
; /* Private attributes array */
7672 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7673 "get_subscriptions(con=%p[%d], uri=%s)",
7674 con
, con
->number
, uri
->values
[0].string
.text
);
7677 * Is the destination valid?
7680 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7681 sizeof(scheme
), username
, sizeof(username
), host
,
7682 sizeof(host
), &port
, resource
, sizeof(resource
));
7684 if (!strcmp(resource
, "/") ||
7685 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6) ||
7686 (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10) ||
7687 (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9))
7692 else if (!strncmp(resource
, "/jobs/", 6) && resource
[6])
7695 job
= cupsdFindJob(atoi(resource
+ 6));
7699 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
7700 atoi(resource
+ 6));
7704 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7710 send_ipp_status(con
, IPP_NOT_FOUND
,
7711 _("The printer or class does not exist."));
7714 else if ((attr
= ippFindAttribute(con
->request
, "notify-job-id",
7715 IPP_TAG_INTEGER
)) != NULL
)
7717 job
= cupsdFindJob(attr
->values
[0].integer
);
7721 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
7722 attr
->values
[0].integer
);
7734 policy
= printer
->op_policy_ptr
;
7736 policy
= DefaultPolicyPtr
;
7738 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
7740 send_http_error(con
, status
, printer
);
7745 * Expire subscriptions as needed...
7748 cupsdExpireSubscriptions(NULL
, NULL
);
7751 * Copy the subscription attributes to the response using the
7752 * requested-attributes attribute that may be provided by the client.
7755 ra
= create_requested_array(con
->request
);
7757 if ((attr
= ippFindAttribute(con
->request
, "limit",
7758 IPP_TAG_INTEGER
)) != NULL
)
7759 limit
= attr
->values
[0].integer
;
7764 * See if we only want to see subscriptions for a specific user...
7767 if ((attr
= ippFindAttribute(con
->request
, "my-subscriptions",
7768 IPP_TAG_BOOLEAN
)) != NULL
&&
7769 attr
->values
[0].boolean
)
7770 strlcpy(username
, get_username(con
), sizeof(username
));
7774 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
), count
= 0;
7776 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
7777 if ((!printer
|| sub
->dest
== printer
) && (!job
|| sub
->job
== job
) &&
7778 (!username
[0] || !_cups_strcasecmp(username
, sub
->owner
)))
7780 ippAddSeparator(con
->response
);
7782 exclude
= cupsdGetPrivateAttrs(sub
->dest
? sub
->dest
->op_policy_ptr
:
7783 policy
, con
, sub
->dest
,
7786 copy_subscription_attrs(con
, sub
, ra
, exclude
);
7789 if (limit
&& count
>= limit
)
7793 cupsArrayDelete(ra
);
7796 con
->response
->request
.status
.status_code
= IPP_OK
;
7798 send_ipp_status(con
, IPP_NOT_FOUND
, _("No subscriptions found."));
7803 * 'get_username()' - Get the username associated with a request.
7806 static const char * /* O - Username */
7807 get_username(cupsd_client_t
*con
) /* I - Connection */
7809 ipp_attribute_t
*attr
; /* Attribute */
7812 if (con
->username
[0])
7813 return (con
->username
);
7814 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7815 IPP_TAG_NAME
)) != NULL
)
7816 return (attr
->values
[0].string
.text
);
7818 return ("anonymous");
7823 * 'hold_job()' - Hold a print job.
7827 hold_job(cupsd_client_t
*con
, /* I - Client connection */
7828 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
7830 ipp_attribute_t
*attr
; /* Current job-hold-until */
7831 const char *when
; /* New value */
7832 int jobid
; /* Job ID */
7833 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
7834 username
[HTTP_MAX_URI
], /* Username portion of URI */
7835 host
[HTTP_MAX_URI
], /* Host portion of URI */
7836 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7837 int port
; /* Port portion of URI */
7838 cupsd_job_t
*job
; /* Job information */
7841 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_job(%p[%d], %s)", con
, con
->number
,
7842 uri
->values
[0].string
.text
);
7845 * See if we have a job URI or a printer URI...
7848 if (!strcmp(uri
->name
, "printer-uri"))
7851 * Got a printer URI; see if we also have a job-id attribute...
7854 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7855 IPP_TAG_INTEGER
)) == NULL
)
7857 send_ipp_status(con
, IPP_BAD_REQUEST
,
7858 _("Got a printer-uri attribute but no job-id."));
7862 jobid
= attr
->values
[0].integer
;
7867 * Got a job URI; parse it to get the job ID...
7870 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7871 sizeof(scheme
), username
, sizeof(username
), host
,
7872 sizeof(host
), &port
, resource
, sizeof(resource
));
7874 if (strncmp(resource
, "/jobs/", 6))
7880 send_ipp_status(con
, IPP_BAD_REQUEST
,
7881 _("Bad job-uri \"%s\"."),
7882 uri
->values
[0].string
.text
);
7886 jobid
= atoi(resource
+ 6);
7890 * See if the job exists...
7893 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7896 * Nope - return a "not found" error...
7899 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
7904 * See if the job is owned by the requesting user...
7907 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7909 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
7910 cupsdFindDest(job
->dest
));
7915 * See if the job is in a state that allows holding...
7918 if (job
->state_value
> IPP_JOB_STOPPED
)
7921 * Return a "not-possible" error...
7924 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
7925 _("Job #%d is finished and cannot be altered."),
7931 * Hold the job and return...
7934 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
7935 IPP_TAG_KEYWORD
)) == NULL
)
7936 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
7940 when
= attr
->values
[0].string
.text
;
7942 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
7943 "Job job-hold-until value changed by user.");
7946 when
= "indefinite";
7948 cupsdSetJobHoldUntil(job
, when
, 1);
7949 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
, "Job held by \"%s\".",
7952 con
->response
->request
.status
.status_code
= IPP_OK
;
7957 * 'hold_new_jobs()' - Hold pending/new jobs on a printer or class.
7961 hold_new_jobs(cupsd_client_t
*con
, /* I - Connection */
7962 ipp_attribute_t
*uri
) /* I - Printer URI */
7964 http_status_t status
; /* Policy status */
7965 cups_ptype_t dtype
; /* Destination type (printer/class) */
7966 cupsd_printer_t
*printer
; /* Printer data */
7969 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_new_jobs(%p[%d], %s)", con
,
7970 con
->number
, uri
->values
[0].string
.text
);
7973 * Is the destination valid?
7976 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7982 send_ipp_status(con
, IPP_NOT_FOUND
,
7983 _("The printer or class does not exist."));
7991 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7993 send_http_error(con
, status
, printer
);
7998 * Hold pending/new jobs sent to the printer...
8001 printer
->holding_new_jobs
= 1;
8003 cupsdSetPrinterReasons(printer
, "+hold-new-jobs");
8005 if (dtype
& CUPS_PRINTER_CLASS
)
8006 cupsdLogMessage(CUPSD_LOG_INFO
,
8007 "Class \"%s\" now holding pending/new jobs (\"%s\").",
8008 printer
->name
, get_username(con
));
8010 cupsdLogMessage(CUPSD_LOG_INFO
,
8011 "Printer \"%s\" now holding pending/new jobs (\"%s\").",
8012 printer
->name
, get_username(con
));
8015 * Everything was ok, so return OK status...
8018 con
->response
->request
.status
.status_code
= IPP_OK
;
8023 * 'move_job()' - Move a job to a new destination.
8027 move_job(cupsd_client_t
*con
, /* I - Client connection */
8028 ipp_attribute_t
*uri
) /* I - Job URI */
8030 http_status_t status
; /* Policy status */
8031 ipp_attribute_t
*attr
; /* Current attribute */
8032 int jobid
; /* Job ID */
8033 cupsd_job_t
*job
; /* Current job */
8034 const char *src
; /* Source printer/class */
8035 cups_ptype_t stype
, /* Source type (printer or class) */
8036 dtype
; /* Destination type (printer/class) */
8037 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
8038 username
[HTTP_MAX_URI
], /* Username portion of URI */
8039 host
[HTTP_MAX_URI
], /* Host portion of URI */
8040 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8041 int port
; /* Port portion of URI */
8042 cupsd_printer_t
*sprinter
, /* Source printer */
8043 *dprinter
; /* Destination printer */
8046 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "move_job(%p[%d], %s)", con
, con
->number
,
8047 uri
->values
[0].string
.text
);
8050 * Get the new printer or class...
8053 if ((attr
= ippFindAttribute(con
->request
, "job-printer-uri",
8054 IPP_TAG_URI
)) == NULL
)
8057 * Need job-printer-uri...
8060 send_ipp_status(con
, IPP_BAD_REQUEST
,
8061 _("job-printer-uri attribute missing."));
8065 if (!cupsdValidateDest(attr
->values
[0].string
.text
, &dtype
, &dprinter
))
8071 send_ipp_status(con
, IPP_NOT_FOUND
,
8072 _("The printer or class does not exist."));
8077 * See if we have a job URI or a printer URI...
8080 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8081 sizeof(scheme
), username
, sizeof(username
), host
,
8082 sizeof(host
), &port
, resource
, sizeof(resource
));
8084 if (!strcmp(uri
->name
, "printer-uri"))
8087 * Got a printer URI; see if we also have a job-id attribute...
8090 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8091 IPP_TAG_INTEGER
)) == NULL
)
8097 if ((src
= cupsdValidateDest(uri
->values
[0].string
.text
, &stype
,
8098 &sprinter
)) == NULL
)
8104 send_ipp_status(con
, IPP_NOT_FOUND
,
8105 _("The printer or class does not exist."));
8114 * Otherwise, just move a single job...
8117 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
8120 * Nope - return a "not found" error...
8123 send_ipp_status(con
, IPP_NOT_FOUND
,
8124 _("Job #%d does not exist."), attr
->values
[0].integer
);
8130 * Job found, initialize source pointers...
8141 * Got a job URI; parse it to get the job ID...
8144 if (strncmp(resource
, "/jobs/", 6))
8150 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
8151 uri
->values
[0].string
.text
);
8156 * See if the job exists...
8159 jobid
= atoi(resource
+ 6);
8161 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8164 * Nope - return a "not found" error...
8167 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
8173 * Job found, initialize source pointers...
8182 * Check the policy of the destination printer...
8185 if ((status
= cupsdCheckPolicy(dprinter
->op_policy_ptr
, con
,
8186 job
? job
->username
: NULL
)) != HTTP_OK
)
8188 send_http_error(con
, status
, dprinter
);
8193 * Now move the job or jobs...
8199 * See if the job has been completed...
8202 if (job
->state_value
> IPP_JOB_STOPPED
)
8205 * Return a "not-possible" error...
8208 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8209 _("Job #%d is finished and cannot be altered."),
8215 * See if the job is owned by the requesting user...
8218 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8220 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8221 cupsdFindDest(job
->dest
));
8226 * Move the job to a different printer or class...
8229 cupsdMoveJob(job
, dprinter
);
8234 * Got the source printer, now look through the jobs...
8237 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
8239 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
8242 * See if the job is pointing at the source printer or has not been
8246 if (_cups_strcasecmp(job
->dest
, src
) ||
8247 job
->state_value
> IPP_JOB_STOPPED
)
8251 * See if the job can be moved by the requesting user...
8254 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8258 * Move the job to a different printer or class...
8261 cupsdMoveJob(job
, dprinter
);
8266 * Start jobs if possible...
8272 * Return with "everything is OK" status...
8275 con
->response
->request
.status
.status_code
= IPP_OK
;
8280 * 'ppd_parse_line()' - Parse a PPD default line.
8283 static int /* O - 0 on success, -1 on failure */
8284 ppd_parse_line(const char *line
, /* I - Line */
8285 char *option
, /* O - Option name */
8286 int olen
, /* I - Size of option name */
8287 char *choice
, /* O - Choice name */
8288 int clen
) /* I - Size of choice name */
8291 * Verify this is a default option line...
8294 if (strncmp(line
, "*Default", 8))
8298 * Read the option name...
8301 for (line
+= 8, olen
--;
8302 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
8313 * Skip everything else up to the colon (:)...
8316 while (*line
&& *line
!= ':')
8325 * Now grab the option choice, skipping leading whitespace...
8328 while (isspace(*line
& 255))
8332 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
8343 * Return with no errors...
8351 * 'print_job()' - Print a file to a printer or class.
8355 print_job(cupsd_client_t
*con
, /* I - Client connection */
8356 ipp_attribute_t
*uri
) /* I - Printer URI */
8358 ipp_attribute_t
*attr
; /* Current attribute */
8359 ipp_attribute_t
*doc_name
; /* document-name attribute */
8360 ipp_attribute_t
*format
; /* Document-format attribute */
8361 const char *default_format
; /* document-format-default value */
8362 cupsd_job_t
*job
; /* New job */
8363 char filename
[1024]; /* Job filename */
8364 mime_type_t
*filetype
; /* Type of file */
8365 char super
[MIME_MAX_SUPER
], /* Supertype of file */
8366 type
[MIME_MAX_TYPE
], /* Subtype of file */
8367 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
8368 /* Textual name of mime type */
8369 cupsd_printer_t
*printer
; /* Printer data */
8370 struct stat fileinfo
; /* File information */
8371 int kbytes
; /* Size of file */
8372 int compression
; /* Document compression */
8375 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "print_job(%p[%d], %s)", con
, con
->number
,
8376 uri
->values
[0].string
.text
);
8379 * Validate print file attributes, for now just document-format and
8380 * compression (CUPS only supports "none" and "gzip")...
8383 compression
= CUPS_FILE_NONE
;
8385 if ((attr
= ippFindAttribute(con
->request
, "compression",
8386 IPP_TAG_KEYWORD
)) != NULL
)
8388 if (strcmp(attr
->values
[0].string
.text
, "none")
8390 && strcmp(attr
->values
[0].string
.text
, "gzip")
8391 #endif /* HAVE_LIBZ */
8394 send_ipp_status(con
, IPP_ATTRIBUTES
,
8395 _("Unsupported compression \"%s\"."),
8396 attr
->values
[0].string
.text
);
8397 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
8398 "compression", NULL
, attr
->values
[0].string
.text
);
8403 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
8404 compression
= CUPS_FILE_GZIP
;
8405 #endif /* HAVE_LIBZ */
8409 * Do we have a file to print?
8414 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file in print request."));
8419 * Is the destination valid?
8422 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
8428 send_ipp_status(con
, IPP_NOT_FOUND
,
8429 _("The printer or class does not exist."));
8434 * Is it a format we support?
8437 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
8439 ippSetName(con
->request
, &doc_name
, "document-name-supplied");
8441 if ((format
= ippFindAttribute(con
->request
, "document-format",
8442 IPP_TAG_MIMETYPE
)) != NULL
)
8445 * Grab format from client...
8448 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%255[^;]", super
,
8451 send_ipp_status(con
, IPP_BAD_REQUEST
,
8452 _("Bad document-format \"%s\"."),
8453 format
->values
[0].string
.text
);
8457 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format-supplied", NULL
, ippGetString(format
, 0, NULL
));
8459 else if ((default_format
= cupsGetOption("document-format",
8460 printer
->num_options
,
8461 printer
->options
)) != NULL
)
8464 * Use default document format...
8467 if (sscanf(default_format
, "%15[^/]/%255[^;]", super
, type
) != 2)
8469 send_ipp_status(con
, IPP_BAD_REQUEST
,
8470 _("Bad document-format \"%s\"."),
8481 strlcpy(super
, "application", sizeof(super
));
8482 strlcpy(type
, "octet-stream", sizeof(type
));
8485 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
8488 * Auto-type the file...
8491 cupsdLogMessage(CUPSD_LOG_DEBUG
, "[Job ???] Auto-typing file...");
8494 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
8495 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
8499 filetype
= mimeType(MimeDatabase
, super
, type
);
8501 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job ???] Request file type is %s/%s.",
8502 filetype
->super
, filetype
->type
);
8504 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
, filetype
->type
);
8505 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format-detected", NULL
, mimetype
);
8508 filetype
= mimeType(MimeDatabase
, super
, type
);
8512 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
8515 * Replace the document-format attribute value with the auto-typed or
8519 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
8523 ippSetString(con
->request
, &format
, 0, mimetype
);
8525 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
8526 "document-format", NULL
, mimetype
);
8530 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
8531 _("Unsupported document-format \"%s\"."),
8532 format
? format
->values
[0].string
.text
:
8533 "application/octet-stream");
8534 cupsdLogMessage(CUPSD_LOG_INFO
,
8535 "Hint: Do you have the raw file printing rules enabled?");
8538 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
8539 "document-format", NULL
, format
->values
[0].string
.text
);
8545 * Read any embedded job ticket info from PS files...
8548 if (!_cups_strcasecmp(filetype
->super
, "application") &&
8549 (!_cups_strcasecmp(filetype
->type
, "postscript") ||
8550 !_cups_strcasecmp(filetype
->type
, "pdf")))
8551 read_job_ticket(con
);
8554 * Create the job object...
8557 if ((job
= add_job(con
, printer
, filetype
)) == NULL
)
8561 * Update quota data...
8564 if (stat(con
->filename
, &fileinfo
))
8567 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
8569 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
8571 job
->koctets
+= kbytes
;
8573 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets", IPP_TAG_INTEGER
)) != NULL
)
8574 attr
->values
[0].integer
+= kbytes
;
8577 * Add the job file...
8580 if (add_file(con
, job
, filetype
, compression
))
8583 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
, job
->num_files
);
8584 if (rename(con
->filename
, filename
))
8586 cupsdLogJob(job
, CUPSD_LOG_ERROR
, "Unable to rename job document file \"%s\": %s", filename
, strerror(errno
));
8588 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to rename job document file."));
8592 cupsdClearString(&con
->filename
);
8595 * See if we need to add the ending sheet...
8598 if (cupsdTimeoutJob(job
))
8602 * Log and save the job...
8605 cupsdLogJob(job
, CUPSD_LOG_INFO
,
8606 "File of type %s/%s queued by \"%s\".",
8607 filetype
->super
, filetype
->type
, job
->username
);
8608 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "hold_until=%d", (int)job
->hold_until
);
8609 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
8610 job
->dest
, job
->username
);
8613 * Start the job if possible...
8621 * 'read_job_ticket()' - Read a job ticket embedded in a print file.
8623 * This function only gets called when printing a single PDF or PostScript
8624 * file using the Print-Job operation. It doesn't work for Create-Job +
8625 * Send-File, since the job attributes need to be set at job creation
8626 * time for banners to work. The embedded job ticket stuff is here
8627 * primarily to allow the Windows printer driver for CUPS to pass in JCL
8628 * options and IPP attributes which otherwise would be lost.
8630 * The format of a job ticket is simple:
8632 * %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
8634 * %cupsJobTicket: attr1=value1
8635 * %cupsJobTicket: attr2=value2
8637 * %cupsJobTicket: attrN=valueN
8639 * Job ticket lines must appear immediately after the first line that
8640 * specifies PostScript (%!PS-Adobe-3.0) or PDF (%PDF) format, and CUPS
8641 * stops looking for job ticket info when it finds a line that does not begin
8642 * with "%cupsJobTicket:".
8644 * The maximum length of a job ticket line, including the prefix, is
8645 * 255 characters to conform with the Adobe DSC.
8647 * Read-only attributes are rejected with a notice to the error log in
8648 * case a malicious user tries anything. Since the job ticket is read
8649 * prior to attribute validation in print_job(), job ticket attributes
8650 * will go through the same validation as IPP attributes...
8654 read_job_ticket(cupsd_client_t
*con
) /* I - Client connection */
8656 cups_file_t
*fp
; /* File to read from */
8657 char line
[256]; /* Line data */
8658 int num_options
; /* Number of options */
8659 cups_option_t
*options
; /* Options */
8660 ipp_t
*ticket
; /* New attributes */
8661 ipp_attribute_t
*attr
, /* Current attribute */
8662 *attr2
, /* Job attribute */
8663 *prev2
; /* Previous job attribute */
8667 * First open the print file...
8670 if ((fp
= cupsFileOpen(con
->filename
, "rb")) == NULL
)
8672 cupsdLogMessage(CUPSD_LOG_ERROR
,
8673 "Unable to open print file for job ticket - %s",
8679 * Skip the first line...
8682 if (cupsFileGets(fp
, line
, sizeof(line
)) == NULL
)
8684 cupsdLogMessage(CUPSD_LOG_ERROR
,
8685 "Unable to read from print file for job ticket - %s",
8691 if (strncmp(line
, "%!PS-Adobe-", 11) && strncmp(line
, "%PDF-", 5))
8694 * Not a DSC-compliant file, so no job ticket info will be available...
8702 * Read job ticket info from the file...
8708 while (cupsFileGets(fp
, line
, sizeof(line
)))
8711 * Stop at the first non-ticket line...
8714 if (strncmp(line
, "%cupsJobTicket:", 15))
8718 * Add the options to the option array...
8721 num_options
= cupsParseOptions(line
+ 15, num_options
, &options
);
8725 * Done with the file; see if we have any options...
8730 if (num_options
== 0)
8734 * OK, convert the options to an attribute list, and apply them to
8739 cupsEncodeOptions(ticket
, num_options
, options
);
8742 * See what the user wants to change.
8745 for (attr
= ticket
->attrs
; attr
; attr
= attr
->next
)
8747 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
8750 if (!strncmp(attr
->name
, "date-time-at-", 13) ||
8751 !strcmp(attr
->name
, "job-impressions-completed") ||
8752 !strcmp(attr
->name
, "job-media-sheets-completed") ||
8753 !strncmp(attr
->name
, "job-k-octets", 12) ||
8754 !strcmp(attr
->name
, "job-id") ||
8755 !strcmp(attr
->name
, "job-originating-host-name") ||
8756 !strcmp(attr
->name
, "job-originating-user-name") ||
8757 !strcmp(attr
->name
, "job-pages-completed") ||
8758 !strcmp(attr
->name
, "job-printer-uri") ||
8759 !strncmp(attr
->name
, "job-state", 9) ||
8760 !strcmp(attr
->name
, "job-uri") ||
8761 !strncmp(attr
->name
, "time-at-", 8))
8762 continue; /* Read-only attrs */
8764 if ((attr2
= ippFindAttribute(con
->request
, attr
->name
,
8765 IPP_TAG_ZERO
)) != NULL
)
8768 * Some other value; first free the old value...
8771 if (con
->request
->attrs
== attr2
)
8773 con
->request
->attrs
= attr2
->next
;
8778 for (prev2
= con
->request
->attrs
; prev2
; prev2
= prev2
->next
)
8779 if (prev2
->next
== attr2
)
8781 prev2
->next
= attr2
->next
;
8786 if (con
->request
->last
== attr2
)
8787 con
->request
->last
= prev2
;
8789 ippDeleteAttribute(NULL
, attr2
);
8793 * Add new option by copying it...
8796 ippCopyAttribute(con
->request
, attr
, 0);
8800 * Then free the attribute list and option array...
8804 cupsFreeOptions(num_options
, options
);
8809 * 'reject_jobs()' - Reject print jobs to a printer.
8813 reject_jobs(cupsd_client_t
*con
, /* I - Client connection */
8814 ipp_attribute_t
*uri
) /* I - Printer or class URI */
8816 http_status_t status
; /* Policy status */
8817 cups_ptype_t dtype
; /* Destination type (printer/class) */
8818 cupsd_printer_t
*printer
; /* Printer data */
8819 ipp_attribute_t
*attr
; /* printer-state-message text */
8822 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "reject_jobs(%p[%d], %s)", con
,
8823 con
->number
, uri
->values
[0].string
.text
);
8826 * Is the destination valid?
8829 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8835 send_ipp_status(con
, IPP_NOT_FOUND
,
8836 _("The printer or class does not exist."));
8844 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8846 send_http_error(con
, status
, printer
);
8851 * Reject jobs sent to the printer...
8854 printer
->accepting
= 0;
8856 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
8857 IPP_TAG_TEXT
)) == NULL
)
8858 strlcpy(printer
->state_message
, "Rejecting Jobs",
8859 sizeof(printer
->state_message
));
8861 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
8862 sizeof(printer
->state_message
));
8864 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
8865 "No longer accepting jobs.");
8867 if (dtype
& CUPS_PRINTER_CLASS
)
8869 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
8871 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" rejecting jobs (\"%s\").",
8872 printer
->name
, get_username(con
));
8876 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
8878 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" rejecting jobs (\"%s\").",
8879 printer
->name
, get_username(con
));
8883 * Everything was ok, so return OK status...
8886 con
->response
->request
.status
.status_code
= IPP_OK
;
8891 * 'release_held_new_jobs()' - Release pending/new jobs on a printer or class.
8895 release_held_new_jobs(
8896 cupsd_client_t
*con
, /* I - Connection */
8897 ipp_attribute_t
*uri
) /* I - Printer URI */
8899 http_status_t status
; /* Policy status */
8900 cups_ptype_t dtype
; /* Destination type (printer/class) */
8901 cupsd_printer_t
*printer
; /* Printer data */
8904 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_held_new_jobs(%p[%d], %s)", con
,
8905 con
->number
, uri
->values
[0].string
.text
);
8908 * Is the destination valid?
8911 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8917 send_ipp_status(con
, IPP_NOT_FOUND
,
8918 _("The printer or class does not exist."));
8926 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8928 send_http_error(con
, status
, printer
);
8933 * Hold pending/new jobs sent to the printer...
8936 printer
->holding_new_jobs
= 0;
8938 cupsdSetPrinterReasons(printer
, "-hold-new-jobs");
8940 if (dtype
& CUPS_PRINTER_CLASS
)
8941 cupsdLogMessage(CUPSD_LOG_INFO
,
8942 "Class \"%s\" now printing pending/new jobs (\"%s\").",
8943 printer
->name
, get_username(con
));
8945 cupsdLogMessage(CUPSD_LOG_INFO
,
8946 "Printer \"%s\" now printing pending/new jobs (\"%s\").",
8947 printer
->name
, get_username(con
));
8952 * Everything was ok, so return OK status...
8955 con
->response
->request
.status
.status_code
= IPP_OK
;
8960 * 'release_job()' - Release a held print job.
8964 release_job(cupsd_client_t
*con
, /* I - Client connection */
8965 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
8967 ipp_attribute_t
*attr
; /* Current attribute */
8968 int jobid
; /* Job ID */
8969 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
8970 username
[HTTP_MAX_URI
], /* Username portion of URI */
8971 host
[HTTP_MAX_URI
], /* Host portion of URI */
8972 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8973 int port
; /* Port portion of URI */
8974 cupsd_job_t
*job
; /* Job information */
8977 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_job(%p[%d], %s)", con
,
8978 con
->number
, uri
->values
[0].string
.text
);
8981 * See if we have a job URI or a printer URI...
8984 if (!strcmp(uri
->name
, "printer-uri"))
8987 * Got a printer URI; see if we also have a job-id attribute...
8990 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8991 IPP_TAG_INTEGER
)) == NULL
)
8993 send_ipp_status(con
, IPP_BAD_REQUEST
,
8994 _("Got a printer-uri attribute but no job-id."));
8998 jobid
= attr
->values
[0].integer
;
9003 * Got a job URI; parse it to get the job ID...
9006 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9007 sizeof(scheme
), username
, sizeof(username
), host
,
9008 sizeof(host
), &port
, resource
, sizeof(resource
));
9010 if (strncmp(resource
, "/jobs/", 6))
9016 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9017 uri
->values
[0].string
.text
);
9021 jobid
= atoi(resource
+ 6);
9025 * See if the job exists...
9028 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9031 * Nope - return a "not found" error...
9034 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9039 * See if job is "held"...
9042 if (job
->state_value
!= IPP_JOB_HELD
)
9045 * Nope - return a "not possible" error...
9048 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not held."), jobid
);
9053 * See if the job is owned by the requesting user...
9056 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9058 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9059 cupsdFindDest(job
->dest
));
9064 * Reset the job-hold-until value to "no-hold"...
9067 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9068 IPP_TAG_KEYWORD
)) == NULL
)
9069 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9073 ippSetValueTag(job
->attrs
, &attr
, IPP_TAG_KEYWORD
);
9074 ippSetString(job
->attrs
, &attr
, 0, "no-hold");
9076 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
9077 "Job job-hold-until value changed by user.");
9078 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
9082 * Release the job and return...
9085 cupsdReleaseJob(job
);
9087 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
9088 "Job released by user.");
9090 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Released by \"%s\".", username
);
9092 con
->response
->request
.status
.status_code
= IPP_OK
;
9099 * 'renew_subscription()' - Renew an existing subscription...
9104 cupsd_client_t
*con
, /* I - Client connection */
9105 int sub_id
) /* I - Subscription ID */
9107 http_status_t status
; /* Policy status */
9108 cupsd_subscription_t
*sub
; /* Subscription */
9109 ipp_attribute_t
*lease
; /* notify-lease-duration */
9112 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
9113 "renew_subscription(con=%p[%d], sub_id=%d)",
9114 con
, con
->number
, sub_id
);
9117 * Is the subscription ID valid?
9120 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
9123 * Bad subscription ID...
9126 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
9134 * Job subscriptions cannot be renewed...
9137 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9138 _("Job subscriptions cannot be renewed."));
9146 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
9148 con
, sub
->owner
)) != HTTP_OK
)
9150 send_http_error(con
, status
, sub
->dest
);
9155 * Renew the subscription...
9158 lease
= ippFindAttribute(con
->request
, "notify-lease-duration",
9161 sub
->lease
= lease
? lease
->values
[0].integer
: DefaultLeaseDuration
;
9163 if (MaxLeaseDuration
&& (sub
->lease
== 0 || sub
->lease
> MaxLeaseDuration
))
9165 cupsdLogMessage(CUPSD_LOG_INFO
,
9166 "renew_subscription: Limiting notify-lease-duration to "
9169 sub
->lease
= MaxLeaseDuration
;
9172 sub
->expire
= sub
->lease
? time(NULL
) + sub
->lease
: 0;
9174 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
9176 con
->response
->request
.status
.status_code
= IPP_OK
;
9178 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
9179 "notify-lease-duration", sub
->lease
);
9184 * 'restart_job()' - Restart an old print job.
9188 restart_job(cupsd_client_t
*con
, /* I - Client connection */
9189 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9191 ipp_attribute_t
*attr
; /* Current attribute */
9192 int jobid
; /* Job ID */
9193 cupsd_job_t
*job
; /* Job information */
9194 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9195 username
[HTTP_MAX_URI
], /* Username portion of URI */
9196 host
[HTTP_MAX_URI
], /* Host portion of URI */
9197 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9198 int port
; /* Port portion of URI */
9201 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "restart_job(%p[%d], %s)", con
,
9202 con
->number
, uri
->values
[0].string
.text
);
9205 * See if we have a job URI or a printer URI...
9208 if (!strcmp(uri
->name
, "printer-uri"))
9211 * Got a printer URI; see if we also have a job-id attribute...
9214 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9215 IPP_TAG_INTEGER
)) == NULL
)
9217 send_ipp_status(con
, IPP_BAD_REQUEST
,
9218 _("Got a printer-uri attribute but no job-id."));
9222 jobid
= attr
->values
[0].integer
;
9227 * Got a job URI; parse it to get the job ID...
9230 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9231 sizeof(scheme
), username
, sizeof(username
), host
,
9232 sizeof(host
), &port
, resource
, sizeof(resource
));
9234 if (strncmp(resource
, "/jobs/", 6))
9240 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9241 uri
->values
[0].string
.text
);
9245 jobid
= atoi(resource
+ 6);
9249 * See if the job exists...
9252 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9255 * Nope - return a "not found" error...
9258 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9263 * See if job is in any of the "completed" states...
9266 if (job
->state_value
<= IPP_JOB_PROCESSING
)
9269 * Nope - return a "not possible" error...
9272 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not complete."),
9278 * See if we have retained the job files...
9283 if (!job
->attrs
|| job
->num_files
== 0)
9286 * Nope - return a "not possible" error...
9289 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9290 _("Job #%d cannot be restarted - no files."), jobid
);
9295 * See if the job is owned by the requesting user...
9298 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9300 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9301 cupsdFindDest(job
->dest
));
9306 * See if the job-hold-until attribute is specified...
9309 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
9310 IPP_TAG_KEYWORD
)) == NULL
)
9311 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
9313 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
9316 * Return the job to a held state...
9319 cupsdLogJob(job
, CUPSD_LOG_DEBUG
,
9320 "Restarted by \"%s\" with job-hold-until=%s.",
9321 username
, attr
->values
[0].string
.text
);
9322 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
9324 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
,
9325 NULL
, job
, "Job restarted by user with job-hold-until=%s",
9326 attr
->values
[0].string
.text
);
9331 * Restart the job...
9334 cupsdRestartJob(job
);
9338 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Restarted by \"%s\".", username
);
9340 con
->response
->request
.status
.status_code
= IPP_OK
;
9345 * 'save_auth_info()' - Save authentication information for a job.
9350 cupsd_client_t
*con
, /* I - Client connection */
9351 cupsd_job_t
*job
, /* I - Job */
9352 ipp_attribute_t
*auth_info
) /* I - auth-info attribute, if any */
9354 int i
; /* Looping var */
9355 char filename
[1024]; /* Job authentication filename */
9356 cups_file_t
*fp
; /* Job authentication file */
9357 char line
[65536]; /* Line for file */
9358 cupsd_printer_t
*dest
; /* Destination printer/class */
9362 * This function saves the in-memory authentication information for
9363 * a job so that it can be used to authenticate with a remote host.
9364 * The information is stored in a file that is readable only by the
9365 * root user. The fields are Base-64 encoded, each on a separate line,
9366 * followed by random number (up to 1024) of newlines to limit the
9367 * amount of information that is exposed.
9369 * Because of the potential for exposing of authentication information,
9370 * this functionality is only enabled when running cupsd as root.
9372 * This caching only works for the Basic and BasicDigest authentication
9373 * types. Digest authentication cannot be cached this way, and in
9374 * the future Kerberos authentication may make all of this obsolete.
9376 * Authentication information is saved whenever an authenticated
9377 * Print-Job, Create-Job, or CUPS-Authenticate-Job operation is
9380 * This information is deleted after a job is completed or canceled,
9381 * so reprints may require subsequent re-authentication.
9387 if ((dest
= cupsdFindDest(job
->dest
)) == NULL
)
9391 * Create the authentication file and change permissions...
9394 snprintf(filename
, sizeof(filename
), "%s/a%05d", RequestRoot
, job
->id
);
9395 if ((fp
= cupsFileOpen(filename
, "w")) == NULL
)
9397 cupsdLogMessage(CUPSD_LOG_ERROR
,
9398 "Unable to save authentication info to \"%s\" - %s",
9399 filename
, strerror(errno
));
9403 fchown(cupsFileNumber(fp
), 0, 0);
9404 fchmod(cupsFileNumber(fp
), 0400);
9406 cupsFilePuts(fp
, "CUPSD-AUTH-V3\n");
9409 i
< (int)(sizeof(job
->auth_env
) / sizeof(job
->auth_env
[0]));
9411 cupsdClearString(job
->auth_env
+ i
);
9413 if (auth_info
&& auth_info
->num_values
== dest
->num_auth_info_required
)
9416 * Write 1 to 3 auth values...
9420 i
< auth_info
->num_values
&&
9421 i
< (int)(sizeof(job
->auth_env
) / sizeof(job
->auth_env
[0]));
9424 if (strcmp(dest
->auth_info_required
[i
], "negotiate"))
9426 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[i
].string
.text
, (int)strlen(auth_info
->values
[i
].string
.text
));
9427 cupsFilePutConf(fp
, dest
->auth_info_required
[i
], line
);
9430 cupsFilePutConf(fp
, dest
->auth_info_required
[i
],
9431 auth_info
->values
[i
].string
.text
);
9433 if (!strcmp(dest
->auth_info_required
[i
], "username"))
9434 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_USERNAME=%s",
9435 auth_info
->values
[i
].string
.text
);
9436 else if (!strcmp(dest
->auth_info_required
[i
], "domain"))
9437 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_DOMAIN=%s",
9438 auth_info
->values
[i
].string
.text
);
9439 else if (!strcmp(dest
->auth_info_required
[i
], "password"))
9440 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_PASSWORD=%s",
9441 auth_info
->values
[i
].string
.text
);
9442 else if (!strcmp(dest
->auth_info_required
[i
], "negotiate"))
9443 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_NEGOTIATE=%s",
9444 auth_info
->values
[i
].string
.text
);
9449 else if (auth_info
&& auth_info
->num_values
== 2 &&
9450 dest
->num_auth_info_required
== 1 &&
9451 !strcmp(dest
->auth_info_required
[0], "negotiate"))
9454 * Allow fallback to username+password for Kerberized queues...
9457 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[0].string
.text
, (int)strlen(auth_info
->values
[0].string
.text
));
9458 cupsFilePutConf(fp
, "username", line
);
9460 cupsdSetStringf(job
->auth_env
+ 0, "AUTH_USERNAME=%s",
9461 auth_info
->values
[0].string
.text
);
9463 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[1].string
.text
, (int)strlen(auth_info
->values
[1].string
.text
));
9464 cupsFilePutConf(fp
, "password", line
);
9466 cupsdSetStringf(job
->auth_env
+ 1, "AUTH_PASSWORD=%s",
9467 auth_info
->values
[1].string
.text
);
9469 else if (con
->username
[0])
9472 * Write the authenticated username...
9475 httpEncode64_2(line
, sizeof(line
), con
->username
, (int)strlen(con
->username
));
9476 cupsFilePutConf(fp
, "username", line
);
9478 cupsdSetStringf(job
->auth_env
+ 0, "AUTH_USERNAME=%s", con
->username
);
9481 * Write the authenticated password...
9484 httpEncode64_2(line
, sizeof(line
), con
->password
, (int)strlen(con
->password
));
9485 cupsFilePutConf(fp
, "password", line
);
9487 cupsdSetStringf(job
->auth_env
+ 1, "AUTH_PASSWORD=%s", con
->password
);
9491 if (con
->gss_uid
> 0)
9493 cupsFilePrintf(fp
, "uid %d\n", (int)con
->gss_uid
);
9494 cupsdSetStringf(&job
->auth_uid
, "AUTH_UID=%d", (int)con
->gss_uid
);
9496 #endif /* HAVE_GSSAPI */
9499 * Write a random number of newlines to the end of the file...
9502 for (i
= (CUPS_RAND() % 1024); i
>= 0; i
--)
9503 cupsFilePutChar(fp
, '\n');
9506 * Close the file and return...
9514 * 'send_document()' - Send a file to a printer or class.
9518 send_document(cupsd_client_t
*con
, /* I - Client connection */
9519 ipp_attribute_t
*uri
) /* I - Printer URI */
9521 ipp_attribute_t
*attr
; /* Current attribute */
9522 ipp_attribute_t
*format
; /* Request's document-format attribute */
9523 ipp_attribute_t
*jformat
; /* Job's document-format attribute */
9524 const char *default_format
;/* document-format-default value */
9525 int jobid
; /* Job ID number */
9526 cupsd_job_t
*job
; /* Current job */
9527 char job_uri
[HTTP_MAX_URI
],
9529 scheme
[HTTP_MAX_URI
],
9530 /* Method portion of URI */
9531 username
[HTTP_MAX_URI
],
9532 /* Username portion of URI */
9534 /* Host portion of URI */
9535 resource
[HTTP_MAX_URI
];
9536 /* Resource portion of URI */
9537 int port
; /* Port portion of URI */
9538 mime_type_t
*filetype
; /* Type of file */
9539 char super
[MIME_MAX_SUPER
],
9540 /* Supertype of file */
9541 type
[MIME_MAX_TYPE
],
9542 /* Subtype of file */
9543 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
9544 /* Textual name of mime type */
9545 char filename
[1024]; /* Job filename */
9546 cupsd_printer_t
*printer
; /* Current printer */
9547 struct stat fileinfo
; /* File information */
9548 int kbytes
; /* Size of file */
9549 int compression
; /* Type of compression */
9550 int start_job
; /* Start the job? */
9553 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "send_document(%p[%d], %s)", con
,
9554 con
->number
, uri
->values
[0].string
.text
);
9557 * See if we have a job URI or a printer URI...
9560 if (!strcmp(uri
->name
, "printer-uri"))
9563 * Got a printer URI; see if we also have a job-id attribute...
9566 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9567 IPP_TAG_INTEGER
)) == NULL
)
9569 send_ipp_status(con
, IPP_BAD_REQUEST
,
9570 _("Got a printer-uri attribute but no job-id."));
9574 jobid
= attr
->values
[0].integer
;
9579 * Got a job URI; parse it to get the job ID...
9582 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9583 sizeof(scheme
), username
, sizeof(username
), host
,
9584 sizeof(host
), &port
, resource
, sizeof(resource
));
9586 if (strncmp(resource
, "/jobs/", 6))
9592 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9593 uri
->values
[0].string
.text
);
9597 jobid
= atoi(resource
+ 6);
9601 * See if the job exists...
9604 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9607 * Nope - return a "not found" error...
9610 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9614 printer
= cupsdFindDest(job
->dest
);
9617 * See if the job is owned by the requesting user...
9620 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9622 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9623 cupsdFindDest(job
->dest
));
9628 * OK, see if the client is sending the document compressed - CUPS
9629 * only supports "none" and "gzip".
9632 compression
= CUPS_FILE_NONE
;
9634 if ((attr
= ippFindAttribute(con
->request
, "compression",
9635 IPP_TAG_KEYWORD
)) != NULL
)
9637 if (strcmp(attr
->values
[0].string
.text
, "none")
9639 && strcmp(attr
->values
[0].string
.text
, "gzip")
9640 #endif /* HAVE_LIBZ */
9643 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Unsupported compression \"%s\"."),
9644 attr
->values
[0].string
.text
);
9645 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
9646 "compression", NULL
, attr
->values
[0].string
.text
);
9651 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
9652 compression
= CUPS_FILE_GZIP
;
9653 #endif /* HAVE_LIBZ */
9657 * Do we have a file to print?
9660 if ((attr
= ippFindAttribute(con
->request
, "last-document",
9661 IPP_TAG_BOOLEAN
)) == NULL
)
9663 send_ipp_status(con
, IPP_BAD_REQUEST
,
9664 _("Missing last-document attribute in request."));
9671 * Check for an empty request with "last-document" set to true, which is
9672 * used to close an "open" job by RFC 2911, section 3.3.2.
9675 if (job
->num_files
> 0 && attr
->values
[0].boolean
)
9678 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file in print request."));
9683 * Is it a format we support?
9688 if ((format
= ippFindAttribute(con
->request
, "document-format",
9689 IPP_TAG_MIMETYPE
)) != NULL
)
9692 * Grab format from client...
9695 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%255[^;]",
9698 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"."),
9699 format
->values
[0].string
.text
);
9703 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format-supplied", NULL
, ippGetString(format
, 0, NULL
));
9705 else if ((default_format
= cupsGetOption("document-format",
9706 printer
->num_options
,
9707 printer
->options
)) != NULL
)
9710 * Use default document format...
9713 if (sscanf(default_format
, "%15[^/]/%255[^;]", super
, type
) != 2)
9715 send_ipp_status(con
, IPP_BAD_REQUEST
,
9716 _("Bad document-format-default \"%s\"."), default_format
);
9723 * No document format attribute? Auto-type it!
9726 strlcpy(super
, "application", sizeof(super
));
9727 strlcpy(type
, "octet-stream", sizeof(type
));
9730 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
9733 * Auto-type the file...
9736 ipp_attribute_t
*doc_name
; /* document-name attribute */
9739 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Auto-typing file...");
9741 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
9742 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
9743 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
9747 filetype
= mimeType(MimeDatabase
, super
, type
);
9750 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Request file type is %s/%s.",
9751 filetype
->super
, filetype
->type
);
9753 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
, filetype
->type
);
9754 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format-detected", NULL
, mimetype
);
9757 filetype
= mimeType(MimeDatabase
, super
, type
);
9762 * Replace the document-format attribute value with the auto-typed or
9766 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9769 if ((jformat
= ippFindAttribute(job
->attrs
, "document-format",
9770 IPP_TAG_MIMETYPE
)) != NULL
)
9771 ippSetString(job
->attrs
, &jformat
, 0, mimetype
);
9773 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
9774 "document-format", NULL
, mimetype
);
9778 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9779 _("Unsupported document-format \"%s/%s\"."), super
, type
);
9780 cupsdLogMessage(CUPSD_LOG_INFO
,
9781 "Hint: Do you have the raw file printing rules enabled?");
9784 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9785 "document-format", NULL
, format
->values
[0].string
.text
);
9790 if (printer
->filetypes
&& !cupsArrayFind(printer
->filetypes
, filetype
))
9792 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9795 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9796 _("Unsupported document-format \"%s\"."), mimetype
);
9798 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9799 "document-format", NULL
, mimetype
);
9805 * Add the file to the job...
9808 if (add_file(con
, job
, filetype
, compression
))
9811 if ((attr
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
)) != NULL
)
9812 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name-supplied", NULL
, ippGetString(attr
, 0, NULL
));
9814 if (stat(con
->filename
, &fileinfo
))
9817 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
9819 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
9821 job
->koctets
+= kbytes
;
9823 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets", IPP_TAG_INTEGER
)) != NULL
)
9824 attr
->values
[0].integer
+= kbytes
;
9826 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
, job
->num_files
);
9827 if (rename(con
->filename
, filename
))
9829 cupsdLogJob(job
, CUPSD_LOG_ERROR
, "Unable to rename job document file \"%s\": %s", filename
, strerror(errno
));
9831 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to rename job document file."));
9835 cupsdClearString(&con
->filename
);
9837 cupsdLogJob(job
, CUPSD_LOG_INFO
, "File of type %s/%s queued by \"%s\".",
9838 filetype
->super
, filetype
->type
, job
->username
);
9841 * Start the job if this is the last document...
9846 if ((attr
= ippFindAttribute(con
->request
, "last-document",
9847 IPP_TAG_BOOLEAN
)) != NULL
&&
9848 attr
->values
[0].boolean
)
9851 * See if we need to add the ending sheet...
9854 if (cupsdTimeoutJob(job
))
9857 if (job
->state_value
== IPP_JOB_STOPPED
)
9859 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9860 job
->state_value
= IPP_JOB_PENDING
;
9862 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
9864 else if (job
->state_value
== IPP_JOB_HELD
)
9866 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9867 IPP_TAG_KEYWORD
)) == NULL
)
9868 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9870 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9872 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9873 job
->state_value
= IPP_JOB_PENDING
;
9875 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
9878 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-hold-until-specified");
9882 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
9888 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9889 IPP_TAG_KEYWORD
)) == NULL
)
9890 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9892 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9894 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
9895 job
->state_value
= IPP_JOB_HELD
;
9896 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
9898 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-incoming");
9901 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
9908 * Fill in the response info...
9911 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
9912 con
->clientname
, con
->clientport
, "/jobs/%d", jobid
);
9913 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
9916 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", jobid
);
9918 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
9920 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons",
9921 NULL
, job
->reasons
->values
[0].string
.text
);
9923 con
->response
->request
.status
.status_code
= IPP_OK
;
9926 * Start the job if necessary...
9935 * 'send_http_error()' - Send a HTTP error back to the IPP client.
9940 cupsd_client_t
*con
, /* I - Client connection */
9941 http_status_t status
, /* I - HTTP status code */
9942 cupsd_printer_t
*printer
) /* I - Printer, if any */
9944 ipp_attribute_t
*uri
; /* Request URI, if any */
9947 if ((uri
= ippFindAttribute(con
->request
, "printer-uri",
9948 IPP_TAG_URI
)) == NULL
)
9949 uri
= ippFindAttribute(con
->request
, "job-uri", IPP_TAG_URI
);
9951 cupsdLogMessage(status
== HTTP_FORBIDDEN
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
9952 "[Client %d] Returning HTTP %s for %s (%s) from %s",
9953 con
->number
, httpStatus(status
),
9955 ippOpString(con
->request
->request
.op
.operation_id
) :
9957 uri
? uri
->values
[0].string
.text
: "no URI",
9958 con
->http
->hostname
);
9962 int auth_type
; /* Type of authentication required */
9965 auth_type
= CUPSD_AUTH_NONE
;
9967 if (status
== HTTP_UNAUTHORIZED
&&
9968 printer
->num_auth_info_required
> 0 &&
9969 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
9971 (con
->request
->request
.op
.operation_id
== IPP_PRINT_JOB
||
9972 con
->request
->request
.op
.operation_id
== IPP_CREATE_JOB
||
9973 con
->request
->request
.op
.operation_id
== CUPS_AUTHENTICATE_JOB
))
9976 * Creating and authenticating jobs requires Kerberos...
9979 auth_type
= CUPSD_AUTH_NEGOTIATE
;
9984 * Use policy/location-defined authentication requirements...
9987 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9988 cupsd_location_t
*auth
; /* Pointer to authentication element */
9991 if (printer
->type
& CUPS_PRINTER_CLASS
)
9992 snprintf(resource
, sizeof(resource
), "/classes/%s", printer
->name
);
9994 snprintf(resource
, sizeof(resource
), "/printers/%s", printer
->name
);
9996 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
9997 auth
->type
== CUPSD_AUTH_NONE
)
9998 auth
= cupsdFindPolicyOp(printer
->op_policy_ptr
,
10000 con
->request
->request
.op
.operation_id
:
10005 if (auth
->type
== CUPSD_AUTH_DEFAULT
)
10006 auth_type
= cupsdDefaultAuthType();
10008 auth_type
= auth
->type
;
10012 cupsdSendError(con
, status
, auth_type
);
10015 cupsdSendError(con
, status
, CUPSD_AUTH_NONE
);
10017 ippDelete(con
->response
);
10018 con
->response
= NULL
;
10025 * 'send_ipp_status()' - Send a status back to the IPP client.
10029 send_ipp_status(cupsd_client_t
*con
, /* I - Client connection */
10030 ipp_status_t status
, /* I - IPP status code */
10031 const char *message
,/* I - Status message */
10032 ...) /* I - Additional args as needed */
10034 va_list ap
; /* Pointer to additional args */
10035 char formatted
[1024]; /* Formatted errror message */
10038 va_start(ap
, message
);
10039 vsnprintf(formatted
, sizeof(formatted
),
10040 _cupsLangString(con
->language
, message
), ap
);
10043 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s: %s",
10044 ippOpString(con
->request
->request
.op
.operation_id
),
10045 ippErrorString(status
), formatted
);
10047 con
->response
->request
.status
.status_code
= status
;
10049 if (ippFindAttribute(con
->response
, "attributes-charset",
10050 IPP_TAG_ZERO
) == NULL
)
10051 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
10052 "attributes-charset", NULL
, "utf-8");
10054 if (ippFindAttribute(con
->response
, "attributes-natural-language",
10055 IPP_TAG_ZERO
) == NULL
)
10056 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
10057 "attributes-natural-language", NULL
, DefaultLanguage
);
10059 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
10060 "status-message", NULL
, formatted
);
10065 * 'set_default()' - Set the default destination...
10069 set_default(cupsd_client_t
*con
, /* I - Client connection */
10070 ipp_attribute_t
*uri
) /* I - Printer URI */
10072 http_status_t status
; /* Policy status */
10073 cups_ptype_t dtype
; /* Destination type (printer/class) */
10074 cupsd_printer_t
*printer
, /* Printer */
10075 *oldprinter
; /* Old default printer */
10078 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_default(%p[%d], %s)", con
,
10079 con
->number
, uri
->values
[0].string
.text
);
10082 * Is the destination valid?
10085 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10091 send_ipp_status(con
, IPP_NOT_FOUND
,
10092 _("The printer or class does not exist."));
10100 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
10102 send_http_error(con
, status
, NULL
);
10107 * Set it as the default...
10110 oldprinter
= DefaultPrinter
;
10111 DefaultPrinter
= printer
;
10114 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, oldprinter
, NULL
,
10115 "%s is no longer the default printer.", oldprinter
->name
);
10117 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
10118 "%s is now the default printer.", printer
->name
);
10120 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
| CUPSD_DIRTY_CLASSES
|
10121 CUPSD_DIRTY_PRINTCAP
);
10123 cupsdLogMessage(CUPSD_LOG_INFO
,
10124 "Default destination set to \"%s\" by \"%s\".",
10125 printer
->name
, get_username(con
));
10128 * Everything was ok, so return OK status...
10131 con
->response
->request
.status
.status_code
= IPP_OK
;
10136 * 'set_job_attrs()' - Set job attributes.
10140 set_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
10141 ipp_attribute_t
*uri
) /* I - Job URI */
10143 ipp_attribute_t
*attr
, /* Current attribute */
10144 *attr2
; /* Job attribute */
10145 int jobid
; /* Job ID */
10146 cupsd_job_t
*job
; /* Current job */
10147 char scheme
[HTTP_MAX_URI
],
10148 /* Method portion of URI */
10149 username
[HTTP_MAX_URI
],
10150 /* Username portion of URI */
10151 host
[HTTP_MAX_URI
],
10152 /* Host portion of URI */
10153 resource
[HTTP_MAX_URI
];
10154 /* Resource portion of URI */
10155 int port
; /* Port portion of URI */
10156 int event
; /* Events? */
10157 int check_jobs
; /* Check jobs? */
10160 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_job_attrs(%p[%d], %s)", con
,
10161 con
->number
, uri
->values
[0].string
.text
);
10164 * Start with "everything is OK" status...
10167 con
->response
->request
.status
.status_code
= IPP_OK
;
10170 * See if we have a job URI or a printer URI...
10173 if (!strcmp(uri
->name
, "printer-uri"))
10176 * Got a printer URI; see if we also have a job-id attribute...
10179 if ((attr
= ippFindAttribute(con
->request
, "job-id",
10180 IPP_TAG_INTEGER
)) == NULL
)
10182 send_ipp_status(con
, IPP_BAD_REQUEST
,
10183 _("Got a printer-uri attribute but no job-id."));
10187 jobid
= attr
->values
[0].integer
;
10192 * Got a job URI; parse it to get the job ID...
10195 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
10196 sizeof(scheme
), username
, sizeof(username
), host
,
10197 sizeof(host
), &port
, resource
, sizeof(resource
));
10199 if (strncmp(resource
, "/jobs/", 6))
10205 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
10206 uri
->values
[0].string
.text
);
10210 jobid
= atoi(resource
+ 6);
10214 * See if the job exists...
10217 if ((job
= cupsdFindJob(jobid
)) == NULL
)
10220 * Nope - return a "not found" error...
10223 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
10228 * See if the job has been completed...
10231 if (job
->state_value
> IPP_JOB_STOPPED
)
10234 * Return a "not-possible" error...
10237 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10238 _("Job #%d is finished and cannot be altered."), jobid
);
10243 * See if the job is owned by the requesting user...
10246 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10248 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
10249 cupsdFindDest(job
->dest
));
10254 * See what the user wants to change.
10262 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10264 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
10267 if (!strcmp(attr
->name
, "attributes-charset") ||
10268 !strcmp(attr
->name
, "attributes-natural-language") ||
10269 !strncmp(attr
->name
, "date-time-at-", 13) ||
10270 !strncmp(attr
->name
, "document-compression", 20) ||
10271 !strncmp(attr
->name
, "document-format", 15) ||
10272 !strcmp(attr
->name
, "job-detailed-status-messages") ||
10273 !strcmp(attr
->name
, "job-document-access-errors") ||
10274 !strcmp(attr
->name
, "job-id") ||
10275 !strcmp(attr
->name
, "job-impressions-completed") ||
10276 !strcmp(attr
->name
, "job-k-octets-completed") ||
10277 !strcmp(attr
->name
, "job-media-sheets-completed") ||
10278 !strcmp(attr
->name
, "job-originating-host-name") ||
10279 !strcmp(attr
->name
, "job-originating-user-name") ||
10280 !strcmp(attr
->name
, "job-pages-completed") ||
10281 !strcmp(attr
->name
, "job-printer-up-time") ||
10282 !strcmp(attr
->name
, "job-printer-uri") ||
10283 !strcmp(attr
->name
, "job-sheets") ||
10284 !strcmp(attr
->name
, "job-state-message") ||
10285 !strcmp(attr
->name
, "job-state-reasons") ||
10286 !strcmp(attr
->name
, "job-uri") ||
10287 !strcmp(attr
->name
, "number-of-documents") ||
10288 !strcmp(attr
->name
, "number-of-intervening-jobs") ||
10289 !strcmp(attr
->name
, "output-device-assigned") ||
10290 !strncmp(attr
->name
, "time-at-", 8))
10296 send_ipp_status(con
, IPP_ATTRIBUTES_NOT_SETTABLE
,
10297 _("%s cannot be changed."), attr
->name
);
10299 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
10300 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
10304 if (!strcmp(attr
->name
, "job-priority"))
10307 * Change the job priority...
10310 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10312 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-priority value."));
10314 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
10315 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
10317 else if (job
->state_value
>= IPP_JOB_PROCESSING
)
10319 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10320 _("Job is completed and cannot be changed."));
10323 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10325 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-priority to %d",
10326 attr
->values
[0].integer
);
10327 cupsdSetJobPriority(job
, attr
->values
[0].integer
);
10330 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
|
10331 CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
;
10334 else if (!strcmp(attr
->name
, "job-state"))
10337 * Change the job state...
10340 if (attr
->value_tag
!= IPP_TAG_ENUM
)
10342 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-state value."));
10344 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
10345 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
10349 switch (attr
->values
[0].integer
)
10351 case IPP_JOB_PENDING
:
10352 case IPP_JOB_HELD
:
10353 if (job
->state_value
> IPP_JOB_HELD
)
10355 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10356 _("Job state cannot be changed."));
10359 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10361 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10362 attr
->values
[0].integer
);
10363 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
, CUPSD_JOB_DEFAULT
, "Job state changed by \"%s\"", username
);
10368 case IPP_JOB_PROCESSING
:
10369 case IPP_JOB_STOPPED
:
10370 if (job
->state_value
!= attr
->values
[0].integer
)
10372 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10373 _("Job state cannot be changed."));
10378 case IPP_JOB_CANCELED
:
10379 case IPP_JOB_ABORTED
:
10380 case IPP_JOB_COMPLETED
:
10381 if (job
->state_value
> IPP_JOB_PROCESSING
)
10383 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10384 _("Job state cannot be changed."));
10387 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10389 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10390 attr
->values
[0].integer
);
10391 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
,
10393 "Job state changed by \"%s\"", username
);
10400 else if (con
->response
->request
.status
.status_code
!= IPP_OK
)
10402 else if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10403 IPP_TAG_ZERO
)) != NULL
)
10406 * Some other value; first free the old value...
10409 if (job
->attrs
->prev
)
10410 job
->attrs
->prev
->next
= attr2
->next
;
10412 job
->attrs
->attrs
= attr2
->next
;
10414 if (job
->attrs
->last
== attr2
)
10415 job
->attrs
->last
= job
->attrs
->prev
;
10417 ippDeleteAttribute(NULL
, attr2
);
10420 * Then copy the attribute...
10423 ippCopyAttribute(job
->attrs
, attr
, 0);
10426 * See if the job-name or job-hold-until is being changed.
10429 if (!strcmp(attr
->name
, "job-hold-until"))
10431 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-hold-until to %s",
10432 attr
->values
[0].string
.text
);
10433 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
10435 if (!strcmp(attr
->values
[0].string
.text
, "no-hold"))
10437 cupsdReleaseJob(job
);
10441 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
,
10442 "Job held by \"%s\".", username
);
10444 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
;
10447 else if (attr
->value_tag
== IPP_TAG_DELETEATTR
)
10450 * Delete the attribute...
10453 if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10454 IPP_TAG_ZERO
)) != NULL
)
10456 if (job
->attrs
->prev
)
10457 job
->attrs
->prev
->next
= attr2
->next
;
10459 job
->attrs
->attrs
= attr2
->next
;
10461 if (attr2
== job
->attrs
->last
)
10462 job
->attrs
->last
= job
->attrs
->prev
;
10464 ippDeleteAttribute(NULL
, attr2
);
10466 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10472 * Add new option by copying it...
10475 ippCopyAttribute(job
->attrs
, attr
, 0);
10477 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10486 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10489 * Send events as needed...
10492 if (event
& CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
)
10493 cupsdAddEvent(CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
,
10494 cupsdFindDest(job
->dest
), job
,
10495 "Job priority changed by user.");
10497 if (event
& CUPSD_EVENT_JOB_STATE
)
10498 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
10499 job
->state_value
== IPP_JOB_HELD
?
10500 "Job held by user." : "Job restarted by user.");
10502 if (event
& CUPSD_EVENT_JOB_CONFIG_CHANGED
)
10503 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
10504 "Job options changed by user.");
10507 * Start jobs if possible...
10516 * 'set_printer_attrs()' - Set printer attributes.
10520 set_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
10521 ipp_attribute_t
*uri
) /* I - Printer */
10523 http_status_t status
; /* Policy status */
10524 cups_ptype_t dtype
; /* Destination type (printer/class) */
10525 cupsd_printer_t
*printer
; /* Printer/class */
10526 ipp_attribute_t
*attr
; /* Printer attribute */
10527 int changed
= 0; /* Was anything changed? */
10530 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_attrs(%p[%d], %s)", con
,
10531 con
->number
, uri
->values
[0].string
.text
);
10534 * Is the destination valid?
10537 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10543 send_ipp_status(con
, IPP_NOT_FOUND
,
10544 _("The printer or class does not exist."));
10552 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10554 send_http_error(con
, status
, printer
);
10559 * Return a list of attributes that can be set via Set-Printer-Attributes.
10562 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
10563 IPP_TAG_TEXT
)) != NULL
)
10565 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
10569 if ((attr
= ippFindAttribute(con
->request
, "printer-geo-location", IPP_TAG_URI
)) != NULL
&& !strncmp(attr
->values
[0].string
.text
, "geo:", 4))
10571 cupsdSetString(&printer
->geo_location
, attr
->values
[0].string
.text
);
10575 if ((attr
= ippFindAttribute(con
->request
, "printer-organization", IPP_TAG_TEXT
)) != NULL
)
10577 cupsdSetString(&printer
->organization
, attr
->values
[0].string
.text
);
10581 if ((attr
= ippFindAttribute(con
->request
, "printer-organizational-unit", IPP_TAG_TEXT
)) != NULL
)
10583 cupsdSetString(&printer
->organizational_unit
, attr
->values
[0].string
.text
);
10587 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
10588 IPP_TAG_TEXT
)) != NULL
)
10590 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
10595 * Update the printer attributes and return...
10600 printer
->config_time
= time(NULL
);
10602 cupsdSetPrinterAttrs(printer
);
10603 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
10605 cupsdAddEvent(CUPSD_EVENT_PRINTER_CONFIG
, printer
, NULL
,
10606 "Printer \"%s\" description or location changed by \"%s\".",
10607 printer
->name
, get_username(con
));
10609 cupsdLogMessage(CUPSD_LOG_INFO
,
10610 "Printer \"%s\" description or location changed by \"%s\".",
10611 printer
->name
, get_username(con
));
10614 con
->response
->request
.status
.status_code
= IPP_OK
;
10619 * 'set_printer_defaults()' - Set printer default options from a request.
10622 static int /* O - 1 on success, 0 on failure */
10623 set_printer_defaults(
10624 cupsd_client_t
*con
, /* I - Client connection */
10625 cupsd_printer_t
*printer
) /* I - Printer */
10627 int i
; /* Looping var */
10628 ipp_attribute_t
*attr
; /* Current attribute */
10629 size_t namelen
; /* Length of attribute name */
10630 char name
[256], /* New attribute name */
10631 value
[256]; /* String version of integer attrs */
10634 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10637 * Skip non-printer attributes...
10640 if (attr
->group_tag
!= IPP_TAG_PRINTER
|| !attr
->name
)
10643 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_defaults: %s", attr
->name
);
10645 if (!strcmp(attr
->name
, "job-sheets-default"))
10648 * Only allow keywords and names...
10651 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10655 * Only allow job-sheets-default to be set when running without a
10656 * system high classification level...
10659 if (Classification
)
10662 cupsdSetString(&printer
->job_sheets
[0], attr
->values
[0].string
.text
);
10664 if (attr
->num_values
> 1)
10665 cupsdSetString(&printer
->job_sheets
[1], attr
->values
[1].string
.text
);
10667 cupsdSetString(&printer
->job_sheets
[1], "none");
10669 else if (!strcmp(attr
->name
, "requesting-user-name-allowed"))
10671 cupsdFreeStrings(&(printer
->users
));
10673 printer
->deny_users
= 0;
10675 if (attr
->value_tag
== IPP_TAG_NAME
&&
10676 (attr
->num_values
> 1 ||
10677 strcmp(attr
->values
[0].string
.text
, "all")))
10679 for (i
= 0; i
< attr
->num_values
; i
++)
10680 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
10683 else if (!strcmp(attr
->name
, "requesting-user-name-denied"))
10685 cupsdFreeStrings(&(printer
->users
));
10687 printer
->deny_users
= 1;
10689 if (attr
->value_tag
== IPP_TAG_NAME
&&
10690 (attr
->num_values
> 1 ||
10691 strcmp(attr
->values
[0].string
.text
, "none")))
10693 for (i
= 0; i
< attr
->num_values
; i
++)
10694 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
10697 else if (!strcmp(attr
->name
, "job-quota-period"))
10699 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10702 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-quota-period to %d...",
10703 attr
->values
[0].integer
);
10704 cupsdFreeQuotas(printer
);
10706 printer
->quota_period
= attr
->values
[0].integer
;
10708 else if (!strcmp(attr
->name
, "job-k-limit"))
10710 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10713 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-k-limit to %d...",
10714 attr
->values
[0].integer
);
10715 cupsdFreeQuotas(printer
);
10717 printer
->k_limit
= attr
->values
[0].integer
;
10719 else if (!strcmp(attr
->name
, "job-page-limit"))
10721 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10724 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-page-limit to %d...",
10725 attr
->values
[0].integer
);
10726 cupsdFreeQuotas(printer
);
10728 printer
->page_limit
= attr
->values
[0].integer
;
10730 else if (!strcmp(attr
->name
, "printer-op-policy"))
10732 cupsd_policy_t
*p
; /* Policy */
10735 if (attr
->value_tag
!= IPP_TAG_NAME
)
10738 if ((p
= cupsdFindPolicy(attr
->values
[0].string
.text
)) != NULL
)
10740 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10741 "Setting printer-op-policy to \"%s\"...",
10742 attr
->values
[0].string
.text
);
10743 cupsdSetString(&printer
->op_policy
, attr
->values
[0].string
.text
);
10744 printer
->op_policy_ptr
= p
;
10748 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10749 _("Unknown printer-op-policy \"%s\"."),
10750 attr
->values
[0].string
.text
);
10754 else if (!strcmp(attr
->name
, "printer-error-policy"))
10756 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10759 if (strcmp(attr
->values
[0].string
.text
, "retry-current-job") &&
10760 ((printer
->type
& CUPS_PRINTER_CLASS
) ||
10761 (strcmp(attr
->values
[0].string
.text
, "abort-job") &&
10762 strcmp(attr
->values
[0].string
.text
, "retry-job") &&
10763 strcmp(attr
->values
[0].string
.text
, "stop-printer"))))
10765 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10766 _("Unknown printer-error-policy \"%s\"."),
10767 attr
->values
[0].string
.text
);
10771 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10772 "Setting printer-error-policy to \"%s\"...",
10773 attr
->values
[0].string
.text
);
10774 cupsdSetString(&printer
->error_policy
, attr
->values
[0].string
.text
);
10778 * Skip any other non-default attributes...
10781 namelen
= strlen(attr
->name
);
10782 if (namelen
< 9 || strcmp(attr
->name
+ namelen
- 8, "-default") ||
10783 namelen
> (sizeof(name
) - 1) || attr
->num_values
!= 1)
10787 * OK, anything else must be a user-defined default...
10790 strlcpy(name
, attr
->name
, sizeof(name
));
10791 name
[namelen
- 8] = '\0'; /* Strip "-default" */
10793 switch (attr
->value_tag
)
10795 case IPP_TAG_DELETEATTR
:
10796 printer
->num_options
= cupsRemoveOption(name
,
10797 printer
->num_options
,
10798 &(printer
->options
));
10799 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10800 "Deleting %s", attr
->name
);
10803 case IPP_TAG_NAME
:
10804 case IPP_TAG_TEXT
:
10805 case IPP_TAG_KEYWORD
:
10807 printer
->num_options
= cupsAddOption(name
,
10808 attr
->values
[0].string
.text
,
10809 printer
->num_options
,
10810 &(printer
->options
));
10811 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10812 "Setting %s to \"%s\"...", attr
->name
,
10813 attr
->values
[0].string
.text
);
10816 case IPP_TAG_BOOLEAN
:
10817 printer
->num_options
= cupsAddOption(name
,
10818 attr
->values
[0].boolean
?
10820 printer
->num_options
,
10821 &(printer
->options
));
10822 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10823 "Setting %s to %s...", attr
->name
,
10824 attr
->values
[0].boolean
? "true" : "false");
10827 case IPP_TAG_INTEGER
:
10828 case IPP_TAG_ENUM
:
10829 sprintf(value
, "%d", attr
->values
[0].integer
);
10830 printer
->num_options
= cupsAddOption(name
, value
,
10831 printer
->num_options
,
10832 &(printer
->options
));
10833 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10834 "Setting %s to %s...", attr
->name
, value
);
10837 case IPP_TAG_RANGE
:
10838 sprintf(value
, "%d-%d", attr
->values
[0].range
.lower
,
10839 attr
->values
[0].range
.upper
);
10840 printer
->num_options
= cupsAddOption(name
, value
,
10841 printer
->num_options
,
10842 &(printer
->options
));
10843 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10844 "Setting %s to %s...", attr
->name
, value
);
10847 case IPP_TAG_RESOLUTION
:
10848 sprintf(value
, "%dx%d%s", attr
->values
[0].resolution
.xres
,
10849 attr
->values
[0].resolution
.yres
,
10850 attr
->values
[0].resolution
.units
== IPP_RES_PER_INCH
?
10852 printer
->num_options
= cupsAddOption(name
, value
,
10853 printer
->num_options
,
10854 &(printer
->options
));
10855 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10856 "Setting %s to %s...", attr
->name
, value
);
10860 /* Do nothing for other values */
10870 * 'start_printer()' - Start a printer.
10874 start_printer(cupsd_client_t
*con
, /* I - Client connection */
10875 ipp_attribute_t
*uri
) /* I - Printer URI */
10877 int i
; /* Temporary variable */
10878 http_status_t status
; /* Policy status */
10879 cups_ptype_t dtype
; /* Destination type (printer/class) */
10880 cupsd_printer_t
*printer
; /* Printer data */
10883 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_printer(%p[%d], %s)", con
,
10884 con
->number
, uri
->values
[0].string
.text
);
10887 * Is the destination valid?
10890 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10896 send_ipp_status(con
, IPP_NOT_FOUND
,
10897 _("The printer or class does not exist."));
10905 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10907 send_http_error(con
, status
, printer
);
10912 * Start the printer...
10915 printer
->state_message
[0] = '\0';
10917 cupsdStartPrinter(printer
, 1);
10919 if (dtype
& CUPS_PRINTER_CLASS
)
10920 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" started by \"%s\".",
10921 printer
->name
, get_username(con
));
10923 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" started by \"%s\".",
10924 printer
->name
, get_username(con
));
10932 if ((i
= check_quotas(con
, printer
)) < 0)
10934 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
10939 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
10944 * Everything was ok, so return OK status...
10947 con
->response
->request
.status
.status_code
= IPP_OK
;
10952 * 'stop_printer()' - Stop a printer.
10956 stop_printer(cupsd_client_t
*con
, /* I - Client connection */
10957 ipp_attribute_t
*uri
) /* I - Printer URI */
10959 http_status_t status
; /* Policy status */
10960 cups_ptype_t dtype
; /* Destination type (printer/class) */
10961 cupsd_printer_t
*printer
; /* Printer data */
10962 ipp_attribute_t
*attr
; /* printer-state-message attribute */
10965 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "stop_printer(%p[%d], %s)", con
,
10966 con
->number
, uri
->values
[0].string
.text
);
10969 * Is the destination valid?
10972 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10978 send_ipp_status(con
, IPP_NOT_FOUND
,
10979 _("The printer or class does not exist."));
10987 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10989 send_http_error(con
, status
, printer
);
10994 * Stop the printer...
10997 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
10998 IPP_TAG_TEXT
)) == NULL
)
10999 strlcpy(printer
->state_message
, "Paused", sizeof(printer
->state_message
));
11002 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
11003 sizeof(printer
->state_message
));
11006 cupsdStopPrinter(printer
, 1);
11008 if (dtype
& CUPS_PRINTER_CLASS
)
11009 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" stopped by \"%s\".",
11010 printer
->name
, get_username(con
));
11012 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" stopped by \"%s\".",
11013 printer
->name
, get_username(con
));
11016 * Everything was ok, so return OK status...
11019 con
->response
->request
.status
.status_code
= IPP_OK
;
11024 * 'url_encode_attr()' - URL-encode a string attribute.
11028 url_encode_attr(ipp_attribute_t
*attr
, /* I - Attribute */
11029 char *buffer
,/* I - String buffer */
11030 size_t bufsize
)/* I - Size of buffer */
11032 int i
; /* Looping var */
11033 char *bufptr
, /* Pointer into buffer */
11034 *bufend
; /* End of buffer */
11037 strlcpy(buffer
, attr
->name
, bufsize
);
11038 bufptr
= buffer
+ strlen(buffer
);
11039 bufend
= buffer
+ bufsize
- 1;
11041 for (i
= 0; i
< attr
->num_values
; i
++)
11043 if (bufptr
>= bufend
)
11051 if (bufptr
>= bufend
)
11056 bufptr
= url_encode_string(attr
->values
[i
].string
.text
, bufptr
, (size_t)(bufend
- bufptr
+ 1));
11058 if (bufptr
>= bufend
)
11069 * 'url_encode_string()' - URL-encode a string.
11072 static char * /* O - End of string */
11073 url_encode_string(const char *s
, /* I - String */
11074 char *buffer
, /* I - String buffer */
11075 size_t bufsize
) /* I - Size of buffer */
11077 char *bufptr
, /* Pointer into buffer */
11078 *bufend
; /* End of buffer */
11079 static const char *hex
= "0123456789ABCDEF";
11084 bufend
= buffer
+ bufsize
- 1;
11086 while (*s
&& bufptr
< bufend
)
11088 if (*s
== ' ' || *s
== '%' || *s
== '+')
11090 if (bufptr
>= (bufend
- 2))
11094 *bufptr
++ = hex
[(*s
>> 4) & 15];
11095 *bufptr
++ = hex
[*s
& 15];
11099 else if (*s
== '\'' || *s
== '\\')
11101 if (bufptr
>= (bufend
- 1))
11118 * 'user_allowed()' - See if a user is allowed to print to a queue.
11121 static int /* O - 0 if not allowed, 1 if allowed */
11122 user_allowed(cupsd_printer_t
*p
, /* I - Printer or class */
11123 const char *username
) /* I - Username */
11125 struct passwd
*pw
; /* User password data */
11126 char baseuser
[256], /* Base username */
11127 *baseptr
, /* Pointer to "@" in base username */
11128 *name
; /* Current user name */
11131 if (cupsArrayCount(p
->users
) == 0)
11134 if (!strcmp(username
, "root"))
11137 if (strchr(username
, '@'))
11140 * Strip @REALM for username check...
11143 strlcpy(baseuser
, username
, sizeof(baseuser
));
11145 if ((baseptr
= strchr(baseuser
, '@')) != NULL
)
11148 username
= baseuser
;
11151 pw
= getpwnam(username
);
11154 for (name
= (char *)cupsArrayFirst(p
->users
);
11156 name
= (char *)cupsArrayNext(p
->users
))
11158 if (name
[0] == '@')
11161 * Check group membership...
11164 if (cupsdCheckGroup(username
, pw
, name
+ 1))
11167 else if (name
[0] == '#')
11173 if (cupsdCheckGroup(username
, pw
, name
))
11176 else if (!_cups_strcasecmp(username
, name
))
11180 return ((name
!= NULL
) != p
->deny_users
);
11185 * 'validate_job()' - Validate printer options and destination.
11189 validate_job(cupsd_client_t
*con
, /* I - Client connection */
11190 ipp_attribute_t
*uri
) /* I - Printer URI */
11192 http_status_t status
; /* Policy status */
11193 ipp_attribute_t
*attr
; /* Current attribute */
11195 ipp_attribute_t
*auth_info
; /* auth-info attribute */
11196 #endif /* HAVE_SSL */
11197 ipp_attribute_t
*format
, /* Document-format attribute */
11198 *name
; /* Job-name attribute */
11199 cups_ptype_t dtype
; /* Destination type (printer/class) */
11200 char super
[MIME_MAX_SUPER
],
11201 /* Supertype of file */
11202 type
[MIME_MAX_TYPE
];
11203 /* Subtype of file */
11204 cupsd_printer_t
*printer
; /* Printer */
11207 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_job(%p[%d], %s)", con
,
11208 con
->number
, uri
->values
[0].string
.text
);
11211 * OK, see if the client is sending the document compressed - CUPS
11212 * doesn't support compression yet...
11215 if ((attr
= ippFindAttribute(con
->request
, "compression",
11216 IPP_TAG_KEYWORD
)) != NULL
)
11218 if (strcmp(attr
->values
[0].string
.text
, "none")
11220 && strcmp(attr
->values
[0].string
.text
, "gzip")
11221 #endif /* HAVE_LIBZ */
11224 send_ipp_status(con
, IPP_ATTRIBUTES
,
11225 _("Unsupported 'compression' value \"%s\"."),
11226 attr
->values
[0].string
.text
);
11227 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
11228 "compression", NULL
, attr
->values
[0].string
.text
);
11234 * Is it a format we support?
11237 if ((format
= ippFindAttribute(con
->request
, "document-format",
11238 IPP_TAG_MIMETYPE
)) != NULL
)
11240 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%255[^;]",
11243 send_ipp_status(con
, IPP_BAD_REQUEST
,
11244 _("Bad 'document-format' value \"%s\"."),
11245 format
->values
[0].string
.text
);
11249 if ((strcmp(super
, "application") || strcmp(type
, "octet-stream")) &&
11250 !mimeType(MimeDatabase
, super
, type
))
11252 cupsdLogMessage(CUPSD_LOG_INFO
,
11253 "Hint: Do you have the raw file printing rules enabled?");
11254 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
11255 _("Unsupported 'document-format' value \"%s\"."),
11256 format
->values
[0].string
.text
);
11257 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
11258 "document-format", NULL
, format
->values
[0].string
.text
);
11264 * Is the job-name valid?
11267 if ((name
= ippFindAttribute(con
->request
, "job-name", IPP_TAG_ZERO
)) != NULL
)
11269 int bad_name
= 0; /* Is the job-name value bad? */
11271 if ((name
->value_tag
!= IPP_TAG_NAME
&& name
->value_tag
!= IPP_TAG_NAMELANG
) ||
11272 name
->num_values
!= 1)
11279 * Validate that job-name conforms to RFC 5198 (Network Unicode) and
11280 * IPP Everywhere requirements for "name" values...
11283 const unsigned char *nameptr
; /* Pointer into "job-name" attribute */
11285 for (nameptr
= (unsigned char *)name
->values
[0].string
.text
;
11289 if (*nameptr
< ' ' && *nameptr
!= '\t')
11291 else if (*nameptr
== 0x7f)
11293 else if ((*nameptr
& 0xe0) == 0xc0)
11295 if ((nameptr
[1] & 0xc0) != 0x80)
11300 else if ((*nameptr
& 0xf0) == 0xe0)
11302 if ((nameptr
[1] & 0xc0) != 0x80 ||
11303 (nameptr
[2] & 0xc0) != 0x80)
11308 else if ((*nameptr
& 0xf8) == 0xf0)
11310 if ((nameptr
[1] & 0xc0) != 0x80 ||
11311 (nameptr
[2] & 0xc0) != 0x80 ||
11312 (nameptr
[3] & 0xc0) != 0x80)
11317 else if (*nameptr
& 0x80)
11327 if (StrictConformance
)
11329 send_ipp_status(con
, IPP_ATTRIBUTES
,
11330 _("Unsupported 'job-name' value."));
11331 ippCopyAttribute(con
->response
, name
, 0);
11336 cupsdLogMessage(CUPSD_LOG_WARN
,
11337 "Unsupported 'job-name' value, deleting from request.");
11338 ippDeleteAttribute(con
->request
, name
);
11344 * Is the destination valid?
11347 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11353 send_ipp_status(con
, IPP_NOT_FOUND
,
11354 _("The printer or class does not exist."));
11363 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
11364 #endif /* HAVE_SSL */
11366 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11368 send_http_error(con
, status
, printer
);
11371 else if (printer
->num_auth_info_required
== 1 &&
11372 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
11375 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
11379 else if (auth_info
&& !con
->http
->tls
&&
11380 !httpAddrLocalhost(con
->http
->hostaddr
))
11383 * Require encryption of auth-info over non-local connections...
11386 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
11389 #endif /* HAVE_SSL */
11392 * Everything was ok, so return OK status...
11395 con
->response
->request
.status
.status_code
= IPP_OK
;
11400 * 'validate_name()' - Make sure the printer name only contains valid chars.
11403 static int /* O - 0 if name is no good, 1 if good */
11404 validate_name(const char *name
) /* I - Name to check */
11406 const char *ptr
; /* Pointer into name */
11410 * Scan the whole name...
11413 for (ptr
= name
; *ptr
; ptr
++)
11414 if ((*ptr
> 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
11418 * All the characters are good; validate the length, too...
11421 return ((ptr
- name
) < 128);
11426 * 'validate_user()' - Validate the user for the request.
11429 static int /* O - 1 if permitted, 0 otherwise */
11430 validate_user(cupsd_job_t
*job
, /* I - Job */
11431 cupsd_client_t
*con
, /* I - Client connection */
11432 const char *owner
, /* I - Owner of job/resource */
11433 char *username
, /* O - Authenticated username */
11434 size_t userlen
) /* I - Length of username */
11436 cupsd_printer_t
*printer
; /* Printer for job */
11439 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
);
11442 * Validate input...
11445 if (!con
|| !owner
|| !username
|| userlen
<= 0)
11449 * Get the best authenticated username that is available.
11452 strlcpy(username
, get_username(con
), userlen
);
11455 * Check the username against the owner...
11458 printer
= cupsdFindDest(job
->dest
);
11460 return (cupsdCheckPolicy(printer
? printer
->op_policy_ptr
: DefaultPolicyPtr
,
11461 con
, owner
) == HTTP_OK
);