2 * IPP routines for the CUPS scheduler.
4 * Copyright © 2007-2019 by Apple Inc.
5 * Copyright © 1997-2007 by Easy Software Products, all rights reserved.
7 * This file contains Kerberos support code, copyright 2006 by
10 * Licensed under Apache License v2.0. See the file "LICENSE" for more
15 * Include necessary headers...
19 #include <cups/ppd-private.h>
22 /*# include <ApplicationServices/ApplicationServices.h>
23 extern CFUUIDRef ColorSyncCreateUUIDFromUInt32(unsigned id);
24 # include <CoreFoundation/CoreFoundation.h>*/
25 # ifdef HAVE_MEMBERSHIP_H
26 # include <membership.h>
27 # endif /* HAVE_MEMBERSHIP_H */
28 # ifdef HAVE_MEMBERSHIPPRIV_H
29 # include <membershipPriv.h>
31 extern int mbr_user_name_to_uuid(const char* name
, uuid_t uu
);
32 extern int mbr_group_name_to_uuid(const char* name
, uuid_t uu
);
33 extern int mbr_check_membership_by_id(uuid_t user
, gid_t group
, int* ismember
);
34 # endif /* HAVE_MEMBERSHIPPRIV_H */
35 #endif /* __APPLE__ */
42 static void accept_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
43 static void add_class(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
44 static int add_file(cupsd_client_t
*con
, cupsd_job_t
*job
,
45 mime_type_t
*filetype
, int compression
);
46 static cupsd_job_t
*add_job(cupsd_client_t
*con
, cupsd_printer_t
*printer
,
47 mime_type_t
*filetype
);
48 static void add_job_subscriptions(cupsd_client_t
*con
, cupsd_job_t
*job
);
49 static void add_job_uuid(cupsd_job_t
*job
);
50 static void add_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
51 static void add_printer_state_reasons(cupsd_client_t
*con
,
53 static void add_queued_job_count(cupsd_client_t
*con
, cupsd_printer_t
*p
);
54 static void apply_printer_defaults(cupsd_printer_t
*printer
,
56 static void authenticate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
57 static void cancel_all_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
58 static void cancel_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
59 static void cancel_subscription(cupsd_client_t
*con
, int id
);
60 static int check_rss_recipient(const char *recipient
);
61 static int check_quotas(cupsd_client_t
*con
, cupsd_printer_t
*p
);
62 static void close_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
63 static void copy_attrs(ipp_t
*to
, ipp_t
*from
, cups_array_t
*ra
,
64 ipp_tag_t group
, int quickcopy
,
65 cups_array_t
*exclude
);
66 static int copy_banner(cupsd_client_t
*con
, cupsd_job_t
*job
,
68 static int copy_file(const char *from
, const char *to
, mode_t mode
);
69 static int copy_model(cupsd_client_t
*con
, const char *from
,
71 static void copy_job_attrs(cupsd_client_t
*con
,
73 cups_array_t
*ra
, cups_array_t
*exclude
);
74 static void copy_printer_attrs(cupsd_client_t
*con
,
75 cupsd_printer_t
*printer
,
77 static void copy_subscription_attrs(cupsd_client_t
*con
,
78 cupsd_subscription_t
*sub
,
80 cups_array_t
*exclude
);
81 static void create_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
82 static void create_local_printer(cupsd_client_t
*con
);
83 static cups_array_t
*create_requested_array(ipp_t
*request
);
84 static void create_subscriptions(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
85 static void delete_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
86 static void get_default(cupsd_client_t
*con
);
87 static void get_devices(cupsd_client_t
*con
);
88 static void get_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
89 static void get_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
90 static void get_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
91 static void get_notifications(cupsd_client_t
*con
);
92 static void get_ppd(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
93 static void get_ppds(cupsd_client_t
*con
);
94 static void get_printers(cupsd_client_t
*con
, int type
);
95 static void get_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
96 static void get_printer_supported(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
97 static void get_subscription_attrs(cupsd_client_t
*con
, int sub_id
);
98 static void get_subscriptions(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
99 static const char *get_username(cupsd_client_t
*con
);
100 static void hold_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
101 static void hold_new_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
102 static void move_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
103 static int ppd_parse_line(const char *line
, char *option
, int olen
,
104 char *choice
, int clen
);
105 static void print_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
106 static void read_job_ticket(cupsd_client_t
*con
);
107 static void reject_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
108 static void release_held_new_jobs(cupsd_client_t
*con
,
109 ipp_attribute_t
*uri
);
110 static void release_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
111 static void renew_subscription(cupsd_client_t
*con
, int sub_id
);
112 static void restart_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
113 static void save_auth_info(cupsd_client_t
*con
, cupsd_job_t
*job
,
114 ipp_attribute_t
*auth_info
);
115 static void send_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
116 static void send_http_error(cupsd_client_t
*con
, http_status_t status
,
117 cupsd_printer_t
*printer
);
118 static void send_ipp_status(cupsd_client_t
*con
, ipp_status_t status
, const char *message
, ...) _CUPS_FORMAT(3, 4);
119 static void set_default(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
120 static void set_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
121 static void set_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
122 static int set_printer_defaults(cupsd_client_t
*con
, cupsd_printer_t
*printer
);
123 static void start_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
124 static void stop_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
125 static void url_encode_attr(ipp_attribute_t
*attr
, char *buffer
, size_t bufsize
);
126 static char *url_encode_string(const char *s
, char *buffer
, size_t bufsize
);
127 static int user_allowed(cupsd_printer_t
*p
, const char *username
);
128 static void validate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
129 static int validate_name(const char *name
);
130 static int validate_user(cupsd_job_t
*job
, cupsd_client_t
*con
, const char *owner
, char *username
, size_t userlen
);
134 * 'cupsdProcessIPPRequest()' - Process an incoming IPP request.
137 int /* O - 1 on success, 0 on failure */
138 cupsdProcessIPPRequest(
139 cupsd_client_t
*con
) /* I - Client connection */
141 ipp_tag_t group
; /* Current group tag */
142 ipp_attribute_t
*attr
; /* Current attribute */
143 ipp_attribute_t
*charset
; /* Character set attribute */
144 ipp_attribute_t
*language
; /* Language attribute */
145 ipp_attribute_t
*uri
= NULL
; /* Printer or job URI attribute */
146 ipp_attribute_t
*username
; /* requesting-user-name attr */
147 int sub_id
; /* Subscription ID */
148 int valid
= 1; /* Valid request? */
151 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdProcessIPPRequest(%p[%d]): operation_id=%04x(%s)", con
, con
->number
, con
->request
->request
.op
.operation_id
, ippOpString(con
->request
->request
.op
.operation_id
));
153 if (LogLevel
>= CUPSD_LOG_DEBUG2
)
155 for (group
= IPP_TAG_ZERO
, attr
= ippFirstAttribute(con
->request
); attr
; attr
= ippNextAttribute(con
->request
))
157 const char *name
; /* Attribute name */
158 char value
[1024]; /* Attribute value */
160 if (group
!= ippGetGroupTag(attr
))
162 group
= ippGetGroupTag(attr
);
163 if (group
!= IPP_TAG_ZERO
)
164 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdProcessIPPRequest: %s", ippTagString(group
));
167 if ((name
= ippGetName(attr
)) == NULL
)
170 ippAttributeString(attr
, value
, sizeof(value
));
172 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdProcessIPPRequest: %s %s%s '%s'", name
, ippGetCount(attr
) > 1 ? "1setOf " : "", ippTagString(ippGetValueTag(attr
)), value
);
177 * First build an empty response message for this request...
180 con
->response
= ippNew();
182 con
->response
->request
.status
.version
[0] = con
->request
->request
.op
.version
[0];
183 con
->response
->request
.status
.version
[1] = con
->request
->request
.op
.version
[1];
184 con
->response
->request
.status
.request_id
= con
->request
->request
.op
.request_id
;
187 * Then validate the request header and required attributes...
190 if (con
->request
->request
.any
.version
[0] != 1 && con
->request
->request
.any
.version
[0] != 2)
193 * Return an error, since we only support IPP 1.x and 2.x.
196 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
, "%04X %s Bad request version number %d.%d.", IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED
, con
->http
->hostname
, con
->request
->request
.any
.version
[0], con
->request
->request
.any
.version
[1]);
198 send_ipp_status(con
, IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED
, _("Bad request version number %d.%d."), con
->request
->request
.any
.version
[0], con
->request
->request
.any
.version
[1]);
200 else if (con
->request
->request
.any
.request_id
< 1)
203 * Return an error, since request IDs must be between 1 and 2^31-1
206 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
, "%04X %s Bad request ID %d.", IPP_STATUS_ERROR_BAD_REQUEST
, con
->http
->hostname
, con
->request
->request
.any
.request_id
);
208 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Bad request ID %d."), con
->request
->request
.any
.request_id
);
210 else if (!con
->request
->attrs
)
212 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
, "%04X %s No attributes in request.", IPP_STATUS_ERROR_BAD_REQUEST
, con
->http
->hostname
);
214 send_ipp_status(con
, IPP_STATUS_ERROR_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
, "%04X %s Attribute groups are out of order", IPP_STATUS_ERROR_BAD_REQUEST
, con
->http
->hostname
);
234 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Attribute groups are out of order (%x < %x)."), attr
->group_tag
, group
);
238 group
= attr
->group_tag
;
243 * Then make sure that the first three attributes are:
246 * attributes-natural-language
247 * printer-uri/job-uri
250 attr
= con
->request
->attrs
;
251 if (attr
&& attr
->name
&& !strcmp(attr
->name
, "attributes-charset") && (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_CHARSET
&& attr
->group_tag
== IPP_TAG_OPERATION
)
259 if (attr
&& attr
->name
&& !strcmp(attr
->name
, "attributes-natural-language") && (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_LANGUAGE
&& attr
->group_tag
== IPP_TAG_OPERATION
)
264 * Reset language for this request if different from Accept-Language.
267 if (!con
->language
||
268 strcmp(attr
->values
[0].string
.text
, con
->language
->language
))
270 cupsLangFree(con
->language
);
271 con
->language
= cupsLangGet(attr
->values
[0].string
.text
);
277 if ((attr
= ippFindAttribute(con
->request
, "printer-uri", IPP_TAG_URI
)) != NULL
&& attr
->group_tag
== IPP_TAG_OPERATION
)
279 else if ((attr
= ippFindAttribute(con
->request
, "job-uri", IPP_TAG_URI
)) != NULL
&& attr
->group_tag
== IPP_TAG_OPERATION
)
281 else if (con
->request
->request
.op
.operation_id
== CUPS_GET_PPD
&& (attr
= ippFindAttribute(con
->request
, "ppd-name", IPP_TAG_NAME
)) != NULL
&& attr
->group_tag
== IPP_TAG_OPERATION
)
287 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
, "attributes-charset", NULL
, charset
->values
[0].string
.text
);
289 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
, "attributes-charset", NULL
, "utf-8");
292 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
, "attributes-natural-language", NULL
, language
->values
[0].string
.text
);
294 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
, "attributes-natural-language", NULL
, DefaultLanguage
);
296 if (charset
&& _cups_strcasecmp(charset
->values
[0].string
.text
, "us-ascii") && _cups_strcasecmp(charset
->values
[0].string
.text
, "utf-8"))
299 * Bad character set...
302 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unsupported character set \"%s\"",
303 charset
->values
[0].string
.text
);
304 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
, "%04X %s Unsupported attributes-charset value \"%s\".", IPP_STATUS_ERROR_CHARSET
, con
->http
->hostname
, charset
->values
[0].string
.text
);
305 send_ipp_status(con
, IPP_STATUS_ERROR_CHARSET
, _("Unsupported character set \"%s\"."), charset
->values
[0].string
.text
);
307 else if (!charset
|| !language
||
309 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEFAULT
&&
310 con
->request
->request
.op
.operation_id
!= CUPS_GET_PRINTERS
&&
311 con
->request
->request
.op
.operation_id
!= CUPS_GET_CLASSES
&&
312 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEVICES
&&
313 con
->request
->request
.op
.operation_id
!= CUPS_GET_PPDS
))
316 * Return an error, since attributes-charset,
317 * attributes-natural-language, and printer-uri/job-uri are required
318 * for all operations.
323 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing attributes-charset attribute.");
325 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
, "%04X %s Missing attributes-charset attribute.", IPP_STATUS_ERROR_BAD_REQUEST
, con
->http
->hostname
);
330 cupsdLogMessage(CUPSD_LOG_ERROR
,
331 "Missing attributes-natural-language attribute.");
333 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
, "%04X %s Missing attributes-natural-language attribute.", IPP_STATUS_ERROR_BAD_REQUEST
, con
->http
->hostname
);
338 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing printer-uri, job-uri, or ppd-name attribute.");
340 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
, "%04X %s Missing printer-uri, job-uri, or ppd-name attribute.", IPP_STATUS_ERROR_BAD_REQUEST
, con
->http
->hostname
);
343 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Request attributes follow...");
345 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
346 cupsdLogMessage(CUPSD_LOG_DEBUG
,
347 "attr \"%s\": group_tag = %x, value_tag = %x",
348 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
351 cupsdLogMessage(CUPSD_LOG_DEBUG
, "End of attributes...");
353 send_ipp_status(con
, IPP_BAD_REQUEST
,
354 _("Missing required attributes."));
359 * OK, all the checks pass so far; validate "requesting-user-name"
363 if ((username
= ippFindAttribute(con
->request
, "requesting-user-name", IPP_TAG_ZERO
)) != NULL
)
366 * Validate "requesting-user-name"...
369 if (username
->group_tag
!= IPP_TAG_OPERATION
&& StrictConformance
)
371 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
, "%04X %s \"requesting-user-name\" attribute in wrong group.", IPP_STATUS_ERROR_BAD_REQUEST
, con
->http
->hostname
);
372 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("\"requesting-user-name\" attribute in wrong group."));
375 else if (username
->value_tag
!= IPP_TAG_NAME
&& username
->value_tag
!= IPP_TAG_NAMELANG
)
377 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
, "%04X %s \"requesting-user-name\" attribute with wrong syntax.", IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES
, con
->http
->hostname
);
378 send_ipp_status(con
, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES
, _("\"requesting-user-name\" attribute with wrong syntax."));
379 if ((attr
= ippCopyAttribute(con
->response
, username
, 0)) != NULL
)
380 attr
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
383 else if (!ippValidateAttribute(username
))
385 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
, "%04X %s \"requesting-user-name\" attribute with bad value.", IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES
, con
->http
->hostname
);
387 if (StrictConformance
)
393 send_ipp_status(con
, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES
, _("\"requesting-user-name\" attribute with wrong syntax."));
394 if ((attr
= ippCopyAttribute(con
->response
, username
, 0)) != NULL
)
395 attr
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
401 * Map bad "requesting-user-name" to 'anonymous'...
404 ippSetString(con
->request
, &username
, 0, "anonymous");
407 else if (!strcmp(username
->values
[0].string
.text
, "root") && _cups_strcasecmp(con
->http
->hostname
, "localhost") && strcmp(con
->username
, "root"))
410 * Remote unauthenticated user masquerading as local root...
413 ippSetString(con
->request
, &username
, 0, RemoteRoot
);
417 if ((attr
= ippFindAttribute(con
->request
, "notify-subscription-id", IPP_TAG_INTEGER
)) != NULL
)
418 sub_id
= attr
->values
[0].integer
;
425 * Try processing the operation...
429 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s", ippOpString(con
->request
->request
.op
.operation_id
), uri
->values
[0].string
.text
);
431 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s", ippOpString(con
->request
->request
.op
.operation_id
));
433 switch (con
->request
->request
.op
.operation_id
)
435 case IPP_OP_PRINT_JOB
:
439 case IPP_OP_VALIDATE_JOB
:
440 validate_job(con
, uri
);
443 case IPP_OP_CREATE_JOB
:
444 create_job(con
, uri
);
447 case IPP_OP_SEND_DOCUMENT
:
448 send_document(con
, uri
);
451 case IPP_OP_CANCEL_JOB
:
452 cancel_job(con
, uri
);
455 case IPP_OP_GET_JOB_ATTRIBUTES
:
456 get_job_attrs(con
, uri
);
459 case IPP_OP_GET_JOBS
:
463 case IPP_OP_GET_PRINTER_ATTRIBUTES
:
464 get_printer_attrs(con
, uri
);
467 case IPP_OP_GET_PRINTER_SUPPORTED_VALUES
:
468 get_printer_supported(con
, uri
);
471 case IPP_OP_HOLD_JOB
:
475 case IPP_OP_RELEASE_JOB
:
476 release_job(con
, uri
);
479 case IPP_OP_RESTART_JOB
:
480 restart_job(con
, uri
);
483 case IPP_OP_PAUSE_PRINTER
:
484 stop_printer(con
, uri
);
487 case IPP_OP_RESUME_PRINTER
:
488 start_printer(con
, uri
);
491 case IPP_OP_PURGE_JOBS
:
492 case IPP_OP_CANCEL_JOBS
:
493 case IPP_OP_CANCEL_MY_JOBS
:
494 cancel_all_jobs(con
, uri
);
497 case IPP_OP_SET_JOB_ATTRIBUTES
:
498 set_job_attrs(con
, uri
);
501 case IPP_OP_SET_PRINTER_ATTRIBUTES
:
502 set_printer_attrs(con
, uri
);
505 case IPP_OP_HOLD_NEW_JOBS
:
506 hold_new_jobs(con
, uri
);
509 case IPP_OP_RELEASE_HELD_NEW_JOBS
:
510 release_held_new_jobs(con
, uri
);
513 case IPP_OP_CLOSE_JOB
:
517 case IPP_OP_CUPS_GET_DEFAULT
:
521 case IPP_OP_CUPS_GET_PRINTERS
:
522 get_printers(con
, 0);
525 case IPP_OP_CUPS_GET_CLASSES
:
526 get_printers(con
, CUPS_PRINTER_CLASS
);
529 case IPP_OP_CUPS_ADD_MODIFY_PRINTER
:
530 add_printer(con
, uri
);
533 case IPP_OP_CUPS_DELETE_PRINTER
:
534 delete_printer(con
, uri
);
537 case IPP_OP_CUPS_ADD_MODIFY_CLASS
:
541 case IPP_OP_CUPS_DELETE_CLASS
:
542 delete_printer(con
, uri
);
545 case IPP_OP_CUPS_ACCEPT_JOBS
:
546 case IPP_OP_ENABLE_PRINTER
:
547 accept_jobs(con
, uri
);
550 case IPP_OP_CUPS_REJECT_JOBS
:
551 case IPP_OP_DISABLE_PRINTER
:
552 reject_jobs(con
, uri
);
555 case IPP_OP_CUPS_SET_DEFAULT
:
556 set_default(con
, uri
);
559 case IPP_OP_CUPS_GET_DEVICES
:
563 case IPP_OP_CUPS_GET_DOCUMENT
:
564 get_document(con
, uri
);
567 case IPP_OP_CUPS_GET_PPD
:
571 case IPP_OP_CUPS_GET_PPDS
:
575 case IPP_OP_CUPS_MOVE_JOB
:
579 case IPP_OP_CUPS_AUTHENTICATE_JOB
:
580 authenticate_job(con
, uri
);
583 case IPP_OP_CREATE_PRINTER_SUBSCRIPTIONS
:
584 case IPP_OP_CREATE_JOB_SUBSCRIPTIONS
:
585 create_subscriptions(con
, uri
);
588 case IPP_OP_GET_SUBSCRIPTION_ATTRIBUTES
:
589 get_subscription_attrs(con
, sub_id
);
592 case IPP_OP_GET_SUBSCRIPTIONS
:
593 get_subscriptions(con
, uri
);
596 case IPP_OP_RENEW_SUBSCRIPTION
:
597 renew_subscription(con
, sub_id
);
600 case IPP_OP_CANCEL_SUBSCRIPTION
:
601 cancel_subscription(con
, sub_id
);
604 case IPP_OP_GET_NOTIFICATIONS
:
605 get_notifications(con
);
608 case IPP_OP_CUPS_CREATE_LOCAL_PRINTER
:
609 create_local_printer(con
);
613 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
, "%04X %s Operation %04X (%s) not supported.", IPP_STATUS_ERROR_OPERATION_NOT_SUPPORTED
, con
->http
->hostname
, con
->request
->request
.op
.operation_id
, ippOpString(con
->request
->request
.op
.operation_id
));
615 send_ipp_status(con
, IPP_STATUS_ERROR_OPERATION_NOT_SUPPORTED
, _("%s not supported."), ippOpString(con
->request
->request
.op
.operation_id
));
626 * Sending data from the scheduler...
629 cupsdLogClient(con
, con
->response
->request
.status
.status_code
>= IPP_STATUS_ERROR_BAD_REQUEST
&& con
->response
->request
.status
.status_code
!= IPP_STATUS_ERROR_NOT_FOUND
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
, "Returning IPP %s for %s (%s) from %s.", ippErrorString(con
->response
->request
.status
.status_code
), ippOpString(con
->request
->request
.op
.operation_id
), uri
? uri
->values
[0].string
.text
: "no URI", con
->http
->hostname
);
631 httpClearFields(con
->http
);
633 #ifdef CUPSD_USE_CHUNKING
635 * Because older versions of CUPS (1.1.17 and older) and some IPP
636 * clients do not implement chunking properly, we cannot use
637 * chunking by default. This may become the default in future
638 * CUPS releases, or we might add a configuration directive for
642 if (con
->http
->version
== HTTP_1_1
)
644 cupsdLogClient(con
, CUPSD_LOG_DEBUG
, "Transfer-Encoding: chunked");
645 cupsdSetLength(con
->http
, 0);
648 #endif /* CUPSD_USE_CHUNKING */
650 size_t length
; /* Length of response */
653 length
= ippLength(con
->response
);
655 if (con
->file
>= 0 && !con
->pipe_pid
)
657 struct stat fileinfo
; /* File information */
659 if (!fstat(con
->file
, &fileinfo
))
660 length
+= (size_t)fileinfo
.st_size
;
663 cupsdLogClient(con
, CUPSD_LOG_DEBUG
, "Content-Length: " CUPS_LLFMT
, CUPS_LLCAST length
);
664 httpSetLength(con
->http
, length
);
667 if (cupsdSendHeader(con
, HTTP_OK
, "application/ipp", CUPSD_AUTH_NONE
))
670 * Tell the caller the response header was sent successfully...
673 cupsdAddSelect(httpGetFd(con
->http
), (cupsd_selfunc_t
)cupsdReadClient
, (cupsd_selfunc_t
)cupsdWriteClient
, con
);
680 * Tell the caller the response header could not be sent...
689 * Sending data from a subprocess like cups-deviced; tell the caller
690 * everything is A-OK so far...
699 * 'cupsdTimeoutJob()' - Timeout a job waiting on job files.
702 int /* O - 0 on success, -1 on error */
703 cupsdTimeoutJob(cupsd_job_t
*job
) /* I - Job to timeout */
705 cupsd_printer_t
*printer
; /* Destination printer or class */
706 ipp_attribute_t
*attr
; /* job-sheets attribute */
707 int kbytes
; /* Kilobytes in banner */
710 job
->pending_timeout
= 0;
713 * See if we need to add the ending sheet...
716 if (!cupsdLoadJob(job
))
719 printer
= cupsdFindDest(job
->dest
);
720 attr
= ippFindAttribute(job
->attrs
, "job-sheets", IPP_TAG_NAME
);
722 if (printer
&& !(printer
->type
& CUPS_PRINTER_REMOTE
) &&
723 attr
&& attr
->num_values
> 1)
729 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding end banner page \"%s\".",
730 attr
->values
[1].string
.text
);
732 if ((kbytes
= copy_banner(NULL
, job
, attr
->values
[1].string
.text
)) < 0)
735 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
743 * 'accept_jobs()' - Accept print jobs to a printer.
747 accept_jobs(cupsd_client_t
*con
, /* I - Client connection */
748 ipp_attribute_t
*uri
) /* I - Printer or class URI */
750 http_status_t status
; /* Policy status */
751 cups_ptype_t dtype
; /* Destination type (printer/class) */
752 cupsd_printer_t
*printer
; /* Printer data */
755 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "accept_jobs(%p[%d], %s)", con
,
756 con
->number
, uri
->values
[0].string
.text
);
759 * Is the destination valid?
762 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
768 send_ipp_status(con
, IPP_NOT_FOUND
,
769 _("The printer or class does not exist."));
777 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
779 send_http_error(con
, status
, printer
);
784 * Accept jobs sent to the printer...
787 printer
->accepting
= 1;
788 printer
->state_message
[0] = '\0';
790 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
791 "Now accepting jobs.");
793 if (dtype
& CUPS_PRINTER_CLASS
)
795 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
797 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" now accepting jobs (\"%s\").",
798 printer
->name
, get_username(con
));
802 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
804 cupsdLogMessage(CUPSD_LOG_INFO
,
805 "Printer \"%s\" now accepting jobs (\"%s\").",
806 printer
->name
, get_username(con
));
810 * Everything was ok, so return OK status...
813 con
->response
->request
.status
.status_code
= IPP_OK
;
818 * 'add_class()' - Add a class to the system.
822 add_class(cupsd_client_t
*con
, /* I - Client connection */
823 ipp_attribute_t
*uri
) /* I - URI of class */
825 http_status_t status
; /* Policy status */
826 int i
; /* Looping var */
827 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
828 username
[HTTP_MAX_URI
], /* Username portion of URI */
829 host
[HTTP_MAX_URI
], /* Host portion of URI */
830 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
831 int port
; /* Port portion of URI */
832 cupsd_printer_t
*pclass
, /* Class */
833 *member
; /* Member printer/class */
834 cups_ptype_t dtype
; /* Destination type */
835 ipp_attribute_t
*attr
; /* Printer attribute */
836 int modify
; /* Non-zero if we just modified */
837 int need_restart_job
; /* Need to restart job? */
840 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_class(%p[%d], %s)", con
,
841 con
->number
, uri
->values
[0].string
.text
);
844 * Do we have a valid URI?
847 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
848 sizeof(scheme
), username
, sizeof(username
), host
,
849 sizeof(host
), &port
, resource
, sizeof(resource
));
852 if (strncmp(resource
, "/classes/", 9) || strlen(resource
) == 9)
855 * No, return an error...
858 send_ipp_status(con
, IPP_BAD_REQUEST
,
859 _("The printer-uri must be of the form "
860 "\"ipp://HOSTNAME/classes/CLASSNAME\"."));
865 * Do we have a valid printer name?
868 if (!validate_name(resource
+ 9))
871 * No, return an error...
874 send_ipp_status(con
, IPP_BAD_REQUEST
,
875 _("The printer-uri \"%s\" contains invalid characters."),
876 uri
->values
[0].string
.text
);
881 * See if the class already exists; if not, create a new class...
884 if ((pclass
= cupsdFindClass(resource
+ 9)) == NULL
)
887 * Class doesn't exist; see if we have a printer of the same name...
890 if ((pclass
= cupsdFindPrinter(resource
+ 9)) != NULL
)
893 * Yes, return an error...
896 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
897 _("A printer named \"%s\" already exists."),
903 * No, check the default policy and then add the class...
906 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
908 send_http_error(con
, status
, NULL
);
912 pclass
= cupsdAddClass(resource
+ 9);
915 pclass
->printer_id
= NextPrinterId
++;
917 else if ((status
= cupsdCheckPolicy(pclass
->op_policy_ptr
, con
,
920 send_http_error(con
, status
, pclass
);
927 * Look for attributes and copy them over as needed...
930 need_restart_job
= 0;
932 if ((attr
= ippFindAttribute(con
->request
, "printer-location", IPP_TAG_TEXT
)) != NULL
)
933 cupsdSetString(&pclass
->location
, attr
->values
[0].string
.text
);
935 if ((attr
= ippFindAttribute(con
->request
, "printer-geo-location", IPP_TAG_URI
)) != NULL
&& !strncmp(attr
->values
[0].string
.text
, "geo:", 4))
936 cupsdSetString(&pclass
->geo_location
, attr
->values
[0].string
.text
);
938 if ((attr
= ippFindAttribute(con
->request
, "printer-organization", IPP_TAG_TEXT
)) != NULL
)
939 cupsdSetString(&pclass
->organization
, attr
->values
[0].string
.text
);
941 if ((attr
= ippFindAttribute(con
->request
, "printer-organizational-unit", IPP_TAG_TEXT
)) != NULL
)
942 cupsdSetString(&pclass
->organizational_unit
, attr
->values
[0].string
.text
);
944 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
945 IPP_TAG_TEXT
)) != NULL
)
946 cupsdSetString(&pclass
->info
, attr
->values
[0].string
.text
);
948 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
949 IPP_TAG_BOOLEAN
)) != NULL
&&
950 attr
->values
[0].boolean
!= pclass
->accepting
)
952 cupsdLogMessage(CUPSD_LOG_INFO
,
953 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
954 pclass
->name
, attr
->values
[0].boolean
, pclass
->accepting
);
956 pclass
->accepting
= attr
->values
[0].boolean
;
958 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s accepting jobs.",
959 pclass
->accepting
? "Now" : "No longer");
962 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared", IPP_TAG_BOOLEAN
)) != NULL
)
964 if (pclass
->type
& CUPS_PRINTER_REMOTE
)
967 * Cannot re-share remote printers.
970 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Cannot change printer-is-shared for remote queues."));
972 cupsdDeletePrinter(pclass
, 0);
977 if (pclass
->shared
&& !ippGetBoolean(attr
, 0))
978 cupsdDeregisterPrinter(pclass
, 1);
980 cupsdLogMessage(CUPSD_LOG_INFO
,
981 "Setting %s printer-is-shared to %d (was %d.)",
982 pclass
->name
, attr
->values
[0].boolean
, pclass
->shared
);
984 pclass
->shared
= ippGetBoolean(attr
, 0);
987 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
988 IPP_TAG_ENUM
)) != NULL
)
990 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
991 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
993 send_ipp_status(con
, IPP_BAD_REQUEST
,
994 _("Attempt to set %s printer-state to bad value %d."),
995 pclass
->name
, attr
->values
[0].integer
);
997 cupsdDeletePrinter(pclass
, 0);
1002 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
1003 pclass
->name
, attr
->values
[0].integer
, pclass
->state
);
1005 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
1006 cupsdStopPrinter(pclass
, 0);
1009 cupsdSetPrinterState(pclass
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
1010 need_restart_job
= 1;
1013 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
1014 IPP_TAG_TEXT
)) != NULL
)
1016 strlcpy(pclass
->state_message
, attr
->values
[0].string
.text
,
1017 sizeof(pclass
->state_message
));
1019 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s",
1020 pclass
->state_message
);
1022 if ((attr
= ippFindAttribute(con
->request
, "member-uris",
1023 IPP_TAG_URI
)) != NULL
)
1026 * Clear the printer array as needed...
1029 need_restart_job
= 1;
1031 if (pclass
->num_printers
> 0)
1033 free(pclass
->printers
);
1034 pclass
->num_printers
= 0;
1038 * Add each printer or class that is listed...
1041 for (i
= 0; i
< attr
->num_values
; i
++)
1044 * Search for the printer or class URI...
1047 if (!cupsdValidateDest(attr
->values
[i
].string
.text
, &dtype
, &member
))
1053 send_ipp_status(con
, IPP_NOT_FOUND
,
1054 _("The printer or class does not exist."));
1056 cupsdDeletePrinter(pclass
, 0);
1060 else if (dtype
& CUPS_PRINTER_CLASS
)
1062 send_ipp_status(con
, IPP_BAD_REQUEST
,
1063 _("Nested classes are not allowed."));
1065 cupsdDeletePrinter(pclass
, 0);
1071 * Add it to the class...
1074 cupsdAddPrinterToClass(pclass
, member
);
1078 if (!set_printer_defaults(con
, pclass
))
1081 cupsdDeletePrinter(pclass
, 0);
1086 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
1087 IPP_TAG_KEYWORD
)) != NULL
)
1088 cupsdSetAuthInfoRequired(pclass
, NULL
, attr
);
1090 pclass
->config_time
= time(NULL
);
1093 * Update the printer class attributes and return...
1096 cupsdSetPrinterAttrs(pclass
);
1097 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
1099 if (need_restart_job
&& pclass
->job
)
1102 * Reset the current job to a "pending" status...
1105 cupsdSetJobState(pclass
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
1106 "Job restarted because the class was modified.");
1109 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1113 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
1114 pclass
, NULL
, "Class \"%s\" modified by \"%s\".",
1115 pclass
->name
, get_username(con
));
1117 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" modified by \"%s\".",
1118 pclass
->name
, get_username(con
));
1122 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
1123 pclass
, NULL
, "New class \"%s\" added by \"%s\".",
1124 pclass
->name
, get_username(con
));
1126 cupsdLogMessage(CUPSD_LOG_INFO
, "New class \"%s\" added by \"%s\".",
1127 pclass
->name
, get_username(con
));
1130 con
->response
->request
.status
.status_code
= IPP_OK
;
1135 * 'add_file()' - Add a file to a job.
1138 static int /* O - 0 on success, -1 on error */
1139 add_file(cupsd_client_t
*con
, /* I - Connection to client */
1140 cupsd_job_t
*job
, /* I - Job to add to */
1141 mime_type_t
*filetype
, /* I - Type of file */
1142 int compression
) /* I - Compression */
1144 mime_type_t
**filetypes
; /* New filetypes array... */
1145 int *compressions
; /* New compressions array... */
1148 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1149 "add_file(con=%p[%d], job=%d, filetype=%s/%s, "
1150 "compression=%d)", con
, con
? con
->number
: -1, job
->id
,
1151 filetype
->super
, filetype
->type
, compression
);
1154 * Add the file to the job...
1157 if (job
->num_files
== 0)
1159 compressions
= (int *)malloc(sizeof(int));
1160 filetypes
= (mime_type_t
**)malloc(sizeof(mime_type_t
*));
1164 compressions
= (int *)realloc(job
->compressions
,
1165 (size_t)(job
->num_files
+ 1) * sizeof(int));
1166 filetypes
= (mime_type_t
**)realloc(job
->filetypes
,
1167 (size_t)(job
->num_files
+ 1) *
1168 sizeof(mime_type_t
*));
1172 job
->compressions
= compressions
;
1175 job
->filetypes
= filetypes
;
1177 if (!compressions
|| !filetypes
)
1179 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1180 "Job aborted because the scheduler ran out of memory.");
1183 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1184 _("Unable to allocate memory for file types."));
1189 job
->compressions
[job
->num_files
] = compression
;
1190 job
->filetypes
[job
->num_files
] = filetype
;
1195 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1202 * 'add_job()' - Add a job to a print queue.
1205 static cupsd_job_t
* /* O - Job object */
1206 add_job(cupsd_client_t
*con
, /* I - Client connection */
1207 cupsd_printer_t
*printer
, /* I - Destination printer */
1208 mime_type_t
*filetype
) /* I - First print file type, if any */
1210 http_status_t status
; /* Policy status */
1211 ipp_attribute_t
*attr
, /* Current attribute */
1212 *auth_info
; /* auth-info attribute */
1213 const char *mandatory
; /* Current mandatory job attribute */
1214 const char *val
; /* Default option value */
1215 int priority
; /* Job priority */
1216 cupsd_job_t
*job
; /* Current job */
1217 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
1218 int kbytes
; /* Size of print file */
1219 int i
; /* Looping var */
1220 int lowerpagerange
; /* Page range bound */
1221 int exact
; /* Did we have an exact match? */
1222 ipp_attribute_t
*media_col
, /* media-col attribute */
1223 *media_margin
; /* media-*-margin attribute */
1224 ipp_t
*unsup_col
; /* media-col in unsupported response */
1225 static const char * const readonly
[] =/* List of read-only attributes */
1227 "date-time-at-completed",
1228 "date-time-at-creation",
1229 "date-time-at-processing",
1230 "job-detailed-status-messages",
1231 "job-document-access-errors",
1233 "job-impressions-completed",
1234 "job-k-octets-completed",
1235 "job-media-sheets-completed",
1236 "job-pages-completed",
1237 "job-printer-up-time",
1240 "job-state-message",
1241 "job-state-reasons",
1243 "number-of-documents",
1244 "number-of-intervening-jobs",
1245 "output-device-assigned",
1246 "time-at-completed",
1248 "time-at-processing"
1252 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job(%p[%d], %p(%s), %p(%s/%s))",
1253 con
, con
->number
, printer
, printer
->name
,
1254 filetype
, filetype
? filetype
->super
: "none",
1255 filetype
? filetype
->type
: "none");
1258 * Check remote printing to non-shared printer...
1261 if (!printer
->shared
&&
1262 _cups_strcasecmp(con
->http
->hostname
, "localhost") &&
1263 _cups_strcasecmp(con
->http
->hostname
, ServerName
))
1265 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
1266 _("The printer or class is not shared."));
1274 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
1276 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
1278 send_http_error(con
, status
, printer
);
1281 else if (printer
->num_auth_info_required
== 1 &&
1282 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
1285 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
1289 else if (auth_info
&& !con
->http
->tls
&&
1290 !httpAddrLocalhost(con
->http
->hostaddr
))
1293 * Require encryption of auth-info over non-local connections...
1296 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
1299 #endif /* HAVE_SSL */
1302 * See if the printer is accepting jobs...
1305 if (!printer
->accepting
)
1307 send_ipp_status(con
, IPP_NOT_ACCEPTING
,
1308 _("Destination \"%s\" is not accepting jobs."),
1314 * Validate job template attributes; for now just document-format,
1315 * copies, job-sheets, number-up, page-ranges, mandatory attributes, and
1319 for (i
= 0; i
< (int)(sizeof(readonly
) / sizeof(readonly
[0])); i
++)
1321 if ((attr
= ippFindAttribute(con
->request
, readonly
[i
], IPP_TAG_ZERO
)) != NULL
)
1323 ippDeleteAttribute(con
->request
, attr
);
1325 if (StrictConformance
)
1327 send_ipp_status(con
, IPP_BAD_REQUEST
, _("The '%s' Job Status attribute cannot be supplied in a job creation request."), readonly
[i
]);
1331 cupsdLogMessage(CUPSD_LOG_INFO
, "Unexpected '%s' Job Status attribute in a job creation request.", readonly
[i
]);
1337 for (mandatory
= (char *)cupsArrayFirst(printer
->pc
->mandatory
);
1339 mandatory
= (char *)cupsArrayNext(printer
->pc
->mandatory
))
1341 if (!ippFindAttribute(con
->request
, mandatory
, IPP_TAG_ZERO
))
1344 * Missing a required attribute...
1347 send_ipp_status(con
, IPP_CONFLICT
,
1348 _("The \"%s\" attribute is required for print jobs."),
1355 if (filetype
&& printer
->filetypes
&&
1356 !cupsArrayFind(printer
->filetypes
, filetype
))
1358 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
1359 /* MIME media type string */
1362 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
1365 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
1366 _("Unsupported format \"%s\"."), mimetype
);
1368 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
1369 "document-format", NULL
, mimetype
);
1374 if ((attr
= ippFindAttribute(con
->request
, "copies",
1375 IPP_TAG_INTEGER
)) != NULL
)
1377 if (attr
->values
[0].integer
< 1 || attr
->values
[0].integer
> MaxCopies
)
1379 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad copies value %d."),
1380 attr
->values
[0].integer
);
1381 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1382 "copies", attr
->values
[0].integer
);
1387 if ((attr
= ippFindAttribute(con
->request
, "job-sheets",
1388 IPP_TAG_ZERO
)) != NULL
)
1390 if (attr
->value_tag
!= IPP_TAG_KEYWORD
&&
1391 attr
->value_tag
!= IPP_TAG_NAME
)
1393 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value type."));
1397 if (attr
->num_values
> 2)
1399 send_ipp_status(con
, IPP_BAD_REQUEST
,
1400 _("Too many job-sheets values (%d > 2)."),
1405 for (i
= 0; i
< attr
->num_values
; i
++)
1406 if (strcmp(attr
->values
[i
].string
.text
, "none") &&
1407 !cupsdFindBanner(attr
->values
[i
].string
.text
))
1409 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value \"%s\"."),
1410 attr
->values
[i
].string
.text
);
1415 if ((attr
= ippFindAttribute(con
->request
, "number-up",
1416 IPP_TAG_INTEGER
)) != NULL
)
1418 if (attr
->values
[0].integer
!= 1 &&
1419 attr
->values
[0].integer
!= 2 &&
1420 attr
->values
[0].integer
!= 4 &&
1421 attr
->values
[0].integer
!= 6 &&
1422 attr
->values
[0].integer
!= 9 &&
1423 attr
->values
[0].integer
!= 16)
1425 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad number-up value %d."),
1426 attr
->values
[0].integer
);
1427 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1428 "number-up", attr
->values
[0].integer
);
1433 if ((attr
= ippFindAttribute(con
->request
, "page-ranges",
1434 IPP_TAG_RANGE
)) != NULL
)
1436 for (i
= 0, lowerpagerange
= 1; i
< attr
->num_values
; i
++)
1438 if (attr
->values
[i
].range
.lower
< lowerpagerange
||
1439 attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
1441 send_ipp_status(con
, IPP_BAD_REQUEST
,
1442 _("Bad page-ranges values %d-%d."),
1443 attr
->values
[i
].range
.lower
,
1444 attr
->values
[i
].range
.upper
);
1448 lowerpagerange
= attr
->values
[i
].range
.upper
+ 1;
1453 * Do media selection as needed...
1456 if (!ippFindAttribute(con
->request
, "PageRegion", IPP_TAG_ZERO
) &&
1457 !ippFindAttribute(con
->request
, "PageSize", IPP_TAG_ZERO
) &&
1458 _ppdCacheGetPageSize(printer
->pc
, con
->request
, NULL
, &exact
))
1461 (media_col
= ippFindAttribute(con
->request
, "media-col",
1462 IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
1464 send_ipp_status(con
, IPP_OK_SUBST
, _("Unsupported margins."));
1466 unsup_col
= ippNew();
1467 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1468 "media-bottom-margin",
1469 IPP_TAG_INTEGER
)) != NULL
)
1470 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1471 "media-bottom-margin", media_margin
->values
[0].integer
);
1473 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1474 "media-left-margin",
1475 IPP_TAG_INTEGER
)) != NULL
)
1476 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1477 "media-left-margin", media_margin
->values
[0].integer
);
1479 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1480 "media-right-margin",
1481 IPP_TAG_INTEGER
)) != NULL
)
1482 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1483 "media-right-margin", media_margin
->values
[0].integer
);
1485 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1487 IPP_TAG_INTEGER
)) != NULL
)
1488 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1489 "media-top-margin", media_margin
->values
[0].integer
);
1491 ippAddCollection(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, "media-col",
1493 ippDelete(unsup_col
);
1498 * Make sure we aren't over our limit...
1501 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1504 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1506 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Too many active jobs."));
1510 if ((i
= check_quotas(con
, printer
)) < 0)
1512 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
1517 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
1522 * Create the job and set things up...
1525 if ((attr
= ippFindAttribute(con
->request
, "job-priority",
1526 IPP_TAG_INTEGER
)) != NULL
)
1527 priority
= attr
->values
[0].integer
;
1530 if ((val
= cupsGetOption("job-priority", printer
->num_options
,
1531 printer
->options
)) != NULL
)
1532 priority
= atoi(val
);
1536 ippAddInteger(con
->request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-priority",
1540 if ((attr
= ippFindAttribute(con
->request
, "job-name", IPP_TAG_ZERO
)) == NULL
)
1541 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
, "Untitled");
1542 else if ((attr
->value_tag
!= IPP_TAG_NAME
&&
1543 attr
->value_tag
!= IPP_TAG_NAMELANG
) ||
1544 attr
->num_values
!= 1)
1546 send_ipp_status(con
, IPP_ATTRIBUTES
,
1547 _("Bad job-name value: Wrong type or count."));
1548 if ((attr
= ippCopyAttribute(con
->response
, attr
, 0)) != NULL
)
1549 attr
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
1551 if (StrictConformance
)
1554 /* Don't use invalid attribute */
1555 ippDeleteAttribute(con
->request
, attr
);
1557 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
, "Untitled");
1559 else if (!ippValidateAttribute(attr
))
1561 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad job-name value: %s"),
1562 cupsLastErrorString());
1564 if ((attr
= ippCopyAttribute(con
->response
, attr
, 0)) != NULL
)
1565 attr
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
1567 if (StrictConformance
)
1570 /* Don't use invalid attribute */
1571 ippDeleteAttribute(con
->request
, attr
);
1573 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
, "Untitled");
1576 attr
= ippFindAttribute(con
->request
, "requesting-user-name", IPP_TAG_NAME
);
1578 if ((job
= cupsdAddJob(priority
, printer
->name
)) == NULL
)
1580 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1581 _("Unable to add job for destination \"%s\"."),
1586 job
->dtype
= printer
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
1587 job
->attrs
= con
->request
;
1589 con
->request
= ippNewRequest(job
->attrs
->request
.op
.operation_id
);
1591 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1594 apply_printer_defaults(printer
, job
);
1596 if (con
->username
[0])
1598 cupsdSetString(&job
->username
, con
->username
);
1601 ippSetString(job
->attrs
, &attr
, 0, con
->username
);
1605 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1606 "add_job: requesting-user-name=\"%s\"",
1607 attr
->values
[0].string
.text
);
1609 cupsdSetString(&job
->username
, attr
->values
[0].string
.text
);
1612 cupsdSetString(&job
->username
, "anonymous");
1615 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1616 "job-originating-user-name", NULL
, job
->username
);
1619 ippSetGroupTag(job
->attrs
, &attr
, IPP_TAG_JOB
);
1620 ippSetName(job
->attrs
, &attr
, "job-originating-user-name");
1623 if (con
->username
[0] || auth_info
)
1625 save_auth_info(con
, job
, auth_info
);
1628 * Remove the auth-info attribute from the attribute data...
1632 ippDeleteAttribute(job
->attrs
, auth_info
);
1635 if ((attr
= ippFindAttribute(con
->request
, "job-name", IPP_TAG_NAME
)) != NULL
)
1636 cupsdSetString(&(job
->name
), attr
->values
[0].string
.text
);
1638 if ((attr
= ippFindAttribute(job
->attrs
, "job-originating-host-name",
1639 IPP_TAG_ZERO
)) != NULL
)
1642 * Request contains a job-originating-host-name attribute; validate it...
1645 if (attr
->value_tag
!= IPP_TAG_NAME
||
1646 attr
->num_values
!= 1 ||
1647 strcmp(con
->http
->hostname
, "localhost"))
1650 * Can't override the value if we aren't connected via localhost.
1651 * Also, we can only have 1 value and it must be a name value.
1654 ippDeleteAttribute(job
->attrs
, attr
);
1655 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-originating-host-name", NULL
, con
->http
->hostname
);
1658 ippSetGroupTag(job
->attrs
, &attr
, IPP_TAG_JOB
);
1663 * No job-originating-host-name attribute, so use the hostname from
1667 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1668 "job-originating-host-name", NULL
, con
->http
->hostname
);
1671 ippAddOutOfBand(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NOVALUE
, "date-time-at-completed");
1672 ippAddDate(job
->attrs
, IPP_TAG_JOB
, "date-time-at-creation", ippTimeToDate(time(NULL
)));
1673 ippAddOutOfBand(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NOVALUE
, "date-time-at-processing");
1674 ippAddOutOfBand(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NOVALUE
, "time-at-completed");
1675 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation", time(NULL
));
1676 ippAddOutOfBand(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NOVALUE
, "time-at-processing");
1679 * Add remaining job attributes...
1682 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1683 job
->state
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_ENUM
,
1684 "job-state", IPP_JOB_STOPPED
);
1685 job
->state_value
= (ipp_jstate_t
)job
->state
->values
[0].integer
;
1686 job
->reasons
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1687 "job-state-reasons", NULL
, "job-incoming");
1688 job
->impressions
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-impressions-completed", 0);
1689 job
->sheets
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1690 "job-media-sheets-completed", 0);
1691 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-printer-uri", NULL
,
1694 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets", IPP_TAG_INTEGER
)) != NULL
)
1695 attr
->values
[0].integer
= 0;
1697 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-k-octets", 0);
1699 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
1700 IPP_TAG_KEYWORD
)) == NULL
)
1701 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
1704 if ((val
= cupsGetOption("job-hold-until", printer
->num_options
,
1705 printer
->options
)) == NULL
)
1708 attr
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1709 "job-hold-until", NULL
, val
);
1712 if (printer
->holding_new_jobs
)
1715 * Hold all new jobs on this printer...
1718 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
1719 cupsdSetJobHoldUntil(job
, ippGetString(attr
, 0, NULL
), 0);
1721 cupsdSetJobHoldUntil(job
, "indefinite", 0);
1723 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1724 job
->state_value
= IPP_JOB_HELD
;
1726 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-held-on-create");
1728 else if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
1731 * Hold job until specified time...
1734 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
1736 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1737 job
->state_value
= IPP_JOB_HELD
;
1739 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-hold-until-specified");
1741 else if (job
->attrs
->request
.op
.operation_id
== IPP_CREATE_JOB
)
1743 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
1744 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1745 job
->state_value
= IPP_JOB_HELD
;
1749 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1750 job
->state_value
= IPP_JOB_PENDING
;
1752 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
1755 if (!(printer
->type
& CUPS_PRINTER_REMOTE
) || Classification
)
1758 * Add job sheets options...
1761 if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1762 IPP_TAG_ZERO
)) == NULL
)
1764 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1765 "Adding default job-sheets values \"%s,%s\"...",
1766 printer
->job_sheets
[0], printer
->job_sheets
[1]);
1768 attr
= ippAddStrings(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-sheets",
1770 ippSetString(job
->attrs
, &attr
, 0, printer
->job_sheets
[0]);
1771 ippSetString(job
->attrs
, &attr
, 1, printer
->job_sheets
[1]);
1774 job
->job_sheets
= attr
;
1777 * Enforce classification level if set...
1782 cupsdLogMessage(CUPSD_LOG_INFO
,
1783 "Classification=\"%s\", ClassifyOverride=%d",
1784 Classification
? Classification
: "(null)",
1787 if (ClassifyOverride
)
1789 if (!strcmp(attr
->values
[0].string
.text
, "none") &&
1790 (attr
->num_values
== 1 ||
1791 !strcmp(attr
->values
[1].string
.text
, "none")))
1794 * Force the leading banner to have the classification on it...
1797 ippSetString(job
->attrs
, &attr
, 0, Classification
);
1799 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1800 "job-sheets=\"%s,none\", "
1801 "job-originating-user-name=\"%s\"",
1802 Classification
, job
->username
);
1804 else if (attr
->num_values
== 2 &&
1805 strcmp(attr
->values
[0].string
.text
,
1806 attr
->values
[1].string
.text
) &&
1807 strcmp(attr
->values
[0].string
.text
, "none") &&
1808 strcmp(attr
->values
[1].string
.text
, "none"))
1811 * Can't put two different security markings on the same document!
1814 ippSetString(job
->attrs
, &attr
, 1, attr
->values
[0].string
.text
);
1816 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1817 "job-sheets=\"%s,%s\", "
1818 "job-originating-user-name=\"%s\"",
1819 attr
->values
[0].string
.text
,
1820 attr
->values
[1].string
.text
, job
->username
);
1822 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1823 strcmp(attr
->values
[0].string
.text
, "none") &&
1824 (attr
->num_values
== 1 ||
1825 (strcmp(attr
->values
[1].string
.text
, Classification
) &&
1826 strcmp(attr
->values
[1].string
.text
, "none"))))
1828 if (attr
->num_values
== 1)
1829 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1830 "CLASSIFICATION OVERRIDDEN "
1831 "job-sheets=\"%s\", "
1832 "job-originating-user-name=\"%s\"",
1833 attr
->values
[0].string
.text
, job
->username
);
1835 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1836 "CLASSIFICATION OVERRIDDEN "
1837 "job-sheets=\"%s,%s\",fffff "
1838 "job-originating-user-name=\"%s\"",
1839 attr
->values
[0].string
.text
,
1840 attr
->values
[1].string
.text
, job
->username
);
1843 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1844 (attr
->num_values
== 1 ||
1845 strcmp(attr
->values
[1].string
.text
, Classification
)))
1848 * Force the banner to have the classification on it...
1851 if (attr
->num_values
> 1 &&
1852 !strcmp(attr
->values
[0].string
.text
, attr
->values
[1].string
.text
))
1854 ippSetString(job
->attrs
, &attr
, 0, Classification
);
1855 ippSetString(job
->attrs
, &attr
, 1, Classification
);
1859 if (attr
->num_values
== 1 ||
1860 strcmp(attr
->values
[0].string
.text
, "none"))
1861 ippSetString(job
->attrs
, &attr
, 0, Classification
);
1863 if (attr
->num_values
> 1 &&
1864 strcmp(attr
->values
[1].string
.text
, "none"))
1865 ippSetString(job
->attrs
, &attr
, 1, Classification
);
1868 if (attr
->num_values
> 1)
1869 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1870 "CLASSIFICATION FORCED "
1871 "job-sheets=\"%s,%s\", "
1872 "job-originating-user-name=\"%s\"",
1873 attr
->values
[0].string
.text
,
1874 attr
->values
[1].string
.text
, job
->username
);
1876 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1877 "CLASSIFICATION FORCED "
1878 "job-sheets=\"%s\", "
1879 "job-originating-user-name=\"%s\"",
1880 Classification
, job
->username
);
1885 * See if we need to add the starting sheet...
1888 if (!(printer
->type
& CUPS_PRINTER_REMOTE
))
1890 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding start banner page \"%s\".",
1891 attr
->values
[0].string
.text
);
1893 if ((kbytes
= copy_banner(con
, job
, attr
->values
[0].string
.text
)) < 0)
1895 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1896 "Aborting job because the start banner could not be "
1901 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
1904 else if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1905 IPP_TAG_ZERO
)) != NULL
)
1906 job
->job_sheets
= attr
;
1909 * Fill in the response info...
1912 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
1913 con
->clientname
, con
->clientport
, "/jobs/%d", job
->id
);
1914 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
1917 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1919 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
1921 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_TEXT
, "job-state-message", NULL
, "");
1922 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons",
1923 NULL
, job
->reasons
->values
[0].string
.text
);
1925 con
->response
->request
.status
.status_code
= IPP_OK
;
1928 * Add any job subscriptions...
1931 add_job_subscriptions(con
, job
);
1934 * Set all but the first two attributes to the job attributes group...
1937 for (attr
= job
->attrs
->attrs
->next
->next
; attr
; attr
= attr
->next
)
1938 attr
->group_tag
= IPP_TAG_JOB
;
1941 * Fire the "job created" event...
1944 cupsdAddEvent(CUPSD_EVENT_JOB_CREATED
, printer
, job
, "Job created.");
1947 * Return the new job...
1955 * 'add_job_subscriptions()' - Add any subscriptions for a job.
1959 add_job_subscriptions(
1960 cupsd_client_t
*con
, /* I - Client connection */
1961 cupsd_job_t
*job
) /* I - Newly created job */
1963 int i
; /* Looping var */
1964 ipp_attribute_t
*prev
, /* Previous attribute */
1965 *next
, /* Next attribute */
1966 *attr
; /* Current attribute */
1967 cupsd_subscription_t
*sub
; /* Subscription object */
1968 const char *recipient
, /* notify-recipient-uri */
1969 *pullmethod
; /* notify-pull-method */
1970 ipp_attribute_t
*user_data
; /* notify-user-data */
1971 int interval
; /* notify-time-interval */
1972 unsigned mask
; /* notify-events */
1976 * Find the first subscription group attribute; return if we have
1980 for (attr
= job
->attrs
->attrs
; attr
; attr
= attr
->next
)
1981 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
1988 * Process the subscription attributes in the request...
1997 mask
= CUPSD_EVENT_NONE
;
1999 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
2001 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
2002 attr
->value_tag
== IPP_TAG_URI
)
2005 * Validate the recipient scheme against the ServerBin/notifier
2009 char notifier
[1024], /* Notifier filename */
2010 scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
2011 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
2012 host
[HTTP_MAX_URI
], /* Host portion of URI */
2013 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2014 int port
; /* Port portion of URI */
2015 struct stat info
; /* File information */
2017 recipient
= attr
->values
[0].string
.text
;
2019 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
2020 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
2021 host
, sizeof(host
), &port
,
2022 resource
, sizeof(resource
)) < HTTP_URI_OK
)
2024 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2025 _("Bad notify-recipient-uri \"%s\"."), recipient
);
2026 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2027 "notify-status-code", IPP_URI_SCHEME
);
2031 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
, scheme
);
2032 if (access(notifier
, X_OK
) || stat(notifier
, &info
) || !S_ISREG(info
.st_mode
))
2034 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2035 _("notify-recipient-uri URI \"%s\" uses unknown "
2036 "scheme."), recipient
);
2037 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2038 "notify-status-code", IPP_URI_SCHEME
);
2042 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
2044 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2045 _("notify-recipient-uri URI \"%s\" is already used."),
2047 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2048 "notify-status-code", IPP_ATTRIBUTES
);
2052 else if (!strcmp(attr
->name
, "notify-pull-method") &&
2053 attr
->value_tag
== IPP_TAG_KEYWORD
)
2055 pullmethod
= attr
->values
[0].string
.text
;
2057 if (strcmp(pullmethod
, "ippget"))
2059 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2060 _("Bad notify-pull-method \"%s\"."), pullmethod
);
2061 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2062 "notify-status-code", IPP_ATTRIBUTES
);
2066 else if (!strcmp(attr
->name
, "notify-charset") &&
2067 attr
->value_tag
== IPP_TAG_CHARSET
&&
2068 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
2069 strcmp(attr
->values
[0].string
.text
, "utf-8"))
2071 send_ipp_status(con
, IPP_CHARSET
,
2072 _("Character set \"%s\" not supported."),
2073 attr
->values
[0].string
.text
);
2076 else if (!strcmp(attr
->name
, "notify-natural-language") &&
2077 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
2078 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
2080 send_ipp_status(con
, IPP_CHARSET
,
2081 _("Language \"%s\" not supported."),
2082 attr
->values
[0].string
.text
);
2085 else if (!strcmp(attr
->name
, "notify-user-data") &&
2086 attr
->value_tag
== IPP_TAG_STRING
)
2088 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
2090 send_ipp_status(con
, IPP_REQUEST_VALUE
,
2091 _("The notify-user-data value is too large "
2092 "(%d > 63 octets)."),
2093 attr
->values
[0].unknown
.length
);
2099 else if (!strcmp(attr
->name
, "notify-events") &&
2100 attr
->value_tag
== IPP_TAG_KEYWORD
)
2102 for (i
= 0; i
< attr
->num_values
; i
++)
2103 mask
|= cupsdEventValue(attr
->values
[i
].string
.text
);
2105 else if (!strcmp(attr
->name
, "notify-lease-duration"))
2107 send_ipp_status(con
, IPP_BAD_REQUEST
,
2108 _("The notify-lease-duration attribute cannot be "
2109 "used with job subscriptions."));
2112 else if (!strcmp(attr
->name
, "notify-time-interval") &&
2113 attr
->value_tag
== IPP_TAG_INTEGER
)
2114 interval
= attr
->values
[0].integer
;
2119 if (!recipient
&& !pullmethod
)
2122 if (mask
== CUPSD_EVENT_NONE
)
2123 mask
= CUPSD_EVENT_JOB_COMPLETED
;
2125 if ((sub
= cupsdAddSubscription(mask
, cupsdFindDest(job
->dest
), job
,
2126 recipient
, 0)) != NULL
)
2128 sub
->interval
= interval
;
2130 cupsdSetString(&sub
->owner
, job
->username
);
2134 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
2135 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
2136 (size_t)sub
->user_data_len
);
2139 ippAddSeparator(con
->response
);
2140 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
2141 "notify-subscription-id", sub
->id
);
2143 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
2151 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
2154 * Remove all of the subscription attributes from the job request...
2156 * TODO: Optimize this since subscription groups have to come at the
2157 * end of the request...
2160 for (attr
= job
->attrs
->attrs
, prev
= NULL
; attr
; attr
= next
)
2164 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
||
2165 attr
->group_tag
== IPP_TAG_ZERO
)
2168 * Free and remove this attribute...
2171 ippDeleteAttribute(NULL
, attr
);
2176 job
->attrs
->attrs
= next
;
2182 job
->attrs
->last
= prev
;
2183 job
->attrs
->current
= prev
;
2188 * 'add_job_uuid()' - Add job-uuid attribute to a job.
2190 * See RFC 4122 for the definition of UUIDs and the format.
2194 add_job_uuid(cupsd_job_t
*job
) /* I - Job */
2196 char uuid
[64]; /* job-uuid string */
2200 * Add a job-uuid attribute if none exists...
2203 if (!ippFindAttribute(job
->attrs
, "job-uuid", IPP_TAG_URI
))
2204 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uuid", NULL
,
2205 httpAssembleUUID(ServerName
, RemotePort
, job
->dest
, job
->id
,
2206 uuid
, sizeof(uuid
)));
2211 * 'add_printer()' - Add a printer to the system.
2215 add_printer(cupsd_client_t
*con
, /* I - Client connection */
2216 ipp_attribute_t
*uri
) /* I - URI of printer */
2218 http_status_t status
; /* Policy status */
2219 int i
; /* Looping var */
2220 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
2221 username
[HTTP_MAX_URI
], /* Username portion of URI */
2222 host
[HTTP_MAX_URI
], /* Host portion of URI */
2223 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2224 int port
; /* Port portion of URI */
2225 cupsd_printer_t
*printer
; /* Printer/class */
2226 ipp_attribute_t
*attr
; /* Printer attribute */
2227 cups_file_t
*fp
; /* Script/PPD file */
2228 char line
[1024]; /* Line from file... */
2229 char srcfile
[1024], /* Source Script/PPD file */
2230 dstfile
[1024]; /* Destination Script/PPD file */
2231 int modify
; /* Non-zero if we are modifying */
2232 int changed_driver
, /* Changed the PPD? */
2233 need_restart_job
, /* Need to restart job? */
2234 set_device_uri
, /* Did we set the device URI? */
2235 set_port_monitor
; /* Did we set the port monitor? */
2238 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer(%p[%d], %s)", con
,
2239 con
->number
, uri
->values
[0].string
.text
);
2242 * Do we have a valid URI?
2245 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
2246 sizeof(scheme
), username
, sizeof(username
), host
,
2247 sizeof(host
), &port
, resource
, sizeof(resource
));
2249 if (strncmp(resource
, "/printers/", 10) || strlen(resource
) == 10)
2252 * No, return an error...
2255 send_ipp_status(con
, IPP_BAD_REQUEST
,
2256 _("The printer-uri must be of the form "
2257 "\"ipp://HOSTNAME/printers/PRINTERNAME\"."));
2262 * Do we have a valid printer name?
2265 if (!validate_name(resource
+ 10))
2268 * No, return an error...
2271 send_ipp_status(con
, IPP_BAD_REQUEST
,
2272 _("The printer-uri \"%s\" contains invalid characters."),
2273 uri
->values
[0].string
.text
);
2278 * See if the printer already exists; if not, create a new printer...
2281 if ((printer
= cupsdFindPrinter(resource
+ 10)) == NULL
)
2284 * Printer doesn't exist; see if we have a class of the same name...
2287 if ((printer
= cupsdFindClass(resource
+ 10)) != NULL
)
2290 * Yes, return an error...
2293 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2294 _("A class named \"%s\" already exists."),
2300 * No, check the default policy then add the printer...
2303 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2305 send_http_error(con
, status
, NULL
);
2309 printer
= cupsdAddPrinter(resource
+ 10);
2312 printer
->printer_id
= NextPrinterId
++;
2314 else if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
2317 send_http_error(con
, status
, printer
);
2324 * Look for attributes and copy them over as needed...
2328 need_restart_job
= 0;
2330 if ((attr
= ippFindAttribute(con
->request
, "printer-is-temporary", IPP_TAG_BOOLEAN
)) != NULL
)
2331 printer
->temporary
= ippGetBoolean(attr
, 0);
2333 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
2334 IPP_TAG_TEXT
)) != NULL
)
2335 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
2337 if ((attr
= ippFindAttribute(con
->request
, "printer-geo-location", IPP_TAG_URI
)) != NULL
&& !strncmp(attr
->values
[0].string
.text
, "geo:", 4))
2338 cupsdSetString(&printer
->geo_location
, attr
->values
[0].string
.text
);
2340 if ((attr
= ippFindAttribute(con
->request
, "printer-organization", IPP_TAG_TEXT
)) != NULL
)
2341 cupsdSetString(&printer
->organization
, attr
->values
[0].string
.text
);
2343 if ((attr
= ippFindAttribute(con
->request
, "printer-organizational-unit", IPP_TAG_TEXT
)) != NULL
)
2344 cupsdSetString(&printer
->organizational_unit
, attr
->values
[0].string
.text
);
2346 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
2347 IPP_TAG_TEXT
)) != NULL
)
2348 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
2352 if ((attr
= ippFindAttribute(con
->request
, "device-uri",
2353 IPP_TAG_URI
)) != NULL
)
2356 * Do we have a valid device URI?
2359 http_uri_status_t uri_status
; /* URI separation status */
2360 char old_device_uri
[1024];
2361 /* Old device URI */
2363 need_restart_job
= 1;
2365 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
,
2366 attr
->values
[0].string
.text
,
2367 scheme
, sizeof(scheme
),
2368 username
, sizeof(username
),
2369 host
, sizeof(host
), &port
,
2370 resource
, sizeof(resource
));
2372 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s device-uri: %s", printer
->name
, httpURIStatusString(uri_status
));
2374 if (uri_status
< HTTP_URI_OK
)
2376 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri \"%s\"."),
2377 attr
->values
[0].string
.text
);
2379 cupsdDeletePrinter(printer
, 0);
2384 if (!strcmp(scheme
, "file"))
2387 * See if the administrator has enabled file devices...
2390 if (!FileDevice
&& strcmp(resource
, "/dev/null"))
2393 * File devices are disabled and the URL is not file:/dev/null...
2396 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2397 _("File device URIs have been disabled. "
2398 "To enable, see the FileDevice directive in "
2399 "\"%s/cups-files.conf\"."),
2402 cupsdDeletePrinter(printer
, 0);
2410 * See if the backend exists and is executable...
2413 snprintf(srcfile
, sizeof(srcfile
), "%s/backend/%s", ServerBin
, scheme
);
2414 if (access(srcfile
, X_OK
))
2417 * Could not find device in list!
2420 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2421 _("Bad device-uri scheme \"%s\"."), scheme
);
2423 cupsdDeletePrinter(printer
, 0);
2429 if (printer
->sanitized_device_uri
)
2430 strlcpy(old_device_uri
, printer
->sanitized_device_uri
,
2431 sizeof(old_device_uri
));
2433 old_device_uri
[0] = '\0';
2435 cupsdSetDeviceURI(printer
, attr
->values
[0].string
.text
);
2437 cupsdLogMessage(CUPSD_LOG_INFO
,
2438 "Setting %s device-uri to \"%s\" (was \"%s\".)",
2439 printer
->name
, printer
->sanitized_device_uri
,
2445 set_port_monitor
= 0;
2447 if ((attr
= ippFindAttribute(con
->request
, "port-monitor",
2448 IPP_TAG_NAME
)) != NULL
)
2450 ipp_attribute_t
*supported
; /* port-monitor-supported attribute */
2453 need_restart_job
= 1;
2455 supported
= ippFindAttribute(printer
->ppd_attrs
, "port-monitor-supported",
2459 for (i
= 0; i
< supported
->num_values
; i
++)
2460 if (!strcmp(supported
->values
[i
].string
.text
,
2461 attr
->values
[0].string
.text
))
2465 if (!supported
|| i
>= supported
->num_values
)
2467 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad port-monitor \"%s\"."),
2468 attr
->values
[0].string
.text
);
2470 cupsdDeletePrinter(printer
, 0);
2475 cupsdLogMessage(CUPSD_LOG_INFO
,
2476 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2477 printer
->name
, attr
->values
[0].string
.text
,
2478 printer
->port_monitor
? printer
->port_monitor
: "none");
2480 if (strcmp(attr
->values
[0].string
.text
, "none"))
2481 cupsdSetString(&printer
->port_monitor
, attr
->values
[0].string
.text
);
2483 cupsdClearString(&printer
->port_monitor
);
2485 set_port_monitor
= 1;
2488 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
2489 IPP_TAG_BOOLEAN
)) != NULL
&&
2490 attr
->values
[0].boolean
!= printer
->accepting
)
2492 cupsdLogMessage(CUPSD_LOG_INFO
,
2493 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
2494 printer
->name
, attr
->values
[0].boolean
, printer
->accepting
);
2496 printer
->accepting
= attr
->values
[0].boolean
;
2498 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2499 "%s accepting jobs.",
2500 printer
->accepting
? "Now" : "No longer");
2503 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared", IPP_TAG_BOOLEAN
)) != NULL
)
2505 if (ippGetBoolean(attr
, 0) &&
2506 printer
->num_auth_info_required
== 1 &&
2507 !strcmp(printer
->auth_info_required
[0], "negotiate"))
2509 send_ipp_status(con
, IPP_BAD_REQUEST
,
2510 _("Cannot share a remote Kerberized printer."));
2512 cupsdDeletePrinter(printer
, 0);
2517 if (printer
->type
& CUPS_PRINTER_REMOTE
)
2520 * Cannot re-share remote printers.
2523 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Cannot change printer-is-shared for remote queues."));
2525 cupsdDeletePrinter(printer
, 0);
2530 if (printer
->shared
&& !ippGetBoolean(attr
, 0))
2531 cupsdDeregisterPrinter(printer
, 1);
2533 cupsdLogMessage(CUPSD_LOG_INFO
,
2534 "Setting %s printer-is-shared to %d (was %d.)",
2535 printer
->name
, attr
->values
[0].boolean
, printer
->shared
);
2537 printer
->shared
= ippGetBoolean(attr
, 0);
2538 if (printer
->shared
&& printer
->temporary
)
2539 printer
->temporary
= 0;
2542 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
2543 IPP_TAG_ENUM
)) != NULL
)
2545 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
2546 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
2548 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad printer-state value %d."),
2549 attr
->values
[0].integer
);
2551 cupsdDeletePrinter(printer
, 0);
2556 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
2557 printer
->name
, attr
->values
[0].integer
, printer
->state
);
2559 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
2560 cupsdStopPrinter(printer
, 0);
2563 need_restart_job
= 1;
2564 cupsdSetPrinterState(printer
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
2568 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
2569 IPP_TAG_TEXT
)) != NULL
)
2571 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
2572 sizeof(printer
->state_message
));
2574 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
, "%s",
2575 printer
->state_message
);
2578 if ((attr
= ippFindAttribute(con
->request
, "printer-state-reasons",
2579 IPP_TAG_KEYWORD
)) != NULL
)
2581 if (attr
->num_values
>
2582 (int)(sizeof(printer
->reasons
) / sizeof(printer
->reasons
[0])))
2584 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2585 _("Too many printer-state-reasons values (%d > %d)."),
2587 (int)(sizeof(printer
->reasons
) /
2588 sizeof(printer
->reasons
[0])));
2590 cupsdDeletePrinter(printer
, 0);
2595 for (i
= 0; i
< printer
->num_reasons
; i
++)
2596 _cupsStrFree(printer
->reasons
[i
]);
2598 printer
->num_reasons
= 0;
2599 for (i
= 0; i
< attr
->num_values
; i
++)
2601 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
2604 printer
->reasons
[printer
->num_reasons
] = _cupsStrAlloc(attr
->values
[i
].string
.text
);
2605 printer
->num_reasons
++;
2607 if (!strcmp(attr
->values
[i
].string
.text
, "paused") &&
2608 printer
->state
!= IPP_PRINTER_STOPPED
)
2610 cupsdLogMessage(CUPSD_LOG_INFO
,
2611 "Setting %s printer-state to %d (was %d.)",
2612 printer
->name
, IPP_PRINTER_STOPPED
, printer
->state
);
2613 cupsdStopPrinter(printer
, 0);
2617 if (PrintcapFormat
== PRINTCAP_PLIST
)
2618 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2620 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2621 "Printer \"%s\" state changed.", printer
->name
);
2624 if (!set_printer_defaults(con
, printer
))
2627 cupsdDeletePrinter(printer
, 0);
2632 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
2633 IPP_TAG_KEYWORD
)) != NULL
)
2634 cupsdSetAuthInfoRequired(printer
, NULL
, attr
);
2637 * See if we have all required attributes...
2640 if (!printer
->device_uri
)
2641 cupsdSetString(&printer
->device_uri
, "file:///dev/null");
2644 * See if we have a PPD file attached to the request...
2649 need_restart_job
= 1;
2652 strlcpy(srcfile
, con
->filename
, sizeof(srcfile
));
2654 if ((fp
= cupsFileOpen(srcfile
, "rb")))
2657 * Yes; get the first line from it...
2661 cupsFileGets(fp
, line
, sizeof(line
));
2665 * Then see what kind of file it is...
2668 if (strncmp(line
, "*PPD-Adobe", 10))
2670 send_ipp_status(con
, IPP_STATUS_ERROR_DOCUMENT_FORMAT_NOT_SUPPORTED
, _("Bad PPD file."));
2672 cupsdDeletePrinter(printer
, 0);
2677 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2681 * The new file is a PPD file, so move the file over to the ppd
2685 if (copy_file(srcfile
, dstfile
, ConfigFilePerm
))
2687 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file - %s"), strerror(errno
));
2689 cupsdDeletePrinter(printer
, 0);
2694 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Copied PPD file successfully");
2697 else if ((attr
= ippFindAttribute(con
->request
, "ppd-name", IPP_TAG_NAME
)) != NULL
)
2699 const char *ppd_name
= ippGetString(attr
, 0, NULL
);
2700 /* ppd-name value */
2702 need_restart_job
= 1;
2705 if (!strcmp(ppd_name
, "raw"))
2708 * Raw driver, remove any existing PPD file.
2711 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
, printer
->name
);
2714 else if (strstr(ppd_name
, "../"))
2716 send_ipp_status(con
, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES
, _("Invalid ppd-name value."));
2718 cupsdDeletePrinter(printer
, 0);
2728 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
, printer
->name
);
2730 if (copy_model(con
, ppd_name
, dstfile
))
2732 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file."));
2734 cupsdDeletePrinter(printer
, 0);
2739 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Copied PPD file successfully");
2746 * If we changed the PPD, then remove the printer's cache file and clear the
2747 * printer-state-reasons...
2750 char cache_name
[1024]; /* Cache filename for printer attrs */
2752 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.data", CacheDir
, printer
->name
);
2755 cupsdSetPrinterReasons(printer
, "none");
2758 * (Re)register color profiles...
2761 cupsdRegisterColor(printer
);
2765 * If we set the device URI but not the port monitor, check which port
2766 * monitor to use by default...
2769 if (set_device_uri
&& !set_port_monitor
)
2771 ppd_file_t
*ppd
; /* PPD file */
2772 ppd_attr_t
*ppdattr
; /* cupsPortMonitor attribute */
2775 httpSeparateURI(HTTP_URI_CODING_ALL
, printer
->device_uri
, scheme
,
2776 sizeof(scheme
), username
, sizeof(username
), host
,
2777 sizeof(host
), &port
, resource
, sizeof(resource
));
2779 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
,
2781 if ((ppd
= _ppdOpenFile(srcfile
, _PPD_LOCALIZATION_NONE
)) != NULL
)
2783 for (ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2785 ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
2786 if (!strcmp(scheme
, ppdattr
->spec
))
2788 cupsdLogMessage(CUPSD_LOG_INFO
,
2789 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2790 printer
->name
, ppdattr
->value
,
2791 printer
->port_monitor
? printer
->port_monitor
2794 if (strcmp(ppdattr
->value
, "none"))
2795 cupsdSetString(&printer
->port_monitor
, ppdattr
->value
);
2797 cupsdClearString(&printer
->port_monitor
);
2806 printer
->config_time
= time(NULL
);
2809 * Update the printer attributes and return...
2812 if (!printer
->temporary
)
2814 if (!printer
->printer_id
)
2815 printer
->printer_id
= NextPrinterId
++;
2817 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2820 cupsdSetPrinterAttrs(printer
);
2822 if (need_restart_job
&& printer
->job
)
2825 * Restart the current job...
2828 cupsdSetJobState(printer
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
2829 "Job restarted because the printer was modified.");
2832 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2836 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
2837 printer
, NULL
, "Printer \"%s\" modified by \"%s\".",
2838 printer
->name
, get_username(con
));
2840 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" modified by \"%s\".",
2841 printer
->name
, get_username(con
));
2845 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
2846 printer
, NULL
, "New printer \"%s\" added by \"%s\".",
2847 printer
->name
, get_username(con
));
2849 cupsdLogMessage(CUPSD_LOG_INFO
, "New printer \"%s\" added by \"%s\".",
2850 printer
->name
, get_username(con
));
2853 con
->response
->request
.status
.status_code
= IPP_OK
;
2858 * 'add_printer_state_reasons()' - Add the "printer-state-reasons" attribute
2859 * based upon the printer state...
2863 add_printer_state_reasons(
2864 cupsd_client_t
*con
, /* I - Client connection */
2865 cupsd_printer_t
*p
) /* I - Printer info */
2867 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2868 "add_printer_state_reasons(%p[%d], %p[%s])",
2869 con
, con
->number
, p
, p
->name
);
2871 if (p
->num_reasons
== 0)
2872 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2873 "printer-state-reasons", NULL
, "none");
2875 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2876 "printer-state-reasons", p
->num_reasons
, NULL
,
2877 (const char * const *)p
->reasons
);
2882 * 'add_queued_job_count()' - Add the "queued-job-count" attribute for
2883 * the specified printer or class.
2887 add_queued_job_count(
2888 cupsd_client_t
*con
, /* I - Client connection */
2889 cupsd_printer_t
*p
) /* I - Printer or class */
2891 int count
; /* Number of jobs on destination */
2894 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_queued_job_count(%p[%d], %p[%s])",
2895 con
, con
->number
, p
, p
->name
);
2897 count
= cupsdGetPrinterJobCount(p
->name
);
2899 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2900 "queued-job-count", count
);
2905 * 'apply_printer_defaults()' - Apply printer default options to a job.
2909 apply_printer_defaults(
2910 cupsd_printer_t
*printer
, /* I - Printer */
2911 cupsd_job_t
*job
) /* I - Job */
2913 int i
, /* Looping var */
2914 num_options
; /* Number of default options */
2915 cups_option_t
*options
, /* Default options */
2916 *option
; /* Current option */
2919 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Applying default options...");
2922 * Collect all of the default options and add the missing ones to the
2926 for (i
= printer
->num_options
, num_options
= 0, options
= NULL
,
2927 option
= printer
->options
;
2930 if (!ippFindAttribute(job
->attrs
, option
->name
, IPP_TAG_ZERO
))
2932 if (!strcmp(option
->name
, "print-quality") && ippFindAttribute(job
->attrs
, "cupsPrintQuality", IPP_TAG_NAME
))
2933 continue; /* Don't override cupsPrintQuality */
2935 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Adding default %s=%s", option
->name
, option
->value
);
2937 num_options
= cupsAddOption(option
->name
, option
->value
, num_options
, &options
);
2941 * Encode these options as attributes in the job object...
2944 cupsEncodeOptions2(job
->attrs
, num_options
, options
, IPP_TAG_JOB
);
2945 cupsFreeOptions(num_options
, options
);
2950 * 'authenticate_job()' - Set job authentication info.
2954 authenticate_job(cupsd_client_t
*con
, /* I - Client connection */
2955 ipp_attribute_t
*uri
) /* I - Job URI */
2957 ipp_attribute_t
*attr
, /* job-id attribute */
2958 *auth_info
; /* auth-info attribute */
2959 int jobid
; /* Job ID */
2960 cupsd_job_t
*job
; /* Current job */
2961 char scheme
[HTTP_MAX_URI
],
2962 /* Method portion of URI */
2963 username
[HTTP_MAX_URI
],
2964 /* Username portion of URI */
2966 /* Host portion of URI */
2967 resource
[HTTP_MAX_URI
];
2968 /* Resource portion of URI */
2969 int port
; /* Port portion of URI */
2972 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "authenticate_job(%p[%d], %s)",
2973 con
, con
->number
, uri
->values
[0].string
.text
);
2976 * Start with "everything is OK" status...
2979 con
->response
->request
.status
.status_code
= IPP_OK
;
2982 * See if we have a job URI or a printer URI...
2985 if (!strcmp(uri
->name
, "printer-uri"))
2988 * Got a printer URI; see if we also have a job-id attribute...
2991 if ((attr
= ippFindAttribute(con
->request
, "job-id",
2992 IPP_TAG_INTEGER
)) == NULL
)
2994 send_ipp_status(con
, IPP_BAD_REQUEST
,
2995 _("Got a printer-uri attribute but no job-id."));
2999 jobid
= attr
->values
[0].integer
;
3004 * Got a job URI; parse it to get the job ID...
3007 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
3008 sizeof(scheme
), username
, sizeof(username
), host
,
3009 sizeof(host
), &port
, resource
, sizeof(resource
));
3011 if (strncmp(resource
, "/jobs/", 6))
3017 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
3018 uri
->values
[0].string
.text
);
3022 jobid
= atoi(resource
+ 6);
3026 * See if the job exists...
3029 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3032 * Nope - return a "not found" error...
3035 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
3040 * See if the job has been completed...
3043 if (job
->state_value
!= IPP_JOB_HELD
)
3046 * Return a "not-possible" error...
3049 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3050 _("Job #%d is not held for authentication."),
3056 * See if we have already authenticated...
3059 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
3061 if (!con
->username
[0] && !auth_info
)
3063 cupsd_printer_t
*printer
; /* Job destination */
3066 * No auth data. If we need to authenticate via Kerberos, send a
3067 * HTTP auth challenge, otherwise just return an IPP error...
3070 printer
= cupsdFindDest(job
->dest
);
3072 if (printer
&& printer
->num_auth_info_required
> 0 &&
3073 !strcmp(printer
->auth_info_required
[0], "negotiate"))
3074 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
3076 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
3077 _("No authentication information provided."));
3082 * See if the job is owned by the requesting user...
3085 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3087 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3088 cupsdFindDest(job
->dest
));
3093 * Save the authentication information for this job...
3096 save_auth_info(con
, job
, auth_info
);
3099 * Reset the job-hold-until value to "no-hold"...
3102 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
3103 IPP_TAG_KEYWORD
)) == NULL
)
3104 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
3108 ippSetValueTag(job
->attrs
, &attr
, IPP_TAG_KEYWORD
);
3109 ippSetString(job
->attrs
, &attr
, 0, "no-hold");
3113 * Release the job and return...
3116 cupsdReleaseJob(job
);
3118 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, NULL
, job
, "Job authenticated by user");
3120 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Authenticated by \"%s\".", con
->username
);
3127 * 'cancel_all_jobs()' - Cancel all or selected print jobs.
3131 cancel_all_jobs(cupsd_client_t
*con
, /* I - Client connection */
3132 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3134 int i
; /* Looping var */
3135 http_status_t status
; /* Policy status */
3136 cups_ptype_t dtype
; /* Destination type */
3137 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3138 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
3139 hostname
[HTTP_MAX_URI
], /* Host portion of URI */
3140 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3141 int port
; /* Port portion of URI */
3142 ipp_attribute_t
*attr
; /* Attribute in request */
3143 const char *username
= NULL
; /* Username */
3144 cupsd_jobaction_t purge
= CUPSD_JOB_DEFAULT
;
3146 cupsd_printer_t
*printer
; /* Printer */
3147 ipp_attribute_t
*job_ids
; /* job-ids attribute */
3148 cupsd_job_t
*job
; /* Job */
3151 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_all_jobs(%p[%d], %s)", con
,
3152 con
->number
, uri
->values
[0].string
.text
);
3155 * Get the jobs to cancel/purge...
3158 switch (con
->request
->request
.op
.operation_id
)
3160 case IPP_PURGE_JOBS
:
3162 * Get the username (if any) for the jobs we want to cancel (only if
3163 * "my-jobs" is specified...
3166 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
3167 IPP_TAG_BOOLEAN
)) != NULL
&&
3168 attr
->values
[0].boolean
)
3170 if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3171 IPP_TAG_NAME
)) != NULL
)
3172 username
= attr
->values
[0].string
.text
;
3175 send_ipp_status(con
, IPP_BAD_REQUEST
,
3176 _("Missing requesting-user-name attribute."));
3182 * Look for the "purge-jobs" attribute...
3185 if ((attr
= ippFindAttribute(con
->request
, "purge-jobs",
3186 IPP_TAG_BOOLEAN
)) != NULL
)
3187 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
3189 purge
= CUPSD_JOB_PURGE
;
3192 case IPP_CANCEL_MY_JOBS
:
3193 if (con
->username
[0])
3194 username
= con
->username
;
3195 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3196 IPP_TAG_NAME
)) != NULL
)
3197 username
= attr
->values
[0].string
.text
;
3200 send_ipp_status(con
, IPP_BAD_REQUEST
,
3201 _("Missing requesting-user-name attribute."));
3209 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
3212 * See if we have a printer URI...
3215 if (strcmp(uri
->name
, "printer-uri"))
3217 send_ipp_status(con
, IPP_BAD_REQUEST
,
3218 _("The printer-uri attribute is required."));
3223 * And if the destination is valid...
3226 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3232 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
,
3233 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
3234 hostname
, sizeof(hostname
), &port
,
3235 resource
, sizeof(resource
));
3237 if ((!strncmp(resource
, "/printers/", 10) && resource
[10]) ||
3238 (!strncmp(resource
, "/classes/", 9) && resource
[9]))
3240 send_ipp_status(con
, IPP_NOT_FOUND
,
3241 _("The printer or class does not exist."));
3249 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
3251 send_http_error(con
, status
, NULL
);
3257 for (i
= 0; i
< job_ids
->num_values
; i
++)
3259 if ((job
= cupsdFindJob(job_ids
->values
[i
].integer
)) == NULL
)
3262 if (con
->request
->request
.op
.operation_id
== IPP_CANCEL_MY_JOBS
&&
3263 _cups_strcasecmp(job
->username
, username
))
3267 if (i
< job_ids
->num_values
)
3269 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3270 job_ids
->values
[i
].integer
);
3274 for (i
= 0; i
< job_ids
->num_values
; i
++)
3276 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
3278 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3279 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
3280 "Job canceled by user.");
3283 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
3284 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3290 * Cancel all jobs on all printers...
3293 cupsdCancelJobs(NULL
, username
, purge
);
3295 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs were %s by \"%s\".",
3296 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3306 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
3309 send_http_error(con
, status
, printer
);
3315 for (i
= 0; i
< job_ids
->num_values
; i
++)
3317 if ((job
= cupsdFindJob(job_ids
->values
[i
].integer
)) == NULL
||
3318 _cups_strcasecmp(job
->dest
, printer
->name
))
3321 if (con
->request
->request
.op
.operation_id
== IPP_CANCEL_MY_JOBS
&&
3322 _cups_strcasecmp(job
->username
, username
))
3326 if (i
< job_ids
->num_values
)
3328 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3329 job_ids
->values
[i
].integer
);
3333 for (i
= 0; i
< job_ids
->num_values
; i
++)
3335 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
3337 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3338 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
3339 "Job canceled by user.");
3342 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
3343 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3349 * Cancel all of the jobs on the named printer...
3352 cupsdCancelJobs(printer
->name
, username
, purge
);
3354 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs on \"%s\" were %s by \"%s\".",
3356 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3361 con
->response
->request
.status
.status_code
= IPP_OK
;
3368 * 'cancel_job()' - Cancel a print job.
3372 cancel_job(cupsd_client_t
*con
, /* I - Client connection */
3373 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3375 ipp_attribute_t
*attr
; /* Current attribute */
3376 int jobid
; /* Job ID */
3377 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3378 username
[HTTP_MAX_URI
], /* Username portion of URI */
3379 host
[HTTP_MAX_URI
], /* Host portion of URI */
3380 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3381 int port
; /* Port portion of URI */
3382 cupsd_job_t
*job
; /* Job information */
3383 cups_ptype_t dtype
; /* Destination type (printer/class) */
3384 cupsd_printer_t
*printer
; /* Printer data */
3385 cupsd_jobaction_t purge
; /* Purge the job? */
3388 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_job(%p[%d], %s)", con
,
3389 con
->number
, uri
->values
[0].string
.text
);
3392 * See if we have a job URI or a printer URI...
3395 if (!strcmp(uri
->name
, "printer-uri"))
3398 * Got a printer URI; see if we also have a job-id attribute...
3401 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3402 IPP_TAG_INTEGER
)) == NULL
)
3404 send_ipp_status(con
, IPP_BAD_REQUEST
,
3405 _("Got a printer-uri attribute but no job-id."));
3409 if ((jobid
= attr
->values
[0].integer
) == 0)
3412 * Find the current job on the specified printer...
3415 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3421 send_ipp_status(con
, IPP_NOT_FOUND
,
3422 _("The printer or class does not exist."));
3427 * See if there are any pending jobs...
3430 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3432 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3433 if (job
->state_value
<= IPP_JOB_PROCESSING
&&
3434 !_cups_strcasecmp(job
->dest
, printer
->name
))
3442 * No, try stopped jobs...
3445 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3447 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3448 if (job
->state_value
== IPP_JOB_STOPPED
&&
3449 !_cups_strcasecmp(job
->dest
, printer
->name
))
3456 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("No active jobs on %s."),
3466 * Got a job URI; parse it to get the job ID...
3469 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
3470 sizeof(scheme
), username
, sizeof(username
), host
,
3471 sizeof(host
), &port
, resource
, sizeof(resource
));
3473 if (strncmp(resource
, "/jobs/", 6))
3479 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
3480 uri
->values
[0].string
.text
);
3484 jobid
= atoi(resource
+ 6);
3488 * Look for the "purge-job" attribute...
3491 if ((attr
= ippFindAttribute(con
->request
, "purge-job",
3492 IPP_TAG_BOOLEAN
)) != NULL
)
3493 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
3495 purge
= CUPSD_JOB_DEFAULT
;
3498 * See if the job exists...
3501 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3504 * Nope - return a "not found" error...
3507 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
3512 * See if the job is owned by the requesting user...
3515 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3517 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3518 cupsdFindDest(job
->dest
));
3523 * See if the job is already completed, canceled, or aborted; if so,
3524 * we can't cancel...
3527 if (job
->state_value
>= IPP_JOB_CANCELED
&& purge
!= CUPSD_JOB_PURGE
)
3529 switch (job
->state_value
)
3531 case IPP_JOB_CANCELED
:
3532 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3533 _("Job #%d is already canceled - can\'t cancel."),
3537 case IPP_JOB_ABORTED
:
3538 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3539 _("Job #%d is already aborted - can\'t cancel."),
3544 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3545 _("Job #%d is already completed - can\'t cancel."),
3554 * Cancel the job and return...
3557 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3558 purge
== CUPSD_JOB_PURGE
? "Job purged by \"%s\"" :
3559 "Job canceled by \"%s\"",
3563 if (purge
== CUPSD_JOB_PURGE
)
3564 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Purged by \"%s\".", jobid
,
3567 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Canceled by \"%s\".", jobid
,
3570 con
->response
->request
.status
.status_code
= IPP_OK
;
3575 * 'cancel_subscription()' - Cancel a subscription.
3579 cancel_subscription(
3580 cupsd_client_t
*con
, /* I - Client connection */
3581 int sub_id
) /* I - Subscription ID */
3583 http_status_t status
; /* Policy status */
3584 cupsd_subscription_t
*sub
; /* Subscription */
3587 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3588 "cancel_subscription(con=%p[%d], sub_id=%d)",
3589 con
, con
->number
, sub_id
);
3592 * Is the subscription ID valid?
3595 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
3598 * Bad subscription ID...
3601 send_ipp_status(con
, IPP_NOT_FOUND
,
3602 _("Subscription #%d does not exist."), sub_id
);
3610 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
3612 con
, sub
->owner
)) != HTTP_OK
)
3614 send_http_error(con
, status
, sub
->dest
);
3619 * Cancel the subscription...
3622 cupsdDeleteSubscription(sub
, 1);
3624 con
->response
->request
.status
.status_code
= IPP_OK
;
3629 * 'check_rss_recipient()' - Check that we do not have a duplicate RSS feed URI.
3632 static int /* O - 1 if OK, 0 if not */
3633 check_rss_recipient(
3634 const char *recipient
) /* I - Recipient URI */
3636 cupsd_subscription_t
*sub
; /* Current subscription */
3639 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
);
3641 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
3645 * Compare the URIs up to the first ?...
3648 const char *r1
, *r2
;
3650 for (r1
= recipient
, r2
= sub
->recipient
;
3651 *r1
== *r2
&& *r1
&& *r1
!= '?' && *r2
&& *r2
!= '?';
3663 * 'check_quotas()' - Check quotas for a printer and user.
3666 static int /* O - 1 if OK, 0 if forbidden,
3667 -1 if limit reached */
3668 check_quotas(cupsd_client_t
*con
, /* I - Client connection */
3669 cupsd_printer_t
*p
) /* I - Printer or class */
3671 char username
[33], /* Username */
3672 *name
; /* Current user name */
3673 cupsd_quota_t
*q
; /* Quota data */
3674 #ifdef HAVE_MBR_UID_TO_UUID
3676 * Use Apple membership APIs which require that all names represent
3677 * valid user account or group records accessible by the server.
3680 uuid_t usr_uuid
; /* UUID for job requesting user */
3681 uuid_t usr2_uuid
; /* UUID for ACL user name entry */
3682 uuid_t grp_uuid
; /* UUID for ACL group name entry */
3683 int mbr_err
; /* Error from membership function */
3684 int is_member
; /* Is this user a member? */
3687 * Use standard POSIX APIs for checking users and groups...
3690 struct passwd
*pw
; /* User password data */
3691 #endif /* HAVE_MBR_UID_TO_UUID */
3694 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "check_quotas(%p[%d], %p[%s])",
3695 con
, con
->number
, p
, p
->name
);
3698 * Figure out who is printing...
3701 strlcpy(username
, get_username(con
), sizeof(username
));
3703 if ((name
= strchr(username
, '@')) != NULL
)
3704 *name
= '\0'; /* Strip @REALM */
3707 * Check global active job limits for printers and users...
3710 if (MaxJobsPerPrinter
)
3713 * Check if there are too many pending jobs on this printer...
3716 if (cupsdGetPrinterJobCount(p
->name
) >= MaxJobsPerPrinter
)
3718 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for printer \"%s\"...",
3727 * Check if there are too many pending jobs for this user...
3730 if (cupsdGetUserJobCount(username
) >= MaxJobsPerUser
)
3732 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for user \"%s\"...",
3739 * Check against users...
3742 if (cupsArrayCount(p
->users
) == 0 && p
->k_limit
== 0 && p
->page_limit
== 0)
3745 if (cupsArrayCount(p
->users
))
3747 #ifdef HAVE_MBR_UID_TO_UUID
3749 * Get UUID for job requesting user...
3752 if (mbr_user_name_to_uuid((char *)username
, usr_uuid
))
3758 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3759 "check_quotas: UUID lookup failed for user \"%s\"",
3761 cupsdLogMessage(CUPSD_LOG_INFO
,
3762 "Denying user \"%s\" access to printer \"%s\" "
3763 "(unknown user)...",
3769 * Get UID and GID of requesting user...
3772 pw
= getpwnam(username
);
3774 #endif /* HAVE_MBR_UID_TO_UUID */
3776 for (name
= (char *)cupsArrayFirst(p
->users
);
3778 name
= (char *)cupsArrayNext(p
->users
))
3782 * Check group membership...
3785 #ifdef HAVE_MBR_UID_TO_UUID
3788 if (uuid_parse(name
+ 2, grp_uuid
))
3789 uuid_clear(grp_uuid
);
3791 else if ((mbr_err
= mbr_group_name_to_uuid(name
+ 1, grp_uuid
)) != 0)
3794 * Invalid ACL entries are ignored for matching; just record a
3795 * warning in the log...
3798 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3799 "check_quotas: UUID lookup failed for ACL entry "
3800 "\"%s\" (err=%d)", name
, mbr_err
);
3801 cupsdLogMessage(CUPSD_LOG_WARN
,
3802 "Access control entry \"%s\" not a valid group name; "
3803 "entry ignored", name
);
3806 if ((mbr_err
= mbr_check_membership(usr_uuid
, grp_uuid
,
3810 * At this point, there should be no errors, but check anyways...
3813 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3814 "check_quotas: group \"%s\" membership check "
3815 "failed (err=%d)", name
+ 1, mbr_err
);
3820 * Stop if we found a match...
3827 if (cupsdCheckGroup(username
, pw
, name
+ 1))
3829 #endif /* HAVE_MBR_UID_TO_UUID */
3831 #ifdef HAVE_MBR_UID_TO_UUID
3836 if (uuid_parse(name
+ 1, usr2_uuid
))
3837 uuid_clear(usr2_uuid
);
3839 else if ((mbr_err
= mbr_user_name_to_uuid(name
, usr2_uuid
)) != 0)
3842 * Invalid ACL entries are ignored for matching; just record a
3843 * warning in the log...
3846 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3847 "check_quotas: UUID lookup failed for ACL entry "
3848 "\"%s\" (err=%d)", name
, mbr_err
);
3849 cupsdLogMessage(CUPSD_LOG_WARN
,
3850 "Access control entry \"%s\" not a valid user name; "
3851 "entry ignored", name
);
3854 if (!uuid_compare(usr_uuid
, usr2_uuid
))
3858 else if (!_cups_strcasecmp(username
, name
))
3860 #endif /* HAVE_MBR_UID_TO_UUID */
3862 if ((name
!= NULL
) == p
->deny_users
)
3864 cupsdLogMessage(CUPSD_LOG_INFO
,
3865 "Denying user \"%s\" access to printer \"%s\"...",
3875 if (p
->k_limit
|| p
->page_limit
)
3877 if ((q
= cupsdUpdateQuota(p
, username
, 0, 0)) == NULL
)
3879 cupsdLogMessage(CUPSD_LOG_ERROR
,
3880 "Unable to allocate quota data for user \"%s\"",
3885 if ((q
->k_count
>= p
->k_limit
&& p
->k_limit
) ||
3886 (q
->page_count
>= p
->page_limit
&& p
->page_limit
))
3888 cupsdLogMessage(CUPSD_LOG_INFO
, "User \"%s\" is over the quota limit...",
3895 * If we have gotten this far, we're done!
3903 * 'close_job()' - Close a multi-file job.
3907 close_job(cupsd_client_t
*con
, /* I - Client connection */
3908 ipp_attribute_t
*uri
) /* I - Printer URI */
3910 cupsd_job_t
*job
; /* Job */
3911 ipp_attribute_t
*attr
; /* Attribute */
3912 char job_uri
[HTTP_MAX_URI
],
3914 username
[256]; /* User name */
3917 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "close_job(%p[%d], %s)", con
,
3918 con
->number
, uri
->values
[0].string
.text
);
3921 * See if we have a job URI or a printer URI...
3924 if (strcmp(uri
->name
, "printer-uri"))
3927 * job-uri is not supported by Close-Job!
3930 send_ipp_status(con
, IPP_BAD_REQUEST
,
3931 _("Close-Job doesn't support the job-uri attribute."));
3936 * Got a printer URI; see if we also have a job-id attribute...
3939 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3940 IPP_TAG_INTEGER
)) == NULL
)
3942 send_ipp_status(con
, IPP_BAD_REQUEST
,
3943 _("Got a printer-uri attribute but no job-id."));
3947 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
3950 * Nope - return a "not found" error...
3953 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3954 attr
->values
[0].integer
);
3959 * See if the job is owned by the requesting user...
3962 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3964 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3965 cupsdFindDest(job
->dest
));
3970 * Add any ending sheet...
3973 if (cupsdTimeoutJob(job
))
3976 if (job
->state_value
== IPP_JOB_STOPPED
)
3978 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
3979 job
->state_value
= IPP_JOB_PENDING
;
3981 else if (job
->state_value
== IPP_JOB_HELD
)
3983 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
3984 IPP_TAG_KEYWORD
)) == NULL
)
3985 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
3987 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
3989 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
3990 job
->state_value
= IPP_JOB_PENDING
;
3995 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
3998 * Fill in the response info...
4001 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
4002 con
->clientname
, con
->clientport
, "/jobs/%d", job
->id
);
4003 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
4006 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
4008 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
4011 con
->response
->request
.status
.status_code
= IPP_OK
;
4014 * Start the job if necessary...
4022 * 'copy_attrs()' - Copy attributes from one request to another.
4026 copy_attrs(ipp_t
*to
, /* I - Destination request */
4027 ipp_t
*from
, /* I - Source request */
4028 cups_array_t
*ra
, /* I - Requested attributes */
4029 ipp_tag_t group
, /* I - Group to copy */
4030 int quickcopy
, /* I - Do a quick copy? */
4031 cups_array_t
*exclude
) /* I - Attributes to exclude? */
4033 ipp_attribute_t
*fromattr
; /* Source attribute */
4036 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4037 "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)",
4038 to
, from
, ra
, group
, quickcopy
);
4043 for (fromattr
= from
->attrs
; fromattr
; fromattr
= fromattr
->next
)
4046 * Filter attributes as needed...
4049 if ((group
!= IPP_TAG_ZERO
&& fromattr
->group_tag
!= group
&&
4050 fromattr
->group_tag
!= IPP_TAG_ZERO
) || !fromattr
->name
)
4053 if (!strcmp(fromattr
->name
, "document-password") ||
4054 !strcmp(fromattr
->name
, "job-authorization-uri") ||
4055 !strcmp(fromattr
->name
, "job-password") ||
4056 !strcmp(fromattr
->name
, "job-password-encryption") ||
4057 !strcmp(fromattr
->name
, "job-printer-uri"))
4061 (cupsArrayFind(exclude
, fromattr
->name
) ||
4062 cupsArrayFind(exclude
, "all")))
4065 * We need to exclude this attribute for security reasons; we require the
4066 * job-id attribute regardless of the security settings for IPP
4069 * The job-printer-uri attribute is handled by copy_job_attrs().
4071 * Subscription attribute security is handled by copy_subscription_attrs().
4074 if (strcmp(fromattr
->name
, "job-id"))
4078 if (!ra
|| cupsArrayFind(ra
, fromattr
->name
))
4081 * Don't send collection attributes by default to IPP/1.x clients
4082 * since many do not support collections. Also don't send
4083 * media-col-database unless specifically requested by the client.
4086 if (fromattr
->value_tag
== IPP_TAG_BEGIN_COLLECTION
&&
4088 (to
->request
.status
.version
[0] == 1 ||
4089 !strcmp(fromattr
->name
, "media-col-database")))
4092 ippCopyAttribute(to
, fromattr
, quickcopy
);
4099 * 'copy_banner()' - Copy a banner file to the requests directory for the
4103 static int /* O - Size of banner file in kbytes */
4104 copy_banner(cupsd_client_t
*con
, /* I - Client connection */
4105 cupsd_job_t
*job
, /* I - Job information */
4106 const char *name
) /* I - Name of banner */
4108 int i
; /* Looping var */
4109 int kbytes
; /* Size of banner file in kbytes */
4110 char filename
[1024]; /* Job filename */
4111 cupsd_banner_t
*banner
; /* Pointer to banner */
4112 cups_file_t
*in
; /* Input file */
4113 cups_file_t
*out
; /* Output file */
4114 int ch
; /* Character from file */
4115 char attrname
[255], /* Name of attribute */
4116 *s
; /* Pointer into name */
4117 ipp_attribute_t
*attr
; /* Attribute */
4120 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4121 "copy_banner(con=%p[%d], job=%p[%d], name=\"%s\")",
4122 con
, con
? con
->number
: -1, job
, job
->id
,
4123 name
? name
: "(null)");
4126 * Find the banner; return if not found or "none"...
4129 if (!name
|| !strcmp(name
, "none") ||
4130 (banner
= cupsdFindBanner(name
)) == NULL
)
4134 * Open the banner and job files...
4137 if (add_file(con
, job
, banner
->filetype
, 0))
4140 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
4142 if ((out
= cupsFileOpen(filename
, "w")) == NULL
)
4144 cupsdLogMessage(CUPSD_LOG_ERROR
,
4145 "Unable to create banner job file %s - %s",
4146 filename
, strerror(errno
));
4151 fchmod(cupsFileNumber(out
), 0640);
4152 fchown(cupsFileNumber(out
), RunUser
, Group
);
4155 * Try the localized banner file under the subdirectory...
4158 strlcpy(attrname
, job
->attrs
->attrs
->next
->values
[0].string
.text
,
4160 if (strlen(attrname
) > 2 && attrname
[2] == '-')
4163 * Convert ll-cc to ll_CC...
4167 attrname
[3] = (char)toupper(attrname
[3] & 255);
4168 attrname
[4] = (char)toupper(attrname
[4] & 255);
4171 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4174 if (access(filename
, 0) && strlen(attrname
) > 2)
4177 * Wasn't able to find "ll_CC" locale file; try the non-national
4178 * localization banner directory.
4183 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4187 if (access(filename
, 0))
4190 * Use the non-localized banner file.
4193 snprintf(filename
, sizeof(filename
), "%s/banners/%s", DataDir
, name
);
4196 if ((in
= cupsFileOpen(filename
, "r")) == NULL
)
4200 cupsdLogMessage(CUPSD_LOG_ERROR
,
4201 "Unable to open banner template file %s - %s",
4202 filename
, strerror(errno
));
4208 * Parse the file to the end...
4211 while ((ch
= cupsFileGetChar(in
)) != EOF
)
4215 * Get an attribute name...
4218 for (s
= attrname
; (ch
= cupsFileGetChar(in
)) != EOF
;)
4219 if (!isalpha(ch
& 255) && ch
!= '-' && ch
!= '?')
4221 else if (s
< (attrname
+ sizeof(attrname
) - 1))
4231 * Ignore { followed by stuff that is not an attribute name...
4234 cupsFilePrintf(out
, "{%s%c", attrname
, ch
);
4239 * See if it is defined...
4242 if (attrname
[0] == '?')
4247 if (!strcmp(s
, "printer-name"))
4249 cupsFilePuts(out
, job
->dest
);
4252 else if ((attr
= ippFindAttribute(job
->attrs
, s
, IPP_TAG_ZERO
)) == NULL
)
4255 * See if we have a leading question mark...
4258 if (attrname
[0] != '?')
4261 * Nope, write to file as-is; probably a PostScript procedure...
4264 cupsFilePrintf(out
, "{%s}", attrname
);
4271 * Output value(s)...
4274 for (i
= 0; i
< attr
->num_values
; i
++)
4277 cupsFilePutChar(out
, ',');
4279 switch (attr
->value_tag
)
4281 case IPP_TAG_INTEGER
:
4283 if (!strncmp(s
, "time-at-", 8))
4285 struct timeval tv
; /* Time value */
4287 tv
.tv_sec
= attr
->values
[i
].integer
;
4290 cupsFilePuts(out
, cupsdGetDateTime(&tv
, CUPSD_TIME_STANDARD
));
4293 cupsFilePrintf(out
, "%d", attr
->values
[i
].integer
);
4296 case IPP_TAG_BOOLEAN
:
4297 cupsFilePrintf(out
, "%d", attr
->values
[i
].boolean
);
4300 case IPP_TAG_NOVALUE
:
4301 cupsFilePuts(out
, "novalue");
4304 case IPP_TAG_RANGE
:
4305 cupsFilePrintf(out
, "%d-%d", attr
->values
[i
].range
.lower
,
4306 attr
->values
[i
].range
.upper
);
4309 case IPP_TAG_RESOLUTION
:
4310 cupsFilePrintf(out
, "%dx%d%s", attr
->values
[i
].resolution
.xres
,
4311 attr
->values
[i
].resolution
.yres
,
4312 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
4317 case IPP_TAG_STRING
:
4320 case IPP_TAG_KEYWORD
:
4321 case IPP_TAG_CHARSET
:
4322 case IPP_TAG_LANGUAGE
:
4323 if (!_cups_strcasecmp(banner
->filetype
->type
, "postscript"))
4326 * Need to quote strings for PS banners...
4331 for (p
= attr
->values
[i
].string
.text
; *p
; p
++)
4333 if (*p
== '(' || *p
== ')' || *p
== '\\')
4335 cupsFilePutChar(out
, '\\');
4336 cupsFilePutChar(out
, *p
);
4338 else if (*p
< 32 || *p
> 126)
4339 cupsFilePrintf(out
, "\\%03o", *p
& 255);
4341 cupsFilePutChar(out
, *p
);
4345 cupsFilePuts(out
, attr
->values
[i
].string
.text
);
4349 break; /* anti-compiler-warning-code */
4353 else if (ch
== '\\') /* Quoted char */
4355 ch
= cupsFileGetChar(in
);
4357 if (ch
!= '{') /* Only do special handling for \{ */
4358 cupsFilePutChar(out
, '\\');
4360 cupsFilePutChar(out
, ch
);
4363 cupsFilePutChar(out
, ch
);
4367 kbytes
= (cupsFileTell(out
) + 1023) / 1024;
4369 job
->koctets
+= kbytes
;
4371 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets", IPP_TAG_INTEGER
)) != NULL
)
4372 attr
->values
[0].integer
+= kbytes
;
4381 * 'copy_file()' - Copy a PPD file...
4384 static int /* O - 0 = success, -1 = error */
4385 copy_file(const char *from
, /* I - Source file */
4386 const char *to
, /* I - Destination file */
4387 mode_t mode
) /* I - Permissions */
4389 cups_file_t
*src
, /* Source file */
4390 *dst
; /* Destination file */
4391 int bytes
; /* Bytes to read/write */
4392 char buffer
[2048]; /* Copy buffer */
4395 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_file(\"%s\", \"%s\")", from
, to
);
4398 * Open the source and destination file for a copy...
4401 if ((src
= cupsFileOpen(from
, "rb")) == NULL
)
4404 if ((dst
= cupsdCreateConfFile(to
, mode
)) == NULL
)
4411 * Copy the source file to the destination...
4414 while ((bytes
= cupsFileRead(src
, buffer
, sizeof(buffer
))) > 0)
4415 if (cupsFileWrite(dst
, buffer
, (size_t)bytes
) < bytes
)
4423 * Close both files and return...
4428 return (cupsdCloseCreatedConfFile(dst
, to
));
4433 * 'copy_model()' - Copy a PPD model file, substituting default values
4437 static int /* O - 0 = success, -1 = error */
4438 copy_model(cupsd_client_t
*con
, /* I - Client connection */
4439 const char *from
, /* I - Source file */
4440 const char *to
) /* I - Destination file */
4442 fd_set input
; /* select() input set */
4443 struct timeval timeout
; /* select() timeout */
4444 int maxfd
; /* Max file descriptor for select() */
4445 char tempfile
[1024]; /* Temporary PPD file */
4446 int tempfd
; /* Temporary PPD file descriptor */
4447 int temppid
; /* Process ID of cups-driverd */
4448 int temppipe
[2]; /* Temporary pipes */
4449 char *argv
[4], /* Command-line arguments */
4450 *envp
[MAX_ENV
]; /* Environment */
4451 cups_file_t
*src
, /* Source file */
4452 *dst
; /* Destination file */
4453 ppd_file_t
*ppd
; /* PPD file */
4454 int bytes
, /* Bytes from pipe */
4455 total
; /* Total bytes from pipe */
4456 char buffer
[2048]; /* Copy buffer */
4457 int i
; /* Looping var */
4458 char option
[PPD_MAX_NAME
], /* Option name */
4459 choice
[PPD_MAX_NAME
]; /* Choice name */
4460 ppd_size_t
*size
; /* Default size */
4461 int num_defaults
; /* Number of default options */
4462 cups_option_t
*defaults
; /* Default options */
4463 char cups_protocol
[PPD_MAX_LINE
];
4464 /* cupsProtocol attribute */
4467 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_model(con=%p, from=\"%s\", to=\"%s\")", con
, from
, to
);
4470 * Run cups-driverd to get the PPD file...
4473 argv
[0] = "cups-driverd";
4475 argv
[2] = (char *)from
;
4478 cupsdLoadEnv(envp
, (int)(sizeof(envp
) / sizeof(envp
[0])));
4480 snprintf(buffer
, sizeof(buffer
), "%s/daemon/cups-driverd", ServerBin
);
4481 snprintf(tempfile
, sizeof(tempfile
), "%s/%d.ppd", TempDir
, con
->number
);
4482 tempfd
= open(tempfile
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
4483 if (tempfd
< 0 || cupsdOpenPipe(temppipe
))
4486 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4487 "copy_model: Running \"cups-driverd cat %s\"...", from
);
4489 if (!cupsdStartProcess(buffer
, argv
, envp
, -1, temppipe
[1], CGIPipes
[1],
4490 -1, -1, 0, DefaultProfile
, NULL
, &temppid
))
4501 * Wait up to 30 seconds for the PPD file to be copied...
4506 if (temppipe
[0] > CGIPipes
[0])
4507 maxfd
= temppipe
[0] + 1;
4509 maxfd
= CGIPipes
[0] + 1;
4514 * See if we have data ready...
4518 FD_SET(temppipe
[0], &input
);
4519 FD_SET(CGIPipes
[0], &input
);
4521 timeout
.tv_sec
= 30;
4522 timeout
.tv_usec
= 0;
4524 if ((i
= select(maxfd
, &input
, NULL
, NULL
, &timeout
)) < 0)
4534 * We have timed out...
4540 if (FD_ISSET(temppipe
[0], &input
))
4543 * Read the PPD file from the pipe, and write it to the PPD file.
4546 if ((bytes
= read(temppipe
[0], buffer
, sizeof(buffer
))) > 0)
4548 if (write(tempfd
, buffer
, (size_t)bytes
) < bytes
)
4557 if (FD_ISSET(CGIPipes
[0], &input
))
4567 * No data from cups-deviced...
4570 cupsdLogMessage(CUPSD_LOG_ERROR
, "copy_model: empty PPD file");
4576 * Open the source file for a copy...
4579 if ((src
= cupsFileOpen(tempfile
, "rb")) == NULL
)
4586 * Read the source file and see what page sizes are supported...
4589 if ((ppd
= _ppdOpen(src
, _PPD_LOCALIZATION_NONE
)) == NULL
)
4597 * Open the destination (if possible) and set the default options...
4602 cups_protocol
[0] = '\0';
4604 if ((dst
= cupsFileOpen(to
, "rb")) != NULL
)
4607 * Read all of the default lines from the old PPD...
4610 while (cupsFileGets(dst
, buffer
, sizeof(buffer
)))
4611 if (!strncmp(buffer
, "*Default", 8))
4614 * Add the default option...
4617 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
4618 choice
, sizeof(choice
)))
4620 ppd_option_t
*ppdo
; /* PPD option */
4624 * Only add the default if the default hasn't already been
4625 * set and the choice exists in the new PPD...
4628 if (!cupsGetOption(option
, num_defaults
, defaults
) &&
4629 (ppdo
= ppdFindOption(ppd
, option
)) != NULL
&&
4630 ppdFindChoice(ppdo
, choice
))
4631 num_defaults
= cupsAddOption(option
, choice
, num_defaults
,
4635 else if (!strncmp(buffer
, "*cupsProtocol:", 14))
4636 strlcpy(cups_protocol
, buffer
, sizeof(cups_protocol
));
4640 else if ((size
= ppdPageSize(ppd
, DefaultPaperSize
)) != NULL
)
4643 * Add the default media sizes...
4646 num_defaults
= cupsAddOption("PageSize", size
->name
,
4647 num_defaults
, &defaults
);
4648 num_defaults
= cupsAddOption("PageRegion", size
->name
,
4649 num_defaults
, &defaults
);
4650 num_defaults
= cupsAddOption("PaperDimension", size
->name
,
4651 num_defaults
, &defaults
);
4652 num_defaults
= cupsAddOption("ImageableArea", size
->name
,
4653 num_defaults
, &defaults
);
4659 * Open the destination file for a copy...
4662 if ((dst
= cupsdCreateConfFile(to
, ConfigFilePerm
)) == NULL
)
4664 cupsFreeOptions(num_defaults
, defaults
);
4671 * Copy the source file to the destination...
4674 cupsFileRewind(src
);
4676 while (cupsFileGets(src
, buffer
, sizeof(buffer
)))
4678 if (!strncmp(buffer
, "*Default", 8))
4681 * Check for an previous default option choice...
4684 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
4685 choice
, sizeof(choice
)))
4687 const char *val
; /* Default option value */
4690 if ((val
= cupsGetOption(option
, num_defaults
, defaults
)) != NULL
)
4693 * Substitute the previous choice...
4696 snprintf(buffer
, sizeof(buffer
), "*Default%s: %s", option
, val
);
4701 cupsFilePrintf(dst
, "%s\n", buffer
);
4704 if (cups_protocol
[0])
4705 cupsFilePrintf(dst
, "%s\n", cups_protocol
);
4707 cupsFreeOptions(num_defaults
, defaults
);
4710 * Close both files and return...
4717 return (cupsdCloseCreatedConfFile(dst
, to
));
4722 * 'copy_job_attrs()' - Copy job attributes.
4726 copy_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
4727 cupsd_job_t
*job
, /* I - Job */
4728 cups_array_t
*ra
, /* I - Requested attributes array */
4729 cups_array_t
*exclude
) /* I - Private attributes array */
4731 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
4735 * Send the requested attributes for each job...
4738 if (!cupsArrayFind(exclude
, "all"))
4740 if ((!exclude
|| !cupsArrayFind(exclude
, "number-of-documents")) &&
4741 (!ra
|| cupsArrayFind(ra
, "number-of-documents")))
4742 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4743 "number-of-documents", job
->num_files
);
4745 if ((!exclude
|| !cupsArrayFind(exclude
, "job-media-progress")) &&
4746 (!ra
|| cupsArrayFind(ra
, "job-media-progress")))
4747 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4748 "job-media-progress", job
->progress
);
4750 if ((!exclude
|| !cupsArrayFind(exclude
, "job-more-info")) &&
4751 (!ra
|| cupsArrayFind(ra
, "job-more-info")))
4753 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "http",
4754 NULL
, con
->clientname
, con
->clientport
, "/jobs/%d",
4756 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4757 "job-more-info", NULL
, job_uri
);
4760 if (job
->state_value
> IPP_JOB_PROCESSING
&&
4761 (!exclude
|| !cupsArrayFind(exclude
, "job-preserved")) &&
4762 (!ra
|| cupsArrayFind(ra
, "job-preserved")))
4763 ippAddBoolean(con
->response
, IPP_TAG_JOB
, "job-preserved",
4764 job
->num_files
> 0);
4766 if ((!exclude
|| !cupsArrayFind(exclude
, "job-printer-up-time")) &&
4767 (!ra
|| cupsArrayFind(ra
, "job-printer-up-time")))
4768 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4769 "job-printer-up-time", time(NULL
));
4772 if (!ra
|| cupsArrayFind(ra
, "job-printer-uri"))
4774 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
4775 con
->clientname
, con
->clientport
,
4776 (job
->dtype
& CUPS_PRINTER_CLASS
) ? "/classes/%s" :
4779 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4780 "job-printer-uri", NULL
, job_uri
);
4783 if (!ra
|| cupsArrayFind(ra
, "job-uri"))
4785 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
4786 con
->clientname
, con
->clientport
, "/jobs/%d",
4788 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4789 "job-uri", NULL
, job_uri
);
4794 copy_attrs(con
->response
, job
->attrs
, ra
, IPP_TAG_JOB
, 0, exclude
);
4799 * Generate attributes from the job structure...
4802 if (job
->completed_time
&& (!ra
|| cupsArrayFind(ra
, "date-time-at-completed")))
4803 ippAddDate(con
->response
, IPP_TAG_JOB
, "date-time-at-completed", ippTimeToDate(job
->completed_time
));
4805 if (job
->creation_time
&& (!ra
|| cupsArrayFind(ra
, "date-time-at-creation")))
4806 ippAddDate(con
->response
, IPP_TAG_JOB
, "date-time-at-creation", ippTimeToDate(job
->creation_time
));
4808 if (!ra
|| cupsArrayFind(ra
, "job-id"))
4809 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
4811 if (!ra
|| cupsArrayFind(ra
, "job-k-octets"))
4812 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-k-octets", job
->koctets
);
4814 if (job
->name
&& (!ra
|| cupsArrayFind(ra
, "job-name")))
4815 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
, job
->name
);
4817 if (job
->username
&& (!ra
|| cupsArrayFind(ra
, "job-originating-user-name")))
4818 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-originating-user-name", NULL
, job
->username
);
4820 if (!ra
|| cupsArrayFind(ra
, "job-state"))
4821 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state", (int)job
->state_value
);
4823 if (!ra
|| cupsArrayFind(ra
, "job-state-reasons"))
4825 switch (job
->state_value
)
4827 default : /* Should never get here for processing, pending, held, or stopped jobs since they don't get unloaded... */
4829 case IPP_JSTATE_ABORTED
:
4830 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons", NULL
, "job-aborted-by-system");
4832 case IPP_JSTATE_CANCELED
:
4833 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons", NULL
, "job-canceled-by-user");
4835 case IPP_JSTATE_COMPLETED
:
4836 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons", NULL
, "job-completed-successfully");
4841 if (job
->completed_time
&& (!ra
|| cupsArrayFind(ra
, "time-at-completed")))
4842 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-completed", (int)job
->completed_time
);
4844 if (job
->creation_time
&& (!ra
|| cupsArrayFind(ra
, "time-at-creation")))
4845 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation", (int)job
->creation_time
);
4851 * 'copy_printer_attrs()' - Copy printer attributes.
4856 cupsd_client_t
*con
, /* I - Client connection */
4857 cupsd_printer_t
*printer
, /* I - Printer */
4858 cups_array_t
*ra
) /* I - Requested attributes array */
4860 char uri
[HTTP_MAX_URI
]; /* URI value */
4861 time_t curtime
; /* Current time */
4862 int i
; /* Looping var */
4863 int is_encrypted
= httpIsEncrypted(con
->http
);
4864 /* Is the connection encrypted? */
4868 * Copy the printer attributes to the response using requested-attributes
4869 * and document-format attributes that may be provided by the client.
4872 _cupsRWLockRead(&printer
->lock
);
4874 curtime
= time(NULL
);
4876 if (!ra
|| cupsArrayFind(ra
, "marker-change-time"))
4877 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "marker-change-time", printer
->marker_time
);
4879 if (printer
->num_printers
> 0 && (!ra
|| cupsArrayFind(ra
, "member-uris")))
4881 ipp_attribute_t
*member_uris
; /* member-uris attribute */
4882 cupsd_printer_t
*p2
; /* Printer in class */
4883 ipp_attribute_t
*p2_uri
; /* printer-uri-supported for class printer */
4886 if ((member_uris
= ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "member-uris", printer
->num_printers
, NULL
, NULL
)) != NULL
)
4888 for (i
= 0; i
< printer
->num_printers
; i
++)
4890 p2
= printer
->printers
[i
];
4892 if ((p2_uri
= ippFindAttribute(p2
->attrs
, "printer-uri-supported", IPP_TAG_URI
)) != NULL
)
4894 member_uris
->values
[i
].string
.text
= _cupsStrAlloc(p2_uri
->values
[0].string
.text
);
4898 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), is_encrypted
? "ipps" : "ipp", NULL
, con
->clientname
, con
->clientport
, (p2
->type
& CUPS_PRINTER_CLASS
) ? "/classes/%s" : "/printers/%s", p2
->name
);
4899 member_uris
->values
[i
].string
.text
= _cupsStrAlloc(uri
);
4905 if (printer
->alert
&& (!ra
|| cupsArrayFind(ra
, "printer-alert")))
4906 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_STRING
, "printer-alert", NULL
, printer
->alert
);
4908 if (printer
->alert_description
&& (!ra
|| cupsArrayFind(ra
, "printer-alert-description")))
4909 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-alert-description", NULL
, printer
->alert_description
);
4911 if (!ra
|| cupsArrayFind(ra
, "printer-config-change-date-time"))
4912 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-config-change-date-time", ippTimeToDate(printer
->config_time
));
4914 if (!ra
|| cupsArrayFind(ra
, "printer-config-change-time"))
4915 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "printer-config-change-time", printer
->config_time
);
4917 if (!ra
|| cupsArrayFind(ra
, "printer-current-time"))
4918 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-current-time", ippTimeToDate(curtime
));
4920 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
4921 if (!ra
|| cupsArrayFind(ra
, "printer-dns-sd-name"))
4923 if (printer
->reg_name
)
4924 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-dns-sd-name", NULL
, printer
->reg_name
);
4926 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
, "printer-dns-sd-name", 0);
4928 #endif /* HAVE_DNSSD || HAVE_AVAHI */
4930 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy"))
4931 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-error-policy", NULL
, printer
->error_policy
);
4933 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy-supported"))
4935 static const char * const errors
[] =/* printer-error-policy-supported values */
4938 "retry-current-job",
4943 if (printer
->type
& CUPS_PRINTER_CLASS
)
4944 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_CONST_TAG(IPP_TAG_NAME
), "printer-error-policy-supported", NULL
, "retry-current-job");
4946 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_CONST_TAG(IPP_TAG_NAME
), "printer-error-policy-supported", sizeof(errors
) / sizeof(errors
[0]), NULL
, errors
);
4949 if (!ra
|| cupsArrayFind(ra
, "printer-icons"))
4951 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), is_encrypted
? "https" : "http", NULL
, con
->clientname
, con
->clientport
, "/icons/%s.png", printer
->name
);
4952 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-icons", NULL
, uri
);
4953 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-icons=\"%s\"", uri
);
4956 if (!ra
|| cupsArrayFind(ra
, "printer-is-accepting-jobs"))
4957 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs", (char)printer
->accepting
);
4959 if (!ra
|| cupsArrayFind(ra
, "printer-is-shared"))
4960 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-shared", (char)printer
->shared
);
4962 if (!ra
|| cupsArrayFind(ra
, "printer-is-temporary"))
4963 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-temporary", (char)printer
->temporary
);
4965 if (!ra
|| cupsArrayFind(ra
, "printer-more-info"))
4967 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), is_encrypted
? "https" : "http", NULL
, con
->clientname
, con
->clientport
, (printer
->type
& CUPS_PRINTER_CLASS
) ? "/classes/%s" : "/printers/%s", printer
->name
);
4968 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-more-info", NULL
, uri
);
4971 if (!ra
|| cupsArrayFind(ra
, "printer-op-policy"))
4972 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-op-policy", NULL
, printer
->op_policy
);
4974 if (!ra
|| cupsArrayFind(ra
, "printer-state"))
4975 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state", printer
->state
);
4977 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-date-time"))
4978 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-state-change-date-time", ippTimeToDate(printer
->state_time
));
4980 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-time"))
4981 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "printer-state-change-time", printer
->state_time
);
4983 if (!ra
|| cupsArrayFind(ra
, "printer-state-message"))
4984 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-state-message", NULL
, printer
->state_message
);
4986 if (!ra
|| cupsArrayFind(ra
, "printer-state-reasons"))
4987 add_printer_state_reasons(con
, printer
);
4989 if (!ra
|| cupsArrayFind(ra
, "printer-strings-uri"))
4991 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), is_encrypted
? "https" : "http", NULL
, con
->clientname
, con
->clientport
, "/strings/%s.strings", printer
->name
);
4992 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-strings-uri", NULL
, uri
);
4993 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-strings-uri=\"%s\"", uri
);
4996 if (!ra
|| cupsArrayFind(ra
, "printer-type"))
4998 cups_ptype_t type
; /* printer-type value */
5001 * Add the CUPS-specific printer-type attribute...
5004 type
= printer
->type
;
5006 if (printer
== DefaultPrinter
)
5007 type
|= CUPS_PRINTER_DEFAULT
;
5009 if (!printer
->accepting
)
5010 type
|= CUPS_PRINTER_REJECTING
;
5012 if (!printer
->shared
)
5013 type
|= CUPS_PRINTER_NOT_SHARED
;
5015 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-type", (int)type
);
5018 if (!ra
|| cupsArrayFind(ra
, "printer-up-time"))
5019 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "printer-up-time", curtime
);
5021 if (!ra
|| cupsArrayFind(ra
, "printer-uri-supported"))
5023 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), is_encrypted
? "ipps" : "ipp", NULL
, con
->clientname
, con
->clientport
, (printer
->type
& CUPS_PRINTER_CLASS
) ? "/classes/%s" : "/printers/%s", printer
->name
);
5024 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-uri-supported", NULL
, uri
);
5025 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-uri-supported=\"%s\"", uri
);
5028 if (!ra
|| cupsArrayFind(ra
, "queued-job-count"))
5029 add_queued_job_count(con
, printer
);
5031 copy_attrs(con
->response
, printer
->attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
5032 if (printer
->ppd_attrs
)
5033 copy_attrs(con
->response
, printer
->ppd_attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
5034 copy_attrs(con
->response
, CommonData
, ra
, IPP_TAG_ZERO
, IPP_TAG_COPY
, NULL
);
5036 _cupsRWUnlock(&printer
->lock
);
5041 * 'copy_subscription_attrs()' - Copy subscription attributes.
5045 copy_subscription_attrs(
5046 cupsd_client_t
*con
, /* I - Client connection */
5047 cupsd_subscription_t
*sub
, /* I - Subscription */
5048 cups_array_t
*ra
, /* I - Requested attributes array */
5049 cups_array_t
*exclude
) /* I - Private attributes array */
5051 ipp_attribute_t
*attr
; /* Current attribute */
5052 char printer_uri
[HTTP_MAX_URI
];
5054 int count
; /* Number of events */
5055 unsigned mask
; /* Current event mask */
5056 const char *name
; /* Current event name */
5059 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5060 "copy_subscription_attrs(con=%p, sub=%p, ra=%p, exclude=%p)",
5061 con
, sub
, ra
, exclude
);
5064 * Copy the subscription attributes to the response using the
5065 * requested-attributes attribute that may be provided by the client.
5068 if (!exclude
|| !cupsArrayFind(exclude
, "all"))
5070 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-events")) &&
5071 (!ra
|| cupsArrayFind(ra
, "notify-events")))
5073 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_subscription_attrs: notify-events");
5075 if ((name
= cupsdEventName((cupsd_eventmask_t
)sub
->mask
)) != NULL
)
5078 * Simple event list...
5081 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_CONST_TAG(IPP_TAG_KEYWORD
), "notify-events", NULL
, name
);
5086 * Complex event list...
5089 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5090 if (sub
->mask
& mask
)
5093 attr
= ippAddStrings(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_CONST_TAG(IPP_TAG_KEYWORD
), "notify-events", count
, NULL
, NULL
);
5095 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5096 if (sub
->mask
& mask
)
5098 attr
->values
[count
].string
.text
= (char *)cupsdEventName((cupsd_eventmask_t
)mask
);
5105 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-lease-duration")) &&
5106 (!sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-lease-duration"))))
5107 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5108 "notify-lease-duration", sub
->lease
);
5110 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-recipient-uri")) &&
5111 (sub
->recipient
&& (!ra
|| cupsArrayFind(ra
, "notify-recipient-uri"))))
5112 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5113 "notify-recipient-uri", NULL
, sub
->recipient
);
5114 else if ((!exclude
|| !cupsArrayFind(exclude
, "notify-pull-method")) &&
5115 (!ra
|| cupsArrayFind(ra
, "notify-pull-method")))
5116 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_KEYWORD
,
5117 "notify-pull-method", NULL
, "ippget");
5119 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-subscriber-user-name")) &&
5120 (!ra
|| cupsArrayFind(ra
, "notify-subscriber-user-name")))
5121 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_NAME
,
5122 "notify-subscriber-user-name", NULL
, sub
->owner
);
5124 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-time-interval")) &&
5125 (!ra
|| cupsArrayFind(ra
, "notify-time-interval")))
5126 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5127 "notify-time-interval", sub
->interval
);
5129 if (sub
->user_data_len
> 0 &&
5130 (!exclude
|| !cupsArrayFind(exclude
, "notify-user-data")) &&
5131 (!ra
|| cupsArrayFind(ra
, "notify-user-data")))
5132 ippAddOctetString(con
->response
, IPP_TAG_SUBSCRIPTION
, "notify-user-data",
5133 sub
->user_data
, sub
->user_data_len
);
5136 if (sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-job-id")))
5137 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5138 "notify-job-id", sub
->job
->id
);
5140 if (sub
->dest
&& (!ra
|| cupsArrayFind(ra
, "notify-printer-uri")))
5142 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5143 "ipp", NULL
, con
->clientname
, con
->clientport
,
5144 "/printers/%s", sub
->dest
->name
);
5145 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5146 "notify-printer-uri", NULL
, printer_uri
);
5149 if (!ra
|| cupsArrayFind(ra
, "notify-subscription-id"))
5150 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5151 "notify-subscription-id", sub
->id
);
5156 * 'create_job()' - Print a file to a printer or class.
5160 create_job(cupsd_client_t
*con
, /* I - Client connection */
5161 ipp_attribute_t
*uri
) /* I - Printer URI */
5163 int i
; /* Looping var */
5164 cupsd_printer_t
*printer
; /* Printer */
5165 cupsd_job_t
*job
; /* New job */
5166 static const char * const forbidden_attrs
[] =
5167 { /* List of forbidden attributes */
5171 "document-natural-language"
5175 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "create_job(%p[%d], %s)", con
,
5176 con
->number
, uri
->values
[0].string
.text
);
5179 * Is the destination valid?
5182 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
5188 send_ipp_status(con
, IPP_NOT_FOUND
,
5189 _("The printer or class does not exist."));
5194 * Check for invalid Create-Job attributes and log a warning or error depending
5195 * on whether cupsd is running in "strict conformance" mode...
5199 i
< (int)(sizeof(forbidden_attrs
) / sizeof(forbidden_attrs
[0]));
5201 if (ippFindAttribute(con
->request
, forbidden_attrs
[i
], IPP_TAG_ZERO
))
5203 if (StrictConformance
)
5205 send_ipp_status(con
, IPP_BAD_REQUEST
,
5206 _("The '%s' operation attribute cannot be supplied in a "
5207 "Create-Job request."), forbidden_attrs
[i
]);
5211 cupsdLogMessage(CUPSD_LOG_WARN
,
5212 "Unexpected '%s' operation attribute in a Create-Job "
5213 "request.", forbidden_attrs
[i
]);
5217 * Create the job object...
5220 if ((job
= add_job(con
, printer
, NULL
)) == NULL
)
5223 job
->pending_timeout
= 1;
5226 * Save and log the job...
5229 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
5230 job
->dest
, job
->username
);
5235 * 'create_local_bg_thread()' - Background thread for creating a local print queue.
5238 static void * /* O - Exit status */
5239 create_local_bg_thread(
5240 cupsd_printer_t
*printer
) /* I - Printer */
5242 cups_file_t
*from
, /* Source file */
5243 *to
; /* Destination file */
5244 char fromppd
[1024], /* Source PPD */
5245 toppd
[1024], /* Destination PPD */
5246 scheme
[32], /* URI scheme */
5247 userpass
[256], /* User:pass */
5248 host
[256], /* Hostname */
5249 resource
[1024], /* Resource path */
5250 line
[1024]; /* Line from PPD */
5251 int port
; /* Port number */
5252 http_encryption_t encryption
; /* Type of encryption to use */
5253 http_t
*http
; /* Connection to printer */
5254 ipp_t
*request
, /* Request to printer */
5255 *response
; /* Response from printer */
5256 ipp_attribute_t
*attr
; /* Attribute in response */
5257 ipp_status_t status
; /* Status code */
5258 static const char * const pattrs
[] = /* Printer attributes we need */
5261 "media-col-database"
5266 * Try connecting to the printer...
5269 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s: Generating PPD file from \"%s\"...", printer
->name
, printer
->device_uri
);
5271 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
)
5273 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: Bad device URI \"%s\".", printer
->name
, printer
->device_uri
);
5277 if (!strcmp(scheme
, "ipps") || port
== 443)
5278 encryption
= HTTP_ENCRYPTION_ALWAYS
;
5280 encryption
= HTTP_ENCRYPTION_IF_REQUESTED
;
5282 if ((http
= httpConnect2(host
, port
, NULL
, AF_UNSPEC
, encryption
, 1, 30000, NULL
)) == NULL
)
5284 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: Unable to connect to %s:%d: %s", printer
->name
, host
, port
, cupsLastErrorString());
5289 * Query the printer for its capabilities...
5292 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s: Connected to %s:%d, sending Get-Printer-Attributes request...", printer
->name
, host
, port
);
5294 request
= ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES
);
5295 ippSetVersion(request
, 2, 0);
5296 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
, printer
->device_uri
);
5297 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
, "requested-attributes", (int)(sizeof(pattrs
) / sizeof(pattrs
[0])), NULL
, pattrs
);
5299 response
= cupsDoRequest(http
, request
, resource
);
5300 status
= cupsLastError();
5302 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s: Get-Printer-Attributes returned %s (%s)", printer
->name
, ippErrorString(cupsLastError()), cupsLastErrorString());
5304 if (status
== IPP_STATUS_ERROR_BAD_REQUEST
|| status
== IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED
)
5307 * Try request using IPP/1.1, in case we are talking to an old CUPS server or
5311 ippDelete(response
);
5313 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s: Re-sending Get-Printer-Attributes request using IPP/1.1...", printer
->name
);
5315 request
= ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES
);
5316 ippSetVersion(request
, 1, 1);
5317 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
, printer
->device_uri
);
5318 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
, "requested-attributes", NULL
, "all");
5320 response
= cupsDoRequest(http
, request
, resource
);
5322 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s: IPP/1.1 Get-Printer-Attributes returned %s (%s)", printer
->name
, ippErrorString(cupsLastError()), cupsLastErrorString());
5325 // TODO: Grab printer icon file...
5329 * Write the PPD for the queue...
5332 if (_ppdCreateFromIPP(fromppd
, sizeof(fromppd
), response
))
5334 _cupsRWLockWrite(&printer
->lock
);
5336 if ((!printer
->info
|| !*(printer
->info
)) && (attr
= ippFindAttribute(response
, "printer-info", IPP_TAG_TEXT
)) != NULL
)
5337 cupsdSetString(&printer
->info
, ippGetString(attr
, 0, NULL
));
5339 if ((!printer
->location
|| !*(printer
->location
)) && (attr
= ippFindAttribute(response
, "printer-location", IPP_TAG_TEXT
)) != NULL
)
5340 cupsdSetString(&printer
->location
, ippGetString(attr
, 0, NULL
));
5342 if ((!printer
->geo_location
|| !*(printer
->geo_location
)) && (attr
= ippFindAttribute(response
, "printer-geo-location", IPP_TAG_URI
)) != NULL
)
5343 cupsdSetString(&printer
->geo_location
, ippGetString(attr
, 0, NULL
));
5345 _cupsRWUnlock(&printer
->lock
);
5347 if ((from
= cupsFileOpen(fromppd
, "r")) == NULL
)
5349 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: Unable to read generated PPD: %s", printer
->name
, strerror(errno
));
5353 snprintf(toppd
, sizeof(toppd
), "%s/ppd/%s.ppd", ServerRoot
, printer
->name
);
5354 if ((to
= cupsdCreateConfFile(toppd
, ConfigFilePerm
)) == NULL
)
5356 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: Unable to create PPD for printer: %s", printer
->name
, strerror(errno
));
5357 cupsFileClose(from
);
5361 while (cupsFileGets(from
, line
, sizeof(line
)))
5362 cupsFilePrintf(to
, "%s\n", line
);
5364 cupsFileClose(from
);
5365 if (!cupsdCloseCreatedConfFile(to
, toppd
))
5367 printer
->config_time
= time(NULL
);
5368 printer
->state
= IPP_PSTATE_IDLE
;
5369 printer
->accepting
= 1;
5371 cupsdSetPrinterAttrs(printer
);
5373 cupsdAddEvent(CUPSD_EVENT_PRINTER_CONFIG
, printer
, NULL
, "Printer \"%s\" is now available.", printer
->name
);
5374 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" is now available.", printer
->name
);
5378 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: PPD creation failed: %s", printer
->name
, cupsLastErrorString());
5385 * 'create_local_printer()' - Create a local (temporary) print queue.
5389 create_local_printer(
5390 cupsd_client_t
*con
) /* I - Client connection */
5392 ipp_attribute_t
*device_uri
, /* device-uri attribute */
5393 *printer_geo_location
, /* printer-geo-location attribute */
5394 *printer_info
, /* printer-info attribute */
5395 *printer_location
, /* printer-location attribute */
5396 *printer_name
; /* printer-name attribute */
5397 cupsd_printer_t
*printer
; /* New printer */
5398 http_status_t status
; /* Policy status */
5399 char name
[128], /* Sanitized printer name */
5400 *nameptr
, /* Pointer into name */
5401 uri
[1024]; /* printer-uri-supported value */
5402 const char *ptr
; /* Pointer into attribute value */
5406 * Require local access to create a local printer...
5409 if (!httpAddrLocalhost(httpGetAddress(con
->http
)))
5411 send_ipp_status(con
, IPP_STATUS_ERROR_FORBIDDEN
, _("Only local users can create a local printer."));
5416 * Check any other policy limits...
5419 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5421 send_http_error(con
, status
, NULL
);
5426 * Grab needed attributes...
5429 if ((printer_name
= ippFindAttribute(con
->request
, "printer-name", IPP_TAG_ZERO
)) == NULL
|| ippGetGroupTag(printer_name
) != IPP_TAG_PRINTER
|| ippGetValueTag(printer_name
) != IPP_TAG_NAME
)
5432 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Missing required attribute \"%s\"."), "printer-name");
5433 else if (ippGetGroupTag(printer_name
) != IPP_TAG_PRINTER
)
5434 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Attribute \"%s\" is in the wrong group."), "printer-name");
5436 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Attribute \"%s\" is the wrong value type."), "printer-name");
5441 for (nameptr
= name
, ptr
= ippGetString(printer_name
, 0, NULL
); *ptr
&& nameptr
< (name
+ sizeof(name
) - 1); ptr
++)
5444 * Sanitize the printer name...
5447 if (_cups_isalnum(*ptr
))
5449 else if (nameptr
== name
|| nameptr
[-1] != '_')
5455 if ((device_uri
= ippFindAttribute(con
->request
, "device-uri", IPP_TAG_ZERO
)) == NULL
|| ippGetGroupTag(device_uri
) != IPP_TAG_PRINTER
|| ippGetValueTag(device_uri
) != IPP_TAG_URI
)
5458 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Missing required attribute \"%s\"."), "device-uri");
5459 else if (ippGetGroupTag(device_uri
) != IPP_TAG_PRINTER
)
5460 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Attribute \"%s\" is in the wrong group."), "device-uri");
5462 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Attribute \"%s\" is the wrong value type."), "device-uri");
5467 printer_geo_location
= ippFindAttribute(con
->request
, "printer-geo-location", IPP_TAG_URI
);
5468 printer_info
= ippFindAttribute(con
->request
, "printer-info", IPP_TAG_TEXT
);
5469 printer_location
= ippFindAttribute(con
->request
, "printer-location", IPP_TAG_TEXT
);
5472 * See if the printer already exists...
5475 if ((printer
= cupsdFindDest(name
)) != NULL
)
5477 send_ipp_status(con
, IPP_STATUS_ERROR_NOT_POSSIBLE
, _("Printer \"%s\" already exists."), name
);
5478 goto add_printer_attributes
;
5482 * Create the printer...
5485 if ((printer
= cupsdAddPrinter(name
)) == NULL
)
5487 send_ipp_status(con
, IPP_STATUS_ERROR_INTERNAL
, _("Unable to create printer."));
5491 printer
->shared
= 0;
5492 printer
->temporary
= 1;
5494 cupsdSetDeviceURI(printer
, ippGetString(device_uri
, 0, NULL
));
5496 if (printer_geo_location
)
5497 cupsdSetString(&printer
->geo_location
, ippGetString(printer_geo_location
, 0, NULL
));
5499 cupsdSetString(&printer
->info
, ippGetString(printer_info
, 0, NULL
));
5500 if (printer_location
)
5501 cupsdSetString(&printer
->location
, ippGetString(printer_location
, 0, NULL
));
5503 cupsdSetPrinterAttrs(printer
);
5506 * Run a background thread to create the PPD...
5509 _cupsThreadCreate((_cups_thread_func_t
)create_local_bg_thread
, printer
);
5512 * Return printer attributes...
5515 send_ipp_status(con
, IPP_STATUS_OK
, _("Local printer created."));
5517 add_printer_attributes
:
5519 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs", (char)printer
->accepting
);
5520 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state", printer
->state
);
5521 add_printer_state_reasons(con
, printer
);
5523 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), httpIsEncrypted(con
->http
) ? "ipps" : "ipp", NULL
, con
->clientname
, con
->clientport
, "/printers/%s", printer
->name
);
5524 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-uri-supported", NULL
, uri
);
5529 * 'create_requested_array()' - Create an array for the requested-attributes.
5532 static cups_array_t
* /* O - Array of attributes or NULL */
5533 create_requested_array(ipp_t
*request
) /* I - IPP request */
5535 cups_array_t
*ra
; /* Requested attributes array */
5539 * Create the array for standard attributes...
5542 ra
= ippCreateRequestedArray(request
);
5545 * Add CUPS defaults as needed...
5548 if (cupsArrayFind(ra
, "printer-defaults"))
5551 * Include user-set defaults...
5554 char *name
; /* Option name */
5556 cupsArrayRemove(ra
, "printer-defaults");
5558 for (name
= (char *)cupsArrayFirst(CommonDefaults
);
5560 name
= (char *)cupsArrayNext(CommonDefaults
))
5561 if (!cupsArrayFind(ra
, name
))
5562 cupsArrayAdd(ra
, name
);
5570 * 'create_subscriptions()' - Create one or more notification subscriptions.
5574 create_subscriptions(
5575 cupsd_client_t
*con
, /* I - Client connection */
5576 ipp_attribute_t
*uri
) /* I - Printer URI */
5578 http_status_t status
; /* Policy status */
5579 int i
; /* Looping var */
5580 ipp_attribute_t
*attr
; /* Current attribute */
5581 cups_ptype_t dtype
; /* Destination type (printer/class) */
5582 char scheme
[HTTP_MAX_URI
],
5583 /* Scheme portion of URI */
5584 userpass
[HTTP_MAX_URI
],
5585 /* Username portion of URI */
5587 /* Host portion of URI */
5588 resource
[HTTP_MAX_URI
];
5589 /* Resource portion of URI */
5590 int port
; /* Port portion of URI */
5591 cupsd_printer_t
*printer
; /* Printer/class */
5592 cupsd_job_t
*job
; /* Job */
5593 int jobid
; /* Job ID */
5594 cupsd_subscription_t
*sub
; /* Subscription object */
5595 const char *username
, /* requesting-user-name or
5596 authenticated username */
5597 *recipient
, /* notify-recipient-uri */
5598 *pullmethod
; /* notify-pull-method */
5599 ipp_attribute_t
*user_data
; /* notify-user-data */
5600 int interval
, /* notify-time-interval */
5601 lease
; /* notify-lease-duration */
5602 unsigned mask
; /* notify-events */
5603 ipp_attribute_t
*notify_events
,/* notify-events(-default) */
5604 *notify_lease
; /* notify-lease-duration(-default) */
5608 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
5610 if (attr
->group_tag
!= IPP_TAG_ZERO
)
5611 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "g%04x v%04x %s", attr
->group_tag
,
5612 attr
->value_tag
, attr
->name
);
5614 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "----SEP----");
5619 * Is the destination valid?
5622 cupsdLogMessage(CUPSD_LOG_DEBUG
, "create_subscriptions(con=%p(%d), uri=\"%s\")", con
, con
->number
, uri
->values
[0].string
.text
);
5624 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
5625 sizeof(scheme
), userpass
, sizeof(userpass
), host
,
5626 sizeof(host
), &port
, resource
, sizeof(resource
));
5628 if (!strcmp(resource
, "/"))
5630 dtype
= (cups_ptype_t
)0;
5633 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
5635 dtype
= (cups_ptype_t
)0;
5638 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
5640 dtype
= CUPS_PRINTER_CLASS
;
5643 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
5649 send_ipp_status(con
, IPP_NOT_FOUND
,
5650 _("The printer or class does not exist."));
5660 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
5663 send_http_error(con
, status
, printer
);
5667 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5669 send_http_error(con
, status
, NULL
);
5674 * Get the user that is requesting the subscription...
5677 username
= get_username(con
);
5680 * Find the first subscription group attribute; return if we have
5684 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
5685 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
5690 send_ipp_status(con
, IPP_BAD_REQUEST
,
5691 _("No subscription attributes in request."));
5696 * Process the subscription attributes in the request...
5699 con
->response
->request
.status
.status_code
= IPP_BAD_REQUEST
;
5707 lease
= DefaultLeaseDuration
;
5709 mask
= CUPSD_EVENT_NONE
;
5713 notify_events
= ippFindAttribute(printer
->attrs
, "notify-events-default",
5715 notify_lease
= ippFindAttribute(printer
->attrs
,
5716 "notify-lease-duration-default",
5720 lease
= notify_lease
->values
[0].integer
;
5724 notify_events
= NULL
;
5725 notify_lease
= NULL
;
5728 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
5730 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
5731 attr
->value_tag
== IPP_TAG_URI
)
5734 * Validate the recipient scheme against the ServerBin/notifier
5738 char notifier
[1024]; /* Notifier filename */
5741 recipient
= attr
->values
[0].string
.text
;
5743 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
5744 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
5745 host
, sizeof(host
), &port
,
5746 resource
, sizeof(resource
)) < HTTP_URI_OK
)
5748 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5749 _("Bad notify-recipient-uri \"%s\"."), recipient
);
5750 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5751 "notify-status-code", IPP_URI_SCHEME
);
5755 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
5757 if (access(notifier
, X_OK
) || !strcmp(scheme
, ".") || !strcmp(scheme
, ".."))
5759 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5760 _("notify-recipient-uri URI \"%s\" uses unknown "
5761 "scheme."), recipient
);
5762 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5763 "notify-status-code", IPP_URI_SCHEME
);
5767 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
5769 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5770 _("notify-recipient-uri URI \"%s\" is already used."),
5772 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5773 "notify-status-code", IPP_ATTRIBUTES
);
5777 else if (!strcmp(attr
->name
, "notify-pull-method") &&
5778 attr
->value_tag
== IPP_TAG_KEYWORD
)
5780 pullmethod
= attr
->values
[0].string
.text
;
5782 if (strcmp(pullmethod
, "ippget"))
5784 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5785 _("Bad notify-pull-method \"%s\"."), pullmethod
);
5786 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5787 "notify-status-code", IPP_ATTRIBUTES
);
5791 else if (!strcmp(attr
->name
, "notify-charset") &&
5792 attr
->value_tag
== IPP_TAG_CHARSET
&&
5793 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
5794 strcmp(attr
->values
[0].string
.text
, "utf-8"))
5796 send_ipp_status(con
, IPP_CHARSET
,
5797 _("Character set \"%s\" not supported."),
5798 attr
->values
[0].string
.text
);
5801 else if (!strcmp(attr
->name
, "notify-natural-language") &&
5802 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
5803 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
5805 send_ipp_status(con
, IPP_CHARSET
,
5806 _("Language \"%s\" not supported."),
5807 attr
->values
[0].string
.text
);
5810 else if (!strcmp(attr
->name
, "notify-user-data") &&
5811 attr
->value_tag
== IPP_TAG_STRING
)
5813 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
5815 send_ipp_status(con
, IPP_REQUEST_VALUE
,
5816 _("The notify-user-data value is too large "
5817 "(%d > 63 octets)."),
5818 attr
->values
[0].unknown
.length
);
5824 else if (!strcmp(attr
->name
, "notify-events") &&
5825 attr
->value_tag
== IPP_TAG_KEYWORD
)
5826 notify_events
= attr
;
5827 else if (!strcmp(attr
->name
, "notify-lease-duration") &&
5828 attr
->value_tag
== IPP_TAG_INTEGER
)
5829 lease
= attr
->values
[0].integer
;
5830 else if (!strcmp(attr
->name
, "notify-time-interval") &&
5831 attr
->value_tag
== IPP_TAG_INTEGER
)
5832 interval
= attr
->values
[0].integer
;
5833 else if (!strcmp(attr
->name
, "notify-job-id") &&
5834 attr
->value_tag
== IPP_TAG_INTEGER
)
5835 jobid
= attr
->values
[0].integer
;
5842 for (i
= 0; i
< notify_events
->num_values
; i
++)
5843 mask
|= cupsdEventValue(notify_events
->values
[i
].string
.text
);
5848 cupsdLogMessage(CUPSD_LOG_DEBUG
, "recipient=\"%s\"", recipient
);
5851 if (!strncmp(recipient
, "mailto:", 7) && user_data
)
5853 char temp
[64]; /* Temporary string */
5855 memcpy(temp
, user_data
->values
[0].unknown
.data
, (size_t)user_data
->values
[0].unknown
.length
);
5856 temp
[user_data
->values
[0].unknown
.length
] = '\0';
5858 if (httpSeparateURI(HTTP_URI_CODING_ALL
, temp
, scheme
, sizeof(scheme
), userpass
, sizeof(userpass
), host
, sizeof(host
), &port
, resource
, sizeof(resource
)) < HTTP_URI_OK
)
5860 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad notify-user-data \"%s\"."), temp
);
5861 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
, "notify-status-code", IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES
);
5868 cupsdLogMessage(CUPSD_LOG_DEBUG
, "pullmethod=\"%s\"", pullmethod
);
5869 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-lease-duration=%d", lease
);
5870 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-time-interval=%d", interval
);
5872 if (!recipient
&& !pullmethod
)
5875 if (mask
== CUPSD_EVENT_NONE
)
5878 mask
= CUPSD_EVENT_JOB_COMPLETED
;
5880 mask
= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
5883 send_ipp_status(con
, IPP_BAD_REQUEST
,
5884 _("notify-events not specified."));
5889 if (MaxLeaseDuration
&& (lease
== 0 || lease
> MaxLeaseDuration
))
5891 cupsdLogMessage(CUPSD_LOG_INFO
,
5892 "create_subscriptions: Limiting notify-lease-duration to "
5895 lease
= MaxLeaseDuration
;
5900 if ((job
= cupsdFindJob(jobid
)) == NULL
)
5902 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
5910 if ((sub
= cupsdAddSubscription(mask
, printer
, job
, recipient
, 0)) == NULL
)
5912 send_ipp_status(con
, IPP_TOO_MANY_SUBSCRIPTIONS
,
5913 _("There are too many subscriptions."));
5918 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription #%d for job %d.",
5921 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5922 "Added subscription #%d for printer \"%s\".",
5923 sub
->id
, printer
->name
);
5925 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription #%d for server.",
5928 sub
->interval
= interval
;
5930 sub
->expire
= lease
? time(NULL
) + lease
: 0;
5932 cupsdSetString(&sub
->owner
, username
);
5936 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
5937 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
5938 (size_t)sub
->user_data_len
);
5941 ippAddSeparator(con
->response
);
5942 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5943 "notify-subscription-id", sub
->id
);
5945 con
->response
->request
.status
.status_code
= IPP_OK
;
5951 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
5956 * 'delete_printer()' - Remove a printer or class from the system.
5960 delete_printer(cupsd_client_t
*con
, /* I - Client connection */
5961 ipp_attribute_t
*uri
) /* I - URI of printer or class */
5963 http_status_t status
; /* Policy status */
5964 cups_ptype_t dtype
; /* Destination type (printer/class) */
5965 cupsd_printer_t
*printer
; /* Printer/class */
5966 char filename
[1024]; /* Script/PPD filename */
5967 int temporary
; /* Temporary queue? */
5970 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "delete_printer(%p[%d], %s)", con
,
5971 con
->number
, uri
->values
[0].string
.text
);
5974 * Do we have a valid URI?
5977 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
5983 send_ipp_status(con
, IPP_NOT_FOUND
,
5984 _("The printer or class does not exist."));
5992 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5994 send_http_error(con
, status
, NULL
);
5999 * Remove old jobs...
6002 cupsdCancelJobs(printer
->name
, NULL
, 1);
6005 * Remove old subscriptions and send a "deleted printer" event...
6008 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED
, printer
, NULL
,
6009 "%s \"%s\" deleted by \"%s\".",
6010 (dtype
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
6011 printer
->name
, get_username(con
));
6013 cupsdExpireSubscriptions(printer
, NULL
);
6016 * Remove any old PPD or script files...
6019 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
6022 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd.O", ServerRoot
,
6026 snprintf(filename
, sizeof(filename
), "%s/%s.png", CacheDir
, printer
->name
);
6029 snprintf(filename
, sizeof(filename
), "%s/%s.data", CacheDir
, printer
->name
);
6033 * Unregister color profiles...
6036 cupsdUnregisterColor(printer
);
6038 temporary
= printer
->temporary
;
6040 if (dtype
& CUPS_PRINTER_CLASS
)
6042 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" deleted by \"%s\".",
6043 printer
->name
, get_username(con
));
6045 cupsdDeletePrinter(printer
, 0);
6047 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
6051 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" deleted by \"%s\".",
6052 printer
->name
, get_username(con
));
6054 if (cupsdDeletePrinter(printer
, 0) && !temporary
)
6055 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
6058 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
6062 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
6065 * Return with no errors...
6068 con
->response
->request
.status
.status_code
= IPP_OK
;
6073 * 'get_default()' - Get the default destination.
6077 get_default(cupsd_client_t
*con
) /* I - Client connection */
6079 http_status_t status
; /* Policy status */
6080 cups_array_t
*ra
; /* Requested attributes array */
6083 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_default(%p[%d])", con
, con
->number
);
6089 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6091 send_http_error(con
, status
, NULL
);
6097 ra
= create_requested_array(con
->request
);
6099 copy_printer_attrs(con
, DefaultPrinter
, ra
);
6101 cupsArrayDelete(ra
);
6103 con
->response
->request
.status
.status_code
= IPP_OK
;
6106 send_ipp_status(con
, IPP_NOT_FOUND
, _("No default printer."));
6111 * 'get_devices()' - Get the list of available devices on the local system.
6115 get_devices(cupsd_client_t
*con
) /* I - Client connection */
6117 http_status_t status
; /* Policy status */
6118 ipp_attribute_t
*limit
, /* limit attribute */
6119 *timeout
, /* timeout attribute */
6120 *requested
, /* requested-attributes attribute */
6121 *exclude
, /* exclude-schemes attribute */
6122 *include
; /* include-schemes attribute */
6123 char command
[1024], /* cups-deviced command */
6124 options
[2048], /* Options to pass to command */
6126 /* String for requested attributes */
6128 /* String for excluded schemes */
6130 /* String for included schemes */
6133 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_devices(%p[%d])", con
, con
->number
);
6139 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6141 send_http_error(con
, status
, NULL
);
6146 * Run cups-deviced command with the given options...
6149 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
6150 timeout
= ippFindAttribute(con
->request
, "timeout", IPP_TAG_INTEGER
);
6151 requested
= ippFindAttribute(con
->request
, "requested-attributes",
6153 exclude
= ippFindAttribute(con
->request
, "exclude-schemes", IPP_TAG_NAME
);
6154 include
= ippFindAttribute(con
->request
, "include-schemes", IPP_TAG_NAME
);
6157 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
6159 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
6162 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
6164 exclude_str
[0] = '\0';
6167 url_encode_attr(include
, include_str
, sizeof(include_str
));
6169 include_str
[0] = '\0';
6171 snprintf(command
, sizeof(command
), "%s/daemon/cups-deviced", ServerBin
);
6172 snprintf(options
, sizeof(options
),
6173 "%d+%d+%d+%d+%s%s%s%s%s",
6174 con
->request
->request
.op
.request_id
,
6175 limit
? limit
->values
[0].integer
: 0,
6176 timeout
? timeout
->values
[0].integer
: 15,
6179 exclude_str
[0] ? "%20" : "", exclude_str
,
6180 include_str
[0] ? "%20" : "", include_str
);
6182 if (cupsdSendCommand(con
, command
, options
, 1))
6185 * Command started successfully, don't send an IPP response here...
6188 ippDelete(con
->response
);
6189 con
->response
= NULL
;
6194 * Command failed, return "internal error" so the user knows something
6198 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
6199 _("cups-deviced failed to execute."));
6205 * 'get_document()' - Get a copy of a job file.
6209 get_document(cupsd_client_t
*con
, /* I - Client connection */
6210 ipp_attribute_t
*uri
) /* I - Job URI */
6212 http_status_t status
; /* Policy status */
6213 ipp_attribute_t
*attr
; /* Current attribute */
6214 int jobid
; /* Job ID */
6215 int docnum
; /* Document number */
6216 cupsd_job_t
*job
; /* Current job */
6217 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
6218 username
[HTTP_MAX_URI
], /* Username portion of URI */
6219 host
[HTTP_MAX_URI
], /* Host portion of URI */
6220 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6221 int port
; /* Port portion of URI */
6222 char filename
[1024], /* Filename for document */
6223 format
[1024]; /* Format for document */
6226 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_document(%p[%d], %s)", con
,
6227 con
->number
, uri
->values
[0].string
.text
);
6230 * See if we have a job URI or a printer URI...
6233 if (!strcmp(uri
->name
, "printer-uri"))
6236 * Got a printer URI; see if we also have a job-id attribute...
6239 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6240 IPP_TAG_INTEGER
)) == NULL
)
6242 send_ipp_status(con
, IPP_BAD_REQUEST
,
6243 _("Got a printer-uri attribute but no job-id."));
6247 jobid
= attr
->values
[0].integer
;
6252 * Got a job URI; parse it to get the job ID...
6255 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6256 sizeof(scheme
), username
, sizeof(username
), host
,
6257 sizeof(host
), &port
, resource
, sizeof(resource
));
6259 if (strncmp(resource
, "/jobs/", 6))
6265 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
6266 uri
->values
[0].string
.text
);
6270 jobid
= atoi(resource
+ 6);
6274 * See if the job exists...
6277 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6280 * Nope - return a "not found" error...
6283 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
6291 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
,
6292 job
->username
)) != HTTP_OK
)
6294 send_http_error(con
, status
, NULL
);
6299 * Get the document number...
6302 if ((attr
= ippFindAttribute(con
->request
, "document-number",
6303 IPP_TAG_INTEGER
)) == NULL
)
6305 send_ipp_status(con
, IPP_BAD_REQUEST
,
6306 _("Missing document-number attribute."));
6310 if ((docnum
= attr
->values
[0].integer
) < 1 || docnum
> job
->num_files
||
6311 attr
->num_values
> 1)
6313 send_ipp_status(con
, IPP_NOT_FOUND
,
6314 _("Document #%d does not exist in job #%d."), docnum
,
6319 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, jobid
,
6321 if ((con
->file
= open(filename
, O_RDONLY
)) == -1)
6323 cupsdLogMessage(CUPSD_LOG_ERROR
,
6324 "Unable to open document %d in job %d - %s", docnum
, jobid
,
6326 send_ipp_status(con
, IPP_NOT_FOUND
,
6327 _("Unable to open document #%d in job #%d."), docnum
,
6332 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
6336 snprintf(format
, sizeof(format
), "%s/%s", job
->filetypes
[docnum
- 1]->super
,
6337 job
->filetypes
[docnum
- 1]->type
);
6339 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format",
6341 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "document-number",
6343 if ((attr
= ippFindAttribute(job
->attrs
, "document-name",
6344 IPP_TAG_NAME
)) != NULL
)
6345 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name",
6346 NULL
, attr
->values
[0].string
.text
);
6351 * 'get_job_attrs()' - Get job attributes.
6355 get_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
6356 ipp_attribute_t
*uri
) /* I - Job URI */
6358 http_status_t status
; /* Policy status */
6359 ipp_attribute_t
*attr
; /* Current attribute */
6360 int jobid
; /* Job ID */
6361 cupsd_job_t
*job
; /* Current job */
6362 cupsd_printer_t
*printer
; /* Current printer */
6363 cupsd_policy_t
*policy
; /* Current security policy */
6364 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6365 username
[HTTP_MAX_URI
], /* Username portion of URI */
6366 host
[HTTP_MAX_URI
], /* Host portion of URI */
6367 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6368 int port
; /* Port portion of URI */
6369 cups_array_t
*ra
, /* Requested attributes array */
6370 *exclude
; /* Private attributes array */
6373 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_job_attrs(%p[%d], %s)", con
,
6374 con
->number
, uri
->values
[0].string
.text
);
6377 * See if we have a job URI or a printer URI...
6380 if (!strcmp(uri
->name
, "printer-uri"))
6383 * Got a printer URI; see if we also have a job-id attribute...
6386 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6387 IPP_TAG_INTEGER
)) == NULL
)
6389 send_ipp_status(con
, IPP_BAD_REQUEST
,
6390 _("Got a printer-uri attribute but no job-id."));
6394 jobid
= attr
->values
[0].integer
;
6399 * Got a job URI; parse it to get the job ID...
6402 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6403 sizeof(scheme
), username
, sizeof(username
), host
,
6404 sizeof(host
), &port
, resource
, sizeof(resource
));
6406 if (strncmp(resource
, "/jobs/", 6))
6412 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
6413 uri
->values
[0].string
.text
);
6417 jobid
= atoi(resource
+ 6);
6421 * See if the job exists...
6424 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6427 * Nope - return a "not found" error...
6430 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
6438 if ((printer
= job
->printer
) == NULL
)
6439 printer
= cupsdFindDest(job
->dest
);
6442 policy
= printer
->op_policy_ptr
;
6444 policy
= DefaultPolicyPtr
;
6446 if ((status
= cupsdCheckPolicy(policy
, con
, job
->username
)) != HTTP_OK
)
6448 send_http_error(con
, status
, NULL
);
6452 exclude
= cupsdGetPrivateAttrs(policy
, con
, printer
, job
->username
);
6455 * Copy attributes...
6460 ra
= create_requested_array(con
->request
);
6461 copy_job_attrs(con
, job
, ra
, exclude
);
6462 cupsArrayDelete(ra
);
6464 con
->response
->request
.status
.status_code
= IPP_OK
;
6469 * 'get_jobs()' - Get a list of jobs for the specified printer.
6473 get_jobs(cupsd_client_t
*con
, /* I - Client connection */
6474 ipp_attribute_t
*uri
) /* I - Printer URI */
6476 http_status_t status
; /* Policy status */
6477 ipp_attribute_t
*attr
; /* Current attribute */
6478 const char *dest
; /* Destination */
6479 cups_ptype_t dtype
; /* Destination type (printer/class) */
6480 cups_ptype_t dmask
; /* Destination type mask */
6481 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6482 username
[HTTP_MAX_URI
], /* Username portion of URI */
6483 host
[HTTP_MAX_URI
], /* Host portion of URI */
6484 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6485 int port
; /* Port portion of URI */
6486 int job_comparison
; /* Job comparison */
6487 ipp_jstate_t job_state
; /* job-state value */
6488 int first_job_id
= 1, /* First job ID */
6489 first_index
= 1, /* First index */
6490 limit
= 0, /* Maximum number of jobs to return */
6491 count
, /* Number of jobs that match */
6492 need_load_job
= 0; /* Do we need to load the job? */
6493 const char *job_attr
; /* Job attribute requested */
6494 ipp_attribute_t
*job_ids
; /* job-ids attribute */
6495 cupsd_job_t
*job
; /* Current job pointer */
6496 cupsd_printer_t
*printer
; /* Printer */
6497 cups_array_t
*list
; /* Which job list... */
6498 int delete_list
= 0; /* Delete the list afterwards? */
6499 cups_array_t
*ra
, /* Requested attributes array */
6500 *exclude
; /* Private attributes array */
6501 cupsd_policy_t
*policy
; /* Current policy */
6504 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs(%p[%d], %s)", con
, con
->number
,
6505 uri
->values
[0].string
.text
);
6508 * Is the destination valid?
6511 if (strcmp(uri
->name
, "printer-uri"))
6513 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No printer-uri in request."));
6517 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6518 sizeof(scheme
), username
, sizeof(username
), host
,
6519 sizeof(host
), &port
, resource
, sizeof(resource
));
6521 if (!strcmp(resource
, "/") || !strcmp(resource
, "/jobs"))
6524 dtype
= (cups_ptype_t
)0;
6525 dmask
= (cups_ptype_t
)0;
6528 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6531 dtype
= (cups_ptype_t
)0;
6532 dmask
= CUPS_PRINTER_CLASS
;
6535 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6538 dtype
= CUPS_PRINTER_CLASS
;
6539 dmask
= CUPS_PRINTER_CLASS
;
6542 else if ((dest
= cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
,
6549 send_ipp_status(con
, IPP_NOT_FOUND
,
6550 _("The printer or class does not exist."));
6555 dtype
&= CUPS_PRINTER_CLASS
;
6556 dmask
= CUPS_PRINTER_CLASS
;
6564 policy
= printer
->op_policy_ptr
;
6566 policy
= DefaultPolicyPtr
;
6568 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
6570 send_http_error(con
, status
, NULL
);
6574 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
6577 * See if the "which-jobs" attribute have been specified...
6580 if ((attr
= ippFindAttribute(con
->request
, "which-jobs",
6581 IPP_TAG_KEYWORD
)) != NULL
&& job_ids
)
6583 send_ipp_status(con
, IPP_CONFLICT
,
6584 _("The %s attribute cannot be provided with job-ids."),
6588 else if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "not-completed"))
6590 job_comparison
= -1;
6591 job_state
= IPP_JOB_STOPPED
;
6594 else if (!strcmp(attr
->values
[0].string
.text
, "completed"))
6597 job_state
= IPP_JOB_CANCELED
;
6598 list
= cupsdGetCompletedJobs(printer
);
6601 else if (!strcmp(attr
->values
[0].string
.text
, "aborted"))
6604 job_state
= IPP_JOB_ABORTED
;
6605 list
= cupsdGetCompletedJobs(printer
);
6608 else if (!strcmp(attr
->values
[0].string
.text
, "all"))
6611 job_state
= IPP_JOB_PENDING
;
6614 else if (!strcmp(attr
->values
[0].string
.text
, "canceled"))
6617 job_state
= IPP_JOB_CANCELED
;
6618 list
= cupsdGetCompletedJobs(printer
);
6621 else if (!strcmp(attr
->values
[0].string
.text
, "pending"))
6624 job_state
= IPP_JOB_PENDING
;
6627 else if (!strcmp(attr
->values
[0].string
.text
, "pending-held"))
6630 job_state
= IPP_JOB_HELD
;
6633 else if (!strcmp(attr
->values
[0].string
.text
, "processing"))
6636 job_state
= IPP_JOB_PROCESSING
;
6637 list
= PrintingJobs
;
6639 else if (!strcmp(attr
->values
[0].string
.text
, "processing-stopped"))
6642 job_state
= IPP_JOB_STOPPED
;
6647 send_ipp_status(con
, IPP_ATTRIBUTES
,
6648 _("The which-jobs value \"%s\" is not supported."),
6649 attr
->values
[0].string
.text
);
6650 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
6651 "which-jobs", NULL
, attr
->values
[0].string
.text
);
6656 * See if they want to limit the number of jobs reported...
6659 if ((attr
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
)) != NULL
)
6663 send_ipp_status(con
, IPP_CONFLICT
,
6664 _("The %s attribute cannot be provided with job-ids."),
6669 limit
= attr
->values
[0].integer
;
6672 if ((attr
= ippFindAttribute(con
->request
, "first-index", IPP_TAG_INTEGER
)) != NULL
)
6676 send_ipp_status(con
, IPP_CONFLICT
,
6677 _("The %s attribute cannot be provided with job-ids."),
6682 first_index
= attr
->values
[0].integer
;
6684 else if ((attr
= ippFindAttribute(con
->request
, "first-job-id", IPP_TAG_INTEGER
)) != NULL
)
6688 send_ipp_status(con
, IPP_CONFLICT
,
6689 _("The %s attribute cannot be provided with job-ids."),
6694 first_job_id
= attr
->values
[0].integer
;
6698 * See if we only want to see jobs for a specific user...
6701 if ((attr
= ippFindAttribute(con
->request
, "my-jobs", IPP_TAG_BOOLEAN
)) != NULL
&& job_ids
)
6703 send_ipp_status(con
, IPP_CONFLICT
,
6704 _("The %s attribute cannot be provided with job-ids."),
6708 else if (attr
&& attr
->values
[0].boolean
)
6709 strlcpy(username
, get_username(con
), sizeof(username
));
6713 ra
= create_requested_array(con
->request
);
6714 for (job_attr
= (char *)cupsArrayFirst(ra
); job_attr
; job_attr
= (char *)cupsArrayNext(ra
))
6715 if (strcmp(job_attr
, "job-id") &&
6716 strcmp(job_attr
, "job-k-octets") &&
6717 strcmp(job_attr
, "job-media-progress") &&
6718 strcmp(job_attr
, "job-more-info") &&
6719 strcmp(job_attr
, "job-name") &&
6720 strcmp(job_attr
, "job-originating-user-name") &&
6721 strcmp(job_attr
, "job-preserved") &&
6722 strcmp(job_attr
, "job-printer-up-time") &&
6723 strcmp(job_attr
, "job-printer-uri") &&
6724 strcmp(job_attr
, "job-state") &&
6725 strcmp(job_attr
, "job-state-reasons") &&
6726 strcmp(job_attr
, "job-uri") &&
6727 strcmp(job_attr
, "time-at-completed") &&
6728 strcmp(job_attr
, "time-at-creation") &&
6729 strcmp(job_attr
, "number-of-documents"))
6735 if (need_load_job
&& (limit
== 0 || limit
> 500) && (list
== Jobs
|| delete_list
))
6738 * Limit expensive Get-Jobs for job history to 500 jobs...
6741 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
, "limit", 500);
6744 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
, "limit", limit
);
6748 cupsdLogClient(con
, CUPSD_LOG_INFO
, "Limiting Get-Jobs response to %d jobs.", limit
);
6752 * OK, build a list of jobs for this printer...
6757 int i
; /* Looping var */
6759 for (i
= 0; i
< job_ids
->num_values
; i
++)
6761 if (!cupsdFindJob(job_ids
->values
[i
].integer
))
6765 if (i
< job_ids
->num_values
)
6767 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
6768 job_ids
->values
[i
].integer
);
6772 for (i
= 0; i
< job_ids
->num_values
; i
++)
6774 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
6776 if (need_load_job
&& !job
->attrs
)
6782 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d", job
->id
);
6788 ippAddSeparator(con
->response
);
6790 exclude
= cupsdGetPrivateAttrs(job
->printer
?
6791 job
->printer
->op_policy_ptr
:
6792 policy
, con
, job
->printer
,
6795 copy_job_attrs(con
, job
, ra
, exclude
);
6800 if (first_index
> 1)
6801 job
= (cupsd_job_t
*)cupsArrayIndex(list
, first_index
- 1);
6803 job
= (cupsd_job_t
*)cupsArrayFirst(list
);
6805 for (count
= 0; (limit
<= 0 || count
< limit
) && job
; job
= (cupsd_job_t
*)cupsArrayNext(list
))
6808 * Filter out jobs that don't match...
6811 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
6812 "get_jobs: job->id=%d, dest=\"%s\", username=\"%s\", "
6813 "state_value=%d, attrs=%p", job
->id
, job
->dest
,
6814 job
->username
, job
->state_value
, job
->attrs
);
6816 if (!job
->dest
|| !job
->username
)
6819 if (!job
->dest
|| !job
->username
)
6822 if ((dest
&& strcmp(job
->dest
, dest
)) &&
6823 (!job
->printer
|| !dest
|| strcmp(job
->printer
->name
, dest
)))
6825 if ((job
->dtype
& dmask
) != dtype
&&
6826 (!job
->printer
|| (job
->printer
->type
& dmask
) != dtype
))
6829 if ((job_comparison
< 0 && job
->state_value
> job_state
) ||
6830 (job_comparison
== 0 && job
->state_value
!= job_state
) ||
6831 (job_comparison
> 0 && job
->state_value
< job_state
))
6834 if (job
->id
< first_job_id
)
6837 if (need_load_job
&& !job
->attrs
)
6843 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d", job
->id
);
6848 if (username
[0] && _cups_strcasecmp(username
, job
->username
))
6852 ippAddSeparator(con
->response
);
6856 exclude
= cupsdGetPrivateAttrs(job
->printer
?
6857 job
->printer
->op_policy_ptr
:
6858 policy
, con
, job
->printer
,
6861 copy_job_attrs(con
, job
, ra
, exclude
);
6864 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: count=%d", count
);
6867 cupsArrayDelete(ra
);
6870 cupsArrayDelete(list
);
6872 con
->response
->request
.status
.status_code
= IPP_OK
;
6877 * 'get_notifications()' - Get events for a subscription.
6881 get_notifications(cupsd_client_t
*con
) /* I - Client connection */
6883 int i
, j
; /* Looping vars */
6884 http_status_t status
; /* Policy status */
6885 cupsd_subscription_t
*sub
; /* Subscription */
6886 ipp_attribute_t
*ids
, /* notify-subscription-ids */
6887 *sequences
; /* notify-sequence-numbers */
6888 int min_seq
; /* Minimum sequence number */
6889 int interval
; /* Poll interval */
6892 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_notifications(con=%p[%d])",
6896 * Get subscription attributes...
6899 ids
= ippFindAttribute(con
->request
, "notify-subscription-ids",
6901 sequences
= ippFindAttribute(con
->request
, "notify-sequence-numbers",
6906 send_ipp_status(con
, IPP_BAD_REQUEST
,
6907 _("Missing notify-subscription-ids attribute."));
6912 * Are the subscription IDs valid?
6915 for (i
= 0, interval
= 60; i
< ids
->num_values
; i
++)
6917 if ((sub
= cupsdFindSubscription(ids
->values
[i
].integer
)) == NULL
)
6920 * Bad subscription ID...
6923 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
6924 ids
->values
[i
].integer
);
6932 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
6934 con
, sub
->owner
)) != HTTP_OK
)
6936 send_http_error(con
, status
, sub
->dest
);
6941 * Check the subscription type and update the interval accordingly.
6944 if (sub
->job
&& sub
->job
->state_value
== IPP_JOB_PROCESSING
&&
6947 else if (sub
->job
&& sub
->job
->state_value
>= IPP_JOB_STOPPED
)
6949 else if (sub
->dest
&& sub
->dest
->state
== IPP_PRINTER_PROCESSING
&&
6955 * Tell the client to poll again in N seconds...
6959 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
6960 "notify-get-interval", interval
);
6962 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
6963 "printer-up-time", time(NULL
));
6966 * Copy the subscription event attributes to the response.
6969 con
->response
->request
.status
.status_code
=
6970 interval
? IPP_OK
: IPP_OK_EVENTS_COMPLETE
;
6972 for (i
= 0; i
< ids
->num_values
; i
++)
6975 * Get the subscription and sequence number...
6978 sub
= cupsdFindSubscription(ids
->values
[i
].integer
);
6980 if (sequences
&& i
< sequences
->num_values
)
6981 min_seq
= sequences
->values
[i
].integer
;
6986 * If we don't have any new events, nothing to do here...
6989 if (min_seq
> (sub
->first_event_id
+ cupsArrayCount(sub
->events
)))
6993 * Otherwise copy all of the new events...
6996 if (sub
->first_event_id
> min_seq
)
6999 j
= min_seq
- sub
->first_event_id
;
7001 for (; j
< cupsArrayCount(sub
->events
); j
++)
7003 ippAddSeparator(con
->response
);
7005 copy_attrs(con
->response
,
7006 ((cupsd_event_t
*)cupsArrayIndex(sub
->events
, j
))->attrs
, NULL
,
7007 IPP_TAG_EVENT_NOTIFICATION
, 0, NULL
);
7014 * 'get_ppd()' - Get a named PPD from the local system.
7018 get_ppd(cupsd_client_t
*con
, /* I - Client connection */
7019 ipp_attribute_t
*uri
) /* I - Printer URI or PPD name */
7021 http_status_t status
; /* Policy status */
7022 cupsd_printer_t
*dest
; /* Destination */
7023 cups_ptype_t dtype
; /* Destination type */
7026 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppd(%p[%d], %p[%s=%s])", con
,
7027 con
->number
, uri
, uri
->name
, uri
->values
[0].string
.text
);
7029 if (!strcmp(ippGetName(uri
), "ppd-name"))
7032 * Return a PPD file from cups-driverd...
7035 const char *ppd_name
= ippGetString(uri
, 0, NULL
);
7036 /* ppd-name value */
7037 char command
[1024], /* cups-driverd command */
7038 options
[1024], /* Options to pass to command */
7039 oppd_name
[1024]; /* Escaped ppd-name */
7045 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7047 send_http_error(con
, status
, NULL
);
7052 * Check ppd-name value...
7055 if (strstr(ppd_name
, "../"))
7057 send_ipp_status(con
, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES
, _("Invalid ppd-name value."));
7062 * Run cups-driverd command with the given options...
7065 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7066 url_encode_string(ppd_name
, oppd_name
, sizeof(oppd_name
));
7067 snprintf(options
, sizeof(options
), "get+%d+%s", ippGetRequestId(con
->request
), oppd_name
);
7069 if (cupsdSendCommand(con
, command
, options
, 0))
7072 * Command started successfully, don't send an IPP response here...
7075 ippDelete(con
->response
);
7076 con
->response
= NULL
;
7081 * Command failed, return "internal error" so the user knows something
7085 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("cups-driverd failed to execute."));
7088 else if (!strcmp(ippGetName(uri
), "printer-uri") && cupsdValidateDest(ippGetString(uri
, 0, NULL
), &dtype
, &dest
))
7090 int i
; /* Looping var */
7091 char filename
[1024]; /* PPD filename */
7097 if ((status
= cupsdCheckPolicy(dest
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7099 send_http_error(con
, status
, dest
);
7104 * See if we need the PPD for a class or remote printer...
7107 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
, dest
->name
);
7109 if ((dtype
& CUPS_PRINTER_REMOTE
) && access(filename
, 0))
7111 send_ipp_status(con
, IPP_STATUS_CUPS_SEE_OTHER
, _("See remote printer."));
7112 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
, dest
->uri
);
7115 else if (dtype
& CUPS_PRINTER_CLASS
)
7117 for (i
= 0; i
< dest
->num_printers
; i
++)
7118 if (!(dest
->printers
[i
]->type
& CUPS_PRINTER_CLASS
))
7120 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
, dest
->printers
[i
]->name
);
7122 if (!access(filename
, 0))
7126 if (i
< dest
->num_printers
)
7127 dest
= dest
->printers
[i
];
7130 send_ipp_status(con
, IPP_STATUS_CUPS_SEE_OTHER
, _("See remote printer."));
7131 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
, dest
->printers
[0]->uri
);
7137 * Found the printer with the PPD file, now see if there is one...
7140 if ((con
->file
= open(filename
, O_RDONLY
)) < 0)
7142 send_ipp_status(con
, IPP_STATUS_ERROR_NOT_FOUND
, _("The PPD file \"%s\" could not be opened: %s"), ippGetString(uri
, 0, NULL
), strerror(errno
));
7146 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
7150 ippSetStatusCode(con
->response
, IPP_STATUS_OK
);
7153 send_ipp_status(con
, IPP_STATUS_ERROR_NOT_FOUND
, _("The PPD file \"%s\" could not be found."), ippGetString(uri
, 0, NULL
));
7158 * 'get_ppds()' - Get the list of PPD files on the local system.
7162 get_ppds(cupsd_client_t
*con
) /* I - Client connection */
7164 http_status_t status
; /* Policy status */
7165 ipp_attribute_t
*limit
, /* Limit attribute */
7166 *device
, /* ppd-device-id attribute */
7167 *language
, /* ppd-natural-language attribute */
7168 *make
, /* ppd-make attribute */
7169 *model
, /* ppd-make-and-model attribute */
7170 *model_number
, /* ppd-model-number attribute */
7171 *product
, /* ppd-product attribute */
7172 *psversion
, /* ppd-psverion attribute */
7173 *type
, /* ppd-type attribute */
7174 *requested
, /* requested-attributes attribute */
7175 *exclude
, /* exclude-schemes attribute */
7176 *include
; /* include-schemes attribute */
7177 char command
[1024], /* cups-driverd command */
7178 options
[4096], /* Options to pass to command */
7179 device_str
[256],/* Escaped ppd-device-id string */
7181 /* Escaped ppd-natural-language */
7182 make_str
[256], /* Escaped ppd-make string */
7183 model_str
[256], /* Escaped ppd-make-and-model string */
7184 model_number_str
[256],
7185 /* ppd-model-number string */
7187 /* Escaped ppd-product string */
7189 /* Escaped ppd-psversion string */
7190 type_str
[256], /* Escaped ppd-type string */
7192 /* String for requested attributes */
7194 /* String for excluded schemes */
7196 /* String for included schemes */
7199 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppds(%p[%d])", con
, con
->number
);
7205 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7207 send_http_error(con
, status
, NULL
);
7212 * Run cups-driverd command with the given options...
7215 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
7216 device
= ippFindAttribute(con
->request
, "ppd-device-id", IPP_TAG_TEXT
);
7217 language
= ippFindAttribute(con
->request
, "ppd-natural-language",
7219 make
= ippFindAttribute(con
->request
, "ppd-make", IPP_TAG_TEXT
);
7220 model
= ippFindAttribute(con
->request
, "ppd-make-and-model",
7222 model_number
= ippFindAttribute(con
->request
, "ppd-model-number",
7224 product
= ippFindAttribute(con
->request
, "ppd-product", IPP_TAG_TEXT
);
7225 psversion
= ippFindAttribute(con
->request
, "ppd-psversion", IPP_TAG_TEXT
);
7226 type
= ippFindAttribute(con
->request
, "ppd-type", IPP_TAG_KEYWORD
);
7227 requested
= ippFindAttribute(con
->request
, "requested-attributes",
7229 exclude
= ippFindAttribute(con
->request
, "exclude-schemes",
7231 include
= ippFindAttribute(con
->request
, "include-schemes",
7235 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
7237 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
7240 url_encode_attr(device
, device_str
, sizeof(device_str
));
7242 device_str
[0] = '\0';
7245 url_encode_attr(language
, language_str
, sizeof(language_str
));
7247 language_str
[0] = '\0';
7250 url_encode_attr(make
, make_str
, sizeof(make_str
));
7255 url_encode_attr(model
, model_str
, sizeof(model_str
));
7257 model_str
[0] = '\0';
7260 snprintf(model_number_str
, sizeof(model_number_str
), "ppd-model-number=%d",
7261 model_number
->values
[0].integer
);
7263 model_number_str
[0] = '\0';
7266 url_encode_attr(product
, product_str
, sizeof(product_str
));
7268 product_str
[0] = '\0';
7271 url_encode_attr(psversion
, psversion_str
, sizeof(psversion_str
));
7273 psversion_str
[0] = '\0';
7276 url_encode_attr(type
, type_str
, sizeof(type_str
));
7281 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
7283 exclude_str
[0] = '\0';
7286 url_encode_attr(include
, include_str
, sizeof(include_str
));
7288 include_str
[0] = '\0';
7290 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7291 snprintf(options
, sizeof(options
),
7292 "list+%d+%d+%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
7293 con
->request
->request
.op
.request_id
,
7294 limit
? limit
->values
[0].integer
: 0,
7296 device
? "%20" : "", device_str
,
7297 language
? "%20" : "", language_str
,
7298 make
? "%20" : "", make_str
,
7299 model
? "%20" : "", model_str
,
7300 model_number
? "%20" : "", model_number_str
,
7301 product
? "%20" : "", product_str
,
7302 psversion
? "%20" : "", psversion_str
,
7303 type
? "%20" : "", type_str
,
7304 exclude_str
[0] ? "%20" : "", exclude_str
,
7305 include_str
[0] ? "%20" : "", include_str
);
7307 if (cupsdSendCommand(con
, command
, options
, 0))
7310 * Command started successfully, don't send an IPP response here...
7313 ippDelete(con
->response
);
7314 con
->response
= NULL
;
7319 * Command failed, return "internal error" so the user knows something
7323 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7324 _("cups-driverd failed to execute."));
7330 * 'get_printer_attrs()' - Get printer attributes.
7334 get_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
7335 ipp_attribute_t
*uri
) /* I - Printer URI */
7337 http_status_t status
; /* Policy status */
7338 cups_ptype_t dtype
; /* Destination type (printer/class) */
7339 cupsd_printer_t
*printer
; /* Printer/class */
7340 cups_array_t
*ra
; /* Requested attributes array */
7343 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_attrs(%p[%d], %s)", con
,
7344 con
->number
, uri
->values
[0].string
.text
);
7347 * Is the destination valid?
7350 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7356 send_ipp_status(con
, IPP_NOT_FOUND
,
7357 _("The printer or class does not exist."));
7365 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7367 send_http_error(con
, status
, printer
);
7372 * Send the attributes...
7375 ra
= create_requested_array(con
->request
);
7377 copy_printer_attrs(con
, printer
, ra
);
7379 cupsArrayDelete(ra
);
7381 con
->response
->request
.status
.status_code
= IPP_OK
;
7386 * 'get_printer_supported()' - Get printer supported values.
7390 get_printer_supported(
7391 cupsd_client_t
*con
, /* I - Client connection */
7392 ipp_attribute_t
*uri
) /* I - Printer URI */
7394 http_status_t status
; /* Policy status */
7395 cups_ptype_t dtype
; /* Destination type (printer/class) */
7396 cupsd_printer_t
*printer
; /* Printer/class */
7399 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_supported(%p[%d], %s)", con
,
7400 con
->number
, uri
->values
[0].string
.text
);
7403 * Is the destination valid?
7406 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7412 send_ipp_status(con
, IPP_NOT_FOUND
,
7413 _("The printer or class does not exist."));
7421 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7423 send_http_error(con
, status
, printer
);
7428 * Return a list of attributes that can be set via Set-Printer-Attributes.
7431 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7432 "printer-geo-location", 0);
7433 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7435 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7436 "printer-location", 0);
7437 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7438 "printer-organization", 0);
7439 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7440 "printer-organizational-unit", 0);
7442 con
->response
->request
.status
.status_code
= IPP_OK
;
7447 * 'get_printers()' - Get a list of printers or classes.
7451 get_printers(cupsd_client_t
*con
, /* I - Client connection */
7452 int type
) /* I - 0 or CUPS_PRINTER_CLASS */
7454 http_status_t status
; /* Policy status */
7455 ipp_attribute_t
*attr
; /* Current attribute */
7456 int limit
; /* Max number of printers to return */
7457 int count
; /* Number of printers that match */
7458 int printer_id
; /* Printer we are interested in */
7459 cupsd_printer_t
*printer
; /* Current printer pointer */
7460 cups_ptype_t printer_type
, /* printer-type attribute */
7461 printer_mask
; /* printer-type-mask attribute */
7462 char *location
; /* Location string */
7463 const char *username
; /* Current user */
7464 char *first_printer_name
; /* first-printer-name attribute */
7465 cups_array_t
*ra
; /* Requested attributes array */
7466 int local
; /* Local connection? */
7469 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printers(%p[%d], %x)", con
,
7476 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7478 send_http_error(con
, status
, NULL
);
7483 * Check for printers...
7486 if (!Printers
|| !cupsArrayCount(Printers
))
7488 send_ipp_status(con
, IPP_NOT_FOUND
, _("No destinations added."));
7493 * See if they want to limit the number of printers reported...
7496 if ((attr
= ippFindAttribute(con
->request
, "limit",
7497 IPP_TAG_INTEGER
)) != NULL
)
7498 limit
= attr
->values
[0].integer
;
7502 if ((attr
= ippFindAttribute(con
->request
, "first-printer-name",
7503 IPP_TAG_NAME
)) != NULL
)
7504 first_printer_name
= attr
->values
[0].string
.text
;
7506 first_printer_name
= NULL
;
7509 * Support filtering...
7512 if ((attr
= ippFindAttribute(con
->request
, "printer-id", IPP_TAG_INTEGER
)) != NULL
)
7514 if ((printer_id
= ippGetInteger(attr
, 0)) <= 0)
7516 send_ipp_status(con
, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES
, _("Bad \"printer-id\" value %d."), printer_id
);
7523 if ((attr
= ippFindAttribute(con
->request
, "printer-type",
7524 IPP_TAG_ENUM
)) != NULL
)
7525 printer_type
= (cups_ptype_t
)attr
->values
[0].integer
;
7527 printer_type
= (cups_ptype_t
)0;
7529 if ((attr
= ippFindAttribute(con
->request
, "printer-type-mask",
7530 IPP_TAG_ENUM
)) != NULL
)
7531 printer_mask
= (cups_ptype_t
)attr
->values
[0].integer
;
7533 printer_mask
= (cups_ptype_t
)0;
7535 local
= httpAddrLocalhost(&(con
->clientaddr
));
7537 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
7538 IPP_TAG_TEXT
)) != NULL
)
7539 location
= attr
->values
[0].string
.text
;
7543 if (con
->username
[0])
7544 username
= con
->username
;
7545 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7546 IPP_TAG_NAME
)) != NULL
)
7547 username
= attr
->values
[0].string
.text
;
7551 ra
= create_requested_array(con
->request
);
7554 * OK, build a list of printers for this printer...
7557 if (first_printer_name
)
7559 if ((printer
= cupsdFindDest(first_printer_name
)) == NULL
)
7560 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7563 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7566 count
< limit
&& printer
;
7567 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
7569 if (!local
&& !printer
->shared
)
7572 if (printer_id
&& printer
->printer_id
!= printer_id
)
7575 if ((!type
|| (printer
->type
& CUPS_PRINTER_CLASS
) == type
) &&
7576 (printer
->type
& printer_mask
) == printer_type
&&
7578 (printer
->location
&& !_cups_strcasecmp(printer
->location
, location
))))
7581 * If a username is specified, see if it is allowed or denied
7585 if (cupsArrayCount(printer
->users
) && username
&&
7586 !user_allowed(printer
, username
))
7590 * Add the group separator as needed...
7594 ippAddSeparator(con
->response
);
7599 * Send the attributes...
7602 copy_printer_attrs(con
, printer
, ra
);
7606 cupsArrayDelete(ra
);
7608 con
->response
->request
.status
.status_code
= IPP_OK
;
7613 * 'get_subscription_attrs()' - Get subscription attributes.
7617 get_subscription_attrs(
7618 cupsd_client_t
*con
, /* I - Client connection */
7619 int sub_id
) /* I - Subscription ID */
7621 http_status_t status
; /* Policy status */
7622 cupsd_subscription_t
*sub
; /* Subscription */
7623 cupsd_policy_t
*policy
; /* Current security policy */
7624 cups_array_t
*ra
, /* Requested attributes array */
7625 *exclude
; /* Private attributes array */
7628 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7629 "get_subscription_attrs(con=%p[%d], sub_id=%d)",
7630 con
, con
->number
, sub_id
);
7633 * Expire subscriptions as needed...
7636 cupsdExpireSubscriptions(NULL
, NULL
);
7639 * Is the subscription ID valid?
7642 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
7645 * Bad subscription ID...
7648 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
7658 policy
= sub
->dest
->op_policy_ptr
;
7660 policy
= DefaultPolicyPtr
;
7662 if ((status
= cupsdCheckPolicy(policy
, con
, sub
->owner
)) != HTTP_OK
)
7664 send_http_error(con
, status
, sub
->dest
);
7668 exclude
= cupsdGetPrivateAttrs(policy
, con
, sub
->dest
, sub
->owner
);
7671 * Copy the subscription attributes to the response using the
7672 * requested-attributes attribute that may be provided by the client.
7675 ra
= create_requested_array(con
->request
);
7677 copy_subscription_attrs(con
, sub
, ra
, exclude
);
7679 cupsArrayDelete(ra
);
7681 con
->response
->request
.status
.status_code
= IPP_OK
;
7686 * 'get_subscriptions()' - Get subscriptions.
7690 get_subscriptions(cupsd_client_t
*con
, /* I - Client connection */
7691 ipp_attribute_t
*uri
) /* I - Printer/job URI */
7693 http_status_t status
; /* Policy status */
7694 int count
; /* Number of subscriptions */
7695 int limit
; /* Limit */
7696 cupsd_subscription_t
*sub
; /* Subscription */
7697 cups_array_t
*ra
; /* Requested attributes array */
7698 ipp_attribute_t
*attr
; /* Attribute */
7699 cups_ptype_t dtype
; /* Destination type (printer/class) */
7700 char scheme
[HTTP_MAX_URI
],
7701 /* Scheme portion of URI */
7702 username
[HTTP_MAX_URI
],
7703 /* Username portion of URI */
7705 /* Host portion of URI */
7706 resource
[HTTP_MAX_URI
];
7707 /* Resource portion of URI */
7708 int port
; /* Port portion of URI */
7709 cupsd_job_t
*job
; /* Job pointer */
7710 cupsd_printer_t
*printer
; /* Printer */
7711 cupsd_policy_t
*policy
; /* Policy */
7712 cups_array_t
*exclude
; /* Private attributes array */
7715 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7716 "get_subscriptions(con=%p[%d], uri=%s)",
7717 con
, con
->number
, uri
->values
[0].string
.text
);
7720 * Is the destination valid?
7723 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7724 sizeof(scheme
), username
, sizeof(username
), host
,
7725 sizeof(host
), &port
, resource
, sizeof(resource
));
7727 if (!strcmp(resource
, "/") ||
7728 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6) ||
7729 (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10) ||
7730 (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9))
7735 else if (!strncmp(resource
, "/jobs/", 6) && resource
[6])
7738 job
= cupsdFindJob(atoi(resource
+ 6));
7742 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
7743 atoi(resource
+ 6));
7747 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7753 send_ipp_status(con
, IPP_NOT_FOUND
,
7754 _("The printer or class does not exist."));
7757 else if ((attr
= ippFindAttribute(con
->request
, "notify-job-id",
7758 IPP_TAG_INTEGER
)) != NULL
)
7760 job
= cupsdFindJob(attr
->values
[0].integer
);
7764 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
7765 attr
->values
[0].integer
);
7777 policy
= printer
->op_policy_ptr
;
7779 policy
= DefaultPolicyPtr
;
7781 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
7783 send_http_error(con
, status
, printer
);
7788 * Expire subscriptions as needed...
7791 cupsdExpireSubscriptions(NULL
, NULL
);
7794 * Copy the subscription attributes to the response using the
7795 * requested-attributes attribute that may be provided by the client.
7798 ra
= create_requested_array(con
->request
);
7800 if ((attr
= ippFindAttribute(con
->request
, "limit",
7801 IPP_TAG_INTEGER
)) != NULL
)
7802 limit
= attr
->values
[0].integer
;
7807 * See if we only want to see subscriptions for a specific user...
7810 if ((attr
= ippFindAttribute(con
->request
, "my-subscriptions",
7811 IPP_TAG_BOOLEAN
)) != NULL
&&
7812 attr
->values
[0].boolean
)
7813 strlcpy(username
, get_username(con
), sizeof(username
));
7817 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
), count
= 0;
7819 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
7820 if ((!printer
|| sub
->dest
== printer
) && (!job
|| sub
->job
== job
) &&
7821 (!username
[0] || !_cups_strcasecmp(username
, sub
->owner
)))
7823 ippAddSeparator(con
->response
);
7825 exclude
= cupsdGetPrivateAttrs(sub
->dest
? sub
->dest
->op_policy_ptr
:
7826 policy
, con
, sub
->dest
,
7829 copy_subscription_attrs(con
, sub
, ra
, exclude
);
7832 if (limit
&& count
>= limit
)
7836 cupsArrayDelete(ra
);
7839 con
->response
->request
.status
.status_code
= IPP_OK
;
7841 send_ipp_status(con
, IPP_NOT_FOUND
, _("No subscriptions found."));
7846 * 'get_username()' - Get the username associated with a request.
7849 static const char * /* O - Username */
7850 get_username(cupsd_client_t
*con
) /* I - Connection */
7852 ipp_attribute_t
*attr
; /* Attribute */
7855 if (con
->username
[0])
7856 return (con
->username
);
7857 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7858 IPP_TAG_NAME
)) != NULL
)
7859 return (attr
->values
[0].string
.text
);
7861 return ("anonymous");
7866 * 'hold_job()' - Hold a print job.
7870 hold_job(cupsd_client_t
*con
, /* I - Client connection */
7871 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
7873 ipp_attribute_t
*attr
; /* Current job-hold-until */
7874 const char *when
; /* New value */
7875 int jobid
; /* Job ID */
7876 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
7877 username
[HTTP_MAX_URI
], /* Username portion of URI */
7878 host
[HTTP_MAX_URI
], /* Host portion of URI */
7879 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7880 int port
; /* Port portion of URI */
7881 cupsd_job_t
*job
; /* Job information */
7884 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_job(%p[%d], %s)", con
, con
->number
,
7885 uri
->values
[0].string
.text
);
7888 * See if we have a job URI or a printer URI...
7891 if (!strcmp(uri
->name
, "printer-uri"))
7894 * Got a printer URI; see if we also have a job-id attribute...
7897 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7898 IPP_TAG_INTEGER
)) == NULL
)
7900 send_ipp_status(con
, IPP_BAD_REQUEST
,
7901 _("Got a printer-uri attribute but no job-id."));
7905 jobid
= attr
->values
[0].integer
;
7910 * Got a job URI; parse it to get the job ID...
7913 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7914 sizeof(scheme
), username
, sizeof(username
), host
,
7915 sizeof(host
), &port
, resource
, sizeof(resource
));
7917 if (strncmp(resource
, "/jobs/", 6))
7923 send_ipp_status(con
, IPP_BAD_REQUEST
,
7924 _("Bad job-uri \"%s\"."),
7925 uri
->values
[0].string
.text
);
7929 jobid
= atoi(resource
+ 6);
7933 * See if the job exists...
7936 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7939 * Nope - return a "not found" error...
7942 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
7947 * See if the job is owned by the requesting user...
7950 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7952 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
7953 cupsdFindDest(job
->dest
));
7958 * See if the job is in a state that allows holding...
7961 if (job
->state_value
> IPP_JOB_STOPPED
)
7964 * Return a "not-possible" error...
7967 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
7968 _("Job #%d is finished and cannot be altered."),
7974 * Hold the job and return...
7977 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_ZERO
)) != NULL
)
7979 if ((ippGetValueTag(attr
) != IPP_TAG_KEYWORD
&& ippGetValueTag(attr
) != IPP_TAG_NAME
&& ippGetValueTag(attr
) != IPP_TAG_NAMELANG
) || ippGetCount(attr
) != 1 || !ippValidateAttribute(attr
))
7981 send_ipp_status(con
, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES
, _("Unsupported 'job-hold-until' value."));
7982 ippCopyAttribute(con
->response
, attr
, 0);
7986 when
= ippGetString(attr
, 0, NULL
);
7988 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
7989 "Job job-hold-until value changed by user.");
7992 when
= "indefinite";
7994 cupsdSetJobHoldUntil(job
, when
, 1);
7995 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
, "Job held by \"%s\".",
7998 con
->response
->request
.status
.status_code
= IPP_OK
;
8003 * 'hold_new_jobs()' - Hold pending/new jobs on a printer or class.
8007 hold_new_jobs(cupsd_client_t
*con
, /* I - Connection */
8008 ipp_attribute_t
*uri
) /* I - Printer URI */
8010 http_status_t status
; /* Policy status */
8011 cups_ptype_t dtype
; /* Destination type (printer/class) */
8012 cupsd_printer_t
*printer
; /* Printer data */
8015 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_new_jobs(%p[%d], %s)", con
,
8016 con
->number
, uri
->values
[0].string
.text
);
8019 * Is the destination valid?
8022 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8028 send_ipp_status(con
, IPP_NOT_FOUND
,
8029 _("The printer or class does not exist."));
8037 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8039 send_http_error(con
, status
, printer
);
8044 * Hold pending/new jobs sent to the printer...
8047 printer
->holding_new_jobs
= 1;
8049 cupsdSetPrinterReasons(printer
, "+hold-new-jobs");
8051 if (dtype
& CUPS_PRINTER_CLASS
)
8052 cupsdLogMessage(CUPSD_LOG_INFO
,
8053 "Class \"%s\" now holding pending/new jobs (\"%s\").",
8054 printer
->name
, get_username(con
));
8056 cupsdLogMessage(CUPSD_LOG_INFO
,
8057 "Printer \"%s\" now holding pending/new jobs (\"%s\").",
8058 printer
->name
, get_username(con
));
8061 * Everything was ok, so return OK status...
8064 con
->response
->request
.status
.status_code
= IPP_OK
;
8069 * 'move_job()' - Move a job to a new destination.
8073 move_job(cupsd_client_t
*con
, /* I - Client connection */
8074 ipp_attribute_t
*uri
) /* I - Job URI */
8076 http_status_t status
; /* Policy status */
8077 ipp_attribute_t
*attr
; /* Current attribute */
8078 int jobid
; /* Job ID */
8079 cupsd_job_t
*job
; /* Current job */
8080 const char *src
; /* Source printer/class */
8081 cups_ptype_t stype
, /* Source type (printer or class) */
8082 dtype
; /* Destination type (printer/class) */
8083 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
8084 username
[HTTP_MAX_URI
], /* Username portion of URI */
8085 host
[HTTP_MAX_URI
], /* Host portion of URI */
8086 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8087 int port
; /* Port portion of URI */
8088 cupsd_printer_t
*sprinter
, /* Source printer */
8089 *dprinter
; /* Destination printer */
8092 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "move_job(%p[%d], %s)", con
, con
->number
,
8093 uri
->values
[0].string
.text
);
8096 * Get the new printer or class...
8099 if ((attr
= ippFindAttribute(con
->request
, "job-printer-uri",
8100 IPP_TAG_URI
)) == NULL
)
8103 * Need job-printer-uri...
8106 send_ipp_status(con
, IPP_BAD_REQUEST
,
8107 _("job-printer-uri attribute missing."));
8111 if (!cupsdValidateDest(attr
->values
[0].string
.text
, &dtype
, &dprinter
))
8117 send_ipp_status(con
, IPP_NOT_FOUND
,
8118 _("The printer or class does not exist."));
8123 * See if we have a job URI or a printer URI...
8126 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8127 sizeof(scheme
), username
, sizeof(username
), host
,
8128 sizeof(host
), &port
, resource
, sizeof(resource
));
8130 if (!strcmp(uri
->name
, "printer-uri"))
8133 * Got a printer URI; see if we also have a job-id attribute...
8136 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8137 IPP_TAG_INTEGER
)) == NULL
)
8143 if ((src
= cupsdValidateDest(uri
->values
[0].string
.text
, &stype
,
8144 &sprinter
)) == NULL
)
8150 send_ipp_status(con
, IPP_NOT_FOUND
,
8151 _("The printer or class does not exist."));
8160 * Otherwise, just move a single job...
8163 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
8166 * Nope - return a "not found" error...
8169 send_ipp_status(con
, IPP_NOT_FOUND
,
8170 _("Job #%d does not exist."), attr
->values
[0].integer
);
8176 * Job found, initialize source pointers...
8187 * Got a job URI; parse it to get the job ID...
8190 if (strncmp(resource
, "/jobs/", 6))
8196 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
8197 uri
->values
[0].string
.text
);
8202 * See if the job exists...
8205 jobid
= atoi(resource
+ 6);
8207 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8210 * Nope - return a "not found" error...
8213 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
8219 * Job found, initialize source pointers...
8228 * Check the policy of the destination printer...
8231 if ((status
= cupsdCheckPolicy(dprinter
->op_policy_ptr
, con
,
8232 job
? job
->username
: NULL
)) != HTTP_OK
)
8234 send_http_error(con
, status
, dprinter
);
8239 * Now move the job or jobs...
8245 * See if the job has been completed...
8248 if (job
->state_value
> IPP_JOB_STOPPED
)
8251 * Return a "not-possible" error...
8254 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8255 _("Job #%d is finished and cannot be altered."),
8261 * See if the job is owned by the requesting user...
8264 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8266 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8267 cupsdFindDest(job
->dest
));
8272 * Move the job to a different printer or class...
8275 cupsdMoveJob(job
, dprinter
);
8280 * Got the source printer, now look through the jobs...
8283 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
8285 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
8288 * See if the job is pointing at the source printer or has not been
8292 if (_cups_strcasecmp(job
->dest
, src
) ||
8293 job
->state_value
> IPP_JOB_STOPPED
)
8297 * See if the job can be moved by the requesting user...
8300 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8304 * Move the job to a different printer or class...
8307 cupsdMoveJob(job
, dprinter
);
8312 * Start jobs if possible...
8318 * Return with "everything is OK" status...
8321 con
->response
->request
.status
.status_code
= IPP_OK
;
8326 * 'ppd_parse_line()' - Parse a PPD default line.
8329 static int /* O - 0 on success, -1 on failure */
8330 ppd_parse_line(const char *line
, /* I - Line */
8331 char *option
, /* O - Option name */
8332 int olen
, /* I - Size of option name */
8333 char *choice
, /* O - Choice name */
8334 int clen
) /* I - Size of choice name */
8337 * Verify this is a default option line...
8340 if (strncmp(line
, "*Default", 8))
8344 * Read the option name...
8347 for (line
+= 8, olen
--;
8348 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
8359 * Skip everything else up to the colon (:)...
8362 while (*line
&& *line
!= ':')
8371 * Now grab the option choice, skipping leading whitespace...
8374 while (isspace(*line
& 255))
8378 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
8389 * Return with no errors...
8397 * 'print_job()' - Print a file to a printer or class.
8401 print_job(cupsd_client_t
*con
, /* I - Client connection */
8402 ipp_attribute_t
*uri
) /* I - Printer URI */
8404 ipp_attribute_t
*attr
; /* Current attribute */
8405 ipp_attribute_t
*doc_name
; /* document-name attribute */
8406 ipp_attribute_t
*format
; /* Document-format attribute */
8407 const char *default_format
; /* document-format-default value */
8408 cupsd_job_t
*job
; /* New job */
8409 char filename
[1024]; /* Job filename */
8410 mime_type_t
*filetype
; /* Type of file */
8411 char super
[MIME_MAX_SUPER
], /* Supertype of file */
8412 type
[MIME_MAX_TYPE
], /* Subtype of file */
8413 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
8414 /* Textual name of mime type */
8415 cupsd_printer_t
*printer
; /* Printer data */
8416 struct stat fileinfo
; /* File information */
8417 int kbytes
; /* Size of file */
8418 int compression
; /* Document compression */
8421 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "print_job(%p[%d], %s)", con
, con
->number
,
8422 uri
->values
[0].string
.text
);
8425 * Validate print file attributes, for now just document-format and
8426 * compression (CUPS only supports "none" and "gzip")...
8429 compression
= CUPS_FILE_NONE
;
8431 if ((attr
= ippFindAttribute(con
->request
, "compression",
8432 IPP_TAG_KEYWORD
)) != NULL
)
8434 if (strcmp(attr
->values
[0].string
.text
, "none")
8436 && strcmp(attr
->values
[0].string
.text
, "gzip")
8437 #endif /* HAVE_LIBZ */
8440 send_ipp_status(con
, IPP_ATTRIBUTES
,
8441 _("Unsupported compression \"%s\"."),
8442 attr
->values
[0].string
.text
);
8443 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
8444 "compression", NULL
, attr
->values
[0].string
.text
);
8449 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
8450 compression
= CUPS_FILE_GZIP
;
8451 #endif /* HAVE_LIBZ */
8455 * Do we have a file to print?
8460 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file in print request."));
8465 * Is the destination valid?
8468 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
8474 send_ipp_status(con
, IPP_NOT_FOUND
,
8475 _("The printer or class does not exist."));
8480 * Is it a format we support?
8483 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
8485 ippSetName(con
->request
, &doc_name
, "document-name-supplied");
8487 if ((format
= ippFindAttribute(con
->request
, "document-format",
8488 IPP_TAG_MIMETYPE
)) != NULL
)
8491 * Grab format from client...
8494 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%255[^;]", super
,
8497 send_ipp_status(con
, IPP_BAD_REQUEST
,
8498 _("Bad document-format \"%s\"."),
8499 format
->values
[0].string
.text
);
8503 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format-supplied", NULL
, ippGetString(format
, 0, NULL
));
8505 else if ((default_format
= cupsGetOption("document-format",
8506 printer
->num_options
,
8507 printer
->options
)) != NULL
)
8510 * Use default document format...
8513 if (sscanf(default_format
, "%15[^/]/%255[^;]", super
, type
) != 2)
8515 send_ipp_status(con
, IPP_BAD_REQUEST
,
8516 _("Bad document-format \"%s\"."),
8527 strlcpy(super
, "application", sizeof(super
));
8528 strlcpy(type
, "octet-stream", sizeof(type
));
8531 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
8534 * Auto-type the file...
8537 cupsdLogMessage(CUPSD_LOG_DEBUG
, "[Job ???] Auto-typing file...");
8540 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
8541 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
8545 filetype
= mimeType(MimeDatabase
, super
, type
);
8547 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job ???] Request file type is %s/%s.",
8548 filetype
->super
, filetype
->type
);
8550 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
, filetype
->type
);
8551 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format-detected", NULL
, mimetype
);
8554 filetype
= mimeType(MimeDatabase
, super
, type
);
8558 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
8561 * Replace the document-format attribute value with the auto-typed or
8565 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
8569 ippSetString(con
->request
, &format
, 0, mimetype
);
8571 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
8572 "document-format", NULL
, mimetype
);
8576 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
8577 _("Unsupported document-format \"%s\"."),
8578 format
? format
->values
[0].string
.text
:
8579 "application/octet-stream");
8580 cupsdLogMessage(CUPSD_LOG_INFO
,
8581 "Hint: Do you have the raw file printing rules enabled?");
8584 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
8585 "document-format", NULL
, format
->values
[0].string
.text
);
8591 * Read any embedded job ticket info from PS files...
8594 if (!_cups_strcasecmp(filetype
->super
, "application") &&
8595 (!_cups_strcasecmp(filetype
->type
, "postscript") ||
8596 !_cups_strcasecmp(filetype
->type
, "pdf")))
8597 read_job_ticket(con
);
8600 * Create the job object...
8603 if ((job
= add_job(con
, printer
, filetype
)) == NULL
)
8607 * Update quota data...
8610 if (stat(con
->filename
, &fileinfo
))
8613 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
8615 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
8617 job
->koctets
+= kbytes
;
8619 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets", IPP_TAG_INTEGER
)) != NULL
)
8620 attr
->values
[0].integer
+= kbytes
;
8623 * Add the job file...
8626 if (add_file(con
, job
, filetype
, compression
))
8629 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
, job
->num_files
);
8630 if (rename(con
->filename
, filename
))
8632 cupsdLogJob(job
, CUPSD_LOG_ERROR
, "Unable to rename job document file \"%s\": %s", filename
, strerror(errno
));
8634 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to rename job document file."));
8638 cupsdClearString(&con
->filename
);
8641 * See if we need to add the ending sheet...
8644 if (cupsdTimeoutJob(job
))
8648 * Log and save the job...
8651 cupsdLogJob(job
, CUPSD_LOG_INFO
,
8652 "File of type %s/%s queued by \"%s\".",
8653 filetype
->super
, filetype
->type
, job
->username
);
8654 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "hold_until=%d", (int)job
->hold_until
);
8655 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
8656 job
->dest
, job
->username
);
8659 * Start the job if possible...
8667 * 'read_job_ticket()' - Read a job ticket embedded in a print file.
8669 * This function only gets called when printing a single PDF or PostScript
8670 * file using the Print-Job operation. It doesn't work for Create-Job +
8671 * Send-File, since the job attributes need to be set at job creation
8672 * time for banners to work. The embedded job ticket stuff is here
8673 * primarily to allow the Windows printer driver for CUPS to pass in JCL
8674 * options and IPP attributes which otherwise would be lost.
8676 * The format of a job ticket is simple:
8678 * %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
8680 * %cupsJobTicket: attr1=value1
8681 * %cupsJobTicket: attr2=value2
8683 * %cupsJobTicket: attrN=valueN
8685 * Job ticket lines must appear immediately after the first line that
8686 * specifies PostScript (%!PS-Adobe-3.0) or PDF (%PDF) format, and CUPS
8687 * stops looking for job ticket info when it finds a line that does not begin
8688 * with "%cupsJobTicket:".
8690 * The maximum length of a job ticket line, including the prefix, is
8691 * 255 characters to conform with the Adobe DSC.
8693 * Read-only attributes are rejected with a notice to the error log in
8694 * case a malicious user tries anything. Since the job ticket is read
8695 * prior to attribute validation in print_job(), job ticket attributes
8696 * will go through the same validation as IPP attributes...
8700 read_job_ticket(cupsd_client_t
*con
) /* I - Client connection */
8702 cups_file_t
*fp
; /* File to read from */
8703 char line
[256]; /* Line data */
8704 int num_options
; /* Number of options */
8705 cups_option_t
*options
; /* Options */
8706 ipp_t
*ticket
; /* New attributes */
8707 ipp_attribute_t
*attr
, /* Current attribute */
8708 *attr2
, /* Job attribute */
8709 *prev2
; /* Previous job attribute */
8713 * First open the print file...
8716 if ((fp
= cupsFileOpen(con
->filename
, "rb")) == NULL
)
8718 cupsdLogMessage(CUPSD_LOG_ERROR
,
8719 "Unable to open print file for job ticket - %s",
8725 * Skip the first line...
8728 if (cupsFileGets(fp
, line
, sizeof(line
)) == NULL
)
8730 cupsdLogMessage(CUPSD_LOG_ERROR
,
8731 "Unable to read from print file for job ticket - %s",
8737 if (strncmp(line
, "%!PS-Adobe-", 11) && strncmp(line
, "%PDF-", 5))
8740 * Not a DSC-compliant file, so no job ticket info will be available...
8748 * Read job ticket info from the file...
8754 while (cupsFileGets(fp
, line
, sizeof(line
)))
8757 * Stop at the first non-ticket line...
8760 if (strncmp(line
, "%cupsJobTicket:", 15))
8764 * Add the options to the option array...
8767 num_options
= cupsParseOptions(line
+ 15, num_options
, &options
);
8771 * Done with the file; see if we have any options...
8776 if (num_options
== 0)
8780 * OK, convert the options to an attribute list, and apply them to
8785 cupsEncodeOptions(ticket
, num_options
, options
);
8788 * See what the user wants to change.
8791 for (attr
= ticket
->attrs
; attr
; attr
= attr
->next
)
8793 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
8796 if (!strncmp(attr
->name
, "date-time-at-", 13) ||
8797 !strcmp(attr
->name
, "job-impressions-completed") ||
8798 !strcmp(attr
->name
, "job-media-sheets-completed") ||
8799 !strncmp(attr
->name
, "job-k-octets", 12) ||
8800 !strcmp(attr
->name
, "job-id") ||
8801 !strcmp(attr
->name
, "job-originating-host-name") ||
8802 !strcmp(attr
->name
, "job-originating-user-name") ||
8803 !strcmp(attr
->name
, "job-pages-completed") ||
8804 !strcmp(attr
->name
, "job-printer-uri") ||
8805 !strncmp(attr
->name
, "job-state", 9) ||
8806 !strcmp(attr
->name
, "job-uri") ||
8807 !strncmp(attr
->name
, "time-at-", 8))
8808 continue; /* Read-only attrs */
8810 if ((attr2
= ippFindAttribute(con
->request
, attr
->name
,
8811 IPP_TAG_ZERO
)) != NULL
)
8814 * Some other value; first free the old value...
8817 if (con
->request
->attrs
== attr2
)
8819 con
->request
->attrs
= attr2
->next
;
8824 for (prev2
= con
->request
->attrs
; prev2
; prev2
= prev2
->next
)
8825 if (prev2
->next
== attr2
)
8827 prev2
->next
= attr2
->next
;
8832 if (con
->request
->last
== attr2
)
8833 con
->request
->last
= prev2
;
8835 ippDeleteAttribute(NULL
, attr2
);
8839 * Add new option by copying it...
8842 ippCopyAttribute(con
->request
, attr
, 0);
8846 * Then free the attribute list and option array...
8850 cupsFreeOptions(num_options
, options
);
8855 * 'reject_jobs()' - Reject print jobs to a printer.
8859 reject_jobs(cupsd_client_t
*con
, /* I - Client connection */
8860 ipp_attribute_t
*uri
) /* I - Printer or class URI */
8862 http_status_t status
; /* Policy status */
8863 cups_ptype_t dtype
; /* Destination type (printer/class) */
8864 cupsd_printer_t
*printer
; /* Printer data */
8865 ipp_attribute_t
*attr
; /* printer-state-message text */
8868 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "reject_jobs(%p[%d], %s)", con
,
8869 con
->number
, uri
->values
[0].string
.text
);
8872 * Is the destination valid?
8875 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8881 send_ipp_status(con
, IPP_NOT_FOUND
,
8882 _("The printer or class does not exist."));
8890 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8892 send_http_error(con
, status
, printer
);
8897 * Reject jobs sent to the printer...
8900 printer
->accepting
= 0;
8902 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
8903 IPP_TAG_TEXT
)) == NULL
)
8904 strlcpy(printer
->state_message
, "Rejecting Jobs",
8905 sizeof(printer
->state_message
));
8907 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
8908 sizeof(printer
->state_message
));
8910 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
8911 "No longer accepting jobs.");
8913 if (dtype
& CUPS_PRINTER_CLASS
)
8915 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
8917 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" rejecting jobs (\"%s\").",
8918 printer
->name
, get_username(con
));
8922 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
8924 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" rejecting jobs (\"%s\").",
8925 printer
->name
, get_username(con
));
8929 * Everything was ok, so return OK status...
8932 con
->response
->request
.status
.status_code
= IPP_OK
;
8937 * 'release_held_new_jobs()' - Release pending/new jobs on a printer or class.
8941 release_held_new_jobs(
8942 cupsd_client_t
*con
, /* I - Connection */
8943 ipp_attribute_t
*uri
) /* I - Printer URI */
8945 http_status_t status
; /* Policy status */
8946 cups_ptype_t dtype
; /* Destination type (printer/class) */
8947 cupsd_printer_t
*printer
; /* Printer data */
8950 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_held_new_jobs(%p[%d], %s)", con
,
8951 con
->number
, uri
->values
[0].string
.text
);
8954 * Is the destination valid?
8957 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8963 send_ipp_status(con
, IPP_NOT_FOUND
,
8964 _("The printer or class does not exist."));
8972 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8974 send_http_error(con
, status
, printer
);
8979 * Hold pending/new jobs sent to the printer...
8982 printer
->holding_new_jobs
= 0;
8984 cupsdSetPrinterReasons(printer
, "-hold-new-jobs");
8986 if (dtype
& CUPS_PRINTER_CLASS
)
8987 cupsdLogMessage(CUPSD_LOG_INFO
,
8988 "Class \"%s\" now printing pending/new jobs (\"%s\").",
8989 printer
->name
, get_username(con
));
8991 cupsdLogMessage(CUPSD_LOG_INFO
,
8992 "Printer \"%s\" now printing pending/new jobs (\"%s\").",
8993 printer
->name
, get_username(con
));
8998 * Everything was ok, so return OK status...
9001 con
->response
->request
.status
.status_code
= IPP_OK
;
9006 * 'release_job()' - Release a held print job.
9010 release_job(cupsd_client_t
*con
, /* I - Client connection */
9011 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9013 ipp_attribute_t
*attr
; /* Current attribute */
9014 int jobid
; /* Job ID */
9015 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9016 username
[HTTP_MAX_URI
], /* Username portion of URI */
9017 host
[HTTP_MAX_URI
], /* Host portion of URI */
9018 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9019 int port
; /* Port portion of URI */
9020 cupsd_job_t
*job
; /* Job information */
9023 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_job(%p[%d], %s)", con
,
9024 con
->number
, uri
->values
[0].string
.text
);
9027 * See if we have a job URI or a printer URI...
9030 if (!strcmp(uri
->name
, "printer-uri"))
9033 * Got a printer URI; see if we also have a job-id attribute...
9036 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9037 IPP_TAG_INTEGER
)) == NULL
)
9039 send_ipp_status(con
, IPP_BAD_REQUEST
,
9040 _("Got a printer-uri attribute but no job-id."));
9044 jobid
= attr
->values
[0].integer
;
9049 * Got a job URI; parse it to get the job ID...
9052 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9053 sizeof(scheme
), username
, sizeof(username
), host
,
9054 sizeof(host
), &port
, resource
, sizeof(resource
));
9056 if (strncmp(resource
, "/jobs/", 6))
9062 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9063 uri
->values
[0].string
.text
);
9067 jobid
= atoi(resource
+ 6);
9071 * See if the job exists...
9074 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9077 * Nope - return a "not found" error...
9080 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9085 * See if job is "held"...
9088 if (job
->state_value
!= IPP_JOB_HELD
)
9091 * Nope - return a "not possible" error...
9094 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not held."), jobid
);
9099 * See if the job is owned by the requesting user...
9102 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9104 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9105 cupsdFindDest(job
->dest
));
9110 * Reset the job-hold-until value to "no-hold"...
9113 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9114 IPP_TAG_KEYWORD
)) == NULL
)
9115 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9119 ippSetValueTag(job
->attrs
, &attr
, IPP_TAG_KEYWORD
);
9120 ippSetString(job
->attrs
, &attr
, 0, "no-hold");
9122 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
9123 "Job job-hold-until value changed by user.");
9124 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
9128 * Release the job and return...
9131 cupsdReleaseJob(job
);
9133 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
9134 "Job released by user.");
9136 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Released by \"%s\".", username
);
9138 con
->response
->request
.status
.status_code
= IPP_OK
;
9145 * 'renew_subscription()' - Renew an existing subscription...
9150 cupsd_client_t
*con
, /* I - Client connection */
9151 int sub_id
) /* I - Subscription ID */
9153 http_status_t status
; /* Policy status */
9154 cupsd_subscription_t
*sub
; /* Subscription */
9155 ipp_attribute_t
*lease
; /* notify-lease-duration */
9158 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
9159 "renew_subscription(con=%p[%d], sub_id=%d)",
9160 con
, con
->number
, sub_id
);
9163 * Is the subscription ID valid?
9166 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
9169 * Bad subscription ID...
9172 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
9180 * Job subscriptions cannot be renewed...
9183 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9184 _("Job subscriptions cannot be renewed."));
9192 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
9194 con
, sub
->owner
)) != HTTP_OK
)
9196 send_http_error(con
, status
, sub
->dest
);
9201 * Renew the subscription...
9204 lease
= ippFindAttribute(con
->request
, "notify-lease-duration",
9207 sub
->lease
= lease
? lease
->values
[0].integer
: DefaultLeaseDuration
;
9209 if (MaxLeaseDuration
&& (sub
->lease
== 0 || sub
->lease
> MaxLeaseDuration
))
9211 cupsdLogMessage(CUPSD_LOG_INFO
,
9212 "renew_subscription: Limiting notify-lease-duration to "
9215 sub
->lease
= MaxLeaseDuration
;
9218 sub
->expire
= sub
->lease
? time(NULL
) + sub
->lease
: 0;
9220 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
9222 con
->response
->request
.status
.status_code
= IPP_OK
;
9224 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
9225 "notify-lease-duration", sub
->lease
);
9230 * 'restart_job()' - Restart an old print job.
9234 restart_job(cupsd_client_t
*con
, /* I - Client connection */
9235 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9237 ipp_attribute_t
*attr
; /* Current attribute */
9238 int jobid
; /* Job ID */
9239 cupsd_job_t
*job
; /* Job information */
9240 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9241 username
[HTTP_MAX_URI
], /* Username portion of URI */
9242 host
[HTTP_MAX_URI
], /* Host portion of URI */
9243 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9244 int port
; /* Port portion of URI */
9247 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "restart_job(%p[%d], %s)", con
,
9248 con
->number
, uri
->values
[0].string
.text
);
9251 * See if we have a job URI or a printer URI...
9254 if (!strcmp(uri
->name
, "printer-uri"))
9257 * Got a printer URI; see if we also have a job-id attribute...
9260 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9261 IPP_TAG_INTEGER
)) == NULL
)
9263 send_ipp_status(con
, IPP_BAD_REQUEST
,
9264 _("Got a printer-uri attribute but no job-id."));
9268 jobid
= attr
->values
[0].integer
;
9273 * Got a job URI; parse it to get the job ID...
9276 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9277 sizeof(scheme
), username
, sizeof(username
), host
,
9278 sizeof(host
), &port
, resource
, sizeof(resource
));
9280 if (strncmp(resource
, "/jobs/", 6))
9286 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9287 uri
->values
[0].string
.text
);
9291 jobid
= atoi(resource
+ 6);
9295 * See if the job exists...
9298 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9301 * Nope - return a "not found" error...
9304 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9309 * See if job is in any of the "completed" states...
9312 if (job
->state_value
<= IPP_JOB_PROCESSING
)
9315 * Nope - return a "not possible" error...
9318 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not complete."),
9324 * See if we have retained the job files...
9329 if (!job
->attrs
|| job
->num_files
== 0)
9332 * Nope - return a "not possible" error...
9335 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9336 _("Job #%d cannot be restarted - no files."), jobid
);
9341 * See if the job is owned by the requesting user...
9344 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9346 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9347 cupsdFindDest(job
->dest
));
9352 * See if the job-hold-until attribute is specified...
9355 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
9356 IPP_TAG_KEYWORD
)) == NULL
)
9357 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
9359 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
9362 * Return the job to a held state...
9365 cupsdLogJob(job
, CUPSD_LOG_DEBUG
,
9366 "Restarted by \"%s\" with job-hold-until=%s.",
9367 username
, attr
->values
[0].string
.text
);
9368 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
9370 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
,
9371 NULL
, job
, "Job restarted by user with job-hold-until=%s",
9372 attr
->values
[0].string
.text
);
9377 * Restart the job...
9380 cupsdRestartJob(job
);
9384 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Restarted by \"%s\".", username
);
9386 con
->response
->request
.status
.status_code
= IPP_OK
;
9391 * 'save_auth_info()' - Save authentication information for a job.
9396 cupsd_client_t
*con
, /* I - Client connection */
9397 cupsd_job_t
*job
, /* I - Job */
9398 ipp_attribute_t
*auth_info
) /* I - auth-info attribute, if any */
9400 int i
; /* Looping var */
9401 char filename
[1024]; /* Job authentication filename */
9402 cups_file_t
*fp
; /* Job authentication file */
9403 char line
[65536]; /* Line for file */
9404 cupsd_printer_t
*dest
; /* Destination printer/class */
9408 * This function saves the in-memory authentication information for
9409 * a job so that it can be used to authenticate with a remote host.
9410 * The information is stored in a file that is readable only by the
9411 * root user. The fields are Base-64 encoded, each on a separate line,
9412 * followed by random number (up to 1024) of newlines to limit the
9413 * amount of information that is exposed.
9415 * Because of the potential for exposing of authentication information,
9416 * this functionality is only enabled when running cupsd as root.
9418 * This caching only works for the Basic and BasicDigest authentication
9419 * types. Digest authentication cannot be cached this way, and in
9420 * the future Kerberos authentication may make all of this obsolete.
9422 * Authentication information is saved whenever an authenticated
9423 * Print-Job, Create-Job, or CUPS-Authenticate-Job operation is
9426 * This information is deleted after a job is completed or canceled,
9427 * so reprints may require subsequent re-authentication.
9433 if ((dest
= cupsdFindDest(job
->dest
)) == NULL
)
9437 * Create the authentication file and change permissions...
9440 snprintf(filename
, sizeof(filename
), "%s/a%05d", RequestRoot
, job
->id
);
9441 if ((fp
= cupsFileOpen(filename
, "w")) == NULL
)
9443 cupsdLogMessage(CUPSD_LOG_ERROR
,
9444 "Unable to save authentication info to \"%s\" - %s",
9445 filename
, strerror(errno
));
9449 fchown(cupsFileNumber(fp
), 0, 0);
9450 fchmod(cupsFileNumber(fp
), 0400);
9452 cupsFilePuts(fp
, "CUPSD-AUTH-V3\n");
9455 i
< (int)(sizeof(job
->auth_env
) / sizeof(job
->auth_env
[0]));
9457 cupsdClearString(job
->auth_env
+ i
);
9459 if (auth_info
&& auth_info
->num_values
== dest
->num_auth_info_required
)
9462 * Write 1 to 3 auth values...
9466 i
< auth_info
->num_values
&&
9467 i
< (int)(sizeof(job
->auth_env
) / sizeof(job
->auth_env
[0]));
9470 if (strcmp(dest
->auth_info_required
[i
], "negotiate"))
9472 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[i
].string
.text
, (int)strlen(auth_info
->values
[i
].string
.text
));
9473 cupsFilePutConf(fp
, dest
->auth_info_required
[i
], line
);
9476 cupsFilePutConf(fp
, dest
->auth_info_required
[i
],
9477 auth_info
->values
[i
].string
.text
);
9479 if (!strcmp(dest
->auth_info_required
[i
], "username"))
9480 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_USERNAME=%s",
9481 auth_info
->values
[i
].string
.text
);
9482 else if (!strcmp(dest
->auth_info_required
[i
], "domain"))
9483 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_DOMAIN=%s",
9484 auth_info
->values
[i
].string
.text
);
9485 else if (!strcmp(dest
->auth_info_required
[i
], "password"))
9486 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_PASSWORD=%s",
9487 auth_info
->values
[i
].string
.text
);
9488 else if (!strcmp(dest
->auth_info_required
[i
], "negotiate"))
9489 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_NEGOTIATE=%s",
9490 auth_info
->values
[i
].string
.text
);
9495 else if (auth_info
&& auth_info
->num_values
== 2 &&
9496 dest
->num_auth_info_required
== 1 &&
9497 !strcmp(dest
->auth_info_required
[0], "negotiate"))
9500 * Allow fallback to username+password for Kerberized queues...
9503 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[0].string
.text
, (int)strlen(auth_info
->values
[0].string
.text
));
9504 cupsFilePutConf(fp
, "username", line
);
9506 cupsdSetStringf(job
->auth_env
+ 0, "AUTH_USERNAME=%s",
9507 auth_info
->values
[0].string
.text
);
9509 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[1].string
.text
, (int)strlen(auth_info
->values
[1].string
.text
));
9510 cupsFilePutConf(fp
, "password", line
);
9512 cupsdSetStringf(job
->auth_env
+ 1, "AUTH_PASSWORD=%s",
9513 auth_info
->values
[1].string
.text
);
9515 else if (con
->username
[0])
9518 * Write the authenticated username...
9521 httpEncode64_2(line
, sizeof(line
), con
->username
, (int)strlen(con
->username
));
9522 cupsFilePutConf(fp
, "username", line
);
9524 cupsdSetStringf(job
->auth_env
+ 0, "AUTH_USERNAME=%s", con
->username
);
9527 * Write the authenticated password...
9530 httpEncode64_2(line
, sizeof(line
), con
->password
, (int)strlen(con
->password
));
9531 cupsFilePutConf(fp
, "password", line
);
9533 cupsdSetStringf(job
->auth_env
+ 1, "AUTH_PASSWORD=%s", con
->password
);
9537 if (con
->gss_uid
> 0)
9539 cupsFilePrintf(fp
, "uid %d\n", (int)con
->gss_uid
);
9540 cupsdSetStringf(&job
->auth_uid
, "AUTH_UID=%d", (int)con
->gss_uid
);
9542 #endif /* HAVE_GSSAPI */
9545 * Write a random number of newlines to the end of the file...
9548 for (i
= (CUPS_RAND() % 1024); i
>= 0; i
--)
9549 cupsFilePutChar(fp
, '\n');
9552 * Close the file and return...
9560 * 'send_document()' - Send a file to a printer or class.
9564 send_document(cupsd_client_t
*con
, /* I - Client connection */
9565 ipp_attribute_t
*uri
) /* I - Printer URI */
9567 ipp_attribute_t
*attr
; /* Current attribute */
9568 ipp_attribute_t
*format
; /* Request's document-format attribute */
9569 ipp_attribute_t
*jformat
; /* Job's document-format attribute */
9570 const char *default_format
;/* document-format-default value */
9571 int jobid
; /* Job ID number */
9572 cupsd_job_t
*job
; /* Current job */
9573 char job_uri
[HTTP_MAX_URI
],
9575 scheme
[HTTP_MAX_URI
],
9576 /* Method portion of URI */
9577 username
[HTTP_MAX_URI
],
9578 /* Username portion of URI */
9580 /* Host portion of URI */
9581 resource
[HTTP_MAX_URI
];
9582 /* Resource portion of URI */
9583 int port
; /* Port portion of URI */
9584 mime_type_t
*filetype
; /* Type of file */
9585 char super
[MIME_MAX_SUPER
],
9586 /* Supertype of file */
9587 type
[MIME_MAX_TYPE
],
9588 /* Subtype of file */
9589 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
9590 /* Textual name of mime type */
9591 char filename
[1024]; /* Job filename */
9592 cupsd_printer_t
*printer
; /* Current printer */
9593 struct stat fileinfo
; /* File information */
9594 int kbytes
; /* Size of file */
9595 int compression
; /* Type of compression */
9596 int start_job
; /* Start the job? */
9599 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "send_document(%p[%d], %s)", con
,
9600 con
->number
, uri
->values
[0].string
.text
);
9603 * See if we have a job URI or a printer URI...
9606 if (!strcmp(uri
->name
, "printer-uri"))
9609 * Got a printer URI; see if we also have a job-id attribute...
9612 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9613 IPP_TAG_INTEGER
)) == NULL
)
9615 send_ipp_status(con
, IPP_BAD_REQUEST
,
9616 _("Got a printer-uri attribute but no job-id."));
9620 jobid
= attr
->values
[0].integer
;
9625 * Got a job URI; parse it to get the job ID...
9628 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9629 sizeof(scheme
), username
, sizeof(username
), host
,
9630 sizeof(host
), &port
, resource
, sizeof(resource
));
9632 if (strncmp(resource
, "/jobs/", 6))
9638 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9639 uri
->values
[0].string
.text
);
9643 jobid
= atoi(resource
+ 6);
9647 * See if the job exists...
9650 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9653 * Nope - return a "not found" error...
9656 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9660 printer
= cupsdFindDest(job
->dest
);
9663 * See if the job is owned by the requesting user...
9666 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9668 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9669 cupsdFindDest(job
->dest
));
9674 * OK, see if the client is sending the document compressed - CUPS
9675 * only supports "none" and "gzip".
9678 compression
= CUPS_FILE_NONE
;
9680 if ((attr
= ippFindAttribute(con
->request
, "compression",
9681 IPP_TAG_KEYWORD
)) != NULL
)
9683 if (strcmp(attr
->values
[0].string
.text
, "none")
9685 && strcmp(attr
->values
[0].string
.text
, "gzip")
9686 #endif /* HAVE_LIBZ */
9689 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Unsupported compression \"%s\"."),
9690 attr
->values
[0].string
.text
);
9691 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
9692 "compression", NULL
, attr
->values
[0].string
.text
);
9697 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
9698 compression
= CUPS_FILE_GZIP
;
9699 #endif /* HAVE_LIBZ */
9703 * Do we have a file to print?
9706 if ((attr
= ippFindAttribute(con
->request
, "last-document",
9707 IPP_TAG_BOOLEAN
)) == NULL
)
9709 send_ipp_status(con
, IPP_BAD_REQUEST
,
9710 _("Missing last-document attribute in request."));
9717 * Check for an empty request with "last-document" set to true, which is
9718 * used to close an "open" job by RFC 2911, section 3.3.2.
9721 if (job
->num_files
> 0 && attr
->values
[0].boolean
)
9724 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file in print request."));
9729 * Is it a format we support?
9734 if ((format
= ippFindAttribute(con
->request
, "document-format",
9735 IPP_TAG_MIMETYPE
)) != NULL
)
9738 * Grab format from client...
9741 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%255[^;]",
9744 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"."),
9745 format
->values
[0].string
.text
);
9749 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format-supplied", NULL
, ippGetString(format
, 0, NULL
));
9751 else if ((default_format
= cupsGetOption("document-format",
9752 printer
->num_options
,
9753 printer
->options
)) != NULL
)
9756 * Use default document format...
9759 if (sscanf(default_format
, "%15[^/]/%255[^;]", super
, type
) != 2)
9761 send_ipp_status(con
, IPP_BAD_REQUEST
,
9762 _("Bad document-format-default \"%s\"."), default_format
);
9769 * No document format attribute? Auto-type it!
9772 strlcpy(super
, "application", sizeof(super
));
9773 strlcpy(type
, "octet-stream", sizeof(type
));
9776 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
9779 * Auto-type the file...
9782 ipp_attribute_t
*doc_name
; /* document-name attribute */
9785 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Auto-typing file...");
9787 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
9788 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
9789 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
9793 filetype
= mimeType(MimeDatabase
, super
, type
);
9796 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Request file type is %s/%s.",
9797 filetype
->super
, filetype
->type
);
9799 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
, filetype
->type
);
9800 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format-detected", NULL
, mimetype
);
9803 filetype
= mimeType(MimeDatabase
, super
, type
);
9808 * Replace the document-format attribute value with the auto-typed or
9812 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9815 if ((jformat
= ippFindAttribute(job
->attrs
, "document-format",
9816 IPP_TAG_MIMETYPE
)) != NULL
)
9817 ippSetString(job
->attrs
, &jformat
, 0, mimetype
);
9819 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
9820 "document-format", NULL
, mimetype
);
9824 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9825 _("Unsupported document-format \"%s/%s\"."), super
, type
);
9826 cupsdLogMessage(CUPSD_LOG_INFO
,
9827 "Hint: Do you have the raw file printing rules enabled?");
9830 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9831 "document-format", NULL
, format
->values
[0].string
.text
);
9836 if (printer
->filetypes
&& !cupsArrayFind(printer
->filetypes
, filetype
))
9838 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9841 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9842 _("Unsupported document-format \"%s\"."), mimetype
);
9844 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9845 "document-format", NULL
, mimetype
);
9851 * Add the file to the job...
9854 if (add_file(con
, job
, filetype
, compression
))
9857 if ((attr
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
)) != NULL
)
9858 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name-supplied", NULL
, ippGetString(attr
, 0, NULL
));
9860 if (stat(con
->filename
, &fileinfo
))
9863 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
9865 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
9867 job
->koctets
+= kbytes
;
9869 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets", IPP_TAG_INTEGER
)) != NULL
)
9870 attr
->values
[0].integer
+= kbytes
;
9872 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
, job
->num_files
);
9873 if (rename(con
->filename
, filename
))
9875 cupsdLogJob(job
, CUPSD_LOG_ERROR
, "Unable to rename job document file \"%s\": %s", filename
, strerror(errno
));
9877 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to rename job document file."));
9881 cupsdClearString(&con
->filename
);
9883 cupsdLogJob(job
, CUPSD_LOG_INFO
, "File of type %s/%s queued by \"%s\".",
9884 filetype
->super
, filetype
->type
, job
->username
);
9887 * Start the job if this is the last document...
9892 if ((attr
= ippFindAttribute(con
->request
, "last-document",
9893 IPP_TAG_BOOLEAN
)) != NULL
&&
9894 attr
->values
[0].boolean
)
9897 * See if we need to add the ending sheet...
9900 if (cupsdTimeoutJob(job
))
9903 if (job
->state_value
== IPP_JOB_STOPPED
)
9905 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9906 job
->state_value
= IPP_JOB_PENDING
;
9908 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
9910 else if (job
->state_value
== IPP_JOB_HELD
)
9912 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9913 IPP_TAG_KEYWORD
)) == NULL
)
9914 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9916 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9918 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9919 job
->state_value
= IPP_JOB_PENDING
;
9921 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
9924 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-hold-until-specified");
9928 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
9934 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9935 IPP_TAG_KEYWORD
)) == NULL
)
9936 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9938 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9940 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
9941 job
->state_value
= IPP_JOB_HELD
;
9942 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
9944 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-incoming");
9947 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
9954 * Fill in the response info...
9957 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
9958 con
->clientname
, con
->clientport
, "/jobs/%d", jobid
);
9959 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
9962 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", jobid
);
9964 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
9966 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons",
9967 NULL
, job
->reasons
->values
[0].string
.text
);
9969 con
->response
->request
.status
.status_code
= IPP_OK
;
9972 * Start the job if necessary...
9981 * 'send_http_error()' - Send a HTTP error back to the IPP client.
9986 cupsd_client_t
*con
, /* I - Client connection */
9987 http_status_t status
, /* I - HTTP status code */
9988 cupsd_printer_t
*printer
) /* I - Printer, if any */
9990 ipp_attribute_t
*uri
; /* Request URI, if any */
9993 if ((uri
= ippFindAttribute(con
->request
, "printer-uri",
9994 IPP_TAG_URI
)) == NULL
)
9995 uri
= ippFindAttribute(con
->request
, "job-uri", IPP_TAG_URI
);
9997 cupsdLogMessage(status
== HTTP_FORBIDDEN
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
9998 "[Client %d] Returning HTTP %s for %s (%s) from %s",
9999 con
->number
, httpStatus(status
),
10001 ippOpString(con
->request
->request
.op
.operation_id
) :
10003 uri
? uri
->values
[0].string
.text
: "no URI",
10004 con
->http
->hostname
);
10008 int auth_type
; /* Type of authentication required */
10011 auth_type
= CUPSD_AUTH_NONE
;
10013 if (status
== HTTP_UNAUTHORIZED
&&
10014 printer
->num_auth_info_required
> 0 &&
10015 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
10017 (con
->request
->request
.op
.operation_id
== IPP_PRINT_JOB
||
10018 con
->request
->request
.op
.operation_id
== IPP_CREATE_JOB
||
10019 con
->request
->request
.op
.operation_id
== CUPS_AUTHENTICATE_JOB
))
10022 * Creating and authenticating jobs requires Kerberos...
10025 auth_type
= CUPSD_AUTH_NEGOTIATE
;
10030 * Use policy/location-defined authentication requirements...
10033 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
10034 cupsd_location_t
*auth
; /* Pointer to authentication element */
10037 if (printer
->type
& CUPS_PRINTER_CLASS
)
10038 snprintf(resource
, sizeof(resource
), "/classes/%s", printer
->name
);
10040 snprintf(resource
, sizeof(resource
), "/printers/%s", printer
->name
);
10042 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
10043 auth
->type
== CUPSD_AUTH_NONE
)
10044 auth
= cupsdFindPolicyOp(printer
->op_policy_ptr
,
10046 con
->request
->request
.op
.operation_id
:
10051 if (auth
->type
== CUPSD_AUTH_DEFAULT
)
10052 auth_type
= cupsdDefaultAuthType();
10054 auth_type
= auth
->type
;
10058 cupsdSendError(con
, status
, auth_type
);
10061 cupsdSendError(con
, status
, CUPSD_AUTH_NONE
);
10063 ippDelete(con
->response
);
10064 con
->response
= NULL
;
10071 * 'send_ipp_status()' - Send a status back to the IPP client.
10075 send_ipp_status(cupsd_client_t
*con
, /* I - Client connection */
10076 ipp_status_t status
, /* I - IPP status code */
10077 const char *message
,/* I - Status message */
10078 ...) /* I - Additional args as needed */
10080 va_list ap
; /* Pointer to additional args */
10081 char formatted
[1024]; /* Formatted errror message */
10084 va_start(ap
, message
);
10085 vsnprintf(formatted
, sizeof(formatted
),
10086 _cupsLangString(con
->language
, message
), ap
);
10089 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s: %s",
10090 ippOpString(con
->request
->request
.op
.operation_id
),
10091 ippErrorString(status
), formatted
);
10093 con
->response
->request
.status
.status_code
= status
;
10095 if (ippFindAttribute(con
->response
, "attributes-charset",
10096 IPP_TAG_ZERO
) == NULL
)
10097 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
10098 "attributes-charset", NULL
, "utf-8");
10100 if (ippFindAttribute(con
->response
, "attributes-natural-language",
10101 IPP_TAG_ZERO
) == NULL
)
10102 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
10103 "attributes-natural-language", NULL
, DefaultLanguage
);
10105 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
10106 "status-message", NULL
, formatted
);
10111 * 'set_default()' - Set the default destination...
10115 set_default(cupsd_client_t
*con
, /* I - Client connection */
10116 ipp_attribute_t
*uri
) /* I - Printer URI */
10118 http_status_t status
; /* Policy status */
10119 cups_ptype_t dtype
; /* Destination type (printer/class) */
10120 cupsd_printer_t
*printer
, /* Printer */
10121 *oldprinter
; /* Old default printer */
10124 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_default(%p[%d], %s)", con
,
10125 con
->number
, uri
->values
[0].string
.text
);
10128 * Is the destination valid?
10131 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10137 send_ipp_status(con
, IPP_NOT_FOUND
,
10138 _("The printer or class does not exist."));
10146 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
10148 send_http_error(con
, status
, NULL
);
10153 * Set it as the default...
10156 oldprinter
= DefaultPrinter
;
10157 DefaultPrinter
= printer
;
10160 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, oldprinter
, NULL
,
10161 "%s is no longer the default printer.", oldprinter
->name
);
10163 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
10164 "%s is now the default printer.", printer
->name
);
10166 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
| CUPSD_DIRTY_CLASSES
|
10167 CUPSD_DIRTY_PRINTCAP
);
10169 cupsdLogMessage(CUPSD_LOG_INFO
,
10170 "Default destination set to \"%s\" by \"%s\".",
10171 printer
->name
, get_username(con
));
10174 * Everything was ok, so return OK status...
10177 con
->response
->request
.status
.status_code
= IPP_OK
;
10182 * 'set_job_attrs()' - Set job attributes.
10186 set_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
10187 ipp_attribute_t
*uri
) /* I - Job URI */
10189 ipp_attribute_t
*attr
, /* Current attribute */
10190 *attr2
; /* Job attribute */
10191 int jobid
; /* Job ID */
10192 cupsd_job_t
*job
; /* Current job */
10193 char scheme
[HTTP_MAX_URI
],
10194 /* Method portion of URI */
10195 username
[HTTP_MAX_URI
],
10196 /* Username portion of URI */
10197 host
[HTTP_MAX_URI
],
10198 /* Host portion of URI */
10199 resource
[HTTP_MAX_URI
];
10200 /* Resource portion of URI */
10201 int port
; /* Port portion of URI */
10202 int event
; /* Events? */
10203 int check_jobs
; /* Check jobs? */
10206 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_job_attrs(%p[%d], %s)", con
,
10207 con
->number
, uri
->values
[0].string
.text
);
10210 * Start with "everything is OK" status...
10213 con
->response
->request
.status
.status_code
= IPP_OK
;
10216 * See if we have a job URI or a printer URI...
10219 if (!strcmp(uri
->name
, "printer-uri"))
10222 * Got a printer URI; see if we also have a job-id attribute...
10225 if ((attr
= ippFindAttribute(con
->request
, "job-id",
10226 IPP_TAG_INTEGER
)) == NULL
)
10228 send_ipp_status(con
, IPP_BAD_REQUEST
,
10229 _("Got a printer-uri attribute but no job-id."));
10233 jobid
= attr
->values
[0].integer
;
10238 * Got a job URI; parse it to get the job ID...
10241 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
10242 sizeof(scheme
), username
, sizeof(username
), host
,
10243 sizeof(host
), &port
, resource
, sizeof(resource
));
10245 if (strncmp(resource
, "/jobs/", 6))
10251 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
10252 uri
->values
[0].string
.text
);
10256 jobid
= atoi(resource
+ 6);
10260 * See if the job exists...
10263 if ((job
= cupsdFindJob(jobid
)) == NULL
)
10266 * Nope - return a "not found" error...
10269 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
10274 * See if the job has been completed...
10277 if (job
->state_value
> IPP_JOB_STOPPED
)
10280 * Return a "not-possible" error...
10283 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10284 _("Job #%d is finished and cannot be altered."), jobid
);
10289 * See if the job is owned by the requesting user...
10292 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10294 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
10295 cupsdFindDest(job
->dest
));
10300 * See what the user wants to change.
10308 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10310 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
10313 if (!strcmp(attr
->name
, "attributes-charset") ||
10314 !strcmp(attr
->name
, "attributes-natural-language") ||
10315 !strncmp(attr
->name
, "date-time-at-", 13) ||
10316 !strncmp(attr
->name
, "document-compression", 20) ||
10317 !strncmp(attr
->name
, "document-format", 15) ||
10318 !strcmp(attr
->name
, "job-detailed-status-messages") ||
10319 !strcmp(attr
->name
, "job-document-access-errors") ||
10320 !strcmp(attr
->name
, "job-id") ||
10321 !strcmp(attr
->name
, "job-impressions-completed") ||
10322 !strcmp(attr
->name
, "job-k-octets-completed") ||
10323 !strcmp(attr
->name
, "job-media-sheets-completed") ||
10324 !strcmp(attr
->name
, "job-originating-host-name") ||
10325 !strcmp(attr
->name
, "job-originating-user-name") ||
10326 !strcmp(attr
->name
, "job-pages-completed") ||
10327 !strcmp(attr
->name
, "job-printer-up-time") ||
10328 !strcmp(attr
->name
, "job-printer-uri") ||
10329 !strcmp(attr
->name
, "job-sheets") ||
10330 !strcmp(attr
->name
, "job-state-message") ||
10331 !strcmp(attr
->name
, "job-state-reasons") ||
10332 !strcmp(attr
->name
, "job-uri") ||
10333 !strcmp(attr
->name
, "number-of-documents") ||
10334 !strcmp(attr
->name
, "number-of-intervening-jobs") ||
10335 !strcmp(attr
->name
, "output-device-assigned") ||
10336 !strncmp(attr
->name
, "time-at-", 8))
10342 send_ipp_status(con
, IPP_ATTRIBUTES_NOT_SETTABLE
,
10343 _("%s cannot be changed."), attr
->name
);
10345 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
10346 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
10350 if (!ippValidateAttribute(attr
))
10352 send_ipp_status(con
, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES
, _("Bad '%s' value."), attr
->name
);
10353 ippCopyAttribute(con
->response
, attr
, 0);
10357 if (!strcmp(attr
->name
, "job-hold-until"))
10359 const char *when
= ippGetString(attr
, 0, NULL
);
10360 /* job-hold-until value */
10362 if ((ippGetValueTag(attr
) != IPP_TAG_KEYWORD
&& ippGetValueTag(attr
) != IPP_TAG_NAME
&& ippGetValueTag(attr
) != IPP_TAG_NAMELANG
) || ippGetCount(attr
) != 1)
10364 send_ipp_status(con
, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES
, _("Unsupported 'job-hold-until' value."));
10365 ippCopyAttribute(con
->response
, attr
, 0);
10369 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-hold-until to %s", when
);
10370 cupsdSetJobHoldUntil(job
, when
, 0);
10372 if (!strcmp(when
, "no-hold"))
10374 cupsdReleaseJob(job
);
10378 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
, "Job held by \"%s\".", username
);
10380 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
;
10382 else if (!strcmp(attr
->name
, "job-priority"))
10385 * Change the job priority...
10388 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10390 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-priority value."));
10392 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
10393 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
10395 else if (job
->state_value
>= IPP_JOB_PROCESSING
)
10397 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10398 _("Job is completed and cannot be changed."));
10401 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10403 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-priority to %d",
10404 attr
->values
[0].integer
);
10405 cupsdSetJobPriority(job
, attr
->values
[0].integer
);
10408 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
|
10409 CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
;
10412 else if (!strcmp(attr
->name
, "job-state"))
10415 * Change the job state...
10418 if (attr
->value_tag
!= IPP_TAG_ENUM
)
10420 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-state value."));
10422 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
10423 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
10427 switch (attr
->values
[0].integer
)
10429 case IPP_JOB_PENDING
:
10430 case IPP_JOB_HELD
:
10431 if (job
->state_value
> IPP_JOB_HELD
)
10433 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10434 _("Job state cannot be changed."));
10437 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10439 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10440 attr
->values
[0].integer
);
10441 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
, CUPSD_JOB_DEFAULT
, "Job state changed by \"%s\"", username
);
10446 case IPP_JOB_PROCESSING
:
10447 case IPP_JOB_STOPPED
:
10448 if (job
->state_value
!= attr
->values
[0].integer
)
10450 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10451 _("Job state cannot be changed."));
10456 case IPP_JOB_CANCELED
:
10457 case IPP_JOB_ABORTED
:
10458 case IPP_JOB_COMPLETED
:
10459 if (job
->state_value
> IPP_JOB_PROCESSING
)
10461 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10462 _("Job state cannot be changed."));
10465 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10467 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10468 attr
->values
[0].integer
);
10469 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
,
10471 "Job state changed by \"%s\"", username
);
10478 else if (con
->response
->request
.status
.status_code
!= IPP_OK
)
10480 else if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10481 IPP_TAG_ZERO
)) != NULL
)
10484 * Some other value; first free the old value...
10487 if (job
->attrs
->prev
)
10488 job
->attrs
->prev
->next
= attr2
->next
;
10490 job
->attrs
->attrs
= attr2
->next
;
10492 if (job
->attrs
->last
== attr2
)
10493 job
->attrs
->last
= job
->attrs
->prev
;
10495 ippDeleteAttribute(NULL
, attr2
);
10498 * Then copy the attribute...
10501 ippCopyAttribute(job
->attrs
, attr
, 0);
10503 else if (attr
->value_tag
== IPP_TAG_DELETEATTR
)
10506 * Delete the attribute...
10509 if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10510 IPP_TAG_ZERO
)) != NULL
)
10512 if (job
->attrs
->prev
)
10513 job
->attrs
->prev
->next
= attr2
->next
;
10515 job
->attrs
->attrs
= attr2
->next
;
10517 if (attr2
== job
->attrs
->last
)
10518 job
->attrs
->last
= job
->attrs
->prev
;
10520 ippDeleteAttribute(NULL
, attr2
);
10522 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10528 * Add new option by copying it...
10531 ippCopyAttribute(job
->attrs
, attr
, 0);
10533 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10542 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10545 * Send events as needed...
10548 if (event
& CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
)
10549 cupsdAddEvent(CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
,
10550 cupsdFindDest(job
->dest
), job
,
10551 "Job priority changed by user.");
10553 if (event
& CUPSD_EVENT_JOB_STATE
)
10554 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
10555 job
->state_value
== IPP_JOB_HELD
?
10556 "Job held by user." : "Job restarted by user.");
10558 if (event
& CUPSD_EVENT_JOB_CONFIG_CHANGED
)
10559 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
10560 "Job options changed by user.");
10563 * Start jobs if possible...
10572 * 'set_printer_attrs()' - Set printer attributes.
10576 set_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
10577 ipp_attribute_t
*uri
) /* I - Printer */
10579 http_status_t status
; /* Policy status */
10580 cups_ptype_t dtype
; /* Destination type (printer/class) */
10581 cupsd_printer_t
*printer
; /* Printer/class */
10582 ipp_attribute_t
*attr
; /* Printer attribute */
10583 int changed
= 0; /* Was anything changed? */
10586 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_attrs(%p[%d], %s)", con
,
10587 con
->number
, uri
->values
[0].string
.text
);
10590 * Is the destination valid?
10593 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10599 send_ipp_status(con
, IPP_NOT_FOUND
,
10600 _("The printer or class does not exist."));
10608 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10610 send_http_error(con
, status
, printer
);
10615 * Return a list of attributes that can be set via Set-Printer-Attributes.
10618 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
10619 IPP_TAG_TEXT
)) != NULL
)
10621 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
10625 if ((attr
= ippFindAttribute(con
->request
, "printer-geo-location", IPP_TAG_URI
)) != NULL
&& !strncmp(attr
->values
[0].string
.text
, "geo:", 4))
10627 cupsdSetString(&printer
->geo_location
, attr
->values
[0].string
.text
);
10631 if ((attr
= ippFindAttribute(con
->request
, "printer-organization", IPP_TAG_TEXT
)) != NULL
)
10633 cupsdSetString(&printer
->organization
, attr
->values
[0].string
.text
);
10637 if ((attr
= ippFindAttribute(con
->request
, "printer-organizational-unit", IPP_TAG_TEXT
)) != NULL
)
10639 cupsdSetString(&printer
->organizational_unit
, attr
->values
[0].string
.text
);
10643 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
10644 IPP_TAG_TEXT
)) != NULL
)
10646 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
10651 * Update the printer attributes and return...
10656 printer
->config_time
= time(NULL
);
10658 cupsdSetPrinterAttrs(printer
);
10659 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
10661 cupsdAddEvent(CUPSD_EVENT_PRINTER_CONFIG
, printer
, NULL
,
10662 "Printer \"%s\" description or location changed by \"%s\".",
10663 printer
->name
, get_username(con
));
10665 cupsdLogMessage(CUPSD_LOG_INFO
,
10666 "Printer \"%s\" description or location changed by \"%s\".",
10667 printer
->name
, get_username(con
));
10670 con
->response
->request
.status
.status_code
= IPP_OK
;
10675 * 'set_printer_defaults()' - Set printer default options from a request.
10678 static int /* O - 1 on success, 0 on failure */
10679 set_printer_defaults(
10680 cupsd_client_t
*con
, /* I - Client connection */
10681 cupsd_printer_t
*printer
) /* I - Printer */
10683 int i
; /* Looping var */
10684 ipp_attribute_t
*attr
; /* Current attribute */
10685 size_t namelen
; /* Length of attribute name */
10686 char name
[256], /* New attribute name */
10687 value
[256]; /* String version of integer attrs */
10690 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10693 * Skip non-printer attributes...
10696 if (attr
->group_tag
!= IPP_TAG_PRINTER
|| !attr
->name
)
10699 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_defaults: %s", attr
->name
);
10701 if (!strcmp(attr
->name
, "job-sheets-default"))
10704 * Only allow keywords and names...
10707 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10711 * Only allow job-sheets-default to be set when running without a
10712 * system high classification level...
10715 if (Classification
)
10718 cupsdSetString(&printer
->job_sheets
[0], attr
->values
[0].string
.text
);
10720 if (attr
->num_values
> 1)
10721 cupsdSetString(&printer
->job_sheets
[1], attr
->values
[1].string
.text
);
10723 cupsdSetString(&printer
->job_sheets
[1], "none");
10725 else if (!strcmp(attr
->name
, "requesting-user-name-allowed"))
10727 cupsdFreeStrings(&(printer
->users
));
10729 printer
->deny_users
= 0;
10731 if (attr
->value_tag
== IPP_TAG_NAME
&&
10732 (attr
->num_values
> 1 ||
10733 strcmp(attr
->values
[0].string
.text
, "all")))
10735 for (i
= 0; i
< attr
->num_values
; i
++)
10736 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
10739 else if (!strcmp(attr
->name
, "requesting-user-name-denied"))
10741 cupsdFreeStrings(&(printer
->users
));
10743 printer
->deny_users
= 1;
10745 if (attr
->value_tag
== IPP_TAG_NAME
&&
10746 (attr
->num_values
> 1 ||
10747 strcmp(attr
->values
[0].string
.text
, "none")))
10749 for (i
= 0; i
< attr
->num_values
; i
++)
10750 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
10753 else if (!strcmp(attr
->name
, "job-quota-period"))
10755 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10758 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-quota-period to %d...",
10759 attr
->values
[0].integer
);
10760 cupsdFreeQuotas(printer
);
10762 printer
->quota_period
= attr
->values
[0].integer
;
10764 else if (!strcmp(attr
->name
, "job-k-limit"))
10766 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10769 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-k-limit to %d...",
10770 attr
->values
[0].integer
);
10771 cupsdFreeQuotas(printer
);
10773 printer
->k_limit
= attr
->values
[0].integer
;
10775 else if (!strcmp(attr
->name
, "job-page-limit"))
10777 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10780 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-page-limit to %d...",
10781 attr
->values
[0].integer
);
10782 cupsdFreeQuotas(printer
);
10784 printer
->page_limit
= attr
->values
[0].integer
;
10786 else if (!strcmp(attr
->name
, "printer-op-policy"))
10788 cupsd_policy_t
*p
; /* Policy */
10791 if (attr
->value_tag
!= IPP_TAG_NAME
)
10794 if ((p
= cupsdFindPolicy(attr
->values
[0].string
.text
)) != NULL
)
10796 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10797 "Setting printer-op-policy to \"%s\"...",
10798 attr
->values
[0].string
.text
);
10799 cupsdSetString(&printer
->op_policy
, attr
->values
[0].string
.text
);
10800 printer
->op_policy_ptr
= p
;
10804 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10805 _("Unknown printer-op-policy \"%s\"."),
10806 attr
->values
[0].string
.text
);
10810 else if (!strcmp(attr
->name
, "printer-error-policy"))
10812 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10815 if (strcmp(attr
->values
[0].string
.text
, "retry-current-job") &&
10816 ((printer
->type
& CUPS_PRINTER_CLASS
) ||
10817 (strcmp(attr
->values
[0].string
.text
, "abort-job") &&
10818 strcmp(attr
->values
[0].string
.text
, "retry-job") &&
10819 strcmp(attr
->values
[0].string
.text
, "stop-printer"))))
10821 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10822 _("Unknown printer-error-policy \"%s\"."),
10823 attr
->values
[0].string
.text
);
10827 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10828 "Setting printer-error-policy to \"%s\"...",
10829 attr
->values
[0].string
.text
);
10830 cupsdSetString(&printer
->error_policy
, attr
->values
[0].string
.text
);
10834 * Skip any other non-default attributes...
10837 namelen
= strlen(attr
->name
);
10838 if (namelen
< 9 || strcmp(attr
->name
+ namelen
- 8, "-default") ||
10839 namelen
> (sizeof(name
) - 1) || attr
->num_values
!= 1)
10843 * OK, anything else must be a user-defined default...
10846 strlcpy(name
, attr
->name
, sizeof(name
));
10847 name
[namelen
- 8] = '\0'; /* Strip "-default" */
10849 switch (attr
->value_tag
)
10851 case IPP_TAG_DELETEATTR
:
10852 printer
->num_options
= cupsRemoveOption(name
,
10853 printer
->num_options
,
10854 &(printer
->options
));
10855 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10856 "Deleting %s", attr
->name
);
10859 case IPP_TAG_NAME
:
10860 case IPP_TAG_TEXT
:
10861 case IPP_TAG_KEYWORD
:
10863 printer
->num_options
= cupsAddOption(name
,
10864 attr
->values
[0].string
.text
,
10865 printer
->num_options
,
10866 &(printer
->options
));
10867 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10868 "Setting %s to \"%s\"...", attr
->name
,
10869 attr
->values
[0].string
.text
);
10872 case IPP_TAG_BOOLEAN
:
10873 printer
->num_options
= cupsAddOption(name
,
10874 attr
->values
[0].boolean
?
10876 printer
->num_options
,
10877 &(printer
->options
));
10878 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10879 "Setting %s to %s...", attr
->name
,
10880 attr
->values
[0].boolean
? "true" : "false");
10883 case IPP_TAG_INTEGER
:
10884 case IPP_TAG_ENUM
:
10885 sprintf(value
, "%d", attr
->values
[0].integer
);
10886 printer
->num_options
= cupsAddOption(name
, value
,
10887 printer
->num_options
,
10888 &(printer
->options
));
10889 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10890 "Setting %s to %s...", attr
->name
, value
);
10893 case IPP_TAG_RANGE
:
10894 sprintf(value
, "%d-%d", attr
->values
[0].range
.lower
,
10895 attr
->values
[0].range
.upper
);
10896 printer
->num_options
= cupsAddOption(name
, value
,
10897 printer
->num_options
,
10898 &(printer
->options
));
10899 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10900 "Setting %s to %s...", attr
->name
, value
);
10903 case IPP_TAG_RESOLUTION
:
10904 sprintf(value
, "%dx%d%s", attr
->values
[0].resolution
.xres
,
10905 attr
->values
[0].resolution
.yres
,
10906 attr
->values
[0].resolution
.units
== IPP_RES_PER_INCH
?
10908 printer
->num_options
= cupsAddOption(name
, value
,
10909 printer
->num_options
,
10910 &(printer
->options
));
10911 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10912 "Setting %s to %s...", attr
->name
, value
);
10916 /* Do nothing for other values */
10926 * 'start_printer()' - Start a printer.
10930 start_printer(cupsd_client_t
*con
, /* I - Client connection */
10931 ipp_attribute_t
*uri
) /* I - Printer URI */
10933 int i
; /* Temporary variable */
10934 http_status_t status
; /* Policy status */
10935 cups_ptype_t dtype
; /* Destination type (printer/class) */
10936 cupsd_printer_t
*printer
; /* Printer data */
10939 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_printer(%p[%d], %s)", con
,
10940 con
->number
, uri
->values
[0].string
.text
);
10943 * Is the destination valid?
10946 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10952 send_ipp_status(con
, IPP_NOT_FOUND
,
10953 _("The printer or class does not exist."));
10961 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10963 send_http_error(con
, status
, printer
);
10968 * Start the printer...
10971 printer
->state_message
[0] = '\0';
10973 cupsdStartPrinter(printer
, 1);
10975 if (dtype
& CUPS_PRINTER_CLASS
)
10976 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" started by \"%s\".",
10977 printer
->name
, get_username(con
));
10979 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" started by \"%s\".",
10980 printer
->name
, get_username(con
));
10988 if ((i
= check_quotas(con
, printer
)) < 0)
10990 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
10995 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
11000 * Everything was ok, so return OK status...
11003 con
->response
->request
.status
.status_code
= IPP_OK
;
11008 * 'stop_printer()' - Stop a printer.
11012 stop_printer(cupsd_client_t
*con
, /* I - Client connection */
11013 ipp_attribute_t
*uri
) /* I - Printer URI */
11015 http_status_t status
; /* Policy status */
11016 cups_ptype_t dtype
; /* Destination type (printer/class) */
11017 cupsd_printer_t
*printer
; /* Printer data */
11018 ipp_attribute_t
*attr
; /* printer-state-message attribute */
11021 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "stop_printer(%p[%d], %s)", con
,
11022 con
->number
, uri
->values
[0].string
.text
);
11025 * Is the destination valid?
11028 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11034 send_ipp_status(con
, IPP_NOT_FOUND
,
11035 _("The printer or class does not exist."));
11043 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11045 send_http_error(con
, status
, printer
);
11050 * Stop the printer...
11053 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
11054 IPP_TAG_TEXT
)) == NULL
)
11055 strlcpy(printer
->state_message
, "Paused", sizeof(printer
->state_message
));
11058 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
11059 sizeof(printer
->state_message
));
11062 cupsdStopPrinter(printer
, 1);
11064 if (dtype
& CUPS_PRINTER_CLASS
)
11065 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" stopped by \"%s\".",
11066 printer
->name
, get_username(con
));
11068 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" stopped by \"%s\".",
11069 printer
->name
, get_username(con
));
11072 * Everything was ok, so return OK status...
11075 con
->response
->request
.status
.status_code
= IPP_OK
;
11080 * 'url_encode_attr()' - URL-encode a string attribute.
11084 url_encode_attr(ipp_attribute_t
*attr
, /* I - Attribute */
11085 char *buffer
,/* I - String buffer */
11086 size_t bufsize
)/* I - Size of buffer */
11088 int i
; /* Looping var */
11089 char *bufptr
, /* Pointer into buffer */
11090 *bufend
; /* End of buffer */
11093 strlcpy(buffer
, attr
->name
, bufsize
);
11094 bufptr
= buffer
+ strlen(buffer
);
11095 bufend
= buffer
+ bufsize
- 1;
11097 for (i
= 0; i
< attr
->num_values
; i
++)
11099 if (bufptr
>= bufend
)
11107 if (bufptr
>= bufend
)
11112 bufptr
= url_encode_string(attr
->values
[i
].string
.text
, bufptr
, (size_t)(bufend
- bufptr
+ 1));
11114 if (bufptr
>= bufend
)
11125 * 'url_encode_string()' - URL-encode a string.
11128 static char * /* O - End of string */
11129 url_encode_string(const char *s
, /* I - String */
11130 char *buffer
, /* I - String buffer */
11131 size_t bufsize
) /* I - Size of buffer */
11133 char *bufptr
, /* Pointer into buffer */
11134 *bufend
; /* End of buffer */
11135 static const char *hex
= "0123456789ABCDEF";
11140 bufend
= buffer
+ bufsize
- 1;
11142 while (*s
&& bufptr
< bufend
)
11144 if (*s
== ' ' || *s
== '%' || *s
== '+')
11146 if (bufptr
>= (bufend
- 2))
11150 *bufptr
++ = hex
[(*s
>> 4) & 15];
11151 *bufptr
++ = hex
[*s
& 15];
11155 else if (*s
== '\'' || *s
== '\\')
11157 if (bufptr
>= (bufend
- 1))
11174 * 'user_allowed()' - See if a user is allowed to print to a queue.
11177 static int /* O - 0 if not allowed, 1 if allowed */
11178 user_allowed(cupsd_printer_t
*p
, /* I - Printer or class */
11179 const char *username
) /* I - Username */
11181 struct passwd
*pw
; /* User password data */
11182 char baseuser
[256], /* Base username */
11183 *baseptr
, /* Pointer to "@" in base username */
11184 *name
; /* Current user name */
11187 if (cupsArrayCount(p
->users
) == 0)
11190 if (!strcmp(username
, "root"))
11193 if (strchr(username
, '@'))
11196 * Strip @REALM for username check...
11199 strlcpy(baseuser
, username
, sizeof(baseuser
));
11201 if ((baseptr
= strchr(baseuser
, '@')) != NULL
)
11204 username
= baseuser
;
11207 pw
= getpwnam(username
);
11210 for (name
= (char *)cupsArrayFirst(p
->users
);
11212 name
= (char *)cupsArrayNext(p
->users
))
11214 if (name
[0] == '@')
11217 * Check group membership...
11220 if (cupsdCheckGroup(username
, pw
, name
+ 1))
11223 else if (name
[0] == '#')
11229 if (cupsdCheckGroup(username
, pw
, name
))
11232 else if (!_cups_strcasecmp(username
, name
))
11236 return ((name
!= NULL
) != p
->deny_users
);
11241 * 'validate_job()' - Validate printer options and destination.
11245 validate_job(cupsd_client_t
*con
, /* I - Client connection */
11246 ipp_attribute_t
*uri
) /* I - Printer URI */
11248 http_status_t status
; /* Policy status */
11249 ipp_attribute_t
*attr
; /* Current attribute */
11251 ipp_attribute_t
*auth_info
; /* auth-info attribute */
11252 #endif /* HAVE_SSL */
11253 ipp_attribute_t
*format
, /* Document-format attribute */
11254 *name
; /* Job-name attribute */
11255 cups_ptype_t dtype
; /* Destination type (printer/class) */
11256 char super
[MIME_MAX_SUPER
],
11257 /* Supertype of file */
11258 type
[MIME_MAX_TYPE
];
11259 /* Subtype of file */
11260 cupsd_printer_t
*printer
; /* Printer */
11263 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_job(%p[%d], %s)", con
,
11264 con
->number
, uri
->values
[0].string
.text
);
11267 * OK, see if the client is sending the document compressed - CUPS
11268 * doesn't support compression yet...
11271 if ((attr
= ippFindAttribute(con
->request
, "compression",
11272 IPP_TAG_KEYWORD
)) != NULL
)
11274 if (strcmp(attr
->values
[0].string
.text
, "none")
11276 && strcmp(attr
->values
[0].string
.text
, "gzip")
11277 #endif /* HAVE_LIBZ */
11280 send_ipp_status(con
, IPP_ATTRIBUTES
,
11281 _("Unsupported 'compression' value \"%s\"."),
11282 attr
->values
[0].string
.text
);
11283 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
11284 "compression", NULL
, attr
->values
[0].string
.text
);
11290 * Is it a format we support?
11293 if ((format
= ippFindAttribute(con
->request
, "document-format",
11294 IPP_TAG_MIMETYPE
)) != NULL
)
11296 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%255[^;]",
11299 send_ipp_status(con
, IPP_BAD_REQUEST
,
11300 _("Bad 'document-format' value \"%s\"."),
11301 format
->values
[0].string
.text
);
11305 if ((strcmp(super
, "application") || strcmp(type
, "octet-stream")) &&
11306 !mimeType(MimeDatabase
, super
, type
))
11308 cupsdLogMessage(CUPSD_LOG_INFO
,
11309 "Hint: Do you have the raw file printing rules enabled?");
11310 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
11311 _("Unsupported 'document-format' value \"%s\"."),
11312 format
->values
[0].string
.text
);
11313 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
11314 "document-format", NULL
, format
->values
[0].string
.text
);
11320 * Is the job-hold-until value valid?
11323 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_ZERO
)) != NULL
&& ((ippGetValueTag(attr
) != IPP_TAG_KEYWORD
&& ippGetValueTag(attr
) != IPP_TAG_NAME
&& ippGetValueTag(attr
) != IPP_TAG_NAMELANG
) || ippGetCount(attr
) != 1 || !ippValidateAttribute(attr
)))
11325 send_ipp_status(con
, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES
, _("Unsupported 'job-hold-until' value."));
11326 ippCopyAttribute(con
->response
, attr
, 0);
11331 * Is the job-name valid?
11334 if ((name
= ippFindAttribute(con
->request
, "job-name", IPP_TAG_ZERO
)) != NULL
)
11336 if ((name
->value_tag
!= IPP_TAG_NAME
&& name
->value_tag
!= IPP_TAG_NAMELANG
) ||
11337 name
->num_values
!= 1 || !ippValidateAttribute(name
))
11339 if (StrictConformance
)
11341 send_ipp_status(con
, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES
, _("Unsupported 'job-name' value."));
11342 ippCopyAttribute(con
->response
, name
, 0);
11347 cupsdLogMessage(CUPSD_LOG_WARN
, "Unsupported 'job-name' value, deleting from request.");
11348 ippDeleteAttribute(con
->request
, name
);
11354 * Is the destination valid?
11357 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11363 send_ipp_status(con
, IPP_NOT_FOUND
,
11364 _("The printer or class does not exist."));
11373 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
11374 #endif /* HAVE_SSL */
11376 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11378 send_http_error(con
, status
, printer
);
11381 else if (printer
->num_auth_info_required
== 1 &&
11382 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
11385 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
11389 else if (auth_info
&& !con
->http
->tls
&&
11390 !httpAddrLocalhost(con
->http
->hostaddr
))
11393 * Require encryption of auth-info over non-local connections...
11396 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
11399 #endif /* HAVE_SSL */
11402 * Everything was ok, so return OK status...
11405 con
->response
->request
.status
.status_code
= IPP_OK
;
11410 * 'validate_name()' - Make sure the printer name only contains valid chars.
11413 static int /* O - 0 if name is no good, 1 if good */
11414 validate_name(const char *name
) /* I - Name to check */
11416 const char *ptr
; /* Pointer into name */
11420 * Scan the whole name...
11423 for (ptr
= name
; *ptr
; ptr
++)
11424 if ((*ptr
> 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
11428 * All the characters are good; validate the length, too...
11431 return ((ptr
- name
) < 128);
11436 * 'validate_user()' - Validate the user for the request.
11439 static int /* O - 1 if permitted, 0 otherwise */
11440 validate_user(cupsd_job_t
*job
, /* I - Job */
11441 cupsd_client_t
*con
, /* I - Client connection */
11442 const char *owner
, /* I - Owner of job/resource */
11443 char *username
, /* O - Authenticated username */
11444 size_t userlen
) /* I - Length of username */
11446 cupsd_printer_t
*printer
; /* Printer for job */
11449 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
);
11452 * Validate input...
11455 if (!con
|| !owner
|| !username
|| userlen
<= 0)
11459 * Get the best authenticated username that is available.
11462 strlcpy(username
, get_username(con
), userlen
);
11465 * Check the username against the owner...
11468 printer
= cupsdFindDest(job
->dest
);
11470 return (cupsdCheckPolicy(printer
? printer
->op_policy_ptr
: DefaultPolicyPtr
,
11471 con
, owner
) == HTTP_OK
);