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 # ifdef HAVE_MEMBERSHIP_H
23 # include <membership.h>
24 # endif /* HAVE_MEMBERSHIP_H */
25 extern int mbr_user_name_to_uuid(const char* name
, uuid_t uu
);
26 extern int mbr_group_name_to_uuid(const char* name
, uuid_t uu
);
27 extern int mbr_check_membership_by_id(uuid_t user
, gid_t group
, int* ismember
);
28 #endif /* __APPLE__ */
35 static void accept_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
36 static void add_class(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
37 static int add_file(cupsd_client_t
*con
, cupsd_job_t
*job
,
38 mime_type_t
*filetype
, int compression
);
39 static cupsd_job_t
*add_job(cupsd_client_t
*con
, cupsd_printer_t
*printer
,
40 mime_type_t
*filetype
);
41 static void add_job_subscriptions(cupsd_client_t
*con
, cupsd_job_t
*job
);
42 static void add_job_uuid(cupsd_job_t
*job
);
43 static void add_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
44 static void add_printer_state_reasons(cupsd_client_t
*con
,
46 static void add_queued_job_count(cupsd_client_t
*con
, cupsd_printer_t
*p
);
47 static void apply_printer_defaults(cupsd_printer_t
*printer
,
49 static void authenticate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
50 static void cancel_all_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
51 static void cancel_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
52 static void cancel_subscription(cupsd_client_t
*con
, int id
);
53 static int check_rss_recipient(const char *recipient
);
54 static int check_quotas(cupsd_client_t
*con
, cupsd_printer_t
*p
);
55 static void close_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
56 static void copy_attrs(ipp_t
*to
, ipp_t
*from
, cups_array_t
*ra
,
57 ipp_tag_t group
, int quickcopy
,
58 cups_array_t
*exclude
);
59 static int copy_banner(cupsd_client_t
*con
, cupsd_job_t
*job
,
61 static int copy_file(const char *from
, const char *to
, mode_t mode
);
62 static int copy_model(cupsd_client_t
*con
, const char *from
,
64 static void copy_job_attrs(cupsd_client_t
*con
,
66 cups_array_t
*ra
, cups_array_t
*exclude
);
67 static void copy_printer_attrs(cupsd_client_t
*con
,
68 cupsd_printer_t
*printer
,
70 static void copy_subscription_attrs(cupsd_client_t
*con
,
71 cupsd_subscription_t
*sub
,
73 cups_array_t
*exclude
);
74 static void create_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
75 static void create_local_printer(cupsd_client_t
*con
);
76 static cups_array_t
*create_requested_array(ipp_t
*request
);
77 static void create_subscriptions(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
78 static void delete_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
79 static void get_default(cupsd_client_t
*con
);
80 static void get_devices(cupsd_client_t
*con
);
81 static void get_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
82 static void get_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
83 static void get_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
84 static void get_notifications(cupsd_client_t
*con
);
85 static void get_ppd(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
86 static void get_ppds(cupsd_client_t
*con
);
87 static void get_printers(cupsd_client_t
*con
, int type
);
88 static void get_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
89 static void get_printer_supported(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
90 static void get_subscription_attrs(cupsd_client_t
*con
, int sub_id
);
91 static void get_subscriptions(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
92 static const char *get_username(cupsd_client_t
*con
);
93 static void hold_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
94 static void hold_new_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
95 static void move_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
96 static int ppd_parse_line(const char *line
, char *option
, int olen
,
97 char *choice
, int clen
);
98 static void print_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
99 static void read_job_ticket(cupsd_client_t
*con
);
100 static void reject_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
101 static void release_held_new_jobs(cupsd_client_t
*con
,
102 ipp_attribute_t
*uri
);
103 static void release_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
104 static void renew_subscription(cupsd_client_t
*con
, int sub_id
);
105 static void restart_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
106 static void save_auth_info(cupsd_client_t
*con
, cupsd_job_t
*job
,
107 ipp_attribute_t
*auth_info
);
108 static void send_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
109 static void send_http_error(cupsd_client_t
*con
, http_status_t status
,
110 cupsd_printer_t
*printer
);
111 static void send_ipp_status(cupsd_client_t
*con
, ipp_status_t status
, const char *message
, ...) _CUPS_FORMAT(3, 4);
112 static void set_default(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
113 static void set_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
114 static void set_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
115 static int set_printer_defaults(cupsd_client_t
*con
, cupsd_printer_t
*printer
);
116 static void start_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
117 static void stop_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
118 static void url_encode_attr(ipp_attribute_t
*attr
, char *buffer
, size_t bufsize
);
119 static char *url_encode_string(const char *s
, char *buffer
, size_t bufsize
);
120 static int user_allowed(cupsd_printer_t
*p
, const char *username
);
121 static void validate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
122 static int validate_name(const char *name
);
123 static int validate_user(cupsd_job_t
*job
, cupsd_client_t
*con
, const char *owner
, char *username
, size_t userlen
);
127 * 'cupsdProcessIPPRequest()' - Process an incoming IPP request.
130 int /* O - 1 on success, 0 on failure */
131 cupsdProcessIPPRequest(
132 cupsd_client_t
*con
) /* I - Client connection */
134 ipp_tag_t group
; /* Current group tag */
135 ipp_attribute_t
*attr
; /* Current attribute */
136 ipp_attribute_t
*charset
; /* Character set attribute */
137 ipp_attribute_t
*language
; /* Language attribute */
138 ipp_attribute_t
*uri
= NULL
; /* Printer or job URI attribute */
139 ipp_attribute_t
*username
; /* requesting-user-name attr */
140 int sub_id
; /* Subscription ID */
141 int valid
= 1; /* Valid request? */
144 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
));
146 if (LogLevel
>= CUPSD_LOG_DEBUG2
)
148 for (group
= IPP_TAG_ZERO
, attr
= ippFirstAttribute(con
->request
); attr
; attr
= ippNextAttribute(con
->request
))
150 const char *name
; /* Attribute name */
151 char value
[1024]; /* Attribute value */
153 if (group
!= ippGetGroupTag(attr
))
155 group
= ippGetGroupTag(attr
);
156 if (group
!= IPP_TAG_ZERO
)
157 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdProcessIPPRequest: %s", ippTagString(group
));
160 if ((name
= ippGetName(attr
)) == NULL
)
163 ippAttributeString(attr
, value
, sizeof(value
));
165 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdProcessIPPRequest: %s %s%s '%s'", name
, ippGetCount(attr
) > 1 ? "1setOf " : "", ippTagString(ippGetValueTag(attr
)), value
);
170 * First build an empty response message for this request...
173 con
->response
= ippNew();
175 con
->response
->request
.status
.version
[0] = con
->request
->request
.op
.version
[0];
176 con
->response
->request
.status
.version
[1] = con
->request
->request
.op
.version
[1];
177 con
->response
->request
.status
.request_id
= con
->request
->request
.op
.request_id
;
180 * Then validate the request header and required attributes...
183 if (con
->request
->request
.any
.version
[0] != 1 && con
->request
->request
.any
.version
[0] != 2)
186 * Return an error, since we only support IPP 1.x and 2.x.
189 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]);
191 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]);
193 else if (con
->request
->request
.any
.request_id
< 1)
196 * Return an error, since request IDs must be between 1 and 2^31-1
199 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
);
201 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Bad request ID %d."), con
->request
->request
.any
.request_id
);
203 else if (!con
->request
->attrs
)
205 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
, "%04X %s No attributes in request.", IPP_STATUS_ERROR_BAD_REQUEST
, con
->http
->hostname
);
207 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("No attributes in request."));
212 * Make sure that the attributes are provided in the correct order and
213 * don't repeat groups...
216 for (attr
= con
->request
->attrs
, group
= attr
->group_tag
;
219 if (attr
->group_tag
< group
&& attr
->group_tag
!= IPP_TAG_ZERO
)
222 * Out of order; return an error...
225 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
, "%04X %s Attribute groups are out of order", IPP_STATUS_ERROR_BAD_REQUEST
, con
->http
->hostname
);
227 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Attribute groups are out of order (%x < %x)."), attr
->group_tag
, group
);
231 group
= attr
->group_tag
;
236 * Then make sure that the first three attributes are:
239 * attributes-natural-language
240 * printer-uri/job-uri
243 attr
= con
->request
->attrs
;
244 if (attr
&& attr
->name
&& !strcmp(attr
->name
, "attributes-charset") && (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_CHARSET
&& attr
->group_tag
== IPP_TAG_OPERATION
)
252 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
)
257 * Reset language for this request if different from Accept-Language.
260 if (!con
->language
||
261 strcmp(attr
->values
[0].string
.text
, con
->language
->language
))
263 cupsLangFree(con
->language
);
264 con
->language
= cupsLangGet(attr
->values
[0].string
.text
);
270 if ((attr
= ippFindAttribute(con
->request
, "printer-uri", IPP_TAG_URI
)) != NULL
&& attr
->group_tag
== IPP_TAG_OPERATION
)
272 else if ((attr
= ippFindAttribute(con
->request
, "job-uri", IPP_TAG_URI
)) != NULL
&& attr
->group_tag
== IPP_TAG_OPERATION
)
274 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
)
280 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
, "attributes-charset", NULL
, charset
->values
[0].string
.text
);
282 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
, "attributes-charset", NULL
, "utf-8");
285 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
, "attributes-natural-language", NULL
, language
->values
[0].string
.text
);
287 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
, "attributes-natural-language", NULL
, DefaultLanguage
);
289 if (charset
&& _cups_strcasecmp(charset
->values
[0].string
.text
, "us-ascii") && _cups_strcasecmp(charset
->values
[0].string
.text
, "utf-8"))
292 * Bad character set...
295 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unsupported character set \"%s\"",
296 charset
->values
[0].string
.text
);
297 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
);
298 send_ipp_status(con
, IPP_STATUS_ERROR_CHARSET
, _("Unsupported character set \"%s\"."), charset
->values
[0].string
.text
);
300 else if (!charset
|| !language
||
302 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEFAULT
&&
303 con
->request
->request
.op
.operation_id
!= CUPS_GET_PRINTERS
&&
304 con
->request
->request
.op
.operation_id
!= CUPS_GET_CLASSES
&&
305 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEVICES
&&
306 con
->request
->request
.op
.operation_id
!= CUPS_GET_PPDS
))
309 * Return an error, since attributes-charset,
310 * attributes-natural-language, and printer-uri/job-uri are required
311 * for all operations.
316 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing attributes-charset attribute.");
318 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
, "%04X %s Missing attributes-charset attribute.", IPP_STATUS_ERROR_BAD_REQUEST
, con
->http
->hostname
);
323 cupsdLogMessage(CUPSD_LOG_ERROR
,
324 "Missing attributes-natural-language attribute.");
326 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
, "%04X %s Missing attributes-natural-language attribute.", IPP_STATUS_ERROR_BAD_REQUEST
, con
->http
->hostname
);
331 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing printer-uri, job-uri, or ppd-name attribute.");
333 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
);
336 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Request attributes follow...");
338 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
339 cupsdLogMessage(CUPSD_LOG_DEBUG
,
340 "attr \"%s\": group_tag = %x, value_tag = %x",
341 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
344 cupsdLogMessage(CUPSD_LOG_DEBUG
, "End of attributes...");
346 send_ipp_status(con
, IPP_BAD_REQUEST
,
347 _("Missing required attributes."));
352 * OK, all the checks pass so far; validate "requesting-user-name"
356 if ((username
= ippFindAttribute(con
->request
, "requesting-user-name", IPP_TAG_ZERO
)) != NULL
)
359 * Validate "requesting-user-name"...
362 if (username
->group_tag
!= IPP_TAG_OPERATION
&& StrictConformance
)
364 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
, "%04X %s \"requesting-user-name\" attribute in wrong group.", IPP_STATUS_ERROR_BAD_REQUEST
, con
->http
->hostname
);
365 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("\"requesting-user-name\" attribute in wrong group."));
368 else if (username
->value_tag
!= IPP_TAG_NAME
&& username
->value_tag
!= IPP_TAG_NAMELANG
)
370 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
);
371 send_ipp_status(con
, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES
, _("\"requesting-user-name\" attribute with wrong syntax."));
372 if ((attr
= ippCopyAttribute(con
->response
, username
, 0)) != NULL
)
373 attr
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
376 else if (!ippValidateAttribute(username
))
378 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
);
380 if (StrictConformance
)
386 send_ipp_status(con
, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES
, _("\"requesting-user-name\" attribute with wrong syntax."));
387 if ((attr
= ippCopyAttribute(con
->response
, username
, 0)) != NULL
)
388 attr
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
394 * Map bad "requesting-user-name" to 'anonymous'...
397 ippSetString(con
->request
, &username
, 0, "anonymous");
400 else if (!strcmp(username
->values
[0].string
.text
, "root") && _cups_strcasecmp(con
->http
->hostname
, "localhost") && strcmp(con
->username
, "root"))
403 * Remote unauthenticated user masquerading as local root...
406 ippSetString(con
->request
, &username
, 0, RemoteRoot
);
410 if ((attr
= ippFindAttribute(con
->request
, "notify-subscription-id", IPP_TAG_INTEGER
)) != NULL
)
411 sub_id
= attr
->values
[0].integer
;
418 * Try processing the operation...
422 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s", ippOpString(con
->request
->request
.op
.operation_id
), uri
->values
[0].string
.text
);
424 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s", ippOpString(con
->request
->request
.op
.operation_id
));
426 switch (con
->request
->request
.op
.operation_id
)
428 case IPP_OP_PRINT_JOB
:
432 case IPP_OP_VALIDATE_JOB
:
433 validate_job(con
, uri
);
436 case IPP_OP_CREATE_JOB
:
437 create_job(con
, uri
);
440 case IPP_OP_SEND_DOCUMENT
:
441 send_document(con
, uri
);
444 case IPP_OP_CANCEL_JOB
:
445 cancel_job(con
, uri
);
448 case IPP_OP_GET_JOB_ATTRIBUTES
:
449 get_job_attrs(con
, uri
);
452 case IPP_OP_GET_JOBS
:
456 case IPP_OP_GET_PRINTER_ATTRIBUTES
:
457 get_printer_attrs(con
, uri
);
460 case IPP_OP_GET_PRINTER_SUPPORTED_VALUES
:
461 get_printer_supported(con
, uri
);
464 case IPP_OP_HOLD_JOB
:
468 case IPP_OP_RELEASE_JOB
:
469 release_job(con
, uri
);
472 case IPP_OP_RESTART_JOB
:
473 restart_job(con
, uri
);
476 case IPP_OP_PAUSE_PRINTER
:
477 stop_printer(con
, uri
);
480 case IPP_OP_RESUME_PRINTER
:
481 start_printer(con
, uri
);
484 case IPP_OP_PURGE_JOBS
:
485 case IPP_OP_CANCEL_JOBS
:
486 case IPP_OP_CANCEL_MY_JOBS
:
487 cancel_all_jobs(con
, uri
);
490 case IPP_OP_SET_JOB_ATTRIBUTES
:
491 set_job_attrs(con
, uri
);
494 case IPP_OP_SET_PRINTER_ATTRIBUTES
:
495 set_printer_attrs(con
, uri
);
498 case IPP_OP_HOLD_NEW_JOBS
:
499 hold_new_jobs(con
, uri
);
502 case IPP_OP_RELEASE_HELD_NEW_JOBS
:
503 release_held_new_jobs(con
, uri
);
506 case IPP_OP_CLOSE_JOB
:
510 case IPP_OP_CUPS_GET_DEFAULT
:
514 case IPP_OP_CUPS_GET_PRINTERS
:
515 get_printers(con
, 0);
518 case IPP_OP_CUPS_GET_CLASSES
:
519 get_printers(con
, CUPS_PRINTER_CLASS
);
522 case IPP_OP_CUPS_ADD_MODIFY_PRINTER
:
523 add_printer(con
, uri
);
526 case IPP_OP_CUPS_DELETE_PRINTER
:
527 delete_printer(con
, uri
);
530 case IPP_OP_CUPS_ADD_MODIFY_CLASS
:
534 case IPP_OP_CUPS_DELETE_CLASS
:
535 delete_printer(con
, uri
);
538 case IPP_OP_CUPS_ACCEPT_JOBS
:
539 case IPP_OP_ENABLE_PRINTER
:
540 accept_jobs(con
, uri
);
543 case IPP_OP_CUPS_REJECT_JOBS
:
544 case IPP_OP_DISABLE_PRINTER
:
545 reject_jobs(con
, uri
);
548 case IPP_OP_CUPS_SET_DEFAULT
:
549 set_default(con
, uri
);
552 case IPP_OP_CUPS_GET_DEVICES
:
556 case IPP_OP_CUPS_GET_DOCUMENT
:
557 get_document(con
, uri
);
560 case IPP_OP_CUPS_GET_PPD
:
564 case IPP_OP_CUPS_GET_PPDS
:
568 case IPP_OP_CUPS_MOVE_JOB
:
572 case IPP_OP_CUPS_AUTHENTICATE_JOB
:
573 authenticate_job(con
, uri
);
576 case IPP_OP_CREATE_PRINTER_SUBSCRIPTIONS
:
577 case IPP_OP_CREATE_JOB_SUBSCRIPTIONS
:
578 create_subscriptions(con
, uri
);
581 case IPP_OP_GET_SUBSCRIPTION_ATTRIBUTES
:
582 get_subscription_attrs(con
, sub_id
);
585 case IPP_OP_GET_SUBSCRIPTIONS
:
586 get_subscriptions(con
, uri
);
589 case IPP_OP_RENEW_SUBSCRIPTION
:
590 renew_subscription(con
, sub_id
);
593 case IPP_OP_CANCEL_SUBSCRIPTION
:
594 cancel_subscription(con
, sub_id
);
597 case IPP_OP_GET_NOTIFICATIONS
:
598 get_notifications(con
);
601 case IPP_OP_CUPS_CREATE_LOCAL_PRINTER
:
602 create_local_printer(con
);
606 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
));
608 send_ipp_status(con
, IPP_STATUS_ERROR_OPERATION_NOT_SUPPORTED
, _("%s not supported."), ippOpString(con
->request
->request
.op
.operation_id
));
619 * Sending data from the scheduler...
622 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
);
624 httpClearFields(con
->http
);
626 #ifdef CUPSD_USE_CHUNKING
628 * Because older versions of CUPS (1.1.17 and older) and some IPP
629 * clients do not implement chunking properly, we cannot use
630 * chunking by default. This may become the default in future
631 * CUPS releases, or we might add a configuration directive for
635 if (con
->http
->version
== HTTP_1_1
)
637 cupsdLogClient(con
, CUPSD_LOG_DEBUG
, "Transfer-Encoding: chunked");
638 cupsdSetLength(con
->http
, 0);
641 #endif /* CUPSD_USE_CHUNKING */
643 size_t length
; /* Length of response */
646 length
= ippLength(con
->response
);
648 if (con
->file
>= 0 && !con
->pipe_pid
)
650 struct stat fileinfo
; /* File information */
652 if (!fstat(con
->file
, &fileinfo
))
653 length
+= (size_t)fileinfo
.st_size
;
656 cupsdLogClient(con
, CUPSD_LOG_DEBUG
, "Content-Length: " CUPS_LLFMT
, CUPS_LLCAST length
);
657 httpSetLength(con
->http
, length
);
660 if (cupsdSendHeader(con
, HTTP_OK
, "application/ipp", CUPSD_AUTH_NONE
))
663 * Tell the caller the response header was sent successfully...
666 cupsdAddSelect(httpGetFd(con
->http
), (cupsd_selfunc_t
)cupsdReadClient
, (cupsd_selfunc_t
)cupsdWriteClient
, con
);
673 * Tell the caller the response header could not be sent...
682 * Sending data from a subprocess like cups-deviced; tell the caller
683 * everything is A-OK so far...
692 * 'cupsdTimeoutJob()' - Timeout a job waiting on job files.
695 int /* O - 0 on success, -1 on error */
696 cupsdTimeoutJob(cupsd_job_t
*job
) /* I - Job to timeout */
698 cupsd_printer_t
*printer
; /* Destination printer or class */
699 ipp_attribute_t
*attr
; /* job-sheets attribute */
700 int kbytes
; /* Kilobytes in banner */
703 job
->pending_timeout
= 0;
706 * See if we need to add the ending sheet...
709 if (!cupsdLoadJob(job
))
712 printer
= cupsdFindDest(job
->dest
);
713 attr
= ippFindAttribute(job
->attrs
, "job-sheets", IPP_TAG_NAME
);
715 if (printer
&& !(printer
->type
& CUPS_PRINTER_REMOTE
) &&
716 attr
&& attr
->num_values
> 1)
722 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding end banner page \"%s\".",
723 attr
->values
[1].string
.text
);
725 if ((kbytes
= copy_banner(NULL
, job
, attr
->values
[1].string
.text
)) < 0)
728 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
736 * 'accept_jobs()' - Accept print jobs to a printer.
740 accept_jobs(cupsd_client_t
*con
, /* I - Client connection */
741 ipp_attribute_t
*uri
) /* I - Printer or class URI */
743 http_status_t status
; /* Policy status */
744 cups_ptype_t dtype
; /* Destination type (printer/class) */
745 cupsd_printer_t
*printer
; /* Printer data */
748 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "accept_jobs(%p[%d], %s)", con
,
749 con
->number
, uri
->values
[0].string
.text
);
752 * Is the destination valid?
755 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
761 send_ipp_status(con
, IPP_NOT_FOUND
,
762 _("The printer or class does not exist."));
770 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
772 send_http_error(con
, status
, printer
);
777 * Accept jobs sent to the printer...
780 printer
->accepting
= 1;
781 printer
->state_message
[0] = '\0';
783 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
784 "Now accepting jobs.");
786 if (dtype
& CUPS_PRINTER_CLASS
)
788 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
790 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" now accepting jobs (\"%s\").",
791 printer
->name
, get_username(con
));
795 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
797 cupsdLogMessage(CUPSD_LOG_INFO
,
798 "Printer \"%s\" now accepting jobs (\"%s\").",
799 printer
->name
, get_username(con
));
803 * Everything was ok, so return OK status...
806 con
->response
->request
.status
.status_code
= IPP_OK
;
811 * 'add_class()' - Add a class to the system.
815 add_class(cupsd_client_t
*con
, /* I - Client connection */
816 ipp_attribute_t
*uri
) /* I - URI of class */
818 http_status_t status
; /* Policy status */
819 int i
; /* Looping var */
820 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
821 username
[HTTP_MAX_URI
], /* Username portion of URI */
822 host
[HTTP_MAX_URI
], /* Host portion of URI */
823 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
824 int port
; /* Port portion of URI */
825 cupsd_printer_t
*pclass
, /* Class */
826 *member
; /* Member printer/class */
827 cups_ptype_t dtype
; /* Destination type */
828 ipp_attribute_t
*attr
; /* Printer attribute */
829 int modify
; /* Non-zero if we just modified */
830 int need_restart_job
; /* Need to restart job? */
833 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_class(%p[%d], %s)", con
,
834 con
->number
, uri
->values
[0].string
.text
);
837 * Do we have a valid URI?
840 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
841 sizeof(scheme
), username
, sizeof(username
), host
,
842 sizeof(host
), &port
, resource
, sizeof(resource
));
845 if (strncmp(resource
, "/classes/", 9) || strlen(resource
) == 9)
848 * No, return an error...
851 send_ipp_status(con
, IPP_BAD_REQUEST
,
852 _("The printer-uri must be of the form "
853 "\"ipp://HOSTNAME/classes/CLASSNAME\"."));
858 * Do we have a valid printer name?
861 if (!validate_name(resource
+ 9))
864 * No, return an error...
867 send_ipp_status(con
, IPP_BAD_REQUEST
,
868 _("The printer-uri \"%s\" contains invalid characters."),
869 uri
->values
[0].string
.text
);
874 * See if the class already exists; if not, create a new class...
877 if ((pclass
= cupsdFindClass(resource
+ 9)) == NULL
)
880 * Class doesn't exist; see if we have a printer of the same name...
883 if ((pclass
= cupsdFindPrinter(resource
+ 9)) != NULL
)
886 * Yes, return an error...
889 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
890 _("A printer named \"%s\" already exists."),
896 * No, check the default policy and then add the class...
899 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
901 send_http_error(con
, status
, NULL
);
905 pclass
= cupsdAddClass(resource
+ 9);
908 pclass
->printer_id
= NextPrinterId
++;
910 else if ((status
= cupsdCheckPolicy(pclass
->op_policy_ptr
, con
,
913 send_http_error(con
, status
, pclass
);
920 * Look for attributes and copy them over as needed...
923 need_restart_job
= 0;
925 if ((attr
= ippFindAttribute(con
->request
, "printer-location", IPP_TAG_TEXT
)) != NULL
)
926 cupsdSetString(&pclass
->location
, attr
->values
[0].string
.text
);
928 if ((attr
= ippFindAttribute(con
->request
, "printer-geo-location", IPP_TAG_URI
)) != NULL
&& !strncmp(attr
->values
[0].string
.text
, "geo:", 4))
929 cupsdSetString(&pclass
->geo_location
, attr
->values
[0].string
.text
);
931 if ((attr
= ippFindAttribute(con
->request
, "printer-organization", IPP_TAG_TEXT
)) != NULL
)
932 cupsdSetString(&pclass
->organization
, attr
->values
[0].string
.text
);
934 if ((attr
= ippFindAttribute(con
->request
, "printer-organizational-unit", IPP_TAG_TEXT
)) != NULL
)
935 cupsdSetString(&pclass
->organizational_unit
, attr
->values
[0].string
.text
);
937 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
938 IPP_TAG_TEXT
)) != NULL
)
939 cupsdSetString(&pclass
->info
, attr
->values
[0].string
.text
);
941 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
942 IPP_TAG_BOOLEAN
)) != NULL
&&
943 attr
->values
[0].boolean
!= pclass
->accepting
)
945 cupsdLogMessage(CUPSD_LOG_INFO
,
946 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
947 pclass
->name
, attr
->values
[0].boolean
, pclass
->accepting
);
949 pclass
->accepting
= attr
->values
[0].boolean
;
951 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s accepting jobs.",
952 pclass
->accepting
? "Now" : "No longer");
955 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared", IPP_TAG_BOOLEAN
)) != NULL
)
957 if (pclass
->type
& CUPS_PRINTER_REMOTE
)
960 * Cannot re-share remote printers.
963 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Cannot change printer-is-shared for remote queues."));
965 cupsdDeletePrinter(pclass
, 0);
970 if (pclass
->shared
&& !ippGetBoolean(attr
, 0))
971 cupsdDeregisterPrinter(pclass
, 1);
973 cupsdLogMessage(CUPSD_LOG_INFO
,
974 "Setting %s printer-is-shared to %d (was %d.)",
975 pclass
->name
, attr
->values
[0].boolean
, pclass
->shared
);
977 pclass
->shared
= ippGetBoolean(attr
, 0);
980 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
981 IPP_TAG_ENUM
)) != NULL
)
983 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
984 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
986 send_ipp_status(con
, IPP_BAD_REQUEST
,
987 _("Attempt to set %s printer-state to bad value %d."),
988 pclass
->name
, attr
->values
[0].integer
);
990 cupsdDeletePrinter(pclass
, 0);
995 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
996 pclass
->name
, attr
->values
[0].integer
, pclass
->state
);
998 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
999 cupsdStopPrinter(pclass
, 0);
1002 cupsdSetPrinterState(pclass
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
1003 need_restart_job
= 1;
1006 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
1007 IPP_TAG_TEXT
)) != NULL
)
1009 strlcpy(pclass
->state_message
, attr
->values
[0].string
.text
,
1010 sizeof(pclass
->state_message
));
1012 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s",
1013 pclass
->state_message
);
1015 if ((attr
= ippFindAttribute(con
->request
, "member-uris",
1016 IPP_TAG_URI
)) != NULL
)
1019 * Clear the printer array as needed...
1022 need_restart_job
= 1;
1024 if (pclass
->num_printers
> 0)
1026 free(pclass
->printers
);
1027 pclass
->num_printers
= 0;
1031 * Add each printer or class that is listed...
1034 for (i
= 0; i
< attr
->num_values
; i
++)
1037 * Search for the printer or class URI...
1040 if (!cupsdValidateDest(attr
->values
[i
].string
.text
, &dtype
, &member
))
1046 send_ipp_status(con
, IPP_NOT_FOUND
,
1047 _("The printer or class does not exist."));
1049 cupsdDeletePrinter(pclass
, 0);
1053 else if (dtype
& CUPS_PRINTER_CLASS
)
1055 send_ipp_status(con
, IPP_BAD_REQUEST
,
1056 _("Nested classes are not allowed."));
1058 cupsdDeletePrinter(pclass
, 0);
1064 * Add it to the class...
1067 cupsdAddPrinterToClass(pclass
, member
);
1071 if (!set_printer_defaults(con
, pclass
))
1074 cupsdDeletePrinter(pclass
, 0);
1079 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
1080 IPP_TAG_KEYWORD
)) != NULL
)
1081 cupsdSetAuthInfoRequired(pclass
, NULL
, attr
);
1083 pclass
->config_time
= time(NULL
);
1086 * Update the printer class attributes and return...
1089 cupsdSetPrinterAttrs(pclass
);
1090 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
1092 if (need_restart_job
&& pclass
->job
)
1095 * Reset the current job to a "pending" status...
1098 cupsdSetJobState(pclass
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
1099 "Job restarted because the class was modified.");
1102 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1106 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
1107 pclass
, NULL
, "Class \"%s\" modified by \"%s\".",
1108 pclass
->name
, get_username(con
));
1110 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" modified by \"%s\".",
1111 pclass
->name
, get_username(con
));
1115 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
1116 pclass
, NULL
, "New class \"%s\" added by \"%s\".",
1117 pclass
->name
, get_username(con
));
1119 cupsdLogMessage(CUPSD_LOG_INFO
, "New class \"%s\" added by \"%s\".",
1120 pclass
->name
, get_username(con
));
1123 con
->response
->request
.status
.status_code
= IPP_OK
;
1128 * 'add_file()' - Add a file to a job.
1131 static int /* O - 0 on success, -1 on error */
1132 add_file(cupsd_client_t
*con
, /* I - Connection to client */
1133 cupsd_job_t
*job
, /* I - Job to add to */
1134 mime_type_t
*filetype
, /* I - Type of file */
1135 int compression
) /* I - Compression */
1137 mime_type_t
**filetypes
; /* New filetypes array... */
1138 int *compressions
; /* New compressions array... */
1141 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1142 "add_file(con=%p[%d], job=%d, filetype=%s/%s, "
1143 "compression=%d)", con
, con
? con
->number
: -1, job
->id
,
1144 filetype
->super
, filetype
->type
, compression
);
1147 * Add the file to the job...
1150 if (job
->num_files
== 0)
1152 compressions
= (int *)malloc(sizeof(int));
1153 filetypes
= (mime_type_t
**)malloc(sizeof(mime_type_t
*));
1157 compressions
= (int *)realloc(job
->compressions
,
1158 (size_t)(job
->num_files
+ 1) * sizeof(int));
1159 filetypes
= (mime_type_t
**)realloc(job
->filetypes
,
1160 (size_t)(job
->num_files
+ 1) *
1161 sizeof(mime_type_t
*));
1165 job
->compressions
= compressions
;
1168 job
->filetypes
= filetypes
;
1170 if (!compressions
|| !filetypes
)
1172 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1173 "Job aborted because the scheduler ran out of memory.");
1176 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1177 _("Unable to allocate memory for file types."));
1182 job
->compressions
[job
->num_files
] = compression
;
1183 job
->filetypes
[job
->num_files
] = filetype
;
1188 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1195 * 'add_job()' - Add a job to a print queue.
1198 static cupsd_job_t
* /* O - Job object */
1199 add_job(cupsd_client_t
*con
, /* I - Client connection */
1200 cupsd_printer_t
*printer
, /* I - Destination printer */
1201 mime_type_t
*filetype
) /* I - First print file type, if any */
1203 http_status_t status
; /* Policy status */
1204 ipp_attribute_t
*attr
, /* Current attribute */
1205 *auth_info
; /* auth-info attribute */
1206 const char *mandatory
; /* Current mandatory job attribute */
1207 const char *val
; /* Default option value */
1208 int priority
; /* Job priority */
1209 cupsd_job_t
*job
; /* Current job */
1210 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
1211 int kbytes
; /* Size of print file */
1212 int i
; /* Looping var */
1213 int lowerpagerange
; /* Page range bound */
1214 int exact
; /* Did we have an exact match? */
1215 ipp_attribute_t
*media_col
, /* media-col attribute */
1216 *media_margin
; /* media-*-margin attribute */
1217 ipp_t
*unsup_col
; /* media-col in unsupported response */
1218 static const char * const readonly
[] =/* List of read-only attributes */
1220 "date-time-at-completed",
1221 "date-time-at-creation",
1222 "date-time-at-processing",
1223 "job-detailed-status-messages",
1224 "job-document-access-errors",
1226 "job-impressions-completed",
1227 "job-k-octets-completed",
1228 "job-media-sheets-completed",
1229 "job-pages-completed",
1230 "job-printer-up-time",
1233 "job-state-message",
1234 "job-state-reasons",
1236 "number-of-documents",
1237 "number-of-intervening-jobs",
1238 "output-device-assigned",
1239 "time-at-completed",
1241 "time-at-processing"
1245 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job(%p[%d], %p(%s), %p(%s/%s))",
1246 con
, con
->number
, printer
, printer
->name
,
1247 filetype
, filetype
? filetype
->super
: "none",
1248 filetype
? filetype
->type
: "none");
1251 * Check remote printing to non-shared printer...
1254 if (!printer
->shared
&&
1255 _cups_strcasecmp(con
->http
->hostname
, "localhost") &&
1256 _cups_strcasecmp(con
->http
->hostname
, ServerName
))
1258 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
1259 _("The printer or class is not shared."));
1267 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
1269 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
1271 send_http_error(con
, status
, printer
);
1274 else if (printer
->num_auth_info_required
== 1 &&
1275 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
1278 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
1282 else if (auth_info
&& !con
->http
->tls
&&
1283 !httpAddrLocalhost(con
->http
->hostaddr
))
1286 * Require encryption of auth-info over non-local connections...
1289 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
1292 #endif /* HAVE_SSL */
1295 * See if the printer is accepting jobs...
1298 if (!printer
->accepting
)
1300 send_ipp_status(con
, IPP_NOT_ACCEPTING
,
1301 _("Destination \"%s\" is not accepting jobs."),
1307 * Validate job template attributes; for now just document-format,
1308 * copies, job-sheets, number-up, page-ranges, mandatory attributes, and
1312 for (i
= 0; i
< (int)(sizeof(readonly
) / sizeof(readonly
[0])); i
++)
1314 if ((attr
= ippFindAttribute(con
->request
, readonly
[i
], IPP_TAG_ZERO
)) != NULL
)
1316 ippDeleteAttribute(con
->request
, attr
);
1318 if (StrictConformance
)
1320 send_ipp_status(con
, IPP_BAD_REQUEST
, _("The '%s' Job Status attribute cannot be supplied in a job creation request."), readonly
[i
]);
1324 cupsdLogMessage(CUPSD_LOG_INFO
, "Unexpected '%s' Job Status attribute in a job creation request.", readonly
[i
]);
1330 for (mandatory
= (char *)cupsArrayFirst(printer
->pc
->mandatory
);
1332 mandatory
= (char *)cupsArrayNext(printer
->pc
->mandatory
))
1334 if (!ippFindAttribute(con
->request
, mandatory
, IPP_TAG_ZERO
))
1337 * Missing a required attribute...
1340 send_ipp_status(con
, IPP_CONFLICT
,
1341 _("The \"%s\" attribute is required for print jobs."),
1348 if (filetype
&& printer
->filetypes
&&
1349 !cupsArrayFind(printer
->filetypes
, filetype
))
1351 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
1352 /* MIME media type string */
1355 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
1358 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
1359 _("Unsupported format \"%s\"."), mimetype
);
1361 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
1362 "document-format", NULL
, mimetype
);
1367 if ((attr
= ippFindAttribute(con
->request
, "copies",
1368 IPP_TAG_INTEGER
)) != NULL
)
1370 if (attr
->values
[0].integer
< 1 || attr
->values
[0].integer
> MaxCopies
)
1372 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad copies value %d."),
1373 attr
->values
[0].integer
);
1374 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1375 "copies", attr
->values
[0].integer
);
1380 if ((attr
= ippFindAttribute(con
->request
, "job-sheets",
1381 IPP_TAG_ZERO
)) != NULL
)
1383 if (attr
->value_tag
!= IPP_TAG_KEYWORD
&&
1384 attr
->value_tag
!= IPP_TAG_NAME
)
1386 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value type."));
1390 if (attr
->num_values
> 2)
1392 send_ipp_status(con
, IPP_BAD_REQUEST
,
1393 _("Too many job-sheets values (%d > 2)."),
1398 for (i
= 0; i
< attr
->num_values
; i
++)
1399 if (strcmp(attr
->values
[i
].string
.text
, "none") &&
1400 !cupsdFindBanner(attr
->values
[i
].string
.text
))
1402 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value \"%s\"."),
1403 attr
->values
[i
].string
.text
);
1408 if ((attr
= ippFindAttribute(con
->request
, "number-up",
1409 IPP_TAG_INTEGER
)) != NULL
)
1411 if (attr
->values
[0].integer
!= 1 &&
1412 attr
->values
[0].integer
!= 2 &&
1413 attr
->values
[0].integer
!= 4 &&
1414 attr
->values
[0].integer
!= 6 &&
1415 attr
->values
[0].integer
!= 9 &&
1416 attr
->values
[0].integer
!= 16)
1418 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad number-up value %d."),
1419 attr
->values
[0].integer
);
1420 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1421 "number-up", attr
->values
[0].integer
);
1426 if ((attr
= ippFindAttribute(con
->request
, "page-ranges",
1427 IPP_TAG_RANGE
)) != NULL
)
1429 for (i
= 0, lowerpagerange
= 1; i
< attr
->num_values
; i
++)
1431 if (attr
->values
[i
].range
.lower
< lowerpagerange
||
1432 attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
1434 send_ipp_status(con
, IPP_BAD_REQUEST
,
1435 _("Bad page-ranges values %d-%d."),
1436 attr
->values
[i
].range
.lower
,
1437 attr
->values
[i
].range
.upper
);
1441 lowerpagerange
= attr
->values
[i
].range
.upper
+ 1;
1446 * Do media selection as needed...
1449 if (!ippFindAttribute(con
->request
, "PageRegion", IPP_TAG_ZERO
) &&
1450 !ippFindAttribute(con
->request
, "PageSize", IPP_TAG_ZERO
) &&
1451 _ppdCacheGetPageSize(printer
->pc
, con
->request
, NULL
, &exact
))
1454 (media_col
= ippFindAttribute(con
->request
, "media-col",
1455 IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
1457 send_ipp_status(con
, IPP_OK_SUBST
, _("Unsupported margins."));
1459 unsup_col
= ippNew();
1460 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1461 "media-bottom-margin",
1462 IPP_TAG_INTEGER
)) != NULL
)
1463 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1464 "media-bottom-margin", media_margin
->values
[0].integer
);
1466 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1467 "media-left-margin",
1468 IPP_TAG_INTEGER
)) != NULL
)
1469 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1470 "media-left-margin", media_margin
->values
[0].integer
);
1472 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1473 "media-right-margin",
1474 IPP_TAG_INTEGER
)) != NULL
)
1475 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1476 "media-right-margin", media_margin
->values
[0].integer
);
1478 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1480 IPP_TAG_INTEGER
)) != NULL
)
1481 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1482 "media-top-margin", media_margin
->values
[0].integer
);
1484 ippAddCollection(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, "media-col",
1486 ippDelete(unsup_col
);
1491 * Make sure we aren't over our limit...
1494 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1497 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1499 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Too many active jobs."));
1503 if ((i
= check_quotas(con
, printer
)) < 0)
1505 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
1510 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
1515 * Create the job and set things up...
1518 if ((attr
= ippFindAttribute(con
->request
, "job-priority",
1519 IPP_TAG_INTEGER
)) != NULL
)
1520 priority
= attr
->values
[0].integer
;
1523 if ((val
= cupsGetOption("job-priority", printer
->num_options
,
1524 printer
->options
)) != NULL
)
1525 priority
= atoi(val
);
1529 ippAddInteger(con
->request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-priority",
1533 if ((attr
= ippFindAttribute(con
->request
, "job-name", IPP_TAG_ZERO
)) == NULL
)
1534 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
, "Untitled");
1535 else if ((attr
->value_tag
!= IPP_TAG_NAME
&&
1536 attr
->value_tag
!= IPP_TAG_NAMELANG
) ||
1537 attr
->num_values
!= 1)
1539 send_ipp_status(con
, IPP_ATTRIBUTES
,
1540 _("Bad job-name value: Wrong type or count."));
1541 if ((attr
= ippCopyAttribute(con
->response
, attr
, 0)) != NULL
)
1542 attr
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
1544 if (StrictConformance
)
1547 /* Don't use invalid attribute */
1548 ippDeleteAttribute(con
->request
, attr
);
1550 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
, "Untitled");
1552 else if (!ippValidateAttribute(attr
))
1554 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad job-name value: %s"),
1555 cupsLastErrorString());
1557 if ((attr
= ippCopyAttribute(con
->response
, attr
, 0)) != NULL
)
1558 attr
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
1560 if (StrictConformance
)
1563 /* Don't use invalid attribute */
1564 ippDeleteAttribute(con
->request
, attr
);
1566 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
, "Untitled");
1569 attr
= ippFindAttribute(con
->request
, "requesting-user-name", IPP_TAG_NAME
);
1571 if ((job
= cupsdAddJob(priority
, printer
->name
)) == NULL
)
1573 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1574 _("Unable to add job for destination \"%s\"."),
1579 job
->dtype
= printer
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
1580 job
->attrs
= con
->request
;
1582 con
->request
= ippNewRequest(job
->attrs
->request
.op
.operation_id
);
1584 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1587 apply_printer_defaults(printer
, job
);
1589 if (con
->username
[0])
1591 cupsdSetString(&job
->username
, con
->username
);
1594 ippSetString(job
->attrs
, &attr
, 0, con
->username
);
1598 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1599 "add_job: requesting-user-name=\"%s\"",
1600 attr
->values
[0].string
.text
);
1602 cupsdSetString(&job
->username
, attr
->values
[0].string
.text
);
1605 cupsdSetString(&job
->username
, "anonymous");
1608 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1609 "job-originating-user-name", NULL
, job
->username
);
1612 ippSetGroupTag(job
->attrs
, &attr
, IPP_TAG_JOB
);
1613 ippSetName(job
->attrs
, &attr
, "job-originating-user-name");
1616 if (con
->username
[0] || auth_info
)
1618 save_auth_info(con
, job
, auth_info
);
1621 * Remove the auth-info attribute from the attribute data...
1625 ippDeleteAttribute(job
->attrs
, auth_info
);
1628 if ((attr
= ippFindAttribute(con
->request
, "job-name", IPP_TAG_NAME
)) != NULL
)
1629 cupsdSetString(&(job
->name
), attr
->values
[0].string
.text
);
1631 if ((attr
= ippFindAttribute(job
->attrs
, "job-originating-host-name",
1632 IPP_TAG_ZERO
)) != NULL
)
1635 * Request contains a job-originating-host-name attribute; validate it...
1638 if (attr
->value_tag
!= IPP_TAG_NAME
||
1639 attr
->num_values
!= 1 ||
1640 strcmp(con
->http
->hostname
, "localhost"))
1643 * Can't override the value if we aren't connected via localhost.
1644 * Also, we can only have 1 value and it must be a name value.
1647 ippDeleteAttribute(job
->attrs
, attr
);
1648 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-originating-host-name", NULL
, con
->http
->hostname
);
1651 ippSetGroupTag(job
->attrs
, &attr
, IPP_TAG_JOB
);
1656 * No job-originating-host-name attribute, so use the hostname from
1660 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1661 "job-originating-host-name", NULL
, con
->http
->hostname
);
1664 ippAddOutOfBand(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NOVALUE
, "date-time-at-completed");
1665 ippAddDate(job
->attrs
, IPP_TAG_JOB
, "date-time-at-creation", ippTimeToDate(time(NULL
)));
1666 ippAddOutOfBand(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NOVALUE
, "date-time-at-processing");
1667 ippAddOutOfBand(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NOVALUE
, "time-at-completed");
1668 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation", time(NULL
));
1669 ippAddOutOfBand(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NOVALUE
, "time-at-processing");
1672 * Add remaining job attributes...
1675 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1676 job
->state
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_ENUM
,
1677 "job-state", IPP_JOB_STOPPED
);
1678 job
->state_value
= (ipp_jstate_t
)job
->state
->values
[0].integer
;
1679 job
->reasons
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1680 "job-state-reasons", NULL
, "job-incoming");
1681 job
->impressions
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-impressions-completed", 0);
1682 job
->sheets
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1683 "job-media-sheets-completed", 0);
1684 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-printer-uri", NULL
,
1687 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets", IPP_TAG_INTEGER
)) != NULL
)
1688 attr
->values
[0].integer
= 0;
1690 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-k-octets", 0);
1692 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
1693 IPP_TAG_KEYWORD
)) == NULL
)
1694 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
1697 if ((val
= cupsGetOption("job-hold-until", printer
->num_options
,
1698 printer
->options
)) == NULL
)
1701 attr
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1702 "job-hold-until", NULL
, val
);
1705 if (printer
->holding_new_jobs
)
1708 * Hold all new jobs on this printer...
1711 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
1712 cupsdSetJobHoldUntil(job
, ippGetString(attr
, 0, NULL
), 0);
1714 cupsdSetJobHoldUntil(job
, "indefinite", 0);
1716 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1717 job
->state_value
= IPP_JOB_HELD
;
1719 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-held-on-create");
1721 else if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
1724 * Hold job until specified time...
1727 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
1729 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1730 job
->state_value
= IPP_JOB_HELD
;
1732 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-hold-until-specified");
1734 else if (job
->attrs
->request
.op
.operation_id
== IPP_CREATE_JOB
)
1736 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
1737 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1738 job
->state_value
= IPP_JOB_HELD
;
1742 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1743 job
->state_value
= IPP_JOB_PENDING
;
1745 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
1748 if (!(printer
->type
& CUPS_PRINTER_REMOTE
) || Classification
)
1751 * Add job sheets options...
1754 if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1755 IPP_TAG_ZERO
)) == NULL
)
1757 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1758 "Adding default job-sheets values \"%s,%s\"...",
1759 printer
->job_sheets
[0], printer
->job_sheets
[1]);
1761 attr
= ippAddStrings(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-sheets",
1763 ippSetString(job
->attrs
, &attr
, 0, printer
->job_sheets
[0]);
1764 ippSetString(job
->attrs
, &attr
, 1, printer
->job_sheets
[1]);
1767 job
->job_sheets
= attr
;
1770 * Enforce classification level if set...
1775 cupsdLogMessage(CUPSD_LOG_INFO
,
1776 "Classification=\"%s\", ClassifyOverride=%d",
1777 Classification
? Classification
: "(null)",
1780 if (ClassifyOverride
)
1782 if (!strcmp(attr
->values
[0].string
.text
, "none") &&
1783 (attr
->num_values
== 1 ||
1784 !strcmp(attr
->values
[1].string
.text
, "none")))
1787 * Force the leading banner to have the classification on it...
1790 ippSetString(job
->attrs
, &attr
, 0, Classification
);
1792 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1793 "job-sheets=\"%s,none\", "
1794 "job-originating-user-name=\"%s\"",
1795 Classification
, job
->username
);
1797 else if (attr
->num_values
== 2 &&
1798 strcmp(attr
->values
[0].string
.text
,
1799 attr
->values
[1].string
.text
) &&
1800 strcmp(attr
->values
[0].string
.text
, "none") &&
1801 strcmp(attr
->values
[1].string
.text
, "none"))
1804 * Can't put two different security markings on the same document!
1807 ippSetString(job
->attrs
, &attr
, 1, attr
->values
[0].string
.text
);
1809 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1810 "job-sheets=\"%s,%s\", "
1811 "job-originating-user-name=\"%s\"",
1812 attr
->values
[0].string
.text
,
1813 attr
->values
[1].string
.text
, job
->username
);
1815 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1816 strcmp(attr
->values
[0].string
.text
, "none") &&
1817 (attr
->num_values
== 1 ||
1818 (strcmp(attr
->values
[1].string
.text
, Classification
) &&
1819 strcmp(attr
->values
[1].string
.text
, "none"))))
1821 if (attr
->num_values
== 1)
1822 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1823 "CLASSIFICATION OVERRIDDEN "
1824 "job-sheets=\"%s\", "
1825 "job-originating-user-name=\"%s\"",
1826 attr
->values
[0].string
.text
, job
->username
);
1828 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1829 "CLASSIFICATION OVERRIDDEN "
1830 "job-sheets=\"%s,%s\",fffff "
1831 "job-originating-user-name=\"%s\"",
1832 attr
->values
[0].string
.text
,
1833 attr
->values
[1].string
.text
, job
->username
);
1836 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1837 (attr
->num_values
== 1 ||
1838 strcmp(attr
->values
[1].string
.text
, Classification
)))
1841 * Force the banner to have the classification on it...
1844 if (attr
->num_values
> 1 &&
1845 !strcmp(attr
->values
[0].string
.text
, attr
->values
[1].string
.text
))
1847 ippSetString(job
->attrs
, &attr
, 0, Classification
);
1848 ippSetString(job
->attrs
, &attr
, 1, Classification
);
1852 if (attr
->num_values
== 1 ||
1853 strcmp(attr
->values
[0].string
.text
, "none"))
1854 ippSetString(job
->attrs
, &attr
, 0, Classification
);
1856 if (attr
->num_values
> 1 &&
1857 strcmp(attr
->values
[1].string
.text
, "none"))
1858 ippSetString(job
->attrs
, &attr
, 1, Classification
);
1861 if (attr
->num_values
> 1)
1862 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1863 "CLASSIFICATION FORCED "
1864 "job-sheets=\"%s,%s\", "
1865 "job-originating-user-name=\"%s\"",
1866 attr
->values
[0].string
.text
,
1867 attr
->values
[1].string
.text
, job
->username
);
1869 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1870 "CLASSIFICATION FORCED "
1871 "job-sheets=\"%s\", "
1872 "job-originating-user-name=\"%s\"",
1873 Classification
, job
->username
);
1878 * See if we need to add the starting sheet...
1881 if (!(printer
->type
& CUPS_PRINTER_REMOTE
))
1883 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding start banner page \"%s\".",
1884 attr
->values
[0].string
.text
);
1886 if ((kbytes
= copy_banner(con
, job
, attr
->values
[0].string
.text
)) < 0)
1888 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1889 "Aborting job because the start banner could not be "
1894 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
1897 else if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1898 IPP_TAG_ZERO
)) != NULL
)
1899 job
->job_sheets
= attr
;
1902 * Fill in the response info...
1905 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
1906 con
->clientname
, con
->clientport
, "/jobs/%d", job
->id
);
1907 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
1910 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1912 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
1914 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_TEXT
, "job-state-message", NULL
, "");
1915 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons",
1916 NULL
, job
->reasons
->values
[0].string
.text
);
1918 con
->response
->request
.status
.status_code
= IPP_OK
;
1921 * Add any job subscriptions...
1924 add_job_subscriptions(con
, job
);
1927 * Set all but the first two attributes to the job attributes group...
1930 for (attr
= job
->attrs
->attrs
->next
->next
; attr
; attr
= attr
->next
)
1931 attr
->group_tag
= IPP_TAG_JOB
;
1934 * Fire the "job created" event...
1937 cupsdAddEvent(CUPSD_EVENT_JOB_CREATED
, printer
, job
, "Job created.");
1940 * Return the new job...
1948 * 'add_job_subscriptions()' - Add any subscriptions for a job.
1952 add_job_subscriptions(
1953 cupsd_client_t
*con
, /* I - Client connection */
1954 cupsd_job_t
*job
) /* I - Newly created job */
1956 int i
; /* Looping var */
1957 ipp_attribute_t
*prev
, /* Previous attribute */
1958 *next
, /* Next attribute */
1959 *attr
; /* Current attribute */
1960 cupsd_subscription_t
*sub
; /* Subscription object */
1961 const char *recipient
, /* notify-recipient-uri */
1962 *pullmethod
; /* notify-pull-method */
1963 ipp_attribute_t
*user_data
; /* notify-user-data */
1964 int interval
; /* notify-time-interval */
1965 unsigned mask
; /* notify-events */
1969 * Find the first subscription group attribute; return if we have
1973 for (attr
= job
->attrs
->attrs
; attr
; attr
= attr
->next
)
1974 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
1981 * Process the subscription attributes in the request...
1990 mask
= CUPSD_EVENT_NONE
;
1992 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
1994 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
1995 attr
->value_tag
== IPP_TAG_URI
)
1998 * Validate the recipient scheme against the ServerBin/notifier
2002 char notifier
[1024], /* Notifier filename */
2003 scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
2004 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
2005 host
[HTTP_MAX_URI
], /* Host portion of URI */
2006 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2007 int port
; /* Port portion of URI */
2008 struct stat info
; /* File information */
2010 recipient
= attr
->values
[0].string
.text
;
2012 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
2013 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
2014 host
, sizeof(host
), &port
,
2015 resource
, sizeof(resource
)) < HTTP_URI_OK
)
2017 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2018 _("Bad notify-recipient-uri \"%s\"."), recipient
);
2019 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2020 "notify-status-code", IPP_URI_SCHEME
);
2024 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
, scheme
);
2025 if (access(notifier
, X_OK
) || stat(notifier
, &info
) || !S_ISREG(info
.st_mode
))
2027 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2028 _("notify-recipient-uri URI \"%s\" uses unknown "
2029 "scheme."), recipient
);
2030 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2031 "notify-status-code", IPP_URI_SCHEME
);
2035 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
2037 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2038 _("notify-recipient-uri URI \"%s\" is already used."),
2040 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2041 "notify-status-code", IPP_ATTRIBUTES
);
2045 else if (!strcmp(attr
->name
, "notify-pull-method") &&
2046 attr
->value_tag
== IPP_TAG_KEYWORD
)
2048 pullmethod
= attr
->values
[0].string
.text
;
2050 if (strcmp(pullmethod
, "ippget"))
2052 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2053 _("Bad notify-pull-method \"%s\"."), pullmethod
);
2054 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2055 "notify-status-code", IPP_ATTRIBUTES
);
2059 else if (!strcmp(attr
->name
, "notify-charset") &&
2060 attr
->value_tag
== IPP_TAG_CHARSET
&&
2061 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
2062 strcmp(attr
->values
[0].string
.text
, "utf-8"))
2064 send_ipp_status(con
, IPP_CHARSET
,
2065 _("Character set \"%s\" not supported."),
2066 attr
->values
[0].string
.text
);
2069 else if (!strcmp(attr
->name
, "notify-natural-language") &&
2070 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
2071 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
2073 send_ipp_status(con
, IPP_CHARSET
,
2074 _("Language \"%s\" not supported."),
2075 attr
->values
[0].string
.text
);
2078 else if (!strcmp(attr
->name
, "notify-user-data") &&
2079 attr
->value_tag
== IPP_TAG_STRING
)
2081 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
2083 send_ipp_status(con
, IPP_REQUEST_VALUE
,
2084 _("The notify-user-data value is too large "
2085 "(%d > 63 octets)."),
2086 attr
->values
[0].unknown
.length
);
2092 else if (!strcmp(attr
->name
, "notify-events") &&
2093 attr
->value_tag
== IPP_TAG_KEYWORD
)
2095 for (i
= 0; i
< attr
->num_values
; i
++)
2096 mask
|= cupsdEventValue(attr
->values
[i
].string
.text
);
2098 else if (!strcmp(attr
->name
, "notify-lease-duration"))
2100 send_ipp_status(con
, IPP_BAD_REQUEST
,
2101 _("The notify-lease-duration attribute cannot be "
2102 "used with job subscriptions."));
2105 else if (!strcmp(attr
->name
, "notify-time-interval") &&
2106 attr
->value_tag
== IPP_TAG_INTEGER
)
2107 interval
= attr
->values
[0].integer
;
2112 if (!recipient
&& !pullmethod
)
2115 if (mask
== CUPSD_EVENT_NONE
)
2116 mask
= CUPSD_EVENT_JOB_COMPLETED
;
2118 if ((sub
= cupsdAddSubscription(mask
, cupsdFindDest(job
->dest
), job
,
2119 recipient
, 0)) != NULL
)
2121 sub
->interval
= interval
;
2123 cupsdSetString(&sub
->owner
, job
->username
);
2127 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
2128 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
2129 (size_t)sub
->user_data_len
);
2132 ippAddSeparator(con
->response
);
2133 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
2134 "notify-subscription-id", sub
->id
);
2136 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
2144 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
2147 * Remove all of the subscription attributes from the job request...
2149 * TODO: Optimize this since subscription groups have to come at the
2150 * end of the request...
2153 for (attr
= job
->attrs
->attrs
, prev
= NULL
; attr
; attr
= next
)
2157 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
||
2158 attr
->group_tag
== IPP_TAG_ZERO
)
2161 * Free and remove this attribute...
2164 ippDeleteAttribute(NULL
, attr
);
2169 job
->attrs
->attrs
= next
;
2175 job
->attrs
->last
= prev
;
2176 job
->attrs
->current
= prev
;
2181 * 'add_job_uuid()' - Add job-uuid attribute to a job.
2183 * See RFC 4122 for the definition of UUIDs and the format.
2187 add_job_uuid(cupsd_job_t
*job
) /* I - Job */
2189 char uuid
[64]; /* job-uuid string */
2193 * Add a job-uuid attribute if none exists...
2196 if (!ippFindAttribute(job
->attrs
, "job-uuid", IPP_TAG_URI
))
2197 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uuid", NULL
,
2198 httpAssembleUUID(ServerName
, RemotePort
, job
->dest
, job
->id
,
2199 uuid
, sizeof(uuid
)));
2204 * 'add_printer()' - Add a printer to the system.
2208 add_printer(cupsd_client_t
*con
, /* I - Client connection */
2209 ipp_attribute_t
*uri
) /* I - URI of printer */
2211 http_status_t status
; /* Policy status */
2212 int i
; /* Looping var */
2213 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
2214 username
[HTTP_MAX_URI
], /* Username portion of URI */
2215 host
[HTTP_MAX_URI
], /* Host portion of URI */
2216 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2217 int port
; /* Port portion of URI */
2218 cupsd_printer_t
*printer
; /* Printer/class */
2219 ipp_attribute_t
*attr
; /* Printer attribute */
2220 cups_file_t
*fp
; /* Script/PPD file */
2221 char line
[1024]; /* Line from file... */
2222 char srcfile
[1024], /* Source Script/PPD file */
2223 dstfile
[1024]; /* Destination Script/PPD file */
2224 int modify
; /* Non-zero if we are modifying */
2225 int changed_driver
, /* Changed the PPD? */
2226 need_restart_job
, /* Need to restart job? */
2227 set_device_uri
, /* Did we set the device URI? */
2228 set_port_monitor
; /* Did we set the port monitor? */
2231 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer(%p[%d], %s)", con
,
2232 con
->number
, uri
->values
[0].string
.text
);
2235 * Do we have a valid URI?
2238 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
2239 sizeof(scheme
), username
, sizeof(username
), host
,
2240 sizeof(host
), &port
, resource
, sizeof(resource
));
2242 if (strncmp(resource
, "/printers/", 10) || strlen(resource
) == 10)
2245 * No, return an error...
2248 send_ipp_status(con
, IPP_BAD_REQUEST
,
2249 _("The printer-uri must be of the form "
2250 "\"ipp://HOSTNAME/printers/PRINTERNAME\"."));
2255 * Do we have a valid printer name?
2258 if (!validate_name(resource
+ 10))
2261 * No, return an error...
2264 send_ipp_status(con
, IPP_BAD_REQUEST
,
2265 _("The printer-uri \"%s\" contains invalid characters."),
2266 uri
->values
[0].string
.text
);
2271 * See if the printer already exists; if not, create a new printer...
2274 if ((printer
= cupsdFindPrinter(resource
+ 10)) == NULL
)
2277 * Printer doesn't exist; see if we have a class of the same name...
2280 if ((printer
= cupsdFindClass(resource
+ 10)) != NULL
)
2283 * Yes, return an error...
2286 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2287 _("A class named \"%s\" already exists."),
2293 * No, check the default policy then add the printer...
2296 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2298 send_http_error(con
, status
, NULL
);
2302 printer
= cupsdAddPrinter(resource
+ 10);
2305 printer
->printer_id
= NextPrinterId
++;
2307 else if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
2310 send_http_error(con
, status
, printer
);
2317 * Look for attributes and copy them over as needed...
2321 need_restart_job
= 0;
2323 if ((attr
= ippFindAttribute(con
->request
, "printer-is-temporary", IPP_TAG_BOOLEAN
)) != NULL
)
2324 printer
->temporary
= ippGetBoolean(attr
, 0);
2326 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
2327 IPP_TAG_TEXT
)) != NULL
)
2328 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
2330 if ((attr
= ippFindAttribute(con
->request
, "printer-geo-location", IPP_TAG_URI
)) != NULL
&& !strncmp(attr
->values
[0].string
.text
, "geo:", 4))
2331 cupsdSetString(&printer
->geo_location
, attr
->values
[0].string
.text
);
2333 if ((attr
= ippFindAttribute(con
->request
, "printer-organization", IPP_TAG_TEXT
)) != NULL
)
2334 cupsdSetString(&printer
->organization
, attr
->values
[0].string
.text
);
2336 if ((attr
= ippFindAttribute(con
->request
, "printer-organizational-unit", IPP_TAG_TEXT
)) != NULL
)
2337 cupsdSetString(&printer
->organizational_unit
, attr
->values
[0].string
.text
);
2339 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
2340 IPP_TAG_TEXT
)) != NULL
)
2341 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
2345 if ((attr
= ippFindAttribute(con
->request
, "device-uri",
2346 IPP_TAG_URI
)) != NULL
)
2349 * Do we have a valid device URI?
2352 http_uri_status_t uri_status
; /* URI separation status */
2353 char old_device_uri
[1024];
2354 /* Old device URI */
2356 need_restart_job
= 1;
2358 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
,
2359 attr
->values
[0].string
.text
,
2360 scheme
, sizeof(scheme
),
2361 username
, sizeof(username
),
2362 host
, sizeof(host
), &port
,
2363 resource
, sizeof(resource
));
2365 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s device-uri: %s", printer
->name
, httpURIStatusString(uri_status
));
2367 if (uri_status
< HTTP_URI_OK
)
2369 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri \"%s\"."),
2370 attr
->values
[0].string
.text
);
2372 cupsdDeletePrinter(printer
, 0);
2377 if (!strcmp(scheme
, "file"))
2380 * See if the administrator has enabled file devices...
2383 if (!FileDevice
&& strcmp(resource
, "/dev/null"))
2386 * File devices are disabled and the URL is not file:/dev/null...
2389 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2390 _("File device URIs have been disabled. "
2391 "To enable, see the FileDevice directive in "
2392 "\"%s/cups-files.conf\"."),
2395 cupsdDeletePrinter(printer
, 0);
2403 * See if the backend exists and is executable...
2406 snprintf(srcfile
, sizeof(srcfile
), "%s/backend/%s", ServerBin
, scheme
);
2407 if (access(srcfile
, X_OK
))
2410 * Could not find device in list!
2413 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2414 _("Bad device-uri scheme \"%s\"."), scheme
);
2416 cupsdDeletePrinter(printer
, 0);
2422 if (printer
->sanitized_device_uri
)
2423 strlcpy(old_device_uri
, printer
->sanitized_device_uri
,
2424 sizeof(old_device_uri
));
2426 old_device_uri
[0] = '\0';
2428 cupsdSetDeviceURI(printer
, attr
->values
[0].string
.text
);
2430 cupsdLogMessage(CUPSD_LOG_INFO
,
2431 "Setting %s device-uri to \"%s\" (was \"%s\".)",
2432 printer
->name
, printer
->sanitized_device_uri
,
2438 set_port_monitor
= 0;
2440 if ((attr
= ippFindAttribute(con
->request
, "port-monitor",
2441 IPP_TAG_NAME
)) != NULL
)
2443 ipp_attribute_t
*supported
; /* port-monitor-supported attribute */
2446 need_restart_job
= 1;
2448 supported
= ippFindAttribute(printer
->ppd_attrs
, "port-monitor-supported",
2452 for (i
= 0; i
< supported
->num_values
; i
++)
2453 if (!strcmp(supported
->values
[i
].string
.text
,
2454 attr
->values
[0].string
.text
))
2458 if (!supported
|| i
>= supported
->num_values
)
2460 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad port-monitor \"%s\"."),
2461 attr
->values
[0].string
.text
);
2463 cupsdDeletePrinter(printer
, 0);
2468 cupsdLogMessage(CUPSD_LOG_INFO
,
2469 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2470 printer
->name
, attr
->values
[0].string
.text
,
2471 printer
->port_monitor
? printer
->port_monitor
: "none");
2473 if (strcmp(attr
->values
[0].string
.text
, "none"))
2474 cupsdSetString(&printer
->port_monitor
, attr
->values
[0].string
.text
);
2476 cupsdClearString(&printer
->port_monitor
);
2478 set_port_monitor
= 1;
2481 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
2482 IPP_TAG_BOOLEAN
)) != NULL
&&
2483 attr
->values
[0].boolean
!= printer
->accepting
)
2485 cupsdLogMessage(CUPSD_LOG_INFO
,
2486 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
2487 printer
->name
, attr
->values
[0].boolean
, printer
->accepting
);
2489 printer
->accepting
= attr
->values
[0].boolean
;
2491 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2492 "%s accepting jobs.",
2493 printer
->accepting
? "Now" : "No longer");
2496 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared", IPP_TAG_BOOLEAN
)) != NULL
)
2498 if (ippGetBoolean(attr
, 0) &&
2499 printer
->num_auth_info_required
== 1 &&
2500 !strcmp(printer
->auth_info_required
[0], "negotiate"))
2502 send_ipp_status(con
, IPP_BAD_REQUEST
,
2503 _("Cannot share a remote Kerberized printer."));
2505 cupsdDeletePrinter(printer
, 0);
2510 if (printer
->type
& CUPS_PRINTER_REMOTE
)
2513 * Cannot re-share remote printers.
2516 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Cannot change printer-is-shared for remote queues."));
2518 cupsdDeletePrinter(printer
, 0);
2523 if (printer
->shared
&& !ippGetBoolean(attr
, 0))
2524 cupsdDeregisterPrinter(printer
, 1);
2526 cupsdLogMessage(CUPSD_LOG_INFO
,
2527 "Setting %s printer-is-shared to %d (was %d.)",
2528 printer
->name
, attr
->values
[0].boolean
, printer
->shared
);
2530 printer
->shared
= ippGetBoolean(attr
, 0);
2531 if (printer
->shared
&& printer
->temporary
)
2532 printer
->temporary
= 0;
2535 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
2536 IPP_TAG_ENUM
)) != NULL
)
2538 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
2539 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
2541 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad printer-state value %d."),
2542 attr
->values
[0].integer
);
2544 cupsdDeletePrinter(printer
, 0);
2549 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
2550 printer
->name
, attr
->values
[0].integer
, printer
->state
);
2552 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
2553 cupsdStopPrinter(printer
, 0);
2556 need_restart_job
= 1;
2557 cupsdSetPrinterState(printer
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
2561 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
2562 IPP_TAG_TEXT
)) != NULL
)
2564 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
2565 sizeof(printer
->state_message
));
2567 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
, "%s",
2568 printer
->state_message
);
2571 if ((attr
= ippFindAttribute(con
->request
, "printer-state-reasons",
2572 IPP_TAG_KEYWORD
)) != NULL
)
2574 if (attr
->num_values
>
2575 (int)(sizeof(printer
->reasons
) / sizeof(printer
->reasons
[0])))
2577 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2578 _("Too many printer-state-reasons values (%d > %d)."),
2580 (int)(sizeof(printer
->reasons
) /
2581 sizeof(printer
->reasons
[0])));
2583 cupsdDeletePrinter(printer
, 0);
2588 for (i
= 0; i
< printer
->num_reasons
; i
++)
2589 _cupsStrFree(printer
->reasons
[i
]);
2591 printer
->num_reasons
= 0;
2592 for (i
= 0; i
< attr
->num_values
; i
++)
2594 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
2597 printer
->reasons
[printer
->num_reasons
] = _cupsStrAlloc(attr
->values
[i
].string
.text
);
2598 printer
->num_reasons
++;
2600 if (!strcmp(attr
->values
[i
].string
.text
, "paused") &&
2601 printer
->state
!= IPP_PRINTER_STOPPED
)
2603 cupsdLogMessage(CUPSD_LOG_INFO
,
2604 "Setting %s printer-state to %d (was %d.)",
2605 printer
->name
, IPP_PRINTER_STOPPED
, printer
->state
);
2606 cupsdStopPrinter(printer
, 0);
2610 if (PrintcapFormat
== PRINTCAP_PLIST
)
2611 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2613 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2614 "Printer \"%s\" state changed.", printer
->name
);
2617 if (!set_printer_defaults(con
, printer
))
2620 cupsdDeletePrinter(printer
, 0);
2625 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
2626 IPP_TAG_KEYWORD
)) != NULL
)
2627 cupsdSetAuthInfoRequired(printer
, NULL
, attr
);
2630 * See if we have all required attributes...
2633 if (!printer
->device_uri
)
2634 cupsdSetString(&printer
->device_uri
, "file:///dev/null");
2637 * See if we have a PPD file attached to the request...
2642 need_restart_job
= 1;
2645 strlcpy(srcfile
, con
->filename
, sizeof(srcfile
));
2647 if ((fp
= cupsFileOpen(srcfile
, "rb")))
2650 * Yes; get the first line from it...
2654 cupsFileGets(fp
, line
, sizeof(line
));
2658 * Then see what kind of file it is...
2661 if (strncmp(line
, "*PPD-Adobe", 10))
2663 send_ipp_status(con
, IPP_STATUS_ERROR_DOCUMENT_FORMAT_NOT_SUPPORTED
, _("Bad PPD file."));
2665 cupsdDeletePrinter(printer
, 0);
2670 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2674 * The new file is a PPD file, so move the file over to the ppd
2678 if (copy_file(srcfile
, dstfile
, ConfigFilePerm
))
2680 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file - %s"), strerror(errno
));
2682 cupsdDeletePrinter(printer
, 0);
2687 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Copied PPD file successfully");
2690 else if ((attr
= ippFindAttribute(con
->request
, "ppd-name", IPP_TAG_NAME
)) != NULL
)
2692 const char *ppd_name
= ippGetString(attr
, 0, NULL
);
2693 /* ppd-name value */
2695 need_restart_job
= 1;
2698 if (!strcmp(ppd_name
, "raw"))
2701 * Raw driver, remove any existing PPD file.
2704 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
, printer
->name
);
2707 else if (strstr(ppd_name
, "../"))
2709 send_ipp_status(con
, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES
, _("Invalid ppd-name value."));
2711 cupsdDeletePrinter(printer
, 0);
2721 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
, printer
->name
);
2723 if (copy_model(con
, ppd_name
, dstfile
))
2725 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file."));
2727 cupsdDeletePrinter(printer
, 0);
2732 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Copied PPD file successfully");
2739 * If we changed the PPD, then remove the printer's cache file and clear the
2740 * printer-state-reasons...
2743 char cache_name
[1024]; /* Cache filename for printer attrs */
2745 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.data", CacheDir
, printer
->name
);
2748 cupsdSetPrinterReasons(printer
, "none");
2751 * (Re)register color profiles...
2754 cupsdRegisterColor(printer
);
2758 * If we set the device URI but not the port monitor, check which port
2759 * monitor to use by default...
2762 if (set_device_uri
&& !set_port_monitor
)
2764 ppd_file_t
*ppd
; /* PPD file */
2765 ppd_attr_t
*ppdattr
; /* cupsPortMonitor attribute */
2768 httpSeparateURI(HTTP_URI_CODING_ALL
, printer
->device_uri
, scheme
,
2769 sizeof(scheme
), username
, sizeof(username
), host
,
2770 sizeof(host
), &port
, resource
, sizeof(resource
));
2772 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
,
2774 if ((ppd
= _ppdOpenFile(srcfile
, _PPD_LOCALIZATION_NONE
)) != NULL
)
2776 for (ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2778 ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
2779 if (!strcmp(scheme
, ppdattr
->spec
))
2781 cupsdLogMessage(CUPSD_LOG_INFO
,
2782 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2783 printer
->name
, ppdattr
->value
,
2784 printer
->port_monitor
? printer
->port_monitor
2787 if (strcmp(ppdattr
->value
, "none"))
2788 cupsdSetString(&printer
->port_monitor
, ppdattr
->value
);
2790 cupsdClearString(&printer
->port_monitor
);
2799 printer
->config_time
= time(NULL
);
2802 * Update the printer attributes and return...
2805 if (!printer
->temporary
)
2807 if (!printer
->printer_id
)
2808 printer
->printer_id
= NextPrinterId
++;
2810 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2813 cupsdSetPrinterAttrs(printer
);
2815 if (need_restart_job
&& printer
->job
)
2818 * Restart the current job...
2821 cupsdSetJobState(printer
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
2822 "Job restarted because the printer was modified.");
2825 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2829 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
2830 printer
, NULL
, "Printer \"%s\" modified by \"%s\".",
2831 printer
->name
, get_username(con
));
2833 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" modified by \"%s\".",
2834 printer
->name
, get_username(con
));
2838 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
2839 printer
, NULL
, "New printer \"%s\" added by \"%s\".",
2840 printer
->name
, get_username(con
));
2842 cupsdLogMessage(CUPSD_LOG_INFO
, "New printer \"%s\" added by \"%s\".",
2843 printer
->name
, get_username(con
));
2846 con
->response
->request
.status
.status_code
= IPP_OK
;
2851 * 'add_printer_state_reasons()' - Add the "printer-state-reasons" attribute
2852 * based upon the printer state...
2856 add_printer_state_reasons(
2857 cupsd_client_t
*con
, /* I - Client connection */
2858 cupsd_printer_t
*p
) /* I - Printer info */
2860 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2861 "add_printer_state_reasons(%p[%d], %p[%s])",
2862 con
, con
->number
, p
, p
->name
);
2864 if (p
->num_reasons
== 0)
2865 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2866 "printer-state-reasons", NULL
, "none");
2868 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2869 "printer-state-reasons", p
->num_reasons
, NULL
,
2870 (const char * const *)p
->reasons
);
2875 * 'add_queued_job_count()' - Add the "queued-job-count" attribute for
2876 * the specified printer or class.
2880 add_queued_job_count(
2881 cupsd_client_t
*con
, /* I - Client connection */
2882 cupsd_printer_t
*p
) /* I - Printer or class */
2884 int count
; /* Number of jobs on destination */
2887 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_queued_job_count(%p[%d], %p[%s])",
2888 con
, con
->number
, p
, p
->name
);
2890 count
= cupsdGetPrinterJobCount(p
->name
);
2892 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2893 "queued-job-count", count
);
2898 * 'apply_printer_defaults()' - Apply printer default options to a job.
2902 apply_printer_defaults(
2903 cupsd_printer_t
*printer
, /* I - Printer */
2904 cupsd_job_t
*job
) /* I - Job */
2906 int i
, /* Looping var */
2907 num_options
; /* Number of default options */
2908 cups_option_t
*options
, /* Default options */
2909 *option
; /* Current option */
2912 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Applying default options...");
2915 * Collect all of the default options and add the missing ones to the
2919 for (i
= printer
->num_options
, num_options
= 0, options
= NULL
,
2920 option
= printer
->options
;
2923 if (!ippFindAttribute(job
->attrs
, option
->name
, IPP_TAG_ZERO
))
2925 if (!strcmp(option
->name
, "print-quality") && ippFindAttribute(job
->attrs
, "cupsPrintQuality", IPP_TAG_NAME
))
2926 continue; /* Don't override cupsPrintQuality */
2928 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Adding default %s=%s", option
->name
, option
->value
);
2930 num_options
= cupsAddOption(option
->name
, option
->value
, num_options
, &options
);
2934 * Encode these options as attributes in the job object...
2937 cupsEncodeOptions2(job
->attrs
, num_options
, options
, IPP_TAG_JOB
);
2938 cupsFreeOptions(num_options
, options
);
2943 * 'authenticate_job()' - Set job authentication info.
2947 authenticate_job(cupsd_client_t
*con
, /* I - Client connection */
2948 ipp_attribute_t
*uri
) /* I - Job URI */
2950 ipp_attribute_t
*attr
, /* job-id attribute */
2951 *auth_info
; /* auth-info attribute */
2952 int jobid
; /* Job ID */
2953 cupsd_job_t
*job
; /* Current job */
2954 char scheme
[HTTP_MAX_URI
],
2955 /* Method portion of URI */
2956 username
[HTTP_MAX_URI
],
2957 /* Username portion of URI */
2959 /* Host portion of URI */
2960 resource
[HTTP_MAX_URI
];
2961 /* Resource portion of URI */
2962 int port
; /* Port portion of URI */
2965 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "authenticate_job(%p[%d], %s)",
2966 con
, con
->number
, uri
->values
[0].string
.text
);
2969 * Start with "everything is OK" status...
2972 con
->response
->request
.status
.status_code
= IPP_OK
;
2975 * See if we have a job URI or a printer URI...
2978 if (!strcmp(uri
->name
, "printer-uri"))
2981 * Got a printer URI; see if we also have a job-id attribute...
2984 if ((attr
= ippFindAttribute(con
->request
, "job-id",
2985 IPP_TAG_INTEGER
)) == NULL
)
2987 send_ipp_status(con
, IPP_BAD_REQUEST
,
2988 _("Got a printer-uri attribute but no job-id."));
2992 jobid
= attr
->values
[0].integer
;
2997 * Got a job URI; parse it to get the job ID...
3000 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
3001 sizeof(scheme
), username
, sizeof(username
), host
,
3002 sizeof(host
), &port
, resource
, sizeof(resource
));
3004 if (strncmp(resource
, "/jobs/", 6))
3010 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
3011 uri
->values
[0].string
.text
);
3015 jobid
= atoi(resource
+ 6);
3019 * See if the job exists...
3022 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3025 * Nope - return a "not found" error...
3028 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
3033 * See if the job has been completed...
3036 if (job
->state_value
!= IPP_JOB_HELD
)
3039 * Return a "not-possible" error...
3042 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3043 _("Job #%d is not held for authentication."),
3049 * See if we have already authenticated...
3052 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
3054 if (!con
->username
[0] && !auth_info
)
3056 cupsd_printer_t
*printer
; /* Job destination */
3059 * No auth data. If we need to authenticate via Kerberos, send a
3060 * HTTP auth challenge, otherwise just return an IPP error...
3063 printer
= cupsdFindDest(job
->dest
);
3065 if (printer
&& printer
->num_auth_info_required
> 0 &&
3066 !strcmp(printer
->auth_info_required
[0], "negotiate"))
3067 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
3069 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
3070 _("No authentication information provided."));
3075 * See if the job is owned by the requesting user...
3078 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3080 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3081 cupsdFindDest(job
->dest
));
3086 * Save the authentication information for this job...
3089 save_auth_info(con
, job
, auth_info
);
3092 * Reset the job-hold-until value to "no-hold"...
3095 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
3096 IPP_TAG_KEYWORD
)) == NULL
)
3097 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
3101 ippSetValueTag(job
->attrs
, &attr
, IPP_TAG_KEYWORD
);
3102 ippSetString(job
->attrs
, &attr
, 0, "no-hold");
3106 * Release the job and return...
3109 cupsdReleaseJob(job
);
3111 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, NULL
, job
, "Job authenticated by user");
3113 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Authenticated by \"%s\".", con
->username
);
3120 * 'cancel_all_jobs()' - Cancel all or selected print jobs.
3124 cancel_all_jobs(cupsd_client_t
*con
, /* I - Client connection */
3125 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3127 int i
; /* Looping var */
3128 http_status_t status
; /* Policy status */
3129 cups_ptype_t dtype
; /* Destination type */
3130 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3131 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
3132 hostname
[HTTP_MAX_URI
], /* Host portion of URI */
3133 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3134 int port
; /* Port portion of URI */
3135 ipp_attribute_t
*attr
; /* Attribute in request */
3136 const char *username
= NULL
; /* Username */
3137 cupsd_jobaction_t purge
= CUPSD_JOB_DEFAULT
;
3139 cupsd_printer_t
*printer
; /* Printer */
3140 ipp_attribute_t
*job_ids
; /* job-ids attribute */
3141 cupsd_job_t
*job
; /* Job */
3144 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_all_jobs(%p[%d], %s)", con
,
3145 con
->number
, uri
->values
[0].string
.text
);
3148 * Get the jobs to cancel/purge...
3151 switch (con
->request
->request
.op
.operation_id
)
3153 case IPP_PURGE_JOBS
:
3155 * Get the username (if any) for the jobs we want to cancel (only if
3156 * "my-jobs" is specified...
3159 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
3160 IPP_TAG_BOOLEAN
)) != NULL
&&
3161 attr
->values
[0].boolean
)
3163 if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3164 IPP_TAG_NAME
)) != NULL
)
3165 username
= attr
->values
[0].string
.text
;
3168 send_ipp_status(con
, IPP_BAD_REQUEST
,
3169 _("Missing requesting-user-name attribute."));
3175 * Look for the "purge-jobs" attribute...
3178 if ((attr
= ippFindAttribute(con
->request
, "purge-jobs",
3179 IPP_TAG_BOOLEAN
)) != NULL
)
3180 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
3182 purge
= CUPSD_JOB_PURGE
;
3185 case IPP_CANCEL_MY_JOBS
:
3186 if (con
->username
[0])
3187 username
= con
->username
;
3188 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3189 IPP_TAG_NAME
)) != NULL
)
3190 username
= attr
->values
[0].string
.text
;
3193 send_ipp_status(con
, IPP_BAD_REQUEST
,
3194 _("Missing requesting-user-name attribute."));
3202 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
3205 * See if we have a printer URI...
3208 if (strcmp(uri
->name
, "printer-uri"))
3210 send_ipp_status(con
, IPP_BAD_REQUEST
,
3211 _("The printer-uri attribute is required."));
3216 * And if the destination is valid...
3219 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3225 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
,
3226 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
3227 hostname
, sizeof(hostname
), &port
,
3228 resource
, sizeof(resource
));
3230 if ((!strncmp(resource
, "/printers/", 10) && resource
[10]) ||
3231 (!strncmp(resource
, "/classes/", 9) && resource
[9]))
3233 send_ipp_status(con
, IPP_NOT_FOUND
,
3234 _("The printer or class does not exist."));
3242 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
3244 send_http_error(con
, status
, NULL
);
3250 for (i
= 0; i
< job_ids
->num_values
; i
++)
3252 if ((job
= cupsdFindJob(job_ids
->values
[i
].integer
)) == NULL
)
3255 if (con
->request
->request
.op
.operation_id
== IPP_CANCEL_MY_JOBS
&&
3256 _cups_strcasecmp(job
->username
, username
))
3260 if (i
< job_ids
->num_values
)
3262 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3263 job_ids
->values
[i
].integer
);
3267 for (i
= 0; i
< job_ids
->num_values
; i
++)
3269 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
3271 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3272 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
3273 "Job canceled by user.");
3276 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
3277 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3283 * Cancel all jobs on all printers...
3286 cupsdCancelJobs(NULL
, username
, purge
);
3288 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs were %s by \"%s\".",
3289 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3299 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
3302 send_http_error(con
, status
, printer
);
3308 for (i
= 0; i
< job_ids
->num_values
; i
++)
3310 if ((job
= cupsdFindJob(job_ids
->values
[i
].integer
)) == NULL
||
3311 _cups_strcasecmp(job
->dest
, printer
->name
))
3314 if (con
->request
->request
.op
.operation_id
== IPP_CANCEL_MY_JOBS
&&
3315 _cups_strcasecmp(job
->username
, username
))
3319 if (i
< job_ids
->num_values
)
3321 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3322 job_ids
->values
[i
].integer
);
3326 for (i
= 0; i
< job_ids
->num_values
; i
++)
3328 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
3330 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3331 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
3332 "Job canceled by user.");
3335 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
3336 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3342 * Cancel all of the jobs on the named printer...
3345 cupsdCancelJobs(printer
->name
, username
, purge
);
3347 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs on \"%s\" were %s by \"%s\".",
3349 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3354 con
->response
->request
.status
.status_code
= IPP_OK
;
3361 * 'cancel_job()' - Cancel a print job.
3365 cancel_job(cupsd_client_t
*con
, /* I - Client connection */
3366 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3368 ipp_attribute_t
*attr
; /* Current attribute */
3369 int jobid
; /* Job ID */
3370 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3371 username
[HTTP_MAX_URI
], /* Username portion of URI */
3372 host
[HTTP_MAX_URI
], /* Host portion of URI */
3373 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3374 int port
; /* Port portion of URI */
3375 cupsd_job_t
*job
; /* Job information */
3376 cups_ptype_t dtype
; /* Destination type (printer/class) */
3377 cupsd_printer_t
*printer
; /* Printer data */
3378 cupsd_jobaction_t purge
; /* Purge the job? */
3381 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_job(%p[%d], %s)", con
,
3382 con
->number
, uri
->values
[0].string
.text
);
3385 * See if we have a job URI or a printer URI...
3388 if (!strcmp(uri
->name
, "printer-uri"))
3391 * Got a printer URI; see if we also have a job-id attribute...
3394 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3395 IPP_TAG_INTEGER
)) == NULL
)
3397 send_ipp_status(con
, IPP_BAD_REQUEST
,
3398 _("Got a printer-uri attribute but no job-id."));
3402 if ((jobid
= attr
->values
[0].integer
) == 0)
3405 * Find the current job on the specified printer...
3408 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3414 send_ipp_status(con
, IPP_NOT_FOUND
,
3415 _("The printer or class does not exist."));
3420 * See if there are any pending jobs...
3423 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3425 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3426 if (job
->state_value
<= IPP_JOB_PROCESSING
&&
3427 !_cups_strcasecmp(job
->dest
, printer
->name
))
3435 * No, try stopped jobs...
3438 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3440 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3441 if (job
->state_value
== IPP_JOB_STOPPED
&&
3442 !_cups_strcasecmp(job
->dest
, printer
->name
))
3449 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("No active jobs on %s."),
3459 * Got a job URI; parse it to get the job ID...
3462 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
3463 sizeof(scheme
), username
, sizeof(username
), host
,
3464 sizeof(host
), &port
, resource
, sizeof(resource
));
3466 if (strncmp(resource
, "/jobs/", 6))
3472 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
3473 uri
->values
[0].string
.text
);
3477 jobid
= atoi(resource
+ 6);
3481 * Look for the "purge-job" attribute...
3484 if ((attr
= ippFindAttribute(con
->request
, "purge-job",
3485 IPP_TAG_BOOLEAN
)) != NULL
)
3486 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
3488 purge
= CUPSD_JOB_DEFAULT
;
3491 * See if the job exists...
3494 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3497 * Nope - return a "not found" error...
3500 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
3505 * See if the job is owned by the requesting user...
3508 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3510 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3511 cupsdFindDest(job
->dest
));
3516 * See if the job is already completed, canceled, or aborted; if so,
3517 * we can't cancel...
3520 if (job
->state_value
>= IPP_JOB_CANCELED
&& purge
!= CUPSD_JOB_PURGE
)
3522 switch (job
->state_value
)
3524 case IPP_JOB_CANCELED
:
3525 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3526 _("Job #%d is already canceled - can\'t cancel."),
3530 case IPP_JOB_ABORTED
:
3531 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3532 _("Job #%d is already aborted - can\'t cancel."),
3537 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3538 _("Job #%d is already completed - can\'t cancel."),
3547 * Cancel the job and return...
3550 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3551 purge
== CUPSD_JOB_PURGE
? "Job purged by \"%s\"" :
3552 "Job canceled by \"%s\"",
3556 if (purge
== CUPSD_JOB_PURGE
)
3557 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Purged by \"%s\".", jobid
,
3560 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Canceled by \"%s\".", jobid
,
3563 con
->response
->request
.status
.status_code
= IPP_OK
;
3568 * 'cancel_subscription()' - Cancel a subscription.
3572 cancel_subscription(
3573 cupsd_client_t
*con
, /* I - Client connection */
3574 int sub_id
) /* I - Subscription ID */
3576 http_status_t status
; /* Policy status */
3577 cupsd_subscription_t
*sub
; /* Subscription */
3580 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3581 "cancel_subscription(con=%p[%d], sub_id=%d)",
3582 con
, con
->number
, sub_id
);
3585 * Is the subscription ID valid?
3588 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
3591 * Bad subscription ID...
3594 send_ipp_status(con
, IPP_NOT_FOUND
,
3595 _("Subscription #%d does not exist."), sub_id
);
3603 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
3605 con
, sub
->owner
)) != HTTP_OK
)
3607 send_http_error(con
, status
, sub
->dest
);
3612 * Cancel the subscription...
3615 cupsdDeleteSubscription(sub
, 1);
3617 con
->response
->request
.status
.status_code
= IPP_OK
;
3622 * 'check_rss_recipient()' - Check that we do not have a duplicate RSS feed URI.
3625 static int /* O - 1 if OK, 0 if not */
3626 check_rss_recipient(
3627 const char *recipient
) /* I - Recipient URI */
3629 cupsd_subscription_t
*sub
; /* Current subscription */
3632 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
);
3634 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
3638 * Compare the URIs up to the first ?...
3641 const char *r1
, *r2
;
3643 for (r1
= recipient
, r2
= sub
->recipient
;
3644 *r1
== *r2
&& *r1
&& *r1
!= '?' && *r2
&& *r2
!= '?';
3656 * 'check_quotas()' - Check quotas for a printer and user.
3659 static int /* O - 1 if OK, 0 if forbidden,
3660 -1 if limit reached */
3661 check_quotas(cupsd_client_t
*con
, /* I - Client connection */
3662 cupsd_printer_t
*p
) /* I - Printer or class */
3664 char username
[33], /* Username */
3665 *name
; /* Current user name */
3666 cupsd_quota_t
*q
; /* Quota data */
3667 #ifdef HAVE_MBR_UID_TO_UUID
3669 * Use Apple membership APIs which require that all names represent
3670 * valid user account or group records accessible by the server.
3673 uuid_t usr_uuid
; /* UUID for job requesting user */
3674 uuid_t usr2_uuid
; /* UUID for ACL user name entry */
3675 uuid_t grp_uuid
; /* UUID for ACL group name entry */
3676 int mbr_err
; /* Error from membership function */
3677 int is_member
; /* Is this user a member? */
3680 * Use standard POSIX APIs for checking users and groups...
3683 struct passwd
*pw
; /* User password data */
3684 #endif /* HAVE_MBR_UID_TO_UUID */
3687 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "check_quotas(%p[%d], %p[%s])",
3688 con
, con
->number
, p
, p
->name
);
3691 * Figure out who is printing...
3694 strlcpy(username
, get_username(con
), sizeof(username
));
3696 if ((name
= strchr(username
, '@')) != NULL
)
3697 *name
= '\0'; /* Strip @REALM */
3700 * Check global active job limits for printers and users...
3703 if (MaxJobsPerPrinter
)
3706 * Check if there are too many pending jobs on this printer...
3709 if (cupsdGetPrinterJobCount(p
->name
) >= MaxJobsPerPrinter
)
3711 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for printer \"%s\"...",
3720 * Check if there are too many pending jobs for this user...
3723 if (cupsdGetUserJobCount(username
) >= MaxJobsPerUser
)
3725 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for user \"%s\"...",
3732 * Check against users...
3735 if (cupsArrayCount(p
->users
) == 0 && p
->k_limit
== 0 && p
->page_limit
== 0)
3738 if (cupsArrayCount(p
->users
))
3740 #ifdef HAVE_MBR_UID_TO_UUID
3742 * Get UUID for job requesting user...
3745 if (mbr_user_name_to_uuid((char *)username
, usr_uuid
))
3751 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3752 "check_quotas: UUID lookup failed for user \"%s\"",
3754 cupsdLogMessage(CUPSD_LOG_INFO
,
3755 "Denying user \"%s\" access to printer \"%s\" "
3756 "(unknown user)...",
3762 * Get UID and GID of requesting user...
3765 pw
= getpwnam(username
);
3767 #endif /* HAVE_MBR_UID_TO_UUID */
3769 for (name
= (char *)cupsArrayFirst(p
->users
);
3771 name
= (char *)cupsArrayNext(p
->users
))
3775 * Check group membership...
3778 #ifdef HAVE_MBR_UID_TO_UUID
3781 if (uuid_parse(name
+ 2, grp_uuid
))
3782 uuid_clear(grp_uuid
);
3784 else if ((mbr_err
= mbr_group_name_to_uuid(name
+ 1, grp_uuid
)) != 0)
3787 * Invalid ACL entries are ignored for matching; just record a
3788 * warning in the log...
3791 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3792 "check_quotas: UUID lookup failed for ACL entry "
3793 "\"%s\" (err=%d)", name
, mbr_err
);
3794 cupsdLogMessage(CUPSD_LOG_WARN
,
3795 "Access control entry \"%s\" not a valid group name; "
3796 "entry ignored", name
);
3799 if ((mbr_err
= mbr_check_membership(usr_uuid
, grp_uuid
,
3803 * At this point, there should be no errors, but check anyways...
3806 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3807 "check_quotas: group \"%s\" membership check "
3808 "failed (err=%d)", name
+ 1, mbr_err
);
3813 * Stop if we found a match...
3820 if (cupsdCheckGroup(username
, pw
, name
+ 1))
3822 #endif /* HAVE_MBR_UID_TO_UUID */
3824 #ifdef HAVE_MBR_UID_TO_UUID
3829 if (uuid_parse(name
+ 1, usr2_uuid
))
3830 uuid_clear(usr2_uuid
);
3832 else if ((mbr_err
= mbr_user_name_to_uuid(name
, usr2_uuid
)) != 0)
3835 * Invalid ACL entries are ignored for matching; just record a
3836 * warning in the log...
3839 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3840 "check_quotas: UUID lookup failed for ACL entry "
3841 "\"%s\" (err=%d)", name
, mbr_err
);
3842 cupsdLogMessage(CUPSD_LOG_WARN
,
3843 "Access control entry \"%s\" not a valid user name; "
3844 "entry ignored", name
);
3847 if (!uuid_compare(usr_uuid
, usr2_uuid
))
3851 else if (!_cups_strcasecmp(username
, name
))
3853 #endif /* HAVE_MBR_UID_TO_UUID */
3855 if ((name
!= NULL
) == p
->deny_users
)
3857 cupsdLogMessage(CUPSD_LOG_INFO
,
3858 "Denying user \"%s\" access to printer \"%s\"...",
3868 if (p
->k_limit
|| p
->page_limit
)
3870 if ((q
= cupsdUpdateQuota(p
, username
, 0, 0)) == NULL
)
3872 cupsdLogMessage(CUPSD_LOG_ERROR
,
3873 "Unable to allocate quota data for user \"%s\"",
3878 if ((q
->k_count
>= p
->k_limit
&& p
->k_limit
) ||
3879 (q
->page_count
>= p
->page_limit
&& p
->page_limit
))
3881 cupsdLogMessage(CUPSD_LOG_INFO
, "User \"%s\" is over the quota limit...",
3888 * If we have gotten this far, we're done!
3896 * 'close_job()' - Close a multi-file job.
3900 close_job(cupsd_client_t
*con
, /* I - Client connection */
3901 ipp_attribute_t
*uri
) /* I - Printer URI */
3903 cupsd_job_t
*job
; /* Job */
3904 ipp_attribute_t
*attr
; /* Attribute */
3905 char job_uri
[HTTP_MAX_URI
],
3907 username
[256]; /* User name */
3910 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "close_job(%p[%d], %s)", con
,
3911 con
->number
, uri
->values
[0].string
.text
);
3914 * See if we have a job URI or a printer URI...
3917 if (strcmp(uri
->name
, "printer-uri"))
3920 * job-uri is not supported by Close-Job!
3923 send_ipp_status(con
, IPP_BAD_REQUEST
,
3924 _("Close-Job doesn't support the job-uri attribute."));
3929 * Got a printer URI; see if we also have a job-id attribute...
3932 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3933 IPP_TAG_INTEGER
)) == NULL
)
3935 send_ipp_status(con
, IPP_BAD_REQUEST
,
3936 _("Got a printer-uri attribute but no job-id."));
3940 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
3943 * Nope - return a "not found" error...
3946 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3947 attr
->values
[0].integer
);
3952 * See if the job is owned by the requesting user...
3955 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3957 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3958 cupsdFindDest(job
->dest
));
3963 * Add any ending sheet...
3966 if (cupsdTimeoutJob(job
))
3969 if (job
->state_value
== IPP_JOB_STOPPED
)
3971 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
3972 job
->state_value
= IPP_JOB_PENDING
;
3974 else if (job
->state_value
== IPP_JOB_HELD
)
3976 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
3977 IPP_TAG_KEYWORD
)) == NULL
)
3978 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
3980 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
3982 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
3983 job
->state_value
= IPP_JOB_PENDING
;
3988 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
3991 * Fill in the response info...
3994 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
3995 con
->clientname
, con
->clientport
, "/jobs/%d", job
->id
);
3996 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
3999 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
4001 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
4004 con
->response
->request
.status
.status_code
= IPP_OK
;
4007 * Start the job if necessary...
4015 * 'copy_attrs()' - Copy attributes from one request to another.
4019 copy_attrs(ipp_t
*to
, /* I - Destination request */
4020 ipp_t
*from
, /* I - Source request */
4021 cups_array_t
*ra
, /* I - Requested attributes */
4022 ipp_tag_t group
, /* I - Group to copy */
4023 int quickcopy
, /* I - Do a quick copy? */
4024 cups_array_t
*exclude
) /* I - Attributes to exclude? */
4026 ipp_attribute_t
*fromattr
; /* Source attribute */
4029 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4030 "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)",
4031 to
, from
, ra
, group
, quickcopy
);
4036 for (fromattr
= from
->attrs
; fromattr
; fromattr
= fromattr
->next
)
4039 * Filter attributes as needed...
4042 if ((group
!= IPP_TAG_ZERO
&& fromattr
->group_tag
!= group
&&
4043 fromattr
->group_tag
!= IPP_TAG_ZERO
) || !fromattr
->name
)
4046 if (!strcmp(fromattr
->name
, "document-password") ||
4047 !strcmp(fromattr
->name
, "job-authorization-uri") ||
4048 !strcmp(fromattr
->name
, "job-password") ||
4049 !strcmp(fromattr
->name
, "job-password-encryption") ||
4050 !strcmp(fromattr
->name
, "job-printer-uri"))
4054 (cupsArrayFind(exclude
, fromattr
->name
) ||
4055 cupsArrayFind(exclude
, "all")))
4058 * We need to exclude this attribute for security reasons; we require the
4059 * job-id attribute regardless of the security settings for IPP
4062 * The job-printer-uri attribute is handled by copy_job_attrs().
4064 * Subscription attribute security is handled by copy_subscription_attrs().
4067 if (strcmp(fromattr
->name
, "job-id"))
4071 if (!ra
|| cupsArrayFind(ra
, fromattr
->name
))
4074 * Don't send collection attributes by default to IPP/1.x clients
4075 * since many do not support collections. Also don't send
4076 * media-col-database unless specifically requested by the client.
4079 if (fromattr
->value_tag
== IPP_TAG_BEGIN_COLLECTION
&&
4081 (to
->request
.status
.version
[0] == 1 ||
4082 !strcmp(fromattr
->name
, "media-col-database")))
4085 ippCopyAttribute(to
, fromattr
, quickcopy
);
4092 * 'copy_banner()' - Copy a banner file to the requests directory for the
4096 static int /* O - Size of banner file in kbytes */
4097 copy_banner(cupsd_client_t
*con
, /* I - Client connection */
4098 cupsd_job_t
*job
, /* I - Job information */
4099 const char *name
) /* I - Name of banner */
4101 int i
; /* Looping var */
4102 int kbytes
; /* Size of banner file in kbytes */
4103 char filename
[1024]; /* Job filename */
4104 cupsd_banner_t
*banner
; /* Pointer to banner */
4105 cups_file_t
*in
; /* Input file */
4106 cups_file_t
*out
; /* Output file */
4107 int ch
; /* Character from file */
4108 char attrname
[255], /* Name of attribute */
4109 *s
; /* Pointer into name */
4110 ipp_attribute_t
*attr
; /* Attribute */
4113 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4114 "copy_banner(con=%p[%d], job=%p[%d], name=\"%s\")",
4115 con
, con
? con
->number
: -1, job
, job
->id
,
4116 name
? name
: "(null)");
4119 * Find the banner; return if not found or "none"...
4122 if (!name
|| !strcmp(name
, "none") ||
4123 (banner
= cupsdFindBanner(name
)) == NULL
)
4127 * Open the banner and job files...
4130 if (add_file(con
, job
, banner
->filetype
, 0))
4133 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
4135 if ((out
= cupsFileOpen(filename
, "w")) == NULL
)
4137 cupsdLogMessage(CUPSD_LOG_ERROR
,
4138 "Unable to create banner job file %s - %s",
4139 filename
, strerror(errno
));
4144 fchmod(cupsFileNumber(out
), 0640);
4145 fchown(cupsFileNumber(out
), RunUser
, Group
);
4148 * Try the localized banner file under the subdirectory...
4151 strlcpy(attrname
, job
->attrs
->attrs
->next
->values
[0].string
.text
,
4153 if (strlen(attrname
) > 2 && attrname
[2] == '-')
4156 * Convert ll-cc to ll_CC...
4160 attrname
[3] = (char)toupper(attrname
[3] & 255);
4161 attrname
[4] = (char)toupper(attrname
[4] & 255);
4164 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4167 if (access(filename
, 0) && strlen(attrname
) > 2)
4170 * Wasn't able to find "ll_CC" locale file; try the non-national
4171 * localization banner directory.
4176 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4180 if (access(filename
, 0))
4183 * Use the non-localized banner file.
4186 snprintf(filename
, sizeof(filename
), "%s/banners/%s", DataDir
, name
);
4189 if ((in
= cupsFileOpen(filename
, "r")) == NULL
)
4193 cupsdLogMessage(CUPSD_LOG_ERROR
,
4194 "Unable to open banner template file %s - %s",
4195 filename
, strerror(errno
));
4201 * Parse the file to the end...
4204 while ((ch
= cupsFileGetChar(in
)) != EOF
)
4208 * Get an attribute name...
4211 for (s
= attrname
; (ch
= cupsFileGetChar(in
)) != EOF
;)
4212 if (!isalpha(ch
& 255) && ch
!= '-' && ch
!= '?')
4214 else if (s
< (attrname
+ sizeof(attrname
) - 1))
4224 * Ignore { followed by stuff that is not an attribute name...
4227 cupsFilePrintf(out
, "{%s%c", attrname
, ch
);
4232 * See if it is defined...
4235 if (attrname
[0] == '?')
4240 if (!strcmp(s
, "printer-name"))
4242 cupsFilePuts(out
, job
->dest
);
4245 else if ((attr
= ippFindAttribute(job
->attrs
, s
, IPP_TAG_ZERO
)) == NULL
)
4248 * See if we have a leading question mark...
4251 if (attrname
[0] != '?')
4254 * Nope, write to file as-is; probably a PostScript procedure...
4257 cupsFilePrintf(out
, "{%s}", attrname
);
4264 * Output value(s)...
4267 for (i
= 0; i
< attr
->num_values
; i
++)
4270 cupsFilePutChar(out
, ',');
4272 switch (attr
->value_tag
)
4274 case IPP_TAG_INTEGER
:
4276 if (!strncmp(s
, "time-at-", 8))
4278 struct timeval tv
; /* Time value */
4280 tv
.tv_sec
= attr
->values
[i
].integer
;
4283 cupsFilePuts(out
, cupsdGetDateTime(&tv
, CUPSD_TIME_STANDARD
));
4286 cupsFilePrintf(out
, "%d", attr
->values
[i
].integer
);
4289 case IPP_TAG_BOOLEAN
:
4290 cupsFilePrintf(out
, "%d", attr
->values
[i
].boolean
);
4293 case IPP_TAG_NOVALUE
:
4294 cupsFilePuts(out
, "novalue");
4297 case IPP_TAG_RANGE
:
4298 cupsFilePrintf(out
, "%d-%d", attr
->values
[i
].range
.lower
,
4299 attr
->values
[i
].range
.upper
);
4302 case IPP_TAG_RESOLUTION
:
4303 cupsFilePrintf(out
, "%dx%d%s", attr
->values
[i
].resolution
.xres
,
4304 attr
->values
[i
].resolution
.yres
,
4305 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
4310 case IPP_TAG_STRING
:
4313 case IPP_TAG_KEYWORD
:
4314 case IPP_TAG_CHARSET
:
4315 case IPP_TAG_LANGUAGE
:
4316 if (!_cups_strcasecmp(banner
->filetype
->type
, "postscript"))
4319 * Need to quote strings for PS banners...
4324 for (p
= attr
->values
[i
].string
.text
; *p
; p
++)
4326 if (*p
== '(' || *p
== ')' || *p
== '\\')
4328 cupsFilePutChar(out
, '\\');
4329 cupsFilePutChar(out
, *p
);
4331 else if (*p
< 32 || *p
> 126)
4332 cupsFilePrintf(out
, "\\%03o", *p
& 255);
4334 cupsFilePutChar(out
, *p
);
4338 cupsFilePuts(out
, attr
->values
[i
].string
.text
);
4342 break; /* anti-compiler-warning-code */
4346 else if (ch
== '\\') /* Quoted char */
4348 ch
= cupsFileGetChar(in
);
4350 if (ch
!= '{') /* Only do special handling for \{ */
4351 cupsFilePutChar(out
, '\\');
4353 cupsFilePutChar(out
, ch
);
4356 cupsFilePutChar(out
, ch
);
4360 kbytes
= (cupsFileTell(out
) + 1023) / 1024;
4362 job
->koctets
+= kbytes
;
4364 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets", IPP_TAG_INTEGER
)) != NULL
)
4365 attr
->values
[0].integer
+= kbytes
;
4374 * 'copy_file()' - Copy a PPD file...
4377 static int /* O - 0 = success, -1 = error */
4378 copy_file(const char *from
, /* I - Source file */
4379 const char *to
, /* I - Destination file */
4380 mode_t mode
) /* I - Permissions */
4382 cups_file_t
*src
, /* Source file */
4383 *dst
; /* Destination file */
4384 int bytes
; /* Bytes to read/write */
4385 char buffer
[2048]; /* Copy buffer */
4388 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_file(\"%s\", \"%s\")", from
, to
);
4391 * Open the source and destination file for a copy...
4394 if ((src
= cupsFileOpen(from
, "rb")) == NULL
)
4397 if ((dst
= cupsdCreateConfFile(to
, mode
)) == NULL
)
4404 * Copy the source file to the destination...
4407 while ((bytes
= cupsFileRead(src
, buffer
, sizeof(buffer
))) > 0)
4408 if (cupsFileWrite(dst
, buffer
, (size_t)bytes
) < bytes
)
4416 * Close both files and return...
4421 return (cupsdCloseCreatedConfFile(dst
, to
));
4426 * 'copy_model()' - Copy a PPD model file, substituting default values
4430 static int /* O - 0 = success, -1 = error */
4431 copy_model(cupsd_client_t
*con
, /* I - Client connection */
4432 const char *from
, /* I - Source file */
4433 const char *to
) /* I - Destination file */
4435 fd_set input
; /* select() input set */
4436 struct timeval timeout
; /* select() timeout */
4437 int maxfd
; /* Max file descriptor for select() */
4438 char tempfile
[1024]; /* Temporary PPD file */
4439 int tempfd
; /* Temporary PPD file descriptor */
4440 int temppid
; /* Process ID of cups-driverd */
4441 int temppipe
[2]; /* Temporary pipes */
4442 char *argv
[4], /* Command-line arguments */
4443 *envp
[MAX_ENV
]; /* Environment */
4444 cups_file_t
*src
, /* Source file */
4445 *dst
; /* Destination file */
4446 ppd_file_t
*ppd
; /* PPD file */
4447 int bytes
, /* Bytes from pipe */
4448 total
; /* Total bytes from pipe */
4449 char buffer
[2048]; /* Copy buffer */
4450 int i
; /* Looping var */
4451 char option
[PPD_MAX_NAME
], /* Option name */
4452 choice
[PPD_MAX_NAME
]; /* Choice name */
4453 ppd_size_t
*size
; /* Default size */
4454 int num_defaults
; /* Number of default options */
4455 cups_option_t
*defaults
; /* Default options */
4456 char cups_protocol
[PPD_MAX_LINE
];
4457 /* cupsProtocol attribute */
4460 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_model(con=%p, from=\"%s\", to=\"%s\")", con
, from
, to
);
4463 * Run cups-driverd to get the PPD file...
4466 argv
[0] = "cups-driverd";
4468 argv
[2] = (char *)from
;
4471 cupsdLoadEnv(envp
, (int)(sizeof(envp
) / sizeof(envp
[0])));
4473 snprintf(buffer
, sizeof(buffer
), "%s/daemon/cups-driverd", ServerBin
);
4474 snprintf(tempfile
, sizeof(tempfile
), "%s/%d.ppd", TempDir
, con
->number
);
4475 tempfd
= open(tempfile
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
4476 if (tempfd
< 0 || cupsdOpenPipe(temppipe
))
4479 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4480 "copy_model: Running \"cups-driverd cat %s\"...", from
);
4482 if (!cupsdStartProcess(buffer
, argv
, envp
, -1, temppipe
[1], CGIPipes
[1],
4483 -1, -1, 0, DefaultProfile
, NULL
, &temppid
))
4494 * Wait up to 30 seconds for the PPD file to be copied...
4499 if (temppipe
[0] > CGIPipes
[0])
4500 maxfd
= temppipe
[0] + 1;
4502 maxfd
= CGIPipes
[0] + 1;
4507 * See if we have data ready...
4511 FD_SET(temppipe
[0], &input
);
4512 FD_SET(CGIPipes
[0], &input
);
4514 timeout
.tv_sec
= 30;
4515 timeout
.tv_usec
= 0;
4517 if ((i
= select(maxfd
, &input
, NULL
, NULL
, &timeout
)) < 0)
4527 * We have timed out...
4533 if (FD_ISSET(temppipe
[0], &input
))
4536 * Read the PPD file from the pipe, and write it to the PPD file.
4539 if ((bytes
= read(temppipe
[0], buffer
, sizeof(buffer
))) > 0)
4541 if (write(tempfd
, buffer
, (size_t)bytes
) < bytes
)
4550 if (FD_ISSET(CGIPipes
[0], &input
))
4560 * No data from cups-deviced...
4563 cupsdLogMessage(CUPSD_LOG_ERROR
, "copy_model: empty PPD file");
4569 * Open the source file for a copy...
4572 if ((src
= cupsFileOpen(tempfile
, "rb")) == NULL
)
4579 * Read the source file and see what page sizes are supported...
4582 if ((ppd
= _ppdOpen(src
, _PPD_LOCALIZATION_NONE
)) == NULL
)
4590 * Open the destination (if possible) and set the default options...
4595 cups_protocol
[0] = '\0';
4597 if ((dst
= cupsFileOpen(to
, "rb")) != NULL
)
4600 * Read all of the default lines from the old PPD...
4603 while (cupsFileGets(dst
, buffer
, sizeof(buffer
)))
4604 if (!strncmp(buffer
, "*Default", 8))
4607 * Add the default option...
4610 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
4611 choice
, sizeof(choice
)))
4613 ppd_option_t
*ppdo
; /* PPD option */
4617 * Only add the default if the default hasn't already been
4618 * set and the choice exists in the new PPD...
4621 if (!cupsGetOption(option
, num_defaults
, defaults
) &&
4622 (ppdo
= ppdFindOption(ppd
, option
)) != NULL
&&
4623 ppdFindChoice(ppdo
, choice
))
4624 num_defaults
= cupsAddOption(option
, choice
, num_defaults
,
4628 else if (!strncmp(buffer
, "*cupsProtocol:", 14))
4629 strlcpy(cups_protocol
, buffer
, sizeof(cups_protocol
));
4633 else if ((size
= ppdPageSize(ppd
, DefaultPaperSize
)) != NULL
)
4636 * Add the default media sizes...
4639 num_defaults
= cupsAddOption("PageSize", size
->name
,
4640 num_defaults
, &defaults
);
4641 num_defaults
= cupsAddOption("PageRegion", size
->name
,
4642 num_defaults
, &defaults
);
4643 num_defaults
= cupsAddOption("PaperDimension", size
->name
,
4644 num_defaults
, &defaults
);
4645 num_defaults
= cupsAddOption("ImageableArea", size
->name
,
4646 num_defaults
, &defaults
);
4652 * Open the destination file for a copy...
4655 if ((dst
= cupsdCreateConfFile(to
, ConfigFilePerm
)) == NULL
)
4657 cupsFreeOptions(num_defaults
, defaults
);
4664 * Copy the source file to the destination...
4667 cupsFileRewind(src
);
4669 while (cupsFileGets(src
, buffer
, sizeof(buffer
)))
4671 if (!strncmp(buffer
, "*Default", 8))
4674 * Check for an previous default option choice...
4677 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
4678 choice
, sizeof(choice
)))
4680 const char *val
; /* Default option value */
4683 if ((val
= cupsGetOption(option
, num_defaults
, defaults
)) != NULL
)
4686 * Substitute the previous choice...
4689 snprintf(buffer
, sizeof(buffer
), "*Default%s: %s", option
, val
);
4694 cupsFilePrintf(dst
, "%s\n", buffer
);
4697 if (cups_protocol
[0])
4698 cupsFilePrintf(dst
, "%s\n", cups_protocol
);
4700 cupsFreeOptions(num_defaults
, defaults
);
4703 * Close both files and return...
4710 return (cupsdCloseCreatedConfFile(dst
, to
));
4715 * 'copy_job_attrs()' - Copy job attributes.
4719 copy_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
4720 cupsd_job_t
*job
, /* I - Job */
4721 cups_array_t
*ra
, /* I - Requested attributes array */
4722 cups_array_t
*exclude
) /* I - Private attributes array */
4724 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
4728 * Send the requested attributes for each job...
4731 if (!cupsArrayFind(exclude
, "all"))
4733 if ((!exclude
|| !cupsArrayFind(exclude
, "number-of-documents")) &&
4734 (!ra
|| cupsArrayFind(ra
, "number-of-documents")))
4735 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4736 "number-of-documents", job
->num_files
);
4738 if ((!exclude
|| !cupsArrayFind(exclude
, "job-media-progress")) &&
4739 (!ra
|| cupsArrayFind(ra
, "job-media-progress")))
4740 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4741 "job-media-progress", job
->progress
);
4743 if ((!exclude
|| !cupsArrayFind(exclude
, "job-more-info")) &&
4744 (!ra
|| cupsArrayFind(ra
, "job-more-info")))
4746 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "http",
4747 NULL
, con
->clientname
, con
->clientport
, "/jobs/%d",
4749 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4750 "job-more-info", NULL
, job_uri
);
4753 if (job
->state_value
> IPP_JOB_PROCESSING
&&
4754 (!exclude
|| !cupsArrayFind(exclude
, "job-preserved")) &&
4755 (!ra
|| cupsArrayFind(ra
, "job-preserved")))
4756 ippAddBoolean(con
->response
, IPP_TAG_JOB
, "job-preserved",
4757 job
->num_files
> 0);
4759 if ((!exclude
|| !cupsArrayFind(exclude
, "job-printer-up-time")) &&
4760 (!ra
|| cupsArrayFind(ra
, "job-printer-up-time")))
4761 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4762 "job-printer-up-time", time(NULL
));
4765 if (!ra
|| cupsArrayFind(ra
, "job-printer-uri"))
4767 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
4768 con
->clientname
, con
->clientport
,
4769 (job
->dtype
& CUPS_PRINTER_CLASS
) ? "/classes/%s" :
4772 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4773 "job-printer-uri", NULL
, job_uri
);
4776 if (!ra
|| cupsArrayFind(ra
, "job-uri"))
4778 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
4779 con
->clientname
, con
->clientport
, "/jobs/%d",
4781 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4782 "job-uri", NULL
, job_uri
);
4787 copy_attrs(con
->response
, job
->attrs
, ra
, IPP_TAG_JOB
, 0, exclude
);
4792 * Generate attributes from the job structure...
4795 if (job
->completed_time
&& (!ra
|| cupsArrayFind(ra
, "date-time-at-completed")))
4796 ippAddDate(con
->response
, IPP_TAG_JOB
, "date-time-at-completed", ippTimeToDate(job
->completed_time
));
4798 if (job
->creation_time
&& (!ra
|| cupsArrayFind(ra
, "date-time-at-creation")))
4799 ippAddDate(con
->response
, IPP_TAG_JOB
, "date-time-at-creation", ippTimeToDate(job
->creation_time
));
4801 if (!ra
|| cupsArrayFind(ra
, "job-id"))
4802 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
4804 if (!ra
|| cupsArrayFind(ra
, "job-k-octets"))
4805 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-k-octets", job
->koctets
);
4807 if (job
->name
&& (!ra
|| cupsArrayFind(ra
, "job-name")))
4808 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
, job
->name
);
4810 if (job
->username
&& (!ra
|| cupsArrayFind(ra
, "job-originating-user-name")))
4811 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-originating-user-name", NULL
, job
->username
);
4813 if (!ra
|| cupsArrayFind(ra
, "job-state"))
4814 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state", (int)job
->state_value
);
4816 if (!ra
|| cupsArrayFind(ra
, "job-state-reasons"))
4818 switch (job
->state_value
)
4820 default : /* Should never get here for processing, pending, held, or stopped jobs since they don't get unloaded... */
4822 case IPP_JSTATE_ABORTED
:
4823 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons", NULL
, "job-aborted-by-system");
4825 case IPP_JSTATE_CANCELED
:
4826 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons", NULL
, "job-canceled-by-user");
4828 case IPP_JSTATE_COMPLETED
:
4829 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons", NULL
, "job-completed-successfully");
4834 if (job
->completed_time
&& (!ra
|| cupsArrayFind(ra
, "time-at-completed")))
4835 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-completed", (int)job
->completed_time
);
4837 if (job
->creation_time
&& (!ra
|| cupsArrayFind(ra
, "time-at-creation")))
4838 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation", (int)job
->creation_time
);
4844 * 'copy_printer_attrs()' - Copy printer attributes.
4849 cupsd_client_t
*con
, /* I - Client connection */
4850 cupsd_printer_t
*printer
, /* I - Printer */
4851 cups_array_t
*ra
) /* I - Requested attributes array */
4853 char uri
[HTTP_MAX_URI
]; /* URI value */
4854 time_t curtime
; /* Current time */
4855 int i
; /* Looping var */
4856 int is_encrypted
= httpIsEncrypted(con
->http
);
4857 /* Is the connection encrypted? */
4861 * Copy the printer attributes to the response using requested-attributes
4862 * and document-format attributes that may be provided by the client.
4865 _cupsRWLockRead(&printer
->lock
);
4867 curtime
= time(NULL
);
4869 if (!ra
|| cupsArrayFind(ra
, "marker-change-time"))
4870 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "marker-change-time", printer
->marker_time
);
4872 if (printer
->num_printers
> 0 && (!ra
|| cupsArrayFind(ra
, "member-uris")))
4874 ipp_attribute_t
*member_uris
; /* member-uris attribute */
4875 cupsd_printer_t
*p2
; /* Printer in class */
4876 ipp_attribute_t
*p2_uri
; /* printer-uri-supported for class printer */
4879 if ((member_uris
= ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "member-uris", printer
->num_printers
, NULL
, NULL
)) != NULL
)
4881 for (i
= 0; i
< printer
->num_printers
; i
++)
4883 p2
= printer
->printers
[i
];
4885 if ((p2_uri
= ippFindAttribute(p2
->attrs
, "printer-uri-supported", IPP_TAG_URI
)) != NULL
)
4887 member_uris
->values
[i
].string
.text
= _cupsStrAlloc(p2_uri
->values
[0].string
.text
);
4891 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
);
4892 member_uris
->values
[i
].string
.text
= _cupsStrAlloc(uri
);
4898 if (printer
->alert
&& (!ra
|| cupsArrayFind(ra
, "printer-alert")))
4899 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_STRING
, "printer-alert", NULL
, printer
->alert
);
4901 if (printer
->alert_description
&& (!ra
|| cupsArrayFind(ra
, "printer-alert-description")))
4902 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-alert-description", NULL
, printer
->alert_description
);
4904 if (!ra
|| cupsArrayFind(ra
, "printer-config-change-date-time"))
4905 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-config-change-date-time", ippTimeToDate(printer
->config_time
));
4907 if (!ra
|| cupsArrayFind(ra
, "printer-config-change-time"))
4908 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "printer-config-change-time", printer
->config_time
);
4910 if (!ra
|| cupsArrayFind(ra
, "printer-current-time"))
4911 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-current-time", ippTimeToDate(curtime
));
4913 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
4914 if (!ra
|| cupsArrayFind(ra
, "printer-dns-sd-name"))
4916 if (printer
->reg_name
)
4917 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-dns-sd-name", NULL
, printer
->reg_name
);
4919 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
, "printer-dns-sd-name", 0);
4921 #endif /* HAVE_DNSSD || HAVE_AVAHI */
4923 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy"))
4924 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-error-policy", NULL
, printer
->error_policy
);
4926 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy-supported"))
4928 static const char * const errors
[] =/* printer-error-policy-supported values */
4931 "retry-current-job",
4936 if (printer
->type
& CUPS_PRINTER_CLASS
)
4937 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_CONST_TAG(IPP_TAG_NAME
), "printer-error-policy-supported", NULL
, "retry-current-job");
4939 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_CONST_TAG(IPP_TAG_NAME
), "printer-error-policy-supported", sizeof(errors
) / sizeof(errors
[0]), NULL
, errors
);
4942 if (!ra
|| cupsArrayFind(ra
, "printer-icons"))
4944 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), is_encrypted
? "https" : "http", NULL
, con
->clientname
, con
->clientport
, "/icons/%s.png", printer
->name
);
4945 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-icons", NULL
, uri
);
4946 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-icons=\"%s\"", uri
);
4949 if (!ra
|| cupsArrayFind(ra
, "printer-is-accepting-jobs"))
4950 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs", (char)printer
->accepting
);
4952 if (!ra
|| cupsArrayFind(ra
, "printer-is-shared"))
4953 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-shared", (char)printer
->shared
);
4955 if (!ra
|| cupsArrayFind(ra
, "printer-is-temporary"))
4956 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-temporary", (char)printer
->temporary
);
4958 if (!ra
|| cupsArrayFind(ra
, "printer-more-info"))
4960 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
);
4961 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-more-info", NULL
, uri
);
4964 if (!ra
|| cupsArrayFind(ra
, "printer-op-policy"))
4965 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-op-policy", NULL
, printer
->op_policy
);
4967 if (!ra
|| cupsArrayFind(ra
, "printer-state"))
4968 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state", printer
->state
);
4970 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-date-time"))
4971 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-state-change-date-time", ippTimeToDate(printer
->state_time
));
4973 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-time"))
4974 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "printer-state-change-time", printer
->state_time
);
4976 if (!ra
|| cupsArrayFind(ra
, "printer-state-message"))
4977 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-state-message", NULL
, printer
->state_message
);
4979 if (!ra
|| cupsArrayFind(ra
, "printer-state-reasons"))
4980 add_printer_state_reasons(con
, printer
);
4982 if (!ra
|| cupsArrayFind(ra
, "printer-strings-uri"))
4984 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), is_encrypted
? "https" : "http", NULL
, con
->clientname
, con
->clientport
, "/strings/%s.strings", printer
->name
);
4985 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-strings-uri", NULL
, uri
);
4986 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-strings-uri=\"%s\"", uri
);
4989 if (!ra
|| cupsArrayFind(ra
, "printer-type"))
4991 cups_ptype_t type
; /* printer-type value */
4994 * Add the CUPS-specific printer-type attribute...
4997 type
= printer
->type
;
4999 if (printer
== DefaultPrinter
)
5000 type
|= CUPS_PRINTER_DEFAULT
;
5002 if (!printer
->accepting
)
5003 type
|= CUPS_PRINTER_REJECTING
;
5005 if (!printer
->shared
)
5006 type
|= CUPS_PRINTER_NOT_SHARED
;
5008 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-type", (int)type
);
5011 if (!ra
|| cupsArrayFind(ra
, "printer-up-time"))
5012 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "printer-up-time", curtime
);
5014 if (!ra
|| cupsArrayFind(ra
, "printer-uri-supported"))
5016 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
);
5017 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-uri-supported", NULL
, uri
);
5018 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-uri-supported=\"%s\"", uri
);
5021 if (!ra
|| cupsArrayFind(ra
, "queued-job-count"))
5022 add_queued_job_count(con
, printer
);
5024 copy_attrs(con
->response
, printer
->attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
5025 if (printer
->ppd_attrs
)
5026 copy_attrs(con
->response
, printer
->ppd_attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
5027 copy_attrs(con
->response
, CommonData
, ra
, IPP_TAG_ZERO
, IPP_TAG_COPY
, NULL
);
5029 _cupsRWUnlock(&printer
->lock
);
5034 * 'copy_subscription_attrs()' - Copy subscription attributes.
5038 copy_subscription_attrs(
5039 cupsd_client_t
*con
, /* I - Client connection */
5040 cupsd_subscription_t
*sub
, /* I - Subscription */
5041 cups_array_t
*ra
, /* I - Requested attributes array */
5042 cups_array_t
*exclude
) /* I - Private attributes array */
5044 ipp_attribute_t
*attr
; /* Current attribute */
5045 char printer_uri
[HTTP_MAX_URI
];
5047 int count
; /* Number of events */
5048 unsigned mask
; /* Current event mask */
5049 const char *name
; /* Current event name */
5052 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5053 "copy_subscription_attrs(con=%p, sub=%p, ra=%p, exclude=%p)",
5054 con
, sub
, ra
, exclude
);
5057 * Copy the subscription attributes to the response using the
5058 * requested-attributes attribute that may be provided by the client.
5061 if (!exclude
|| !cupsArrayFind(exclude
, "all"))
5063 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-events")) &&
5064 (!ra
|| cupsArrayFind(ra
, "notify-events")))
5066 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_subscription_attrs: notify-events");
5068 if ((name
= cupsdEventName((cupsd_eventmask_t
)sub
->mask
)) != NULL
)
5071 * Simple event list...
5074 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_CONST_TAG(IPP_TAG_KEYWORD
), "notify-events", NULL
, name
);
5079 * Complex event list...
5082 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5083 if (sub
->mask
& mask
)
5086 attr
= ippAddStrings(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_CONST_TAG(IPP_TAG_KEYWORD
), "notify-events", count
, NULL
, NULL
);
5088 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5089 if (sub
->mask
& mask
)
5091 attr
->values
[count
].string
.text
= (char *)cupsdEventName((cupsd_eventmask_t
)mask
);
5098 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-lease-duration")) &&
5099 (!sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-lease-duration"))))
5100 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5101 "notify-lease-duration", sub
->lease
);
5103 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-recipient-uri")) &&
5104 (sub
->recipient
&& (!ra
|| cupsArrayFind(ra
, "notify-recipient-uri"))))
5105 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5106 "notify-recipient-uri", NULL
, sub
->recipient
);
5107 else if ((!exclude
|| !cupsArrayFind(exclude
, "notify-pull-method")) &&
5108 (!ra
|| cupsArrayFind(ra
, "notify-pull-method")))
5109 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_KEYWORD
,
5110 "notify-pull-method", NULL
, "ippget");
5112 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-subscriber-user-name")) &&
5113 (!ra
|| cupsArrayFind(ra
, "notify-subscriber-user-name")))
5114 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_NAME
,
5115 "notify-subscriber-user-name", NULL
, sub
->owner
);
5117 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-time-interval")) &&
5118 (!ra
|| cupsArrayFind(ra
, "notify-time-interval")))
5119 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5120 "notify-time-interval", sub
->interval
);
5122 if (sub
->user_data_len
> 0 &&
5123 (!exclude
|| !cupsArrayFind(exclude
, "notify-user-data")) &&
5124 (!ra
|| cupsArrayFind(ra
, "notify-user-data")))
5125 ippAddOctetString(con
->response
, IPP_TAG_SUBSCRIPTION
, "notify-user-data",
5126 sub
->user_data
, sub
->user_data_len
);
5129 if (sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-job-id")))
5130 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5131 "notify-job-id", sub
->job
->id
);
5133 if (sub
->dest
&& (!ra
|| cupsArrayFind(ra
, "notify-printer-uri")))
5135 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5136 "ipp", NULL
, con
->clientname
, con
->clientport
,
5137 "/printers/%s", sub
->dest
->name
);
5138 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5139 "notify-printer-uri", NULL
, printer_uri
);
5142 if (!ra
|| cupsArrayFind(ra
, "notify-subscription-id"))
5143 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5144 "notify-subscription-id", sub
->id
);
5149 * 'create_job()' - Print a file to a printer or class.
5153 create_job(cupsd_client_t
*con
, /* I - Client connection */
5154 ipp_attribute_t
*uri
) /* I - Printer URI */
5156 int i
; /* Looping var */
5157 cupsd_printer_t
*printer
; /* Printer */
5158 cupsd_job_t
*job
; /* New job */
5159 static const char * const forbidden_attrs
[] =
5160 { /* List of forbidden attributes */
5164 "document-natural-language"
5168 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "create_job(%p[%d], %s)", con
,
5169 con
->number
, uri
->values
[0].string
.text
);
5172 * Is the destination valid?
5175 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
5181 send_ipp_status(con
, IPP_NOT_FOUND
,
5182 _("The printer or class does not exist."));
5187 * Check for invalid Create-Job attributes and log a warning or error depending
5188 * on whether cupsd is running in "strict conformance" mode...
5192 i
< (int)(sizeof(forbidden_attrs
) / sizeof(forbidden_attrs
[0]));
5194 if (ippFindAttribute(con
->request
, forbidden_attrs
[i
], IPP_TAG_ZERO
))
5196 if (StrictConformance
)
5198 send_ipp_status(con
, IPP_BAD_REQUEST
,
5199 _("The '%s' operation attribute cannot be supplied in a "
5200 "Create-Job request."), forbidden_attrs
[i
]);
5204 cupsdLogMessage(CUPSD_LOG_WARN
,
5205 "Unexpected '%s' operation attribute in a Create-Job "
5206 "request.", forbidden_attrs
[i
]);
5210 * Create the job object...
5213 if ((job
= add_job(con
, printer
, NULL
)) == NULL
)
5216 job
->pending_timeout
= 1;
5219 * Save and log the job...
5222 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
5223 job
->dest
, job
->username
);
5228 * 'create_local_bg_thread()' - Background thread for creating a local print queue.
5231 static void * /* O - Exit status */
5232 create_local_bg_thread(
5233 cupsd_printer_t
*printer
) /* I - Printer */
5235 cups_file_t
*from
, /* Source file */
5236 *to
; /* Destination file */
5237 char fromppd
[1024], /* Source PPD */
5238 toppd
[1024], /* Destination PPD */
5239 scheme
[32], /* URI scheme */
5240 userpass
[256], /* User:pass */
5241 host
[256], /* Hostname */
5242 resource
[1024], /* Resource path */
5243 line
[1024]; /* Line from PPD */
5244 int port
; /* Port number */
5245 http_encryption_t encryption
; /* Type of encryption to use */
5246 http_t
*http
; /* Connection to printer */
5247 ipp_t
*request
, /* Request to printer */
5248 *response
; /* Response from printer */
5249 ipp_attribute_t
*attr
; /* Attribute in response */
5250 ipp_status_t status
; /* Status code */
5251 static const char * const pattrs
[] = /* Printer attributes we need */
5254 "media-col-database"
5259 * Try connecting to the printer...
5262 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s: Generating PPD file from \"%s\"...", printer
->name
, printer
->device_uri
);
5264 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
)
5266 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: Bad device URI \"%s\".", printer
->name
, printer
->device_uri
);
5270 if (!strcmp(scheme
, "ipps") || port
== 443)
5271 encryption
= HTTP_ENCRYPTION_ALWAYS
;
5273 encryption
= HTTP_ENCRYPTION_IF_REQUESTED
;
5275 if ((http
= httpConnect2(host
, port
, NULL
, AF_UNSPEC
, encryption
, 1, 30000, NULL
)) == NULL
)
5277 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: Unable to connect to %s:%d: %s", printer
->name
, host
, port
, cupsLastErrorString());
5282 * Query the printer for its capabilities...
5285 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s: Connected to %s:%d, sending Get-Printer-Attributes request...", printer
->name
, host
, port
);
5287 request
= ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES
);
5288 ippSetVersion(request
, 2, 0);
5289 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
, printer
->device_uri
);
5290 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
, "requested-attributes", (int)(sizeof(pattrs
) / sizeof(pattrs
[0])), NULL
, pattrs
);
5292 response
= cupsDoRequest(http
, request
, resource
);
5293 status
= cupsLastError();
5295 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s: Get-Printer-Attributes returned %s (%s)", printer
->name
, ippErrorString(cupsLastError()), cupsLastErrorString());
5297 if (status
== IPP_STATUS_ERROR_BAD_REQUEST
|| status
== IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED
)
5300 * Try request using IPP/1.1, in case we are talking to an old CUPS server or
5304 ippDelete(response
);
5306 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s: Re-sending Get-Printer-Attributes request using IPP/1.1...", printer
->name
);
5308 request
= ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES
);
5309 ippSetVersion(request
, 1, 1);
5310 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
, printer
->device_uri
);
5311 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
, "requested-attributes", NULL
, "all");
5313 response
= cupsDoRequest(http
, request
, resource
);
5315 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s: IPP/1.1 Get-Printer-Attributes returned %s (%s)", printer
->name
, ippErrorString(cupsLastError()), cupsLastErrorString());
5318 // TODO: Grab printer icon file...
5322 * Write the PPD for the queue...
5325 if (_ppdCreateFromIPP(fromppd
, sizeof(fromppd
), response
))
5327 _cupsRWLockWrite(&printer
->lock
);
5329 if ((!printer
->info
|| !*(printer
->info
)) && (attr
= ippFindAttribute(response
, "printer-info", IPP_TAG_TEXT
)) != NULL
)
5330 cupsdSetString(&printer
->info
, ippGetString(attr
, 0, NULL
));
5332 if ((!printer
->location
|| !*(printer
->location
)) && (attr
= ippFindAttribute(response
, "printer-location", IPP_TAG_TEXT
)) != NULL
)
5333 cupsdSetString(&printer
->location
, ippGetString(attr
, 0, NULL
));
5335 if ((!printer
->geo_location
|| !*(printer
->geo_location
)) && (attr
= ippFindAttribute(response
, "printer-geo-location", IPP_TAG_URI
)) != NULL
)
5336 cupsdSetString(&printer
->geo_location
, ippGetString(attr
, 0, NULL
));
5338 _cupsRWUnlock(&printer
->lock
);
5340 if ((from
= cupsFileOpen(fromppd
, "r")) == NULL
)
5342 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: Unable to read generated PPD: %s", printer
->name
, strerror(errno
));
5346 snprintf(toppd
, sizeof(toppd
), "%s/ppd/%s.ppd", ServerRoot
, printer
->name
);
5347 if ((to
= cupsdCreateConfFile(toppd
, ConfigFilePerm
)) == NULL
)
5349 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: Unable to create PPD for printer: %s", printer
->name
, strerror(errno
));
5350 cupsFileClose(from
);
5354 while (cupsFileGets(from
, line
, sizeof(line
)))
5355 cupsFilePrintf(to
, "%s\n", line
);
5357 cupsFileClose(from
);
5358 if (!cupsdCloseCreatedConfFile(to
, toppd
))
5360 printer
->config_time
= time(NULL
);
5361 printer
->state
= IPP_PSTATE_IDLE
;
5362 printer
->accepting
= 1;
5364 cupsdSetPrinterAttrs(printer
);
5366 cupsdAddEvent(CUPSD_EVENT_PRINTER_CONFIG
, printer
, NULL
, "Printer \"%s\" is now available.", printer
->name
);
5367 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" is now available.", printer
->name
);
5371 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: PPD creation failed: %s", printer
->name
, cupsLastErrorString());
5378 * 'create_local_printer()' - Create a local (temporary) print queue.
5382 create_local_printer(
5383 cupsd_client_t
*con
) /* I - Client connection */
5385 ipp_attribute_t
*device_uri
, /* device-uri attribute */
5386 *printer_geo_location
, /* printer-geo-location attribute */
5387 *printer_info
, /* printer-info attribute */
5388 *printer_location
, /* printer-location attribute */
5389 *printer_name
; /* printer-name attribute */
5390 cupsd_printer_t
*printer
; /* New printer */
5391 http_status_t status
; /* Policy status */
5392 char name
[128], /* Sanitized printer name */
5393 *nameptr
, /* Pointer into name */
5394 uri
[1024]; /* printer-uri-supported value */
5395 const char *ptr
; /* Pointer into attribute value */
5399 * Require local access to create a local printer...
5402 if (!httpAddrLocalhost(httpGetAddress(con
->http
)))
5404 send_ipp_status(con
, IPP_STATUS_ERROR_FORBIDDEN
, _("Only local users can create a local printer."));
5409 * Check any other policy limits...
5412 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5414 send_http_error(con
, status
, NULL
);
5419 * Grab needed attributes...
5422 if ((printer_name
= ippFindAttribute(con
->request
, "printer-name", IPP_TAG_ZERO
)) == NULL
|| ippGetGroupTag(printer_name
) != IPP_TAG_PRINTER
|| ippGetValueTag(printer_name
) != IPP_TAG_NAME
)
5425 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Missing required attribute \"%s\"."), "printer-name");
5426 else if (ippGetGroupTag(printer_name
) != IPP_TAG_PRINTER
)
5427 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Attribute \"%s\" is in the wrong group."), "printer-name");
5429 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Attribute \"%s\" is the wrong value type."), "printer-name");
5434 for (nameptr
= name
, ptr
= ippGetString(printer_name
, 0, NULL
); *ptr
&& nameptr
< (name
+ sizeof(name
) - 1); ptr
++)
5437 * Sanitize the printer name...
5440 if (_cups_isalnum(*ptr
))
5442 else if (nameptr
== name
|| nameptr
[-1] != '_')
5448 if ((device_uri
= ippFindAttribute(con
->request
, "device-uri", IPP_TAG_ZERO
)) == NULL
|| ippGetGroupTag(device_uri
) != IPP_TAG_PRINTER
|| ippGetValueTag(device_uri
) != IPP_TAG_URI
)
5451 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Missing required attribute \"%s\"."), "device-uri");
5452 else if (ippGetGroupTag(device_uri
) != IPP_TAG_PRINTER
)
5453 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Attribute \"%s\" is in the wrong group."), "device-uri");
5455 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Attribute \"%s\" is the wrong value type."), "device-uri");
5460 printer_geo_location
= ippFindAttribute(con
->request
, "printer-geo-location", IPP_TAG_URI
);
5461 printer_info
= ippFindAttribute(con
->request
, "printer-info", IPP_TAG_TEXT
);
5462 printer_location
= ippFindAttribute(con
->request
, "printer-location", IPP_TAG_TEXT
);
5465 * See if the printer already exists...
5468 if ((printer
= cupsdFindDest(name
)) != NULL
)
5470 send_ipp_status(con
, IPP_STATUS_ERROR_NOT_POSSIBLE
, _("Printer \"%s\" already exists."), name
);
5471 goto add_printer_attributes
;
5475 * Create the printer...
5478 if ((printer
= cupsdAddPrinter(name
)) == NULL
)
5480 send_ipp_status(con
, IPP_STATUS_ERROR_INTERNAL
, _("Unable to create printer."));
5484 printer
->shared
= 0;
5485 printer
->temporary
= 1;
5487 cupsdSetDeviceURI(printer
, ippGetString(device_uri
, 0, NULL
));
5489 if (printer_geo_location
)
5490 cupsdSetString(&printer
->geo_location
, ippGetString(printer_geo_location
, 0, NULL
));
5492 cupsdSetString(&printer
->info
, ippGetString(printer_info
, 0, NULL
));
5493 if (printer_location
)
5494 cupsdSetString(&printer
->location
, ippGetString(printer_location
, 0, NULL
));
5496 cupsdSetPrinterAttrs(printer
);
5499 * Run a background thread to create the PPD...
5502 _cupsThreadCreate((_cups_thread_func_t
)create_local_bg_thread
, printer
);
5505 * Return printer attributes...
5508 send_ipp_status(con
, IPP_STATUS_OK
, _("Local printer created."));
5510 add_printer_attributes
:
5512 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs", (char)printer
->accepting
);
5513 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state", printer
->state
);
5514 add_printer_state_reasons(con
, printer
);
5516 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), httpIsEncrypted(con
->http
) ? "ipps" : "ipp", NULL
, con
->clientname
, con
->clientport
, "/printers/%s", printer
->name
);
5517 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-uri-supported", NULL
, uri
);
5522 * 'create_requested_array()' - Create an array for the requested-attributes.
5525 static cups_array_t
* /* O - Array of attributes or NULL */
5526 create_requested_array(ipp_t
*request
) /* I - IPP request */
5528 cups_array_t
*ra
; /* Requested attributes array */
5532 * Create the array for standard attributes...
5535 ra
= ippCreateRequestedArray(request
);
5538 * Add CUPS defaults as needed...
5541 if (cupsArrayFind(ra
, "printer-defaults"))
5544 * Include user-set defaults...
5547 char *name
; /* Option name */
5549 cupsArrayRemove(ra
, "printer-defaults");
5551 for (name
= (char *)cupsArrayFirst(CommonDefaults
);
5553 name
= (char *)cupsArrayNext(CommonDefaults
))
5554 if (!cupsArrayFind(ra
, name
))
5555 cupsArrayAdd(ra
, name
);
5563 * 'create_subscriptions()' - Create one or more notification subscriptions.
5567 create_subscriptions(
5568 cupsd_client_t
*con
, /* I - Client connection */
5569 ipp_attribute_t
*uri
) /* I - Printer URI */
5571 http_status_t status
; /* Policy status */
5572 int i
; /* Looping var */
5573 ipp_attribute_t
*attr
; /* Current attribute */
5574 cups_ptype_t dtype
; /* Destination type (printer/class) */
5575 char scheme
[HTTP_MAX_URI
],
5576 /* Scheme portion of URI */
5577 userpass
[HTTP_MAX_URI
],
5578 /* Username portion of URI */
5580 /* Host portion of URI */
5581 resource
[HTTP_MAX_URI
];
5582 /* Resource portion of URI */
5583 int port
; /* Port portion of URI */
5584 cupsd_printer_t
*printer
; /* Printer/class */
5585 cupsd_job_t
*job
; /* Job */
5586 int jobid
; /* Job ID */
5587 cupsd_subscription_t
*sub
; /* Subscription object */
5588 const char *username
, /* requesting-user-name or
5589 authenticated username */
5590 *recipient
, /* notify-recipient-uri */
5591 *pullmethod
; /* notify-pull-method */
5592 ipp_attribute_t
*user_data
; /* notify-user-data */
5593 int interval
, /* notify-time-interval */
5594 lease
; /* notify-lease-duration */
5595 unsigned mask
; /* notify-events */
5596 ipp_attribute_t
*notify_events
,/* notify-events(-default) */
5597 *notify_lease
; /* notify-lease-duration(-default) */
5601 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
5603 if (attr
->group_tag
!= IPP_TAG_ZERO
)
5604 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "g%04x v%04x %s", attr
->group_tag
,
5605 attr
->value_tag
, attr
->name
);
5607 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "----SEP----");
5612 * Is the destination valid?
5615 cupsdLogMessage(CUPSD_LOG_DEBUG
, "create_subscriptions(con=%p(%d), uri=\"%s\")", con
, con
->number
, uri
->values
[0].string
.text
);
5617 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
5618 sizeof(scheme
), userpass
, sizeof(userpass
), host
,
5619 sizeof(host
), &port
, resource
, sizeof(resource
));
5621 if (!strcmp(resource
, "/"))
5623 dtype
= (cups_ptype_t
)0;
5626 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
5628 dtype
= (cups_ptype_t
)0;
5631 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
5633 dtype
= CUPS_PRINTER_CLASS
;
5636 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
5642 send_ipp_status(con
, IPP_NOT_FOUND
,
5643 _("The printer or class does not exist."));
5653 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
5656 send_http_error(con
, status
, printer
);
5660 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5662 send_http_error(con
, status
, NULL
);
5667 * Get the user that is requesting the subscription...
5670 username
= get_username(con
);
5673 * Find the first subscription group attribute; return if we have
5677 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
5678 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
5683 send_ipp_status(con
, IPP_BAD_REQUEST
,
5684 _("No subscription attributes in request."));
5689 * Process the subscription attributes in the request...
5692 con
->response
->request
.status
.status_code
= IPP_BAD_REQUEST
;
5700 lease
= DefaultLeaseDuration
;
5702 mask
= CUPSD_EVENT_NONE
;
5706 notify_events
= ippFindAttribute(printer
->attrs
, "notify-events-default",
5708 notify_lease
= ippFindAttribute(printer
->attrs
,
5709 "notify-lease-duration-default",
5713 lease
= notify_lease
->values
[0].integer
;
5717 notify_events
= NULL
;
5718 notify_lease
= NULL
;
5721 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
5723 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
5724 attr
->value_tag
== IPP_TAG_URI
)
5727 * Validate the recipient scheme against the ServerBin/notifier
5731 char notifier
[1024]; /* Notifier filename */
5734 recipient
= attr
->values
[0].string
.text
;
5736 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
5737 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
5738 host
, sizeof(host
), &port
,
5739 resource
, sizeof(resource
)) < HTTP_URI_OK
)
5741 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5742 _("Bad notify-recipient-uri \"%s\"."), recipient
);
5743 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5744 "notify-status-code", IPP_URI_SCHEME
);
5748 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
5750 if (access(notifier
, X_OK
) || !strcmp(scheme
, ".") || !strcmp(scheme
, ".."))
5752 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5753 _("notify-recipient-uri URI \"%s\" uses unknown "
5754 "scheme."), recipient
);
5755 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5756 "notify-status-code", IPP_URI_SCHEME
);
5760 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
5762 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5763 _("notify-recipient-uri URI \"%s\" is already used."),
5765 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5766 "notify-status-code", IPP_ATTRIBUTES
);
5770 else if (!strcmp(attr
->name
, "notify-pull-method") &&
5771 attr
->value_tag
== IPP_TAG_KEYWORD
)
5773 pullmethod
= attr
->values
[0].string
.text
;
5775 if (strcmp(pullmethod
, "ippget"))
5777 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5778 _("Bad notify-pull-method \"%s\"."), pullmethod
);
5779 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5780 "notify-status-code", IPP_ATTRIBUTES
);
5784 else if (!strcmp(attr
->name
, "notify-charset") &&
5785 attr
->value_tag
== IPP_TAG_CHARSET
&&
5786 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
5787 strcmp(attr
->values
[0].string
.text
, "utf-8"))
5789 send_ipp_status(con
, IPP_CHARSET
,
5790 _("Character set \"%s\" not supported."),
5791 attr
->values
[0].string
.text
);
5794 else if (!strcmp(attr
->name
, "notify-natural-language") &&
5795 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
5796 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
5798 send_ipp_status(con
, IPP_CHARSET
,
5799 _("Language \"%s\" not supported."),
5800 attr
->values
[0].string
.text
);
5803 else if (!strcmp(attr
->name
, "notify-user-data") &&
5804 attr
->value_tag
== IPP_TAG_STRING
)
5806 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
5808 send_ipp_status(con
, IPP_REQUEST_VALUE
,
5809 _("The notify-user-data value is too large "
5810 "(%d > 63 octets)."),
5811 attr
->values
[0].unknown
.length
);
5817 else if (!strcmp(attr
->name
, "notify-events") &&
5818 attr
->value_tag
== IPP_TAG_KEYWORD
)
5819 notify_events
= attr
;
5820 else if (!strcmp(attr
->name
, "notify-lease-duration") &&
5821 attr
->value_tag
== IPP_TAG_INTEGER
)
5822 lease
= attr
->values
[0].integer
;
5823 else if (!strcmp(attr
->name
, "notify-time-interval") &&
5824 attr
->value_tag
== IPP_TAG_INTEGER
)
5825 interval
= attr
->values
[0].integer
;
5826 else if (!strcmp(attr
->name
, "notify-job-id") &&
5827 attr
->value_tag
== IPP_TAG_INTEGER
)
5828 jobid
= attr
->values
[0].integer
;
5835 for (i
= 0; i
< notify_events
->num_values
; i
++)
5836 mask
|= cupsdEventValue(notify_events
->values
[i
].string
.text
);
5841 cupsdLogMessage(CUPSD_LOG_DEBUG
, "recipient=\"%s\"", recipient
);
5844 if (!strncmp(recipient
, "mailto:", 7) && user_data
)
5846 char temp
[64]; /* Temporary string */
5848 memcpy(temp
, user_data
->values
[0].unknown
.data
, (size_t)user_data
->values
[0].unknown
.length
);
5849 temp
[user_data
->values
[0].unknown
.length
] = '\0';
5851 if (httpSeparateURI(HTTP_URI_CODING_ALL
, temp
, scheme
, sizeof(scheme
), userpass
, sizeof(userpass
), host
, sizeof(host
), &port
, resource
, sizeof(resource
)) < HTTP_URI_OK
)
5853 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad notify-user-data \"%s\"."), temp
);
5854 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
, "notify-status-code", IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES
);
5861 cupsdLogMessage(CUPSD_LOG_DEBUG
, "pullmethod=\"%s\"", pullmethod
);
5862 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-lease-duration=%d", lease
);
5863 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-time-interval=%d", interval
);
5865 if (!recipient
&& !pullmethod
)
5868 if (mask
== CUPSD_EVENT_NONE
)
5871 mask
= CUPSD_EVENT_JOB_COMPLETED
;
5873 mask
= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
5876 send_ipp_status(con
, IPP_BAD_REQUEST
,
5877 _("notify-events not specified."));
5882 if (MaxLeaseDuration
&& (lease
== 0 || lease
> MaxLeaseDuration
))
5884 cupsdLogMessage(CUPSD_LOG_INFO
,
5885 "create_subscriptions: Limiting notify-lease-duration to "
5888 lease
= MaxLeaseDuration
;
5893 if ((job
= cupsdFindJob(jobid
)) == NULL
)
5895 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
5903 if ((sub
= cupsdAddSubscription(mask
, printer
, job
, recipient
, 0)) == NULL
)
5905 send_ipp_status(con
, IPP_TOO_MANY_SUBSCRIPTIONS
,
5906 _("There are too many subscriptions."));
5911 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription #%d for job %d.",
5914 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5915 "Added subscription #%d for printer \"%s\".",
5916 sub
->id
, printer
->name
);
5918 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription #%d for server.",
5921 sub
->interval
= interval
;
5923 sub
->expire
= lease
? time(NULL
) + lease
: 0;
5925 cupsdSetString(&sub
->owner
, username
);
5929 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
5930 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
5931 (size_t)sub
->user_data_len
);
5934 ippAddSeparator(con
->response
);
5935 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5936 "notify-subscription-id", sub
->id
);
5938 con
->response
->request
.status
.status_code
= IPP_OK
;
5944 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
5949 * 'delete_printer()' - Remove a printer or class from the system.
5953 delete_printer(cupsd_client_t
*con
, /* I - Client connection */
5954 ipp_attribute_t
*uri
) /* I - URI of printer or class */
5956 http_status_t status
; /* Policy status */
5957 cups_ptype_t dtype
; /* Destination type (printer/class) */
5958 cupsd_printer_t
*printer
; /* Printer/class */
5959 char filename
[1024]; /* Script/PPD filename */
5960 int temporary
; /* Temporary queue? */
5963 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "delete_printer(%p[%d], %s)", con
,
5964 con
->number
, uri
->values
[0].string
.text
);
5967 * Do we have a valid URI?
5970 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
5976 send_ipp_status(con
, IPP_NOT_FOUND
,
5977 _("The printer or class does not exist."));
5985 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5987 send_http_error(con
, status
, NULL
);
5992 * Remove old jobs...
5995 cupsdCancelJobs(printer
->name
, NULL
, 1);
5998 * Remove old subscriptions and send a "deleted printer" event...
6001 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED
, printer
, NULL
,
6002 "%s \"%s\" deleted by \"%s\".",
6003 (dtype
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
6004 printer
->name
, get_username(con
));
6006 cupsdExpireSubscriptions(printer
, NULL
);
6009 * Remove any old PPD or script files...
6012 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
6015 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd.O", ServerRoot
,
6019 snprintf(filename
, sizeof(filename
), "%s/%s.png", CacheDir
, printer
->name
);
6022 snprintf(filename
, sizeof(filename
), "%s/%s.data", CacheDir
, printer
->name
);
6026 * Unregister color profiles...
6029 cupsdUnregisterColor(printer
);
6031 temporary
= printer
->temporary
;
6033 if (dtype
& CUPS_PRINTER_CLASS
)
6035 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" deleted by \"%s\".",
6036 printer
->name
, get_username(con
));
6038 cupsdDeletePrinter(printer
, 0);
6040 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
6044 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" deleted by \"%s\".",
6045 printer
->name
, get_username(con
));
6047 if (cupsdDeletePrinter(printer
, 0) && !temporary
)
6048 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
6051 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
6055 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
6058 * Return with no errors...
6061 con
->response
->request
.status
.status_code
= IPP_OK
;
6066 * 'get_default()' - Get the default destination.
6070 get_default(cupsd_client_t
*con
) /* I - Client connection */
6072 http_status_t status
; /* Policy status */
6073 cups_array_t
*ra
; /* Requested attributes array */
6076 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_default(%p[%d])", con
, con
->number
);
6082 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6084 send_http_error(con
, status
, NULL
);
6090 ra
= create_requested_array(con
->request
);
6092 copy_printer_attrs(con
, DefaultPrinter
, ra
);
6094 cupsArrayDelete(ra
);
6096 con
->response
->request
.status
.status_code
= IPP_OK
;
6099 send_ipp_status(con
, IPP_NOT_FOUND
, _("No default printer."));
6104 * 'get_devices()' - Get the list of available devices on the local system.
6108 get_devices(cupsd_client_t
*con
) /* I - Client connection */
6110 http_status_t status
; /* Policy status */
6111 ipp_attribute_t
*limit
, /* limit attribute */
6112 *timeout
, /* timeout attribute */
6113 *requested
, /* requested-attributes attribute */
6114 *exclude
, /* exclude-schemes attribute */
6115 *include
; /* include-schemes attribute */
6116 char command
[1024], /* cups-deviced command */
6117 options
[2048], /* Options to pass to command */
6119 /* String for requested attributes */
6121 /* String for excluded schemes */
6123 /* String for included schemes */
6126 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_devices(%p[%d])", con
, con
->number
);
6132 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6134 send_http_error(con
, status
, NULL
);
6139 * Run cups-deviced command with the given options...
6142 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
6143 timeout
= ippFindAttribute(con
->request
, "timeout", IPP_TAG_INTEGER
);
6144 requested
= ippFindAttribute(con
->request
, "requested-attributes",
6146 exclude
= ippFindAttribute(con
->request
, "exclude-schemes", IPP_TAG_NAME
);
6147 include
= ippFindAttribute(con
->request
, "include-schemes", IPP_TAG_NAME
);
6150 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
6152 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
6155 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
6157 exclude_str
[0] = '\0';
6160 url_encode_attr(include
, include_str
, sizeof(include_str
));
6162 include_str
[0] = '\0';
6164 snprintf(command
, sizeof(command
), "%s/daemon/cups-deviced", ServerBin
);
6165 snprintf(options
, sizeof(options
),
6166 "%d+%d+%d+%d+%s%s%s%s%s",
6167 con
->request
->request
.op
.request_id
,
6168 limit
? limit
->values
[0].integer
: 0,
6169 timeout
? timeout
->values
[0].integer
: 15,
6172 exclude_str
[0] ? "%20" : "", exclude_str
,
6173 include_str
[0] ? "%20" : "", include_str
);
6175 if (cupsdSendCommand(con
, command
, options
, 1))
6178 * Command started successfully, don't send an IPP response here...
6181 ippDelete(con
->response
);
6182 con
->response
= NULL
;
6187 * Command failed, return "internal error" so the user knows something
6191 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
6192 _("cups-deviced failed to execute."));
6198 * 'get_document()' - Get a copy of a job file.
6202 get_document(cupsd_client_t
*con
, /* I - Client connection */
6203 ipp_attribute_t
*uri
) /* I - Job URI */
6205 http_status_t status
; /* Policy status */
6206 ipp_attribute_t
*attr
; /* Current attribute */
6207 int jobid
; /* Job ID */
6208 int docnum
; /* Document number */
6209 cupsd_job_t
*job
; /* Current job */
6210 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
6211 username
[HTTP_MAX_URI
], /* Username portion of URI */
6212 host
[HTTP_MAX_URI
], /* Host portion of URI */
6213 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6214 int port
; /* Port portion of URI */
6215 char filename
[1024], /* Filename for document */
6216 format
[1024]; /* Format for document */
6219 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_document(%p[%d], %s)", con
,
6220 con
->number
, uri
->values
[0].string
.text
);
6223 * See if we have a job URI or a printer URI...
6226 if (!strcmp(uri
->name
, "printer-uri"))
6229 * Got a printer URI; see if we also have a job-id attribute...
6232 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6233 IPP_TAG_INTEGER
)) == NULL
)
6235 send_ipp_status(con
, IPP_BAD_REQUEST
,
6236 _("Got a printer-uri attribute but no job-id."));
6240 jobid
= attr
->values
[0].integer
;
6245 * Got a job URI; parse it to get the job ID...
6248 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6249 sizeof(scheme
), username
, sizeof(username
), host
,
6250 sizeof(host
), &port
, resource
, sizeof(resource
));
6252 if (strncmp(resource
, "/jobs/", 6))
6258 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
6259 uri
->values
[0].string
.text
);
6263 jobid
= atoi(resource
+ 6);
6267 * See if the job exists...
6270 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6273 * Nope - return a "not found" error...
6276 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
6284 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
,
6285 job
->username
)) != HTTP_OK
)
6287 send_http_error(con
, status
, NULL
);
6292 * Get the document number...
6295 if ((attr
= ippFindAttribute(con
->request
, "document-number",
6296 IPP_TAG_INTEGER
)) == NULL
)
6298 send_ipp_status(con
, IPP_BAD_REQUEST
,
6299 _("Missing document-number attribute."));
6303 if ((docnum
= attr
->values
[0].integer
) < 1 || docnum
> job
->num_files
||
6304 attr
->num_values
> 1)
6306 send_ipp_status(con
, IPP_NOT_FOUND
,
6307 _("Document #%d does not exist in job #%d."), docnum
,
6312 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, jobid
,
6314 if ((con
->file
= open(filename
, O_RDONLY
)) == -1)
6316 cupsdLogMessage(CUPSD_LOG_ERROR
,
6317 "Unable to open document %d in job %d - %s", docnum
, jobid
,
6319 send_ipp_status(con
, IPP_NOT_FOUND
,
6320 _("Unable to open document #%d in job #%d."), docnum
,
6325 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
6329 snprintf(format
, sizeof(format
), "%s/%s", job
->filetypes
[docnum
- 1]->super
,
6330 job
->filetypes
[docnum
- 1]->type
);
6332 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format",
6334 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "document-number",
6336 if ((attr
= ippFindAttribute(job
->attrs
, "document-name",
6337 IPP_TAG_NAME
)) != NULL
)
6338 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name",
6339 NULL
, attr
->values
[0].string
.text
);
6344 * 'get_job_attrs()' - Get job attributes.
6348 get_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
6349 ipp_attribute_t
*uri
) /* I - Job URI */
6351 http_status_t status
; /* Policy status */
6352 ipp_attribute_t
*attr
; /* Current attribute */
6353 int jobid
; /* Job ID */
6354 cupsd_job_t
*job
; /* Current job */
6355 cupsd_printer_t
*printer
; /* Current printer */
6356 cupsd_policy_t
*policy
; /* Current security policy */
6357 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6358 username
[HTTP_MAX_URI
], /* Username portion of URI */
6359 host
[HTTP_MAX_URI
], /* Host portion of URI */
6360 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6361 int port
; /* Port portion of URI */
6362 cups_array_t
*ra
, /* Requested attributes array */
6363 *exclude
; /* Private attributes array */
6366 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_job_attrs(%p[%d], %s)", con
,
6367 con
->number
, uri
->values
[0].string
.text
);
6370 * See if we have a job URI or a printer URI...
6373 if (!strcmp(uri
->name
, "printer-uri"))
6376 * Got a printer URI; see if we also have a job-id attribute...
6379 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6380 IPP_TAG_INTEGER
)) == NULL
)
6382 send_ipp_status(con
, IPP_BAD_REQUEST
,
6383 _("Got a printer-uri attribute but no job-id."));
6387 jobid
= attr
->values
[0].integer
;
6392 * Got a job URI; parse it to get the job ID...
6395 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6396 sizeof(scheme
), username
, sizeof(username
), host
,
6397 sizeof(host
), &port
, resource
, sizeof(resource
));
6399 if (strncmp(resource
, "/jobs/", 6))
6405 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
6406 uri
->values
[0].string
.text
);
6410 jobid
= atoi(resource
+ 6);
6414 * See if the job exists...
6417 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6420 * Nope - return a "not found" error...
6423 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
6431 if ((printer
= job
->printer
) == NULL
)
6432 printer
= cupsdFindDest(job
->dest
);
6435 policy
= printer
->op_policy_ptr
;
6437 policy
= DefaultPolicyPtr
;
6439 if ((status
= cupsdCheckPolicy(policy
, con
, job
->username
)) != HTTP_OK
)
6441 send_http_error(con
, status
, NULL
);
6445 exclude
= cupsdGetPrivateAttrs(policy
, con
, printer
, job
->username
);
6448 * Copy attributes...
6453 ra
= create_requested_array(con
->request
);
6454 copy_job_attrs(con
, job
, ra
, exclude
);
6455 cupsArrayDelete(ra
);
6457 con
->response
->request
.status
.status_code
= IPP_OK
;
6462 * 'get_jobs()' - Get a list of jobs for the specified printer.
6466 get_jobs(cupsd_client_t
*con
, /* I - Client connection */
6467 ipp_attribute_t
*uri
) /* I - Printer URI */
6469 http_status_t status
; /* Policy status */
6470 ipp_attribute_t
*attr
; /* Current attribute */
6471 const char *dest
; /* Destination */
6472 cups_ptype_t dtype
; /* Destination type (printer/class) */
6473 cups_ptype_t dmask
; /* Destination type mask */
6474 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6475 username
[HTTP_MAX_URI
], /* Username portion of URI */
6476 host
[HTTP_MAX_URI
], /* Host portion of URI */
6477 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6478 int port
; /* Port portion of URI */
6479 int job_comparison
; /* Job comparison */
6480 ipp_jstate_t job_state
; /* job-state value */
6481 int first_job_id
= 1, /* First job ID */
6482 first_index
= 1, /* First index */
6483 limit
= 0, /* Maximum number of jobs to return */
6484 count
, /* Number of jobs that match */
6485 need_load_job
= 0; /* Do we need to load the job? */
6486 const char *job_attr
; /* Job attribute requested */
6487 ipp_attribute_t
*job_ids
; /* job-ids attribute */
6488 cupsd_job_t
*job
; /* Current job pointer */
6489 cupsd_printer_t
*printer
; /* Printer */
6490 cups_array_t
*list
; /* Which job list... */
6491 int delete_list
= 0; /* Delete the list afterwards? */
6492 cups_array_t
*ra
, /* Requested attributes array */
6493 *exclude
; /* Private attributes array */
6494 cupsd_policy_t
*policy
; /* Current policy */
6497 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs(%p[%d], %s)", con
, con
->number
,
6498 uri
->values
[0].string
.text
);
6501 * Is the destination valid?
6504 if (strcmp(uri
->name
, "printer-uri"))
6506 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No printer-uri in request."));
6510 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6511 sizeof(scheme
), username
, sizeof(username
), host
,
6512 sizeof(host
), &port
, resource
, sizeof(resource
));
6514 if (!strcmp(resource
, "/") || !strcmp(resource
, "/jobs"))
6517 dtype
= (cups_ptype_t
)0;
6518 dmask
= (cups_ptype_t
)0;
6521 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6524 dtype
= (cups_ptype_t
)0;
6525 dmask
= CUPS_PRINTER_CLASS
;
6528 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6531 dtype
= CUPS_PRINTER_CLASS
;
6532 dmask
= CUPS_PRINTER_CLASS
;
6535 else if ((dest
= cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
,
6542 send_ipp_status(con
, IPP_NOT_FOUND
,
6543 _("The printer or class does not exist."));
6548 dtype
&= CUPS_PRINTER_CLASS
;
6549 dmask
= CUPS_PRINTER_CLASS
;
6557 policy
= printer
->op_policy_ptr
;
6559 policy
= DefaultPolicyPtr
;
6561 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
6563 send_http_error(con
, status
, NULL
);
6567 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
6570 * See if the "which-jobs" attribute have been specified...
6573 if ((attr
= ippFindAttribute(con
->request
, "which-jobs",
6574 IPP_TAG_KEYWORD
)) != NULL
&& job_ids
)
6576 send_ipp_status(con
, IPP_CONFLICT
,
6577 _("The %s attribute cannot be provided with job-ids."),
6581 else if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "not-completed"))
6583 job_comparison
= -1;
6584 job_state
= IPP_JOB_STOPPED
;
6587 else if (!strcmp(attr
->values
[0].string
.text
, "completed"))
6590 job_state
= IPP_JOB_CANCELED
;
6591 list
= cupsdGetCompletedJobs(printer
);
6594 else if (!strcmp(attr
->values
[0].string
.text
, "aborted"))
6597 job_state
= IPP_JOB_ABORTED
;
6598 list
= cupsdGetCompletedJobs(printer
);
6601 else if (!strcmp(attr
->values
[0].string
.text
, "all"))
6604 job_state
= IPP_JOB_PENDING
;
6607 else if (!strcmp(attr
->values
[0].string
.text
, "canceled"))
6610 job_state
= IPP_JOB_CANCELED
;
6611 list
= cupsdGetCompletedJobs(printer
);
6614 else if (!strcmp(attr
->values
[0].string
.text
, "pending"))
6617 job_state
= IPP_JOB_PENDING
;
6620 else if (!strcmp(attr
->values
[0].string
.text
, "pending-held"))
6623 job_state
= IPP_JOB_HELD
;
6626 else if (!strcmp(attr
->values
[0].string
.text
, "processing"))
6629 job_state
= IPP_JOB_PROCESSING
;
6630 list
= PrintingJobs
;
6632 else if (!strcmp(attr
->values
[0].string
.text
, "processing-stopped"))
6635 job_state
= IPP_JOB_STOPPED
;
6640 send_ipp_status(con
, IPP_ATTRIBUTES
,
6641 _("The which-jobs value \"%s\" is not supported."),
6642 attr
->values
[0].string
.text
);
6643 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
6644 "which-jobs", NULL
, attr
->values
[0].string
.text
);
6649 * See if they want to limit the number of jobs reported...
6652 if ((attr
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
)) != NULL
)
6656 send_ipp_status(con
, IPP_CONFLICT
,
6657 _("The %s attribute cannot be provided with job-ids."),
6662 limit
= attr
->values
[0].integer
;
6665 if ((attr
= ippFindAttribute(con
->request
, "first-index", IPP_TAG_INTEGER
)) != NULL
)
6669 send_ipp_status(con
, IPP_CONFLICT
,
6670 _("The %s attribute cannot be provided with job-ids."),
6675 first_index
= attr
->values
[0].integer
;
6677 else if ((attr
= ippFindAttribute(con
->request
, "first-job-id", IPP_TAG_INTEGER
)) != NULL
)
6681 send_ipp_status(con
, IPP_CONFLICT
,
6682 _("The %s attribute cannot be provided with job-ids."),
6687 first_job_id
= attr
->values
[0].integer
;
6691 * See if we only want to see jobs for a specific user...
6694 if ((attr
= ippFindAttribute(con
->request
, "my-jobs", IPP_TAG_BOOLEAN
)) != NULL
&& job_ids
)
6696 send_ipp_status(con
, IPP_CONFLICT
,
6697 _("The %s attribute cannot be provided with job-ids."),
6701 else if (attr
&& attr
->values
[0].boolean
)
6702 strlcpy(username
, get_username(con
), sizeof(username
));
6706 ra
= create_requested_array(con
->request
);
6707 for (job_attr
= (char *)cupsArrayFirst(ra
); job_attr
; job_attr
= (char *)cupsArrayNext(ra
))
6708 if (strcmp(job_attr
, "job-id") &&
6709 strcmp(job_attr
, "job-k-octets") &&
6710 strcmp(job_attr
, "job-media-progress") &&
6711 strcmp(job_attr
, "job-more-info") &&
6712 strcmp(job_attr
, "job-name") &&
6713 strcmp(job_attr
, "job-originating-user-name") &&
6714 strcmp(job_attr
, "job-preserved") &&
6715 strcmp(job_attr
, "job-printer-up-time") &&
6716 strcmp(job_attr
, "job-printer-uri") &&
6717 strcmp(job_attr
, "job-state") &&
6718 strcmp(job_attr
, "job-state-reasons") &&
6719 strcmp(job_attr
, "job-uri") &&
6720 strcmp(job_attr
, "time-at-completed") &&
6721 strcmp(job_attr
, "time-at-creation") &&
6722 strcmp(job_attr
, "number-of-documents"))
6728 if (need_load_job
&& (limit
== 0 || limit
> 500) && (list
== Jobs
|| delete_list
))
6731 * Limit expensive Get-Jobs for job history to 500 jobs...
6734 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
, "limit", 500);
6737 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
, "limit", limit
);
6741 cupsdLogClient(con
, CUPSD_LOG_INFO
, "Limiting Get-Jobs response to %d jobs.", limit
);
6745 * OK, build a list of jobs for this printer...
6750 int i
; /* Looping var */
6752 for (i
= 0; i
< job_ids
->num_values
; i
++)
6754 if (!cupsdFindJob(job_ids
->values
[i
].integer
))
6758 if (i
< job_ids
->num_values
)
6760 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
6761 job_ids
->values
[i
].integer
);
6765 for (i
= 0; i
< job_ids
->num_values
; i
++)
6767 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
6769 if (need_load_job
&& !job
->attrs
)
6775 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d", job
->id
);
6781 ippAddSeparator(con
->response
);
6783 exclude
= cupsdGetPrivateAttrs(job
->printer
?
6784 job
->printer
->op_policy_ptr
:
6785 policy
, con
, job
->printer
,
6788 copy_job_attrs(con
, job
, ra
, exclude
);
6793 if (first_index
> 1)
6794 job
= (cupsd_job_t
*)cupsArrayIndex(list
, first_index
- 1);
6796 job
= (cupsd_job_t
*)cupsArrayFirst(list
);
6798 for (count
= 0; (limit
<= 0 || count
< limit
) && job
; job
= (cupsd_job_t
*)cupsArrayNext(list
))
6801 * Filter out jobs that don't match...
6804 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
6805 "get_jobs: job->id=%d, dest=\"%s\", username=\"%s\", "
6806 "state_value=%d, attrs=%p", job
->id
, job
->dest
,
6807 job
->username
, job
->state_value
, job
->attrs
);
6809 if (!job
->dest
|| !job
->username
)
6812 if (!job
->dest
|| !job
->username
)
6815 if ((dest
&& strcmp(job
->dest
, dest
)) &&
6816 (!job
->printer
|| !dest
|| strcmp(job
->printer
->name
, dest
)))
6818 if ((job
->dtype
& dmask
) != dtype
&&
6819 (!job
->printer
|| (job
->printer
->type
& dmask
) != dtype
))
6822 if ((job_comparison
< 0 && job
->state_value
> job_state
) ||
6823 (job_comparison
== 0 && job
->state_value
!= job_state
) ||
6824 (job_comparison
> 0 && job
->state_value
< job_state
))
6827 if (job
->id
< first_job_id
)
6830 if (need_load_job
&& !job
->attrs
)
6836 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d", job
->id
);
6841 if (username
[0] && _cups_strcasecmp(username
, job
->username
))
6845 ippAddSeparator(con
->response
);
6849 exclude
= cupsdGetPrivateAttrs(job
->printer
?
6850 job
->printer
->op_policy_ptr
:
6851 policy
, con
, job
->printer
,
6854 copy_job_attrs(con
, job
, ra
, exclude
);
6857 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: count=%d", count
);
6860 cupsArrayDelete(ra
);
6863 cupsArrayDelete(list
);
6865 con
->response
->request
.status
.status_code
= IPP_OK
;
6870 * 'get_notifications()' - Get events for a subscription.
6874 get_notifications(cupsd_client_t
*con
) /* I - Client connection */
6876 int i
, j
; /* Looping vars */
6877 http_status_t status
; /* Policy status */
6878 cupsd_subscription_t
*sub
; /* Subscription */
6879 ipp_attribute_t
*ids
, /* notify-subscription-ids */
6880 *sequences
; /* notify-sequence-numbers */
6881 int min_seq
; /* Minimum sequence number */
6882 int interval
; /* Poll interval */
6885 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_notifications(con=%p[%d])",
6889 * Get subscription attributes...
6892 ids
= ippFindAttribute(con
->request
, "notify-subscription-ids",
6894 sequences
= ippFindAttribute(con
->request
, "notify-sequence-numbers",
6899 send_ipp_status(con
, IPP_BAD_REQUEST
,
6900 _("Missing notify-subscription-ids attribute."));
6905 * Are the subscription IDs valid?
6908 for (i
= 0, interval
= 60; i
< ids
->num_values
; i
++)
6910 if ((sub
= cupsdFindSubscription(ids
->values
[i
].integer
)) == NULL
)
6913 * Bad subscription ID...
6916 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
6917 ids
->values
[i
].integer
);
6925 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
6927 con
, sub
->owner
)) != HTTP_OK
)
6929 send_http_error(con
, status
, sub
->dest
);
6934 * Check the subscription type and update the interval accordingly.
6937 if (sub
->job
&& sub
->job
->state_value
== IPP_JOB_PROCESSING
&&
6940 else if (sub
->job
&& sub
->job
->state_value
>= IPP_JOB_STOPPED
)
6942 else if (sub
->dest
&& sub
->dest
->state
== IPP_PRINTER_PROCESSING
&&
6948 * Tell the client to poll again in N seconds...
6952 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
6953 "notify-get-interval", interval
);
6955 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
6956 "printer-up-time", time(NULL
));
6959 * Copy the subscription event attributes to the response.
6962 con
->response
->request
.status
.status_code
=
6963 interval
? IPP_OK
: IPP_OK_EVENTS_COMPLETE
;
6965 for (i
= 0; i
< ids
->num_values
; i
++)
6968 * Get the subscription and sequence number...
6971 sub
= cupsdFindSubscription(ids
->values
[i
].integer
);
6973 if (sequences
&& i
< sequences
->num_values
)
6974 min_seq
= sequences
->values
[i
].integer
;
6979 * If we don't have any new events, nothing to do here...
6982 if (min_seq
> (sub
->first_event_id
+ cupsArrayCount(sub
->events
)))
6986 * Otherwise copy all of the new events...
6989 if (sub
->first_event_id
> min_seq
)
6992 j
= min_seq
- sub
->first_event_id
;
6994 for (; j
< cupsArrayCount(sub
->events
); j
++)
6996 ippAddSeparator(con
->response
);
6998 copy_attrs(con
->response
,
6999 ((cupsd_event_t
*)cupsArrayIndex(sub
->events
, j
))->attrs
, NULL
,
7000 IPP_TAG_EVENT_NOTIFICATION
, 0, NULL
);
7007 * 'get_ppd()' - Get a named PPD from the local system.
7011 get_ppd(cupsd_client_t
*con
, /* I - Client connection */
7012 ipp_attribute_t
*uri
) /* I - Printer URI or PPD name */
7014 http_status_t status
; /* Policy status */
7015 cupsd_printer_t
*dest
; /* Destination */
7016 cups_ptype_t dtype
; /* Destination type */
7019 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppd(%p[%d], %p[%s=%s])", con
,
7020 con
->number
, uri
, uri
->name
, uri
->values
[0].string
.text
);
7022 if (!strcmp(ippGetName(uri
), "ppd-name"))
7025 * Return a PPD file from cups-driverd...
7028 const char *ppd_name
= ippGetString(uri
, 0, NULL
);
7029 /* ppd-name value */
7030 char command
[1024], /* cups-driverd command */
7031 options
[1024], /* Options to pass to command */
7032 oppd_name
[1024]; /* Escaped ppd-name */
7038 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7040 send_http_error(con
, status
, NULL
);
7045 * Check ppd-name value...
7048 if (strstr(ppd_name
, "../"))
7050 send_ipp_status(con
, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES
, _("Invalid ppd-name value."));
7055 * Run cups-driverd command with the given options...
7058 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7059 url_encode_string(ppd_name
, oppd_name
, sizeof(oppd_name
));
7060 snprintf(options
, sizeof(options
), "get+%d+%s", ippGetRequestId(con
->request
), oppd_name
);
7062 if (cupsdSendCommand(con
, command
, options
, 0))
7065 * Command started successfully, don't send an IPP response here...
7068 ippDelete(con
->response
);
7069 con
->response
= NULL
;
7074 * Command failed, return "internal error" so the user knows something
7078 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("cups-driverd failed to execute."));
7081 else if (!strcmp(ippGetName(uri
), "printer-uri") && cupsdValidateDest(ippGetString(uri
, 0, NULL
), &dtype
, &dest
))
7083 int i
; /* Looping var */
7084 char filename
[1024]; /* PPD filename */
7090 if ((status
= cupsdCheckPolicy(dest
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7092 send_http_error(con
, status
, dest
);
7097 * See if we need the PPD for a class or remote printer...
7100 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
, dest
->name
);
7102 if ((dtype
& CUPS_PRINTER_REMOTE
) && access(filename
, 0))
7104 send_ipp_status(con
, IPP_STATUS_CUPS_SEE_OTHER
, _("See remote printer."));
7105 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
, dest
->uri
);
7108 else if (dtype
& CUPS_PRINTER_CLASS
)
7110 for (i
= 0; i
< dest
->num_printers
; i
++)
7111 if (!(dest
->printers
[i
]->type
& CUPS_PRINTER_CLASS
))
7113 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
, dest
->printers
[i
]->name
);
7115 if (!access(filename
, 0))
7119 if (i
< dest
->num_printers
)
7120 dest
= dest
->printers
[i
];
7123 send_ipp_status(con
, IPP_STATUS_CUPS_SEE_OTHER
, _("See remote printer."));
7124 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
, dest
->printers
[0]->uri
);
7130 * Found the printer with the PPD file, now see if there is one...
7133 if ((con
->file
= open(filename
, O_RDONLY
)) < 0)
7135 send_ipp_status(con
, IPP_STATUS_ERROR_NOT_FOUND
, _("The PPD file \"%s\" could not be opened: %s"), ippGetString(uri
, 0, NULL
), strerror(errno
));
7139 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
7143 ippSetStatusCode(con
->response
, IPP_STATUS_OK
);
7146 send_ipp_status(con
, IPP_STATUS_ERROR_NOT_FOUND
, _("The PPD file \"%s\" could not be found."), ippGetString(uri
, 0, NULL
));
7151 * 'get_ppds()' - Get the list of PPD files on the local system.
7155 get_ppds(cupsd_client_t
*con
) /* I - Client connection */
7157 http_status_t status
; /* Policy status */
7158 ipp_attribute_t
*limit
, /* Limit attribute */
7159 *device
, /* ppd-device-id attribute */
7160 *language
, /* ppd-natural-language attribute */
7161 *make
, /* ppd-make attribute */
7162 *model
, /* ppd-make-and-model attribute */
7163 *model_number
, /* ppd-model-number attribute */
7164 *product
, /* ppd-product attribute */
7165 *psversion
, /* ppd-psverion attribute */
7166 *type
, /* ppd-type attribute */
7167 *requested
, /* requested-attributes attribute */
7168 *exclude
, /* exclude-schemes attribute */
7169 *include
; /* include-schemes attribute */
7170 char command
[1024], /* cups-driverd command */
7171 options
[4096], /* Options to pass to command */
7172 device_str
[256],/* Escaped ppd-device-id string */
7174 /* Escaped ppd-natural-language */
7175 make_str
[256], /* Escaped ppd-make string */
7176 model_str
[256], /* Escaped ppd-make-and-model string */
7177 model_number_str
[256],
7178 /* ppd-model-number string */
7180 /* Escaped ppd-product string */
7182 /* Escaped ppd-psversion string */
7183 type_str
[256], /* Escaped ppd-type string */
7185 /* String for requested attributes */
7187 /* String for excluded schemes */
7189 /* String for included schemes */
7192 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppds(%p[%d])", con
, con
->number
);
7198 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7200 send_http_error(con
, status
, NULL
);
7205 * Run cups-driverd command with the given options...
7208 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
7209 device
= ippFindAttribute(con
->request
, "ppd-device-id", IPP_TAG_TEXT
);
7210 language
= ippFindAttribute(con
->request
, "ppd-natural-language",
7212 make
= ippFindAttribute(con
->request
, "ppd-make", IPP_TAG_TEXT
);
7213 model
= ippFindAttribute(con
->request
, "ppd-make-and-model",
7215 model_number
= ippFindAttribute(con
->request
, "ppd-model-number",
7217 product
= ippFindAttribute(con
->request
, "ppd-product", IPP_TAG_TEXT
);
7218 psversion
= ippFindAttribute(con
->request
, "ppd-psversion", IPP_TAG_TEXT
);
7219 type
= ippFindAttribute(con
->request
, "ppd-type", IPP_TAG_KEYWORD
);
7220 requested
= ippFindAttribute(con
->request
, "requested-attributes",
7222 exclude
= ippFindAttribute(con
->request
, "exclude-schemes",
7224 include
= ippFindAttribute(con
->request
, "include-schemes",
7228 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
7230 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
7233 url_encode_attr(device
, device_str
, sizeof(device_str
));
7235 device_str
[0] = '\0';
7238 url_encode_attr(language
, language_str
, sizeof(language_str
));
7240 language_str
[0] = '\0';
7243 url_encode_attr(make
, make_str
, sizeof(make_str
));
7248 url_encode_attr(model
, model_str
, sizeof(model_str
));
7250 model_str
[0] = '\0';
7253 snprintf(model_number_str
, sizeof(model_number_str
), "ppd-model-number=%d",
7254 model_number
->values
[0].integer
);
7256 model_number_str
[0] = '\0';
7259 url_encode_attr(product
, product_str
, sizeof(product_str
));
7261 product_str
[0] = '\0';
7264 url_encode_attr(psversion
, psversion_str
, sizeof(psversion_str
));
7266 psversion_str
[0] = '\0';
7269 url_encode_attr(type
, type_str
, sizeof(type_str
));
7274 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
7276 exclude_str
[0] = '\0';
7279 url_encode_attr(include
, include_str
, sizeof(include_str
));
7281 include_str
[0] = '\0';
7283 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7284 snprintf(options
, sizeof(options
),
7285 "list+%d+%d+%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
7286 con
->request
->request
.op
.request_id
,
7287 limit
? limit
->values
[0].integer
: 0,
7289 device
? "%20" : "", device_str
,
7290 language
? "%20" : "", language_str
,
7291 make
? "%20" : "", make_str
,
7292 model
? "%20" : "", model_str
,
7293 model_number
? "%20" : "", model_number_str
,
7294 product
? "%20" : "", product_str
,
7295 psversion
? "%20" : "", psversion_str
,
7296 type
? "%20" : "", type_str
,
7297 exclude_str
[0] ? "%20" : "", exclude_str
,
7298 include_str
[0] ? "%20" : "", include_str
);
7300 if (cupsdSendCommand(con
, command
, options
, 0))
7303 * Command started successfully, don't send an IPP response here...
7306 ippDelete(con
->response
);
7307 con
->response
= NULL
;
7312 * Command failed, return "internal error" so the user knows something
7316 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7317 _("cups-driverd failed to execute."));
7323 * 'get_printer_attrs()' - Get printer attributes.
7327 get_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
7328 ipp_attribute_t
*uri
) /* I - Printer URI */
7330 http_status_t status
; /* Policy status */
7331 cups_ptype_t dtype
; /* Destination type (printer/class) */
7332 cupsd_printer_t
*printer
; /* Printer/class */
7333 cups_array_t
*ra
; /* Requested attributes array */
7336 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_attrs(%p[%d], %s)", con
,
7337 con
->number
, uri
->values
[0].string
.text
);
7340 * Is the destination valid?
7343 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7349 send_ipp_status(con
, IPP_NOT_FOUND
,
7350 _("The printer or class does not exist."));
7358 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7360 send_http_error(con
, status
, printer
);
7365 * Send the attributes...
7368 ra
= create_requested_array(con
->request
);
7370 copy_printer_attrs(con
, printer
, ra
);
7372 cupsArrayDelete(ra
);
7374 con
->response
->request
.status
.status_code
= IPP_OK
;
7379 * 'get_printer_supported()' - Get printer supported values.
7383 get_printer_supported(
7384 cupsd_client_t
*con
, /* I - Client connection */
7385 ipp_attribute_t
*uri
) /* I - Printer URI */
7387 http_status_t status
; /* Policy status */
7388 cups_ptype_t dtype
; /* Destination type (printer/class) */
7389 cupsd_printer_t
*printer
; /* Printer/class */
7392 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_supported(%p[%d], %s)", con
,
7393 con
->number
, uri
->values
[0].string
.text
);
7396 * Is the destination valid?
7399 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7405 send_ipp_status(con
, IPP_NOT_FOUND
,
7406 _("The printer or class does not exist."));
7414 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7416 send_http_error(con
, status
, printer
);
7421 * Return a list of attributes that can be set via Set-Printer-Attributes.
7424 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7425 "printer-geo-location", 0);
7426 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7428 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7429 "printer-location", 0);
7430 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7431 "printer-organization", 0);
7432 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7433 "printer-organizational-unit", 0);
7435 con
->response
->request
.status
.status_code
= IPP_OK
;
7440 * 'get_printers()' - Get a list of printers or classes.
7444 get_printers(cupsd_client_t
*con
, /* I - Client connection */
7445 int type
) /* I - 0 or CUPS_PRINTER_CLASS */
7447 http_status_t status
; /* Policy status */
7448 ipp_attribute_t
*attr
; /* Current attribute */
7449 int limit
; /* Max number of printers to return */
7450 int count
; /* Number of printers that match */
7451 int printer_id
; /* Printer we are interested in */
7452 cupsd_printer_t
*printer
; /* Current printer pointer */
7453 cups_ptype_t printer_type
, /* printer-type attribute */
7454 printer_mask
; /* printer-type-mask attribute */
7455 char *location
; /* Location string */
7456 const char *username
; /* Current user */
7457 char *first_printer_name
; /* first-printer-name attribute */
7458 cups_array_t
*ra
; /* Requested attributes array */
7459 int local
; /* Local connection? */
7462 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printers(%p[%d], %x)", con
,
7469 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7471 send_http_error(con
, status
, NULL
);
7476 * Check for printers...
7479 if (!Printers
|| !cupsArrayCount(Printers
))
7481 send_ipp_status(con
, IPP_NOT_FOUND
, _("No destinations added."));
7486 * See if they want to limit the number of printers reported...
7489 if ((attr
= ippFindAttribute(con
->request
, "limit",
7490 IPP_TAG_INTEGER
)) != NULL
)
7491 limit
= attr
->values
[0].integer
;
7495 if ((attr
= ippFindAttribute(con
->request
, "first-printer-name",
7496 IPP_TAG_NAME
)) != NULL
)
7497 first_printer_name
= attr
->values
[0].string
.text
;
7499 first_printer_name
= NULL
;
7502 * Support filtering...
7505 if ((attr
= ippFindAttribute(con
->request
, "printer-id", IPP_TAG_INTEGER
)) != NULL
)
7507 if ((printer_id
= ippGetInteger(attr
, 0)) <= 0)
7509 send_ipp_status(con
, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES
, _("Bad \"printer-id\" value %d."), printer_id
);
7516 if ((attr
= ippFindAttribute(con
->request
, "printer-type",
7517 IPP_TAG_ENUM
)) != NULL
)
7518 printer_type
= (cups_ptype_t
)attr
->values
[0].integer
;
7520 printer_type
= (cups_ptype_t
)0;
7522 if ((attr
= ippFindAttribute(con
->request
, "printer-type-mask",
7523 IPP_TAG_ENUM
)) != NULL
)
7524 printer_mask
= (cups_ptype_t
)attr
->values
[0].integer
;
7526 printer_mask
= (cups_ptype_t
)0;
7528 local
= httpAddrLocalhost(&(con
->clientaddr
));
7530 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
7531 IPP_TAG_TEXT
)) != NULL
)
7532 location
= attr
->values
[0].string
.text
;
7536 if (con
->username
[0])
7537 username
= con
->username
;
7538 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7539 IPP_TAG_NAME
)) != NULL
)
7540 username
= attr
->values
[0].string
.text
;
7544 ra
= create_requested_array(con
->request
);
7547 * OK, build a list of printers for this printer...
7550 if (first_printer_name
)
7552 if ((printer
= cupsdFindDest(first_printer_name
)) == NULL
)
7553 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7556 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7559 count
< limit
&& printer
;
7560 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
7562 if (!local
&& !printer
->shared
)
7565 if (printer_id
&& printer
->printer_id
!= printer_id
)
7568 if ((!type
|| (printer
->type
& CUPS_PRINTER_CLASS
) == type
) &&
7569 (printer
->type
& printer_mask
) == printer_type
&&
7571 (printer
->location
&& !_cups_strcasecmp(printer
->location
, location
))))
7574 * If a username is specified, see if it is allowed or denied
7578 if (cupsArrayCount(printer
->users
) && username
&&
7579 !user_allowed(printer
, username
))
7583 * Add the group separator as needed...
7587 ippAddSeparator(con
->response
);
7592 * Send the attributes...
7595 copy_printer_attrs(con
, printer
, ra
);
7599 cupsArrayDelete(ra
);
7601 con
->response
->request
.status
.status_code
= IPP_OK
;
7606 * 'get_subscription_attrs()' - Get subscription attributes.
7610 get_subscription_attrs(
7611 cupsd_client_t
*con
, /* I - Client connection */
7612 int sub_id
) /* I - Subscription ID */
7614 http_status_t status
; /* Policy status */
7615 cupsd_subscription_t
*sub
; /* Subscription */
7616 cupsd_policy_t
*policy
; /* Current security policy */
7617 cups_array_t
*ra
, /* Requested attributes array */
7618 *exclude
; /* Private attributes array */
7621 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7622 "get_subscription_attrs(con=%p[%d], sub_id=%d)",
7623 con
, con
->number
, sub_id
);
7626 * Expire subscriptions as needed...
7629 cupsdExpireSubscriptions(NULL
, NULL
);
7632 * Is the subscription ID valid?
7635 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
7638 * Bad subscription ID...
7641 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
7651 policy
= sub
->dest
->op_policy_ptr
;
7653 policy
= DefaultPolicyPtr
;
7655 if ((status
= cupsdCheckPolicy(policy
, con
, sub
->owner
)) != HTTP_OK
)
7657 send_http_error(con
, status
, sub
->dest
);
7661 exclude
= cupsdGetPrivateAttrs(policy
, con
, sub
->dest
, sub
->owner
);
7664 * Copy the subscription attributes to the response using the
7665 * requested-attributes attribute that may be provided by the client.
7668 ra
= create_requested_array(con
->request
);
7670 copy_subscription_attrs(con
, sub
, ra
, exclude
);
7672 cupsArrayDelete(ra
);
7674 con
->response
->request
.status
.status_code
= IPP_OK
;
7679 * 'get_subscriptions()' - Get subscriptions.
7683 get_subscriptions(cupsd_client_t
*con
, /* I - Client connection */
7684 ipp_attribute_t
*uri
) /* I - Printer/job URI */
7686 http_status_t status
; /* Policy status */
7687 int count
; /* Number of subscriptions */
7688 int limit
; /* Limit */
7689 cupsd_subscription_t
*sub
; /* Subscription */
7690 cups_array_t
*ra
; /* Requested attributes array */
7691 ipp_attribute_t
*attr
; /* Attribute */
7692 cups_ptype_t dtype
; /* Destination type (printer/class) */
7693 char scheme
[HTTP_MAX_URI
],
7694 /* Scheme portion of URI */
7695 username
[HTTP_MAX_URI
],
7696 /* Username portion of URI */
7698 /* Host portion of URI */
7699 resource
[HTTP_MAX_URI
];
7700 /* Resource portion of URI */
7701 int port
; /* Port portion of URI */
7702 cupsd_job_t
*job
; /* Job pointer */
7703 cupsd_printer_t
*printer
; /* Printer */
7704 cupsd_policy_t
*policy
; /* Policy */
7705 cups_array_t
*exclude
; /* Private attributes array */
7708 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7709 "get_subscriptions(con=%p[%d], uri=%s)",
7710 con
, con
->number
, uri
->values
[0].string
.text
);
7713 * Is the destination valid?
7716 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7717 sizeof(scheme
), username
, sizeof(username
), host
,
7718 sizeof(host
), &port
, resource
, sizeof(resource
));
7720 if (!strcmp(resource
, "/") ||
7721 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6) ||
7722 (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10) ||
7723 (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9))
7728 else if (!strncmp(resource
, "/jobs/", 6) && resource
[6])
7731 job
= cupsdFindJob(atoi(resource
+ 6));
7735 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
7736 atoi(resource
+ 6));
7740 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7746 send_ipp_status(con
, IPP_NOT_FOUND
,
7747 _("The printer or class does not exist."));
7750 else if ((attr
= ippFindAttribute(con
->request
, "notify-job-id",
7751 IPP_TAG_INTEGER
)) != NULL
)
7753 job
= cupsdFindJob(attr
->values
[0].integer
);
7757 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
7758 attr
->values
[0].integer
);
7770 policy
= printer
->op_policy_ptr
;
7772 policy
= DefaultPolicyPtr
;
7774 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
7776 send_http_error(con
, status
, printer
);
7781 * Expire subscriptions as needed...
7784 cupsdExpireSubscriptions(NULL
, NULL
);
7787 * Copy the subscription attributes to the response using the
7788 * requested-attributes attribute that may be provided by the client.
7791 ra
= create_requested_array(con
->request
);
7793 if ((attr
= ippFindAttribute(con
->request
, "limit",
7794 IPP_TAG_INTEGER
)) != NULL
)
7795 limit
= attr
->values
[0].integer
;
7800 * See if we only want to see subscriptions for a specific user...
7803 if ((attr
= ippFindAttribute(con
->request
, "my-subscriptions",
7804 IPP_TAG_BOOLEAN
)) != NULL
&&
7805 attr
->values
[0].boolean
)
7806 strlcpy(username
, get_username(con
), sizeof(username
));
7810 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
), count
= 0;
7812 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
7813 if ((!printer
|| sub
->dest
== printer
) && (!job
|| sub
->job
== job
) &&
7814 (!username
[0] || !_cups_strcasecmp(username
, sub
->owner
)))
7816 ippAddSeparator(con
->response
);
7818 exclude
= cupsdGetPrivateAttrs(sub
->dest
? sub
->dest
->op_policy_ptr
:
7819 policy
, con
, sub
->dest
,
7822 copy_subscription_attrs(con
, sub
, ra
, exclude
);
7825 if (limit
&& count
>= limit
)
7829 cupsArrayDelete(ra
);
7832 con
->response
->request
.status
.status_code
= IPP_OK
;
7834 send_ipp_status(con
, IPP_NOT_FOUND
, _("No subscriptions found."));
7839 * 'get_username()' - Get the username associated with a request.
7842 static const char * /* O - Username */
7843 get_username(cupsd_client_t
*con
) /* I - Connection */
7845 ipp_attribute_t
*attr
; /* Attribute */
7848 if (con
->username
[0])
7849 return (con
->username
);
7850 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7851 IPP_TAG_NAME
)) != NULL
)
7852 return (attr
->values
[0].string
.text
);
7854 return ("anonymous");
7859 * 'hold_job()' - Hold a print job.
7863 hold_job(cupsd_client_t
*con
, /* I - Client connection */
7864 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
7866 ipp_attribute_t
*attr
; /* Current job-hold-until */
7867 const char *when
; /* New value */
7868 int jobid
; /* Job ID */
7869 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
7870 username
[HTTP_MAX_URI
], /* Username portion of URI */
7871 host
[HTTP_MAX_URI
], /* Host portion of URI */
7872 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7873 int port
; /* Port portion of URI */
7874 cupsd_job_t
*job
; /* Job information */
7877 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_job(%p[%d], %s)", con
, con
->number
,
7878 uri
->values
[0].string
.text
);
7881 * See if we have a job URI or a printer URI...
7884 if (!strcmp(uri
->name
, "printer-uri"))
7887 * Got a printer URI; see if we also have a job-id attribute...
7890 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7891 IPP_TAG_INTEGER
)) == NULL
)
7893 send_ipp_status(con
, IPP_BAD_REQUEST
,
7894 _("Got a printer-uri attribute but no job-id."));
7898 jobid
= attr
->values
[0].integer
;
7903 * Got a job URI; parse it to get the job ID...
7906 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7907 sizeof(scheme
), username
, sizeof(username
), host
,
7908 sizeof(host
), &port
, resource
, sizeof(resource
));
7910 if (strncmp(resource
, "/jobs/", 6))
7916 send_ipp_status(con
, IPP_BAD_REQUEST
,
7917 _("Bad job-uri \"%s\"."),
7918 uri
->values
[0].string
.text
);
7922 jobid
= atoi(resource
+ 6);
7926 * See if the job exists...
7929 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7932 * Nope - return a "not found" error...
7935 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
7940 * See if the job is owned by the requesting user...
7943 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7945 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
7946 cupsdFindDest(job
->dest
));
7951 * See if the job is in a state that allows holding...
7954 if (job
->state_value
> IPP_JOB_STOPPED
)
7957 * Return a "not-possible" error...
7960 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
7961 _("Job #%d is finished and cannot be altered."),
7967 * Hold the job and return...
7970 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_ZERO
)) != NULL
)
7972 if ((ippGetValueTag(attr
) != IPP_TAG_KEYWORD
&& ippGetValueTag(attr
) != IPP_TAG_NAME
&& ippGetValueTag(attr
) != IPP_TAG_NAMELANG
) || ippGetCount(attr
) != 1 || !ippValidateAttribute(attr
))
7974 send_ipp_status(con
, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES
, _("Unsupported 'job-hold-until' value."));
7975 ippCopyAttribute(con
->response
, attr
, 0);
7979 when
= ippGetString(attr
, 0, NULL
);
7981 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
7982 "Job job-hold-until value changed by user.");
7985 when
= "indefinite";
7987 cupsdSetJobHoldUntil(job
, when
, 1);
7988 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
, "Job held by \"%s\".",
7991 con
->response
->request
.status
.status_code
= IPP_OK
;
7996 * 'hold_new_jobs()' - Hold pending/new jobs on a printer or class.
8000 hold_new_jobs(cupsd_client_t
*con
, /* I - Connection */
8001 ipp_attribute_t
*uri
) /* I - Printer URI */
8003 http_status_t status
; /* Policy status */
8004 cups_ptype_t dtype
; /* Destination type (printer/class) */
8005 cupsd_printer_t
*printer
; /* Printer data */
8008 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_new_jobs(%p[%d], %s)", con
,
8009 con
->number
, uri
->values
[0].string
.text
);
8012 * Is the destination valid?
8015 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8021 send_ipp_status(con
, IPP_NOT_FOUND
,
8022 _("The printer or class does not exist."));
8030 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8032 send_http_error(con
, status
, printer
);
8037 * Hold pending/new jobs sent to the printer...
8040 printer
->holding_new_jobs
= 1;
8042 cupsdSetPrinterReasons(printer
, "+hold-new-jobs");
8044 if (dtype
& CUPS_PRINTER_CLASS
)
8045 cupsdLogMessage(CUPSD_LOG_INFO
,
8046 "Class \"%s\" now holding pending/new jobs (\"%s\").",
8047 printer
->name
, get_username(con
));
8049 cupsdLogMessage(CUPSD_LOG_INFO
,
8050 "Printer \"%s\" now holding pending/new jobs (\"%s\").",
8051 printer
->name
, get_username(con
));
8054 * Everything was ok, so return OK status...
8057 con
->response
->request
.status
.status_code
= IPP_OK
;
8062 * 'move_job()' - Move a job to a new destination.
8066 move_job(cupsd_client_t
*con
, /* I - Client connection */
8067 ipp_attribute_t
*uri
) /* I - Job URI */
8069 http_status_t status
; /* Policy status */
8070 ipp_attribute_t
*attr
; /* Current attribute */
8071 int jobid
; /* Job ID */
8072 cupsd_job_t
*job
; /* Current job */
8073 const char *src
; /* Source printer/class */
8074 cups_ptype_t stype
, /* Source type (printer or class) */
8075 dtype
; /* Destination type (printer/class) */
8076 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
8077 username
[HTTP_MAX_URI
], /* Username portion of URI */
8078 host
[HTTP_MAX_URI
], /* Host portion of URI */
8079 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8080 int port
; /* Port portion of URI */
8081 cupsd_printer_t
*sprinter
, /* Source printer */
8082 *dprinter
; /* Destination printer */
8085 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "move_job(%p[%d], %s)", con
, con
->number
,
8086 uri
->values
[0].string
.text
);
8089 * Get the new printer or class...
8092 if ((attr
= ippFindAttribute(con
->request
, "job-printer-uri",
8093 IPP_TAG_URI
)) == NULL
)
8096 * Need job-printer-uri...
8099 send_ipp_status(con
, IPP_BAD_REQUEST
,
8100 _("job-printer-uri attribute missing."));
8104 if (!cupsdValidateDest(attr
->values
[0].string
.text
, &dtype
, &dprinter
))
8110 send_ipp_status(con
, IPP_NOT_FOUND
,
8111 _("The printer or class does not exist."));
8116 * See if we have a job URI or a printer URI...
8119 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8120 sizeof(scheme
), username
, sizeof(username
), host
,
8121 sizeof(host
), &port
, resource
, sizeof(resource
));
8123 if (!strcmp(uri
->name
, "printer-uri"))
8126 * Got a printer URI; see if we also have a job-id attribute...
8129 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8130 IPP_TAG_INTEGER
)) == NULL
)
8136 if ((src
= cupsdValidateDest(uri
->values
[0].string
.text
, &stype
,
8137 &sprinter
)) == NULL
)
8143 send_ipp_status(con
, IPP_NOT_FOUND
,
8144 _("The printer or class does not exist."));
8153 * Otherwise, just move a single job...
8156 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
8159 * Nope - return a "not found" error...
8162 send_ipp_status(con
, IPP_NOT_FOUND
,
8163 _("Job #%d does not exist."), attr
->values
[0].integer
);
8169 * Job found, initialize source pointers...
8180 * Got a job URI; parse it to get the job ID...
8183 if (strncmp(resource
, "/jobs/", 6))
8189 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
8190 uri
->values
[0].string
.text
);
8195 * See if the job exists...
8198 jobid
= atoi(resource
+ 6);
8200 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8203 * Nope - return a "not found" error...
8206 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
8212 * Job found, initialize source pointers...
8221 * Check the policy of the destination printer...
8224 if ((status
= cupsdCheckPolicy(dprinter
->op_policy_ptr
, con
,
8225 job
? job
->username
: NULL
)) != HTTP_OK
)
8227 send_http_error(con
, status
, dprinter
);
8232 * Now move the job or jobs...
8238 * See if the job has been completed...
8241 if (job
->state_value
> IPP_JOB_STOPPED
)
8244 * Return a "not-possible" error...
8247 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8248 _("Job #%d is finished and cannot be altered."),
8254 * See if the job is owned by the requesting user...
8257 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8259 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8260 cupsdFindDest(job
->dest
));
8265 * Move the job to a different printer or class...
8268 cupsdMoveJob(job
, dprinter
);
8273 * Got the source printer, now look through the jobs...
8276 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
8278 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
8281 * See if the job is pointing at the source printer or has not been
8285 if (_cups_strcasecmp(job
->dest
, src
) ||
8286 job
->state_value
> IPP_JOB_STOPPED
)
8290 * See if the job can be moved by the requesting user...
8293 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8297 * Move the job to a different printer or class...
8300 cupsdMoveJob(job
, dprinter
);
8305 * Start jobs if possible...
8311 * Return with "everything is OK" status...
8314 con
->response
->request
.status
.status_code
= IPP_OK
;
8319 * 'ppd_parse_line()' - Parse a PPD default line.
8322 static int /* O - 0 on success, -1 on failure */
8323 ppd_parse_line(const char *line
, /* I - Line */
8324 char *option
, /* O - Option name */
8325 int olen
, /* I - Size of option name */
8326 char *choice
, /* O - Choice name */
8327 int clen
) /* I - Size of choice name */
8330 * Verify this is a default option line...
8333 if (strncmp(line
, "*Default", 8))
8337 * Read the option name...
8340 for (line
+= 8, olen
--;
8341 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
8352 * Skip everything else up to the colon (:)...
8355 while (*line
&& *line
!= ':')
8364 * Now grab the option choice, skipping leading whitespace...
8367 while (isspace(*line
& 255))
8371 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
8382 * Return with no errors...
8390 * 'print_job()' - Print a file to a printer or class.
8394 print_job(cupsd_client_t
*con
, /* I - Client connection */
8395 ipp_attribute_t
*uri
) /* I - Printer URI */
8397 ipp_attribute_t
*attr
; /* Current attribute */
8398 ipp_attribute_t
*doc_name
; /* document-name attribute */
8399 ipp_attribute_t
*format
; /* Document-format attribute */
8400 const char *default_format
; /* document-format-default value */
8401 cupsd_job_t
*job
; /* New job */
8402 char filename
[1024]; /* Job filename */
8403 mime_type_t
*filetype
; /* Type of file */
8404 char super
[MIME_MAX_SUPER
], /* Supertype of file */
8405 type
[MIME_MAX_TYPE
], /* Subtype of file */
8406 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
8407 /* Textual name of mime type */
8408 cupsd_printer_t
*printer
; /* Printer data */
8409 struct stat fileinfo
; /* File information */
8410 int kbytes
; /* Size of file */
8411 int compression
; /* Document compression */
8414 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "print_job(%p[%d], %s)", con
, con
->number
,
8415 uri
->values
[0].string
.text
);
8418 * Validate print file attributes, for now just document-format and
8419 * compression (CUPS only supports "none" and "gzip")...
8422 compression
= CUPS_FILE_NONE
;
8424 if ((attr
= ippFindAttribute(con
->request
, "compression",
8425 IPP_TAG_KEYWORD
)) != NULL
)
8427 if (strcmp(attr
->values
[0].string
.text
, "none")
8429 && strcmp(attr
->values
[0].string
.text
, "gzip")
8430 #endif /* HAVE_LIBZ */
8433 send_ipp_status(con
, IPP_ATTRIBUTES
,
8434 _("Unsupported compression \"%s\"."),
8435 attr
->values
[0].string
.text
);
8436 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
8437 "compression", NULL
, attr
->values
[0].string
.text
);
8442 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
8443 compression
= CUPS_FILE_GZIP
;
8444 #endif /* HAVE_LIBZ */
8448 * Do we have a file to print?
8453 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file in print request."));
8458 * Is the destination valid?
8461 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
8467 send_ipp_status(con
, IPP_NOT_FOUND
,
8468 _("The printer or class does not exist."));
8473 * Is it a format we support?
8476 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
8478 ippSetName(con
->request
, &doc_name
, "document-name-supplied");
8480 if ((format
= ippFindAttribute(con
->request
, "document-format",
8481 IPP_TAG_MIMETYPE
)) != NULL
)
8484 * Grab format from client...
8487 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%255[^;]", super
,
8490 send_ipp_status(con
, IPP_BAD_REQUEST
,
8491 _("Bad document-format \"%s\"."),
8492 format
->values
[0].string
.text
);
8496 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format-supplied", NULL
, ippGetString(format
, 0, NULL
));
8498 else if ((default_format
= cupsGetOption("document-format",
8499 printer
->num_options
,
8500 printer
->options
)) != NULL
)
8503 * Use default document format...
8506 if (sscanf(default_format
, "%15[^/]/%255[^;]", super
, type
) != 2)
8508 send_ipp_status(con
, IPP_BAD_REQUEST
,
8509 _("Bad document-format \"%s\"."),
8520 strlcpy(super
, "application", sizeof(super
));
8521 strlcpy(type
, "octet-stream", sizeof(type
));
8524 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
8527 * Auto-type the file...
8530 cupsdLogMessage(CUPSD_LOG_DEBUG
, "[Job ???] Auto-typing file...");
8533 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
8534 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
8538 filetype
= mimeType(MimeDatabase
, super
, type
);
8540 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job ???] Request file type is %s/%s.",
8541 filetype
->super
, filetype
->type
);
8543 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
, filetype
->type
);
8544 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format-detected", NULL
, mimetype
);
8547 filetype
= mimeType(MimeDatabase
, super
, type
);
8551 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
8554 * Replace the document-format attribute value with the auto-typed or
8558 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
8562 ippSetString(con
->request
, &format
, 0, mimetype
);
8564 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
8565 "document-format", NULL
, mimetype
);
8569 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
8570 _("Unsupported document-format \"%s\"."),
8571 format
? format
->values
[0].string
.text
:
8572 "application/octet-stream");
8573 cupsdLogMessage(CUPSD_LOG_INFO
,
8574 "Hint: Do you have the raw file printing rules enabled?");
8577 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
8578 "document-format", NULL
, format
->values
[0].string
.text
);
8584 * Read any embedded job ticket info from PS files...
8587 if (!_cups_strcasecmp(filetype
->super
, "application") &&
8588 (!_cups_strcasecmp(filetype
->type
, "postscript") ||
8589 !_cups_strcasecmp(filetype
->type
, "pdf")))
8590 read_job_ticket(con
);
8593 * Create the job object...
8596 if ((job
= add_job(con
, printer
, filetype
)) == NULL
)
8600 * Update quota data...
8603 if (stat(con
->filename
, &fileinfo
))
8606 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
8608 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
8610 job
->koctets
+= kbytes
;
8612 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets", IPP_TAG_INTEGER
)) != NULL
)
8613 attr
->values
[0].integer
+= kbytes
;
8616 * Add the job file...
8619 if (add_file(con
, job
, filetype
, compression
))
8622 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
, job
->num_files
);
8623 if (rename(con
->filename
, filename
))
8625 cupsdLogJob(job
, CUPSD_LOG_ERROR
, "Unable to rename job document file \"%s\": %s", filename
, strerror(errno
));
8627 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to rename job document file."));
8631 cupsdClearString(&con
->filename
);
8634 * See if we need to add the ending sheet...
8637 if (cupsdTimeoutJob(job
))
8641 * Log and save the job...
8644 cupsdLogJob(job
, CUPSD_LOG_INFO
,
8645 "File of type %s/%s queued by \"%s\".",
8646 filetype
->super
, filetype
->type
, job
->username
);
8647 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "hold_until=%d", (int)job
->hold_until
);
8648 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
8649 job
->dest
, job
->username
);
8652 * Start the job if possible...
8660 * 'read_job_ticket()' - Read a job ticket embedded in a print file.
8662 * This function only gets called when printing a single PDF or PostScript
8663 * file using the Print-Job operation. It doesn't work for Create-Job +
8664 * Send-File, since the job attributes need to be set at job creation
8665 * time for banners to work. The embedded job ticket stuff is here
8666 * primarily to allow the Windows printer driver for CUPS to pass in JCL
8667 * options and IPP attributes which otherwise would be lost.
8669 * The format of a job ticket is simple:
8671 * %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
8673 * %cupsJobTicket: attr1=value1
8674 * %cupsJobTicket: attr2=value2
8676 * %cupsJobTicket: attrN=valueN
8678 * Job ticket lines must appear immediately after the first line that
8679 * specifies PostScript (%!PS-Adobe-3.0) or PDF (%PDF) format, and CUPS
8680 * stops looking for job ticket info when it finds a line that does not begin
8681 * with "%cupsJobTicket:".
8683 * The maximum length of a job ticket line, including the prefix, is
8684 * 255 characters to conform with the Adobe DSC.
8686 * Read-only attributes are rejected with a notice to the error log in
8687 * case a malicious user tries anything. Since the job ticket is read
8688 * prior to attribute validation in print_job(), job ticket attributes
8689 * will go through the same validation as IPP attributes...
8693 read_job_ticket(cupsd_client_t
*con
) /* I - Client connection */
8695 cups_file_t
*fp
; /* File to read from */
8696 char line
[256]; /* Line data */
8697 int num_options
; /* Number of options */
8698 cups_option_t
*options
; /* Options */
8699 ipp_t
*ticket
; /* New attributes */
8700 ipp_attribute_t
*attr
, /* Current attribute */
8701 *attr2
, /* Job attribute */
8702 *prev2
; /* Previous job attribute */
8706 * First open the print file...
8709 if ((fp
= cupsFileOpen(con
->filename
, "rb")) == NULL
)
8711 cupsdLogMessage(CUPSD_LOG_ERROR
,
8712 "Unable to open print file for job ticket - %s",
8718 * Skip the first line...
8721 if (cupsFileGets(fp
, line
, sizeof(line
)) == NULL
)
8723 cupsdLogMessage(CUPSD_LOG_ERROR
,
8724 "Unable to read from print file for job ticket - %s",
8730 if (strncmp(line
, "%!PS-Adobe-", 11) && strncmp(line
, "%PDF-", 5))
8733 * Not a DSC-compliant file, so no job ticket info will be available...
8741 * Read job ticket info from the file...
8747 while (cupsFileGets(fp
, line
, sizeof(line
)))
8750 * Stop at the first non-ticket line...
8753 if (strncmp(line
, "%cupsJobTicket:", 15))
8757 * Add the options to the option array...
8760 num_options
= cupsParseOptions(line
+ 15, num_options
, &options
);
8764 * Done with the file; see if we have any options...
8769 if (num_options
== 0)
8773 * OK, convert the options to an attribute list, and apply them to
8778 cupsEncodeOptions(ticket
, num_options
, options
);
8781 * See what the user wants to change.
8784 for (attr
= ticket
->attrs
; attr
; attr
= attr
->next
)
8786 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
8789 if (!strncmp(attr
->name
, "date-time-at-", 13) ||
8790 !strcmp(attr
->name
, "job-impressions-completed") ||
8791 !strcmp(attr
->name
, "job-media-sheets-completed") ||
8792 !strncmp(attr
->name
, "job-k-octets", 12) ||
8793 !strcmp(attr
->name
, "job-id") ||
8794 !strcmp(attr
->name
, "job-originating-host-name") ||
8795 !strcmp(attr
->name
, "job-originating-user-name") ||
8796 !strcmp(attr
->name
, "job-pages-completed") ||
8797 !strcmp(attr
->name
, "job-printer-uri") ||
8798 !strncmp(attr
->name
, "job-state", 9) ||
8799 !strcmp(attr
->name
, "job-uri") ||
8800 !strncmp(attr
->name
, "time-at-", 8))
8801 continue; /* Read-only attrs */
8803 if ((attr2
= ippFindAttribute(con
->request
, attr
->name
,
8804 IPP_TAG_ZERO
)) != NULL
)
8807 * Some other value; first free the old value...
8810 if (con
->request
->attrs
== attr2
)
8812 con
->request
->attrs
= attr2
->next
;
8817 for (prev2
= con
->request
->attrs
; prev2
; prev2
= prev2
->next
)
8818 if (prev2
->next
== attr2
)
8820 prev2
->next
= attr2
->next
;
8825 if (con
->request
->last
== attr2
)
8826 con
->request
->last
= prev2
;
8828 ippDeleteAttribute(NULL
, attr2
);
8832 * Add new option by copying it...
8835 ippCopyAttribute(con
->request
, attr
, 0);
8839 * Then free the attribute list and option array...
8843 cupsFreeOptions(num_options
, options
);
8848 * 'reject_jobs()' - Reject print jobs to a printer.
8852 reject_jobs(cupsd_client_t
*con
, /* I - Client connection */
8853 ipp_attribute_t
*uri
) /* I - Printer or class URI */
8855 http_status_t status
; /* Policy status */
8856 cups_ptype_t dtype
; /* Destination type (printer/class) */
8857 cupsd_printer_t
*printer
; /* Printer data */
8858 ipp_attribute_t
*attr
; /* printer-state-message text */
8861 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "reject_jobs(%p[%d], %s)", con
,
8862 con
->number
, uri
->values
[0].string
.text
);
8865 * Is the destination valid?
8868 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8874 send_ipp_status(con
, IPP_NOT_FOUND
,
8875 _("The printer or class does not exist."));
8883 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8885 send_http_error(con
, status
, printer
);
8890 * Reject jobs sent to the printer...
8893 printer
->accepting
= 0;
8895 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
8896 IPP_TAG_TEXT
)) == NULL
)
8897 strlcpy(printer
->state_message
, "Rejecting Jobs",
8898 sizeof(printer
->state_message
));
8900 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
8901 sizeof(printer
->state_message
));
8903 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
8904 "No longer accepting jobs.");
8906 if (dtype
& CUPS_PRINTER_CLASS
)
8908 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
8910 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" rejecting jobs (\"%s\").",
8911 printer
->name
, get_username(con
));
8915 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
8917 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" rejecting jobs (\"%s\").",
8918 printer
->name
, get_username(con
));
8922 * Everything was ok, so return OK status...
8925 con
->response
->request
.status
.status_code
= IPP_OK
;
8930 * 'release_held_new_jobs()' - Release pending/new jobs on a printer or class.
8934 release_held_new_jobs(
8935 cupsd_client_t
*con
, /* I - Connection */
8936 ipp_attribute_t
*uri
) /* I - Printer URI */
8938 http_status_t status
; /* Policy status */
8939 cups_ptype_t dtype
; /* Destination type (printer/class) */
8940 cupsd_printer_t
*printer
; /* Printer data */
8943 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_held_new_jobs(%p[%d], %s)", con
,
8944 con
->number
, uri
->values
[0].string
.text
);
8947 * Is the destination valid?
8950 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8956 send_ipp_status(con
, IPP_NOT_FOUND
,
8957 _("The printer or class does not exist."));
8965 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8967 send_http_error(con
, status
, printer
);
8972 * Hold pending/new jobs sent to the printer...
8975 printer
->holding_new_jobs
= 0;
8977 cupsdSetPrinterReasons(printer
, "-hold-new-jobs");
8979 if (dtype
& CUPS_PRINTER_CLASS
)
8980 cupsdLogMessage(CUPSD_LOG_INFO
,
8981 "Class \"%s\" now printing pending/new jobs (\"%s\").",
8982 printer
->name
, get_username(con
));
8984 cupsdLogMessage(CUPSD_LOG_INFO
,
8985 "Printer \"%s\" now printing pending/new jobs (\"%s\").",
8986 printer
->name
, get_username(con
));
8991 * Everything was ok, so return OK status...
8994 con
->response
->request
.status
.status_code
= IPP_OK
;
8999 * 'release_job()' - Release a held print job.
9003 release_job(cupsd_client_t
*con
, /* I - Client connection */
9004 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9006 ipp_attribute_t
*attr
; /* Current attribute */
9007 int jobid
; /* Job ID */
9008 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9009 username
[HTTP_MAX_URI
], /* Username portion of URI */
9010 host
[HTTP_MAX_URI
], /* Host portion of URI */
9011 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9012 int port
; /* Port portion of URI */
9013 cupsd_job_t
*job
; /* Job information */
9016 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_job(%p[%d], %s)", con
,
9017 con
->number
, uri
->values
[0].string
.text
);
9020 * See if we have a job URI or a printer URI...
9023 if (!strcmp(uri
->name
, "printer-uri"))
9026 * Got a printer URI; see if we also have a job-id attribute...
9029 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9030 IPP_TAG_INTEGER
)) == NULL
)
9032 send_ipp_status(con
, IPP_BAD_REQUEST
,
9033 _("Got a printer-uri attribute but no job-id."));
9037 jobid
= attr
->values
[0].integer
;
9042 * Got a job URI; parse it to get the job ID...
9045 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9046 sizeof(scheme
), username
, sizeof(username
), host
,
9047 sizeof(host
), &port
, resource
, sizeof(resource
));
9049 if (strncmp(resource
, "/jobs/", 6))
9055 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9056 uri
->values
[0].string
.text
);
9060 jobid
= atoi(resource
+ 6);
9064 * See if the job exists...
9067 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9070 * Nope - return a "not found" error...
9073 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9078 * See if job is "held"...
9081 if (job
->state_value
!= IPP_JOB_HELD
)
9084 * Nope - return a "not possible" error...
9087 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not held."), jobid
);
9092 * See if the job is owned by the requesting user...
9095 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9097 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9098 cupsdFindDest(job
->dest
));
9103 * Reset the job-hold-until value to "no-hold"...
9106 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9107 IPP_TAG_KEYWORD
)) == NULL
)
9108 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9112 ippSetValueTag(job
->attrs
, &attr
, IPP_TAG_KEYWORD
);
9113 ippSetString(job
->attrs
, &attr
, 0, "no-hold");
9115 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
9116 "Job job-hold-until value changed by user.");
9117 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
9121 * Release the job and return...
9124 cupsdReleaseJob(job
);
9126 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
9127 "Job released by user.");
9129 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Released by \"%s\".", username
);
9131 con
->response
->request
.status
.status_code
= IPP_OK
;
9138 * 'renew_subscription()' - Renew an existing subscription...
9143 cupsd_client_t
*con
, /* I - Client connection */
9144 int sub_id
) /* I - Subscription ID */
9146 http_status_t status
; /* Policy status */
9147 cupsd_subscription_t
*sub
; /* Subscription */
9148 ipp_attribute_t
*lease
; /* notify-lease-duration */
9151 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
9152 "renew_subscription(con=%p[%d], sub_id=%d)",
9153 con
, con
->number
, sub_id
);
9156 * Is the subscription ID valid?
9159 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
9162 * Bad subscription ID...
9165 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
9173 * Job subscriptions cannot be renewed...
9176 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9177 _("Job subscriptions cannot be renewed."));
9185 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
9187 con
, sub
->owner
)) != HTTP_OK
)
9189 send_http_error(con
, status
, sub
->dest
);
9194 * Renew the subscription...
9197 lease
= ippFindAttribute(con
->request
, "notify-lease-duration",
9200 sub
->lease
= lease
? lease
->values
[0].integer
: DefaultLeaseDuration
;
9202 if (MaxLeaseDuration
&& (sub
->lease
== 0 || sub
->lease
> MaxLeaseDuration
))
9204 cupsdLogMessage(CUPSD_LOG_INFO
,
9205 "renew_subscription: Limiting notify-lease-duration to "
9208 sub
->lease
= MaxLeaseDuration
;
9211 sub
->expire
= sub
->lease
? time(NULL
) + sub
->lease
: 0;
9213 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
9215 con
->response
->request
.status
.status_code
= IPP_OK
;
9217 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
9218 "notify-lease-duration", sub
->lease
);
9223 * 'restart_job()' - Restart an old print job.
9227 restart_job(cupsd_client_t
*con
, /* I - Client connection */
9228 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9230 ipp_attribute_t
*attr
; /* Current attribute */
9231 int jobid
; /* Job ID */
9232 cupsd_job_t
*job
; /* Job information */
9233 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9234 username
[HTTP_MAX_URI
], /* Username portion of URI */
9235 host
[HTTP_MAX_URI
], /* Host portion of URI */
9236 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9237 int port
; /* Port portion of URI */
9240 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "restart_job(%p[%d], %s)", con
,
9241 con
->number
, uri
->values
[0].string
.text
);
9244 * See if we have a job URI or a printer URI...
9247 if (!strcmp(uri
->name
, "printer-uri"))
9250 * Got a printer URI; see if we also have a job-id attribute...
9253 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9254 IPP_TAG_INTEGER
)) == NULL
)
9256 send_ipp_status(con
, IPP_BAD_REQUEST
,
9257 _("Got a printer-uri attribute but no job-id."));
9261 jobid
= attr
->values
[0].integer
;
9266 * Got a job URI; parse it to get the job ID...
9269 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9270 sizeof(scheme
), username
, sizeof(username
), host
,
9271 sizeof(host
), &port
, resource
, sizeof(resource
));
9273 if (strncmp(resource
, "/jobs/", 6))
9279 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9280 uri
->values
[0].string
.text
);
9284 jobid
= atoi(resource
+ 6);
9288 * See if the job exists...
9291 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9294 * Nope - return a "not found" error...
9297 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9302 * See if job is in any of the "completed" states...
9305 if (job
->state_value
<= IPP_JOB_PROCESSING
)
9308 * Nope - return a "not possible" error...
9311 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not complete."),
9317 * See if we have retained the job files...
9322 if (!job
->attrs
|| job
->num_files
== 0)
9325 * Nope - return a "not possible" error...
9328 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9329 _("Job #%d cannot be restarted - no files."), jobid
);
9334 * See if the job is owned by the requesting user...
9337 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9339 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9340 cupsdFindDest(job
->dest
));
9345 * See if the job-hold-until attribute is specified...
9348 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
9349 IPP_TAG_KEYWORD
)) == NULL
)
9350 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
9352 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
9355 * Return the job to a held state...
9358 cupsdLogJob(job
, CUPSD_LOG_DEBUG
,
9359 "Restarted by \"%s\" with job-hold-until=%s.",
9360 username
, attr
->values
[0].string
.text
);
9361 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
9363 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
,
9364 NULL
, job
, "Job restarted by user with job-hold-until=%s",
9365 attr
->values
[0].string
.text
);
9370 * Restart the job...
9373 cupsdRestartJob(job
);
9377 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Restarted by \"%s\".", username
);
9379 con
->response
->request
.status
.status_code
= IPP_OK
;
9384 * 'save_auth_info()' - Save authentication information for a job.
9389 cupsd_client_t
*con
, /* I - Client connection */
9390 cupsd_job_t
*job
, /* I - Job */
9391 ipp_attribute_t
*auth_info
) /* I - auth-info attribute, if any */
9393 int i
; /* Looping var */
9394 char filename
[1024]; /* Job authentication filename */
9395 cups_file_t
*fp
; /* Job authentication file */
9396 char line
[65536]; /* Line for file */
9397 cupsd_printer_t
*dest
; /* Destination printer/class */
9401 * This function saves the in-memory authentication information for
9402 * a job so that it can be used to authenticate with a remote host.
9403 * The information is stored in a file that is readable only by the
9404 * root user. The fields are Base-64 encoded, each on a separate line,
9405 * followed by random number (up to 1024) of newlines to limit the
9406 * amount of information that is exposed.
9408 * Because of the potential for exposing of authentication information,
9409 * this functionality is only enabled when running cupsd as root.
9411 * This caching only works for the Basic and BasicDigest authentication
9412 * types. Digest authentication cannot be cached this way, and in
9413 * the future Kerberos authentication may make all of this obsolete.
9415 * Authentication information is saved whenever an authenticated
9416 * Print-Job, Create-Job, or CUPS-Authenticate-Job operation is
9419 * This information is deleted after a job is completed or canceled,
9420 * so reprints may require subsequent re-authentication.
9426 if ((dest
= cupsdFindDest(job
->dest
)) == NULL
)
9430 * Create the authentication file and change permissions...
9433 snprintf(filename
, sizeof(filename
), "%s/a%05d", RequestRoot
, job
->id
);
9434 if ((fp
= cupsFileOpen(filename
, "w")) == NULL
)
9436 cupsdLogMessage(CUPSD_LOG_ERROR
,
9437 "Unable to save authentication info to \"%s\" - %s",
9438 filename
, strerror(errno
));
9442 fchown(cupsFileNumber(fp
), 0, 0);
9443 fchmod(cupsFileNumber(fp
), 0400);
9445 cupsFilePuts(fp
, "CUPSD-AUTH-V3\n");
9448 i
< (int)(sizeof(job
->auth_env
) / sizeof(job
->auth_env
[0]));
9450 cupsdClearString(job
->auth_env
+ i
);
9452 if (auth_info
&& auth_info
->num_values
== dest
->num_auth_info_required
)
9455 * Write 1 to 3 auth values...
9459 i
< auth_info
->num_values
&&
9460 i
< (int)(sizeof(job
->auth_env
) / sizeof(job
->auth_env
[0]));
9463 if (strcmp(dest
->auth_info_required
[i
], "negotiate"))
9465 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[i
].string
.text
, (int)strlen(auth_info
->values
[i
].string
.text
));
9466 cupsFilePutConf(fp
, dest
->auth_info_required
[i
], line
);
9469 cupsFilePutConf(fp
, dest
->auth_info_required
[i
],
9470 auth_info
->values
[i
].string
.text
);
9472 if (!strcmp(dest
->auth_info_required
[i
], "username"))
9473 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_USERNAME=%s",
9474 auth_info
->values
[i
].string
.text
);
9475 else if (!strcmp(dest
->auth_info_required
[i
], "domain"))
9476 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_DOMAIN=%s",
9477 auth_info
->values
[i
].string
.text
);
9478 else if (!strcmp(dest
->auth_info_required
[i
], "password"))
9479 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_PASSWORD=%s",
9480 auth_info
->values
[i
].string
.text
);
9481 else if (!strcmp(dest
->auth_info_required
[i
], "negotiate"))
9482 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_NEGOTIATE=%s",
9483 auth_info
->values
[i
].string
.text
);
9488 else if (auth_info
&& auth_info
->num_values
== 2 &&
9489 dest
->num_auth_info_required
== 1 &&
9490 !strcmp(dest
->auth_info_required
[0], "negotiate"))
9493 * Allow fallback to username+password for Kerberized queues...
9496 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[0].string
.text
, (int)strlen(auth_info
->values
[0].string
.text
));
9497 cupsFilePutConf(fp
, "username", line
);
9499 cupsdSetStringf(job
->auth_env
+ 0, "AUTH_USERNAME=%s",
9500 auth_info
->values
[0].string
.text
);
9502 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[1].string
.text
, (int)strlen(auth_info
->values
[1].string
.text
));
9503 cupsFilePutConf(fp
, "password", line
);
9505 cupsdSetStringf(job
->auth_env
+ 1, "AUTH_PASSWORD=%s",
9506 auth_info
->values
[1].string
.text
);
9508 else if (con
->username
[0])
9511 * Write the authenticated username...
9514 httpEncode64_2(line
, sizeof(line
), con
->username
, (int)strlen(con
->username
));
9515 cupsFilePutConf(fp
, "username", line
);
9517 cupsdSetStringf(job
->auth_env
+ 0, "AUTH_USERNAME=%s", con
->username
);
9520 * Write the authenticated password...
9523 httpEncode64_2(line
, sizeof(line
), con
->password
, (int)strlen(con
->password
));
9524 cupsFilePutConf(fp
, "password", line
);
9526 cupsdSetStringf(job
->auth_env
+ 1, "AUTH_PASSWORD=%s", con
->password
);
9530 if (con
->gss_uid
> 0)
9532 cupsFilePrintf(fp
, "uid %d\n", (int)con
->gss_uid
);
9533 cupsdSetStringf(&job
->auth_uid
, "AUTH_UID=%d", (int)con
->gss_uid
);
9535 #endif /* HAVE_GSSAPI */
9538 * Write a random number of newlines to the end of the file...
9541 for (i
= (CUPS_RAND() % 1024); i
>= 0; i
--)
9542 cupsFilePutChar(fp
, '\n');
9545 * Close the file and return...
9553 * 'send_document()' - Send a file to a printer or class.
9557 send_document(cupsd_client_t
*con
, /* I - Client connection */
9558 ipp_attribute_t
*uri
) /* I - Printer URI */
9560 ipp_attribute_t
*attr
; /* Current attribute */
9561 ipp_attribute_t
*format
; /* Request's document-format attribute */
9562 ipp_attribute_t
*jformat
; /* Job's document-format attribute */
9563 const char *default_format
;/* document-format-default value */
9564 int jobid
; /* Job ID number */
9565 cupsd_job_t
*job
; /* Current job */
9566 char job_uri
[HTTP_MAX_URI
],
9568 scheme
[HTTP_MAX_URI
],
9569 /* Method portion of URI */
9570 username
[HTTP_MAX_URI
],
9571 /* Username portion of URI */
9573 /* Host portion of URI */
9574 resource
[HTTP_MAX_URI
];
9575 /* Resource portion of URI */
9576 int port
; /* Port portion of URI */
9577 mime_type_t
*filetype
; /* Type of file */
9578 char super
[MIME_MAX_SUPER
],
9579 /* Supertype of file */
9580 type
[MIME_MAX_TYPE
],
9581 /* Subtype of file */
9582 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
9583 /* Textual name of mime type */
9584 char filename
[1024]; /* Job filename */
9585 cupsd_printer_t
*printer
; /* Current printer */
9586 struct stat fileinfo
; /* File information */
9587 int kbytes
; /* Size of file */
9588 int compression
; /* Type of compression */
9589 int start_job
; /* Start the job? */
9592 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "send_document(%p[%d], %s)", con
,
9593 con
->number
, uri
->values
[0].string
.text
);
9596 * See if we have a job URI or a printer URI...
9599 if (!strcmp(uri
->name
, "printer-uri"))
9602 * Got a printer URI; see if we also have a job-id attribute...
9605 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9606 IPP_TAG_INTEGER
)) == NULL
)
9608 send_ipp_status(con
, IPP_BAD_REQUEST
,
9609 _("Got a printer-uri attribute but no job-id."));
9613 jobid
= attr
->values
[0].integer
;
9618 * Got a job URI; parse it to get the job ID...
9621 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9622 sizeof(scheme
), username
, sizeof(username
), host
,
9623 sizeof(host
), &port
, resource
, sizeof(resource
));
9625 if (strncmp(resource
, "/jobs/", 6))
9631 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9632 uri
->values
[0].string
.text
);
9636 jobid
= atoi(resource
+ 6);
9640 * See if the job exists...
9643 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9646 * Nope - return a "not found" error...
9649 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9653 printer
= cupsdFindDest(job
->dest
);
9656 * See if the job is owned by the requesting user...
9659 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9661 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9662 cupsdFindDest(job
->dest
));
9667 * OK, see if the client is sending the document compressed - CUPS
9668 * only supports "none" and "gzip".
9671 compression
= CUPS_FILE_NONE
;
9673 if ((attr
= ippFindAttribute(con
->request
, "compression",
9674 IPP_TAG_KEYWORD
)) != NULL
)
9676 if (strcmp(attr
->values
[0].string
.text
, "none")
9678 && strcmp(attr
->values
[0].string
.text
, "gzip")
9679 #endif /* HAVE_LIBZ */
9682 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Unsupported compression \"%s\"."),
9683 attr
->values
[0].string
.text
);
9684 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
9685 "compression", NULL
, attr
->values
[0].string
.text
);
9690 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
9691 compression
= CUPS_FILE_GZIP
;
9692 #endif /* HAVE_LIBZ */
9696 * Do we have a file to print?
9699 if ((attr
= ippFindAttribute(con
->request
, "last-document",
9700 IPP_TAG_BOOLEAN
)) == NULL
)
9702 send_ipp_status(con
, IPP_BAD_REQUEST
,
9703 _("Missing last-document attribute in request."));
9710 * Check for an empty request with "last-document" set to true, which is
9711 * used to close an "open" job by RFC 2911, section 3.3.2.
9714 if (job
->num_files
> 0 && attr
->values
[0].boolean
)
9717 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file in print request."));
9722 * Is it a format we support?
9727 if ((format
= ippFindAttribute(con
->request
, "document-format",
9728 IPP_TAG_MIMETYPE
)) != NULL
)
9731 * Grab format from client...
9734 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%255[^;]",
9737 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"."),
9738 format
->values
[0].string
.text
);
9742 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format-supplied", NULL
, ippGetString(format
, 0, NULL
));
9744 else if ((default_format
= cupsGetOption("document-format",
9745 printer
->num_options
,
9746 printer
->options
)) != NULL
)
9749 * Use default document format...
9752 if (sscanf(default_format
, "%15[^/]/%255[^;]", super
, type
) != 2)
9754 send_ipp_status(con
, IPP_BAD_REQUEST
,
9755 _("Bad document-format-default \"%s\"."), default_format
);
9762 * No document format attribute? Auto-type it!
9765 strlcpy(super
, "application", sizeof(super
));
9766 strlcpy(type
, "octet-stream", sizeof(type
));
9769 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
9772 * Auto-type the file...
9775 ipp_attribute_t
*doc_name
; /* document-name attribute */
9778 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Auto-typing file...");
9780 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
9781 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
9782 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
9786 filetype
= mimeType(MimeDatabase
, super
, type
);
9789 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Request file type is %s/%s.",
9790 filetype
->super
, filetype
->type
);
9792 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
, filetype
->type
);
9793 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format-detected", NULL
, mimetype
);
9796 filetype
= mimeType(MimeDatabase
, super
, type
);
9801 * Replace the document-format attribute value with the auto-typed or
9805 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9808 if ((jformat
= ippFindAttribute(job
->attrs
, "document-format",
9809 IPP_TAG_MIMETYPE
)) != NULL
)
9810 ippSetString(job
->attrs
, &jformat
, 0, mimetype
);
9812 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
9813 "document-format", NULL
, mimetype
);
9817 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9818 _("Unsupported document-format \"%s/%s\"."), super
, type
);
9819 cupsdLogMessage(CUPSD_LOG_INFO
,
9820 "Hint: Do you have the raw file printing rules enabled?");
9823 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9824 "document-format", NULL
, format
->values
[0].string
.text
);
9829 if (printer
->filetypes
&& !cupsArrayFind(printer
->filetypes
, filetype
))
9831 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9834 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9835 _("Unsupported document-format \"%s\"."), mimetype
);
9837 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9838 "document-format", NULL
, mimetype
);
9844 * Add the file to the job...
9847 if (add_file(con
, job
, filetype
, compression
))
9850 if ((attr
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
)) != NULL
)
9851 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name-supplied", NULL
, ippGetString(attr
, 0, NULL
));
9853 if (stat(con
->filename
, &fileinfo
))
9856 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
9858 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
9860 job
->koctets
+= kbytes
;
9862 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets", IPP_TAG_INTEGER
)) != NULL
)
9863 attr
->values
[0].integer
+= kbytes
;
9865 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
, job
->num_files
);
9866 if (rename(con
->filename
, filename
))
9868 cupsdLogJob(job
, CUPSD_LOG_ERROR
, "Unable to rename job document file \"%s\": %s", filename
, strerror(errno
));
9870 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to rename job document file."));
9874 cupsdClearString(&con
->filename
);
9876 cupsdLogJob(job
, CUPSD_LOG_INFO
, "File of type %s/%s queued by \"%s\".",
9877 filetype
->super
, filetype
->type
, job
->username
);
9880 * Start the job if this is the last document...
9885 if ((attr
= ippFindAttribute(con
->request
, "last-document",
9886 IPP_TAG_BOOLEAN
)) != NULL
&&
9887 attr
->values
[0].boolean
)
9890 * See if we need to add the ending sheet...
9893 if (cupsdTimeoutJob(job
))
9896 if (job
->state_value
== IPP_JOB_STOPPED
)
9898 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9899 job
->state_value
= IPP_JOB_PENDING
;
9901 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
9903 else if (job
->state_value
== IPP_JOB_HELD
)
9905 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9906 IPP_TAG_KEYWORD
)) == NULL
)
9907 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9909 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9911 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9912 job
->state_value
= IPP_JOB_PENDING
;
9914 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
9917 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-hold-until-specified");
9921 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
9927 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9928 IPP_TAG_KEYWORD
)) == NULL
)
9929 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9931 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9933 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
9934 job
->state_value
= IPP_JOB_HELD
;
9935 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
9937 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-incoming");
9940 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
9947 * Fill in the response info...
9950 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
9951 con
->clientname
, con
->clientport
, "/jobs/%d", jobid
);
9952 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
9955 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", jobid
);
9957 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
9959 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons",
9960 NULL
, job
->reasons
->values
[0].string
.text
);
9962 con
->response
->request
.status
.status_code
= IPP_OK
;
9965 * Start the job if necessary...
9974 * 'send_http_error()' - Send a HTTP error back to the IPP client.
9979 cupsd_client_t
*con
, /* I - Client connection */
9980 http_status_t status
, /* I - HTTP status code */
9981 cupsd_printer_t
*printer
) /* I - Printer, if any */
9983 ipp_attribute_t
*uri
; /* Request URI, if any */
9986 if ((uri
= ippFindAttribute(con
->request
, "printer-uri",
9987 IPP_TAG_URI
)) == NULL
)
9988 uri
= ippFindAttribute(con
->request
, "job-uri", IPP_TAG_URI
);
9990 cupsdLogMessage(status
== HTTP_FORBIDDEN
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
9991 "[Client %d] Returning HTTP %s for %s (%s) from %s",
9992 con
->number
, httpStatus(status
),
9994 ippOpString(con
->request
->request
.op
.operation_id
) :
9996 uri
? uri
->values
[0].string
.text
: "no URI",
9997 con
->http
->hostname
);
10001 int auth_type
; /* Type of authentication required */
10004 auth_type
= CUPSD_AUTH_NONE
;
10006 if (status
== HTTP_UNAUTHORIZED
&&
10007 printer
->num_auth_info_required
> 0 &&
10008 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
10010 (con
->request
->request
.op
.operation_id
== IPP_PRINT_JOB
||
10011 con
->request
->request
.op
.operation_id
== IPP_CREATE_JOB
||
10012 con
->request
->request
.op
.operation_id
== CUPS_AUTHENTICATE_JOB
))
10015 * Creating and authenticating jobs requires Kerberos...
10018 auth_type
= CUPSD_AUTH_NEGOTIATE
;
10023 * Use policy/location-defined authentication requirements...
10026 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
10027 cupsd_location_t
*auth
; /* Pointer to authentication element */
10030 if (printer
->type
& CUPS_PRINTER_CLASS
)
10031 snprintf(resource
, sizeof(resource
), "/classes/%s", printer
->name
);
10033 snprintf(resource
, sizeof(resource
), "/printers/%s", printer
->name
);
10035 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
10036 auth
->type
== CUPSD_AUTH_NONE
)
10037 auth
= cupsdFindPolicyOp(printer
->op_policy_ptr
,
10039 con
->request
->request
.op
.operation_id
:
10044 if (auth
->type
== CUPSD_AUTH_DEFAULT
)
10045 auth_type
= cupsdDefaultAuthType();
10047 auth_type
= auth
->type
;
10051 cupsdSendError(con
, status
, auth_type
);
10054 cupsdSendError(con
, status
, CUPSD_AUTH_NONE
);
10056 ippDelete(con
->response
);
10057 con
->response
= NULL
;
10064 * 'send_ipp_status()' - Send a status back to the IPP client.
10068 send_ipp_status(cupsd_client_t
*con
, /* I - Client connection */
10069 ipp_status_t status
, /* I - IPP status code */
10070 const char *message
,/* I - Status message */
10071 ...) /* I - Additional args as needed */
10073 va_list ap
; /* Pointer to additional args */
10074 char formatted
[1024]; /* Formatted errror message */
10077 va_start(ap
, message
);
10078 vsnprintf(formatted
, sizeof(formatted
),
10079 _cupsLangString(con
->language
, message
), ap
);
10082 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s: %s",
10083 ippOpString(con
->request
->request
.op
.operation_id
),
10084 ippErrorString(status
), formatted
);
10086 con
->response
->request
.status
.status_code
= status
;
10088 if (ippFindAttribute(con
->response
, "attributes-charset",
10089 IPP_TAG_ZERO
) == NULL
)
10090 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
10091 "attributes-charset", NULL
, "utf-8");
10093 if (ippFindAttribute(con
->response
, "attributes-natural-language",
10094 IPP_TAG_ZERO
) == NULL
)
10095 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
10096 "attributes-natural-language", NULL
, DefaultLanguage
);
10098 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
10099 "status-message", NULL
, formatted
);
10104 * 'set_default()' - Set the default destination...
10108 set_default(cupsd_client_t
*con
, /* I - Client connection */
10109 ipp_attribute_t
*uri
) /* I - Printer URI */
10111 http_status_t status
; /* Policy status */
10112 cups_ptype_t dtype
; /* Destination type (printer/class) */
10113 cupsd_printer_t
*printer
, /* Printer */
10114 *oldprinter
; /* Old default printer */
10117 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_default(%p[%d], %s)", con
,
10118 con
->number
, uri
->values
[0].string
.text
);
10121 * Is the destination valid?
10124 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10130 send_ipp_status(con
, IPP_NOT_FOUND
,
10131 _("The printer or class does not exist."));
10139 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
10141 send_http_error(con
, status
, NULL
);
10146 * Set it as the default...
10149 oldprinter
= DefaultPrinter
;
10150 DefaultPrinter
= printer
;
10153 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, oldprinter
, NULL
,
10154 "%s is no longer the default printer.", oldprinter
->name
);
10156 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
10157 "%s is now the default printer.", printer
->name
);
10159 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
| CUPSD_DIRTY_CLASSES
|
10160 CUPSD_DIRTY_PRINTCAP
);
10162 cupsdLogMessage(CUPSD_LOG_INFO
,
10163 "Default destination set to \"%s\" by \"%s\".",
10164 printer
->name
, get_username(con
));
10167 * Everything was ok, so return OK status...
10170 con
->response
->request
.status
.status_code
= IPP_OK
;
10175 * 'set_job_attrs()' - Set job attributes.
10179 set_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
10180 ipp_attribute_t
*uri
) /* I - Job URI */
10182 ipp_attribute_t
*attr
, /* Current attribute */
10183 *attr2
; /* Job attribute */
10184 int jobid
; /* Job ID */
10185 cupsd_job_t
*job
; /* Current job */
10186 char scheme
[HTTP_MAX_URI
],
10187 /* Method portion of URI */
10188 username
[HTTP_MAX_URI
],
10189 /* Username portion of URI */
10190 host
[HTTP_MAX_URI
],
10191 /* Host portion of URI */
10192 resource
[HTTP_MAX_URI
];
10193 /* Resource portion of URI */
10194 int port
; /* Port portion of URI */
10195 int event
; /* Events? */
10196 int check_jobs
; /* Check jobs? */
10199 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_job_attrs(%p[%d], %s)", con
,
10200 con
->number
, uri
->values
[0].string
.text
);
10203 * Start with "everything is OK" status...
10206 con
->response
->request
.status
.status_code
= IPP_OK
;
10209 * See if we have a job URI or a printer URI...
10212 if (!strcmp(uri
->name
, "printer-uri"))
10215 * Got a printer URI; see if we also have a job-id attribute...
10218 if ((attr
= ippFindAttribute(con
->request
, "job-id",
10219 IPP_TAG_INTEGER
)) == NULL
)
10221 send_ipp_status(con
, IPP_BAD_REQUEST
,
10222 _("Got a printer-uri attribute but no job-id."));
10226 jobid
= attr
->values
[0].integer
;
10231 * Got a job URI; parse it to get the job ID...
10234 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
10235 sizeof(scheme
), username
, sizeof(username
), host
,
10236 sizeof(host
), &port
, resource
, sizeof(resource
));
10238 if (strncmp(resource
, "/jobs/", 6))
10244 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
10245 uri
->values
[0].string
.text
);
10249 jobid
= atoi(resource
+ 6);
10253 * See if the job exists...
10256 if ((job
= cupsdFindJob(jobid
)) == NULL
)
10259 * Nope - return a "not found" error...
10262 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
10267 * See if the job has been completed...
10270 if (job
->state_value
> IPP_JOB_STOPPED
)
10273 * Return a "not-possible" error...
10276 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10277 _("Job #%d is finished and cannot be altered."), jobid
);
10282 * See if the job is owned by the requesting user...
10285 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10287 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
10288 cupsdFindDest(job
->dest
));
10293 * See what the user wants to change.
10301 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10303 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
10306 if (!strcmp(attr
->name
, "attributes-charset") ||
10307 !strcmp(attr
->name
, "attributes-natural-language") ||
10308 !strncmp(attr
->name
, "date-time-at-", 13) ||
10309 !strncmp(attr
->name
, "document-compression", 20) ||
10310 !strncmp(attr
->name
, "document-format", 15) ||
10311 !strcmp(attr
->name
, "job-detailed-status-messages") ||
10312 !strcmp(attr
->name
, "job-document-access-errors") ||
10313 !strcmp(attr
->name
, "job-id") ||
10314 !strcmp(attr
->name
, "job-impressions-completed") ||
10315 !strcmp(attr
->name
, "job-k-octets-completed") ||
10316 !strcmp(attr
->name
, "job-media-sheets-completed") ||
10317 !strcmp(attr
->name
, "job-originating-host-name") ||
10318 !strcmp(attr
->name
, "job-originating-user-name") ||
10319 !strcmp(attr
->name
, "job-pages-completed") ||
10320 !strcmp(attr
->name
, "job-printer-up-time") ||
10321 !strcmp(attr
->name
, "job-printer-uri") ||
10322 !strcmp(attr
->name
, "job-sheets") ||
10323 !strcmp(attr
->name
, "job-state-message") ||
10324 !strcmp(attr
->name
, "job-state-reasons") ||
10325 !strcmp(attr
->name
, "job-uri") ||
10326 !strcmp(attr
->name
, "number-of-documents") ||
10327 !strcmp(attr
->name
, "number-of-intervening-jobs") ||
10328 !strcmp(attr
->name
, "output-device-assigned") ||
10329 !strncmp(attr
->name
, "time-at-", 8))
10335 send_ipp_status(con
, IPP_ATTRIBUTES_NOT_SETTABLE
,
10336 _("%s cannot be changed."), attr
->name
);
10338 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
10339 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
10343 if (!ippValidateAttribute(attr
))
10345 send_ipp_status(con
, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES
, _("Bad '%s' value."), attr
->name
);
10346 ippCopyAttribute(con
->response
, attr
, 0);
10350 if (!strcmp(attr
->name
, "job-hold-until"))
10352 const char *when
= ippGetString(attr
, 0, NULL
);
10353 /* job-hold-until value */
10355 if ((ippGetValueTag(attr
) != IPP_TAG_KEYWORD
&& ippGetValueTag(attr
) != IPP_TAG_NAME
&& ippGetValueTag(attr
) != IPP_TAG_NAMELANG
) || ippGetCount(attr
) != 1)
10357 send_ipp_status(con
, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES
, _("Unsupported 'job-hold-until' value."));
10358 ippCopyAttribute(con
->response
, attr
, 0);
10362 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-hold-until to %s", when
);
10363 cupsdSetJobHoldUntil(job
, when
, 0);
10365 if (!strcmp(when
, "no-hold"))
10367 cupsdReleaseJob(job
);
10371 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
, "Job held by \"%s\".", username
);
10373 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
;
10375 else if (!strcmp(attr
->name
, "job-priority"))
10378 * Change the job priority...
10381 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10383 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-priority value."));
10385 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
10386 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
10388 else if (job
->state_value
>= IPP_JOB_PROCESSING
)
10390 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10391 _("Job is completed and cannot be changed."));
10394 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10396 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-priority to %d",
10397 attr
->values
[0].integer
);
10398 cupsdSetJobPriority(job
, attr
->values
[0].integer
);
10401 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
|
10402 CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
;
10405 else if (!strcmp(attr
->name
, "job-state"))
10408 * Change the job state...
10411 if (attr
->value_tag
!= IPP_TAG_ENUM
)
10413 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-state value."));
10415 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
10416 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
10420 switch (attr
->values
[0].integer
)
10422 case IPP_JOB_PENDING
:
10423 case IPP_JOB_HELD
:
10424 if (job
->state_value
> IPP_JOB_HELD
)
10426 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10427 _("Job state cannot be changed."));
10430 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10432 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10433 attr
->values
[0].integer
);
10434 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
, CUPSD_JOB_DEFAULT
, "Job state changed by \"%s\"", username
);
10439 case IPP_JOB_PROCESSING
:
10440 case IPP_JOB_STOPPED
:
10441 if (job
->state_value
!= attr
->values
[0].integer
)
10443 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10444 _("Job state cannot be changed."));
10449 case IPP_JOB_CANCELED
:
10450 case IPP_JOB_ABORTED
:
10451 case IPP_JOB_COMPLETED
:
10452 if (job
->state_value
> IPP_JOB_PROCESSING
)
10454 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10455 _("Job state cannot be changed."));
10458 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10460 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10461 attr
->values
[0].integer
);
10462 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
,
10464 "Job state changed by \"%s\"", username
);
10471 else if (con
->response
->request
.status
.status_code
!= IPP_OK
)
10473 else if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10474 IPP_TAG_ZERO
)) != NULL
)
10477 * Some other value; first free the old value...
10480 if (job
->attrs
->prev
)
10481 job
->attrs
->prev
->next
= attr2
->next
;
10483 job
->attrs
->attrs
= attr2
->next
;
10485 if (job
->attrs
->last
== attr2
)
10486 job
->attrs
->last
= job
->attrs
->prev
;
10488 ippDeleteAttribute(NULL
, attr2
);
10491 * Then copy the attribute...
10494 ippCopyAttribute(job
->attrs
, attr
, 0);
10496 else if (attr
->value_tag
== IPP_TAG_DELETEATTR
)
10499 * Delete the attribute...
10502 if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10503 IPP_TAG_ZERO
)) != NULL
)
10505 if (job
->attrs
->prev
)
10506 job
->attrs
->prev
->next
= attr2
->next
;
10508 job
->attrs
->attrs
= attr2
->next
;
10510 if (attr2
== job
->attrs
->last
)
10511 job
->attrs
->last
= job
->attrs
->prev
;
10513 ippDeleteAttribute(NULL
, attr2
);
10515 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10521 * Add new option by copying it...
10524 ippCopyAttribute(job
->attrs
, attr
, 0);
10526 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10535 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10538 * Send events as needed...
10541 if (event
& CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
)
10542 cupsdAddEvent(CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
,
10543 cupsdFindDest(job
->dest
), job
,
10544 "Job priority changed by user.");
10546 if (event
& CUPSD_EVENT_JOB_STATE
)
10547 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
10548 job
->state_value
== IPP_JOB_HELD
?
10549 "Job held by user." : "Job restarted by user.");
10551 if (event
& CUPSD_EVENT_JOB_CONFIG_CHANGED
)
10552 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
10553 "Job options changed by user.");
10556 * Start jobs if possible...
10565 * 'set_printer_attrs()' - Set printer attributes.
10569 set_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
10570 ipp_attribute_t
*uri
) /* I - Printer */
10572 http_status_t status
; /* Policy status */
10573 cups_ptype_t dtype
; /* Destination type (printer/class) */
10574 cupsd_printer_t
*printer
; /* Printer/class */
10575 ipp_attribute_t
*attr
; /* Printer attribute */
10576 int changed
= 0; /* Was anything changed? */
10579 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_attrs(%p[%d], %s)", con
,
10580 con
->number
, uri
->values
[0].string
.text
);
10583 * Is the destination valid?
10586 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10592 send_ipp_status(con
, IPP_NOT_FOUND
,
10593 _("The printer or class does not exist."));
10601 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10603 send_http_error(con
, status
, printer
);
10608 * Return a list of attributes that can be set via Set-Printer-Attributes.
10611 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
10612 IPP_TAG_TEXT
)) != NULL
)
10614 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
10618 if ((attr
= ippFindAttribute(con
->request
, "printer-geo-location", IPP_TAG_URI
)) != NULL
&& !strncmp(attr
->values
[0].string
.text
, "geo:", 4))
10620 cupsdSetString(&printer
->geo_location
, attr
->values
[0].string
.text
);
10624 if ((attr
= ippFindAttribute(con
->request
, "printer-organization", IPP_TAG_TEXT
)) != NULL
)
10626 cupsdSetString(&printer
->organization
, attr
->values
[0].string
.text
);
10630 if ((attr
= ippFindAttribute(con
->request
, "printer-organizational-unit", IPP_TAG_TEXT
)) != NULL
)
10632 cupsdSetString(&printer
->organizational_unit
, attr
->values
[0].string
.text
);
10636 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
10637 IPP_TAG_TEXT
)) != NULL
)
10639 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
10644 * Update the printer attributes and return...
10649 printer
->config_time
= time(NULL
);
10651 cupsdSetPrinterAttrs(printer
);
10652 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
10654 cupsdAddEvent(CUPSD_EVENT_PRINTER_CONFIG
, printer
, NULL
,
10655 "Printer \"%s\" description or location changed by \"%s\".",
10656 printer
->name
, get_username(con
));
10658 cupsdLogMessage(CUPSD_LOG_INFO
,
10659 "Printer \"%s\" description or location changed by \"%s\".",
10660 printer
->name
, get_username(con
));
10663 con
->response
->request
.status
.status_code
= IPP_OK
;
10668 * 'set_printer_defaults()' - Set printer default options from a request.
10671 static int /* O - 1 on success, 0 on failure */
10672 set_printer_defaults(
10673 cupsd_client_t
*con
, /* I - Client connection */
10674 cupsd_printer_t
*printer
) /* I - Printer */
10676 int i
; /* Looping var */
10677 ipp_attribute_t
*attr
; /* Current attribute */
10678 size_t namelen
; /* Length of attribute name */
10679 char name
[256], /* New attribute name */
10680 value
[256]; /* String version of integer attrs */
10683 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10686 * Skip non-printer attributes...
10689 if (attr
->group_tag
!= IPP_TAG_PRINTER
|| !attr
->name
)
10692 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_defaults: %s", attr
->name
);
10694 if (!strcmp(attr
->name
, "job-sheets-default"))
10697 * Only allow keywords and names...
10700 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10704 * Only allow job-sheets-default to be set when running without a
10705 * system high classification level...
10708 if (Classification
)
10711 cupsdSetString(&printer
->job_sheets
[0], attr
->values
[0].string
.text
);
10713 if (attr
->num_values
> 1)
10714 cupsdSetString(&printer
->job_sheets
[1], attr
->values
[1].string
.text
);
10716 cupsdSetString(&printer
->job_sheets
[1], "none");
10718 else if (!strcmp(attr
->name
, "requesting-user-name-allowed"))
10720 cupsdFreeStrings(&(printer
->users
));
10722 printer
->deny_users
= 0;
10724 if (attr
->value_tag
== IPP_TAG_NAME
&&
10725 (attr
->num_values
> 1 ||
10726 strcmp(attr
->values
[0].string
.text
, "all")))
10728 for (i
= 0; i
< attr
->num_values
; i
++)
10729 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
10732 else if (!strcmp(attr
->name
, "requesting-user-name-denied"))
10734 cupsdFreeStrings(&(printer
->users
));
10736 printer
->deny_users
= 1;
10738 if (attr
->value_tag
== IPP_TAG_NAME
&&
10739 (attr
->num_values
> 1 ||
10740 strcmp(attr
->values
[0].string
.text
, "none")))
10742 for (i
= 0; i
< attr
->num_values
; i
++)
10743 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
10746 else if (!strcmp(attr
->name
, "job-quota-period"))
10748 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10751 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-quota-period to %d...",
10752 attr
->values
[0].integer
);
10753 cupsdFreeQuotas(printer
);
10755 printer
->quota_period
= attr
->values
[0].integer
;
10757 else if (!strcmp(attr
->name
, "job-k-limit"))
10759 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10762 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-k-limit to %d...",
10763 attr
->values
[0].integer
);
10764 cupsdFreeQuotas(printer
);
10766 printer
->k_limit
= attr
->values
[0].integer
;
10768 else if (!strcmp(attr
->name
, "job-page-limit"))
10770 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10773 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-page-limit to %d...",
10774 attr
->values
[0].integer
);
10775 cupsdFreeQuotas(printer
);
10777 printer
->page_limit
= attr
->values
[0].integer
;
10779 else if (!strcmp(attr
->name
, "printer-op-policy"))
10781 cupsd_policy_t
*p
; /* Policy */
10784 if (attr
->value_tag
!= IPP_TAG_NAME
)
10787 if ((p
= cupsdFindPolicy(attr
->values
[0].string
.text
)) != NULL
)
10789 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10790 "Setting printer-op-policy to \"%s\"...",
10791 attr
->values
[0].string
.text
);
10792 cupsdSetString(&printer
->op_policy
, attr
->values
[0].string
.text
);
10793 printer
->op_policy_ptr
= p
;
10797 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10798 _("Unknown printer-op-policy \"%s\"."),
10799 attr
->values
[0].string
.text
);
10803 else if (!strcmp(attr
->name
, "printer-error-policy"))
10805 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10808 if (strcmp(attr
->values
[0].string
.text
, "retry-current-job") &&
10809 ((printer
->type
& CUPS_PRINTER_CLASS
) ||
10810 (strcmp(attr
->values
[0].string
.text
, "abort-job") &&
10811 strcmp(attr
->values
[0].string
.text
, "retry-job") &&
10812 strcmp(attr
->values
[0].string
.text
, "stop-printer"))))
10814 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10815 _("Unknown printer-error-policy \"%s\"."),
10816 attr
->values
[0].string
.text
);
10820 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10821 "Setting printer-error-policy to \"%s\"...",
10822 attr
->values
[0].string
.text
);
10823 cupsdSetString(&printer
->error_policy
, attr
->values
[0].string
.text
);
10827 * Skip any other non-default attributes...
10830 namelen
= strlen(attr
->name
);
10831 if (namelen
< 9 || strcmp(attr
->name
+ namelen
- 8, "-default") ||
10832 namelen
> (sizeof(name
) - 1) || attr
->num_values
!= 1)
10836 * OK, anything else must be a user-defined default...
10839 strlcpy(name
, attr
->name
, sizeof(name
));
10840 name
[namelen
- 8] = '\0'; /* Strip "-default" */
10842 switch (attr
->value_tag
)
10844 case IPP_TAG_DELETEATTR
:
10845 printer
->num_options
= cupsRemoveOption(name
,
10846 printer
->num_options
,
10847 &(printer
->options
));
10848 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10849 "Deleting %s", attr
->name
);
10852 case IPP_TAG_NAME
:
10853 case IPP_TAG_TEXT
:
10854 case IPP_TAG_KEYWORD
:
10856 printer
->num_options
= cupsAddOption(name
,
10857 attr
->values
[0].string
.text
,
10858 printer
->num_options
,
10859 &(printer
->options
));
10860 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10861 "Setting %s to \"%s\"...", attr
->name
,
10862 attr
->values
[0].string
.text
);
10865 case IPP_TAG_BOOLEAN
:
10866 printer
->num_options
= cupsAddOption(name
,
10867 attr
->values
[0].boolean
?
10869 printer
->num_options
,
10870 &(printer
->options
));
10871 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10872 "Setting %s to %s...", attr
->name
,
10873 attr
->values
[0].boolean
? "true" : "false");
10876 case IPP_TAG_INTEGER
:
10877 case IPP_TAG_ENUM
:
10878 sprintf(value
, "%d", attr
->values
[0].integer
);
10879 printer
->num_options
= cupsAddOption(name
, value
,
10880 printer
->num_options
,
10881 &(printer
->options
));
10882 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10883 "Setting %s to %s...", attr
->name
, value
);
10886 case IPP_TAG_RANGE
:
10887 sprintf(value
, "%d-%d", attr
->values
[0].range
.lower
,
10888 attr
->values
[0].range
.upper
);
10889 printer
->num_options
= cupsAddOption(name
, value
,
10890 printer
->num_options
,
10891 &(printer
->options
));
10892 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10893 "Setting %s to %s...", attr
->name
, value
);
10896 case IPP_TAG_RESOLUTION
:
10897 sprintf(value
, "%dx%d%s", attr
->values
[0].resolution
.xres
,
10898 attr
->values
[0].resolution
.yres
,
10899 attr
->values
[0].resolution
.units
== IPP_RES_PER_INCH
?
10901 printer
->num_options
= cupsAddOption(name
, value
,
10902 printer
->num_options
,
10903 &(printer
->options
));
10904 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10905 "Setting %s to %s...", attr
->name
, value
);
10909 /* Do nothing for other values */
10919 * 'start_printer()' - Start a printer.
10923 start_printer(cupsd_client_t
*con
, /* I - Client connection */
10924 ipp_attribute_t
*uri
) /* I - Printer URI */
10926 int i
; /* Temporary variable */
10927 http_status_t status
; /* Policy status */
10928 cups_ptype_t dtype
; /* Destination type (printer/class) */
10929 cupsd_printer_t
*printer
; /* Printer data */
10932 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_printer(%p[%d], %s)", con
,
10933 con
->number
, uri
->values
[0].string
.text
);
10936 * Is the destination valid?
10939 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10945 send_ipp_status(con
, IPP_NOT_FOUND
,
10946 _("The printer or class does not exist."));
10954 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10956 send_http_error(con
, status
, printer
);
10961 * Start the printer...
10964 printer
->state_message
[0] = '\0';
10966 cupsdStartPrinter(printer
, 1);
10968 if (dtype
& CUPS_PRINTER_CLASS
)
10969 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" started by \"%s\".",
10970 printer
->name
, get_username(con
));
10972 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" started by \"%s\".",
10973 printer
->name
, get_username(con
));
10981 if ((i
= check_quotas(con
, printer
)) < 0)
10983 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
10988 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
10993 * Everything was ok, so return OK status...
10996 con
->response
->request
.status
.status_code
= IPP_OK
;
11001 * 'stop_printer()' - Stop a printer.
11005 stop_printer(cupsd_client_t
*con
, /* I - Client connection */
11006 ipp_attribute_t
*uri
) /* I - Printer URI */
11008 http_status_t status
; /* Policy status */
11009 cups_ptype_t dtype
; /* Destination type (printer/class) */
11010 cupsd_printer_t
*printer
; /* Printer data */
11011 ipp_attribute_t
*attr
; /* printer-state-message attribute */
11014 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "stop_printer(%p[%d], %s)", con
,
11015 con
->number
, uri
->values
[0].string
.text
);
11018 * Is the destination valid?
11021 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11027 send_ipp_status(con
, IPP_NOT_FOUND
,
11028 _("The printer or class does not exist."));
11036 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11038 send_http_error(con
, status
, printer
);
11043 * Stop the printer...
11046 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
11047 IPP_TAG_TEXT
)) == NULL
)
11048 strlcpy(printer
->state_message
, "Paused", sizeof(printer
->state_message
));
11051 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
11052 sizeof(printer
->state_message
));
11055 cupsdStopPrinter(printer
, 1);
11057 if (dtype
& CUPS_PRINTER_CLASS
)
11058 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" stopped by \"%s\".",
11059 printer
->name
, get_username(con
));
11061 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" stopped by \"%s\".",
11062 printer
->name
, get_username(con
));
11065 * Everything was ok, so return OK status...
11068 con
->response
->request
.status
.status_code
= IPP_OK
;
11073 * 'url_encode_attr()' - URL-encode a string attribute.
11077 url_encode_attr(ipp_attribute_t
*attr
, /* I - Attribute */
11078 char *buffer
,/* I - String buffer */
11079 size_t bufsize
)/* I - Size of buffer */
11081 int i
; /* Looping var */
11082 char *bufptr
, /* Pointer into buffer */
11083 *bufend
; /* End of buffer */
11086 strlcpy(buffer
, attr
->name
, bufsize
);
11087 bufptr
= buffer
+ strlen(buffer
);
11088 bufend
= buffer
+ bufsize
- 1;
11090 for (i
= 0; i
< attr
->num_values
; i
++)
11092 if (bufptr
>= bufend
)
11100 if (bufptr
>= bufend
)
11105 bufptr
= url_encode_string(attr
->values
[i
].string
.text
, bufptr
, (size_t)(bufend
- bufptr
+ 1));
11107 if (bufptr
>= bufend
)
11118 * 'url_encode_string()' - URL-encode a string.
11121 static char * /* O - End of string */
11122 url_encode_string(const char *s
, /* I - String */
11123 char *buffer
, /* I - String buffer */
11124 size_t bufsize
) /* I - Size of buffer */
11126 char *bufptr
, /* Pointer into buffer */
11127 *bufend
; /* End of buffer */
11128 static const char *hex
= "0123456789ABCDEF";
11133 bufend
= buffer
+ bufsize
- 1;
11135 while (*s
&& bufptr
< bufend
)
11137 if (*s
== ' ' || *s
== '%' || *s
== '+')
11139 if (bufptr
>= (bufend
- 2))
11143 *bufptr
++ = hex
[(*s
>> 4) & 15];
11144 *bufptr
++ = hex
[*s
& 15];
11148 else if (*s
== '\'' || *s
== '\\')
11150 if (bufptr
>= (bufend
- 1))
11167 * 'user_allowed()' - See if a user is allowed to print to a queue.
11170 static int /* O - 0 if not allowed, 1 if allowed */
11171 user_allowed(cupsd_printer_t
*p
, /* I - Printer or class */
11172 const char *username
) /* I - Username */
11174 struct passwd
*pw
; /* User password data */
11175 char baseuser
[256], /* Base username */
11176 *baseptr
, /* Pointer to "@" in base username */
11177 *name
; /* Current user name */
11180 if (cupsArrayCount(p
->users
) == 0)
11183 if (!strcmp(username
, "root"))
11186 if (strchr(username
, '@'))
11189 * Strip @REALM for username check...
11192 strlcpy(baseuser
, username
, sizeof(baseuser
));
11194 if ((baseptr
= strchr(baseuser
, '@')) != NULL
)
11197 username
= baseuser
;
11200 pw
= getpwnam(username
);
11203 for (name
= (char *)cupsArrayFirst(p
->users
);
11205 name
= (char *)cupsArrayNext(p
->users
))
11207 if (name
[0] == '@')
11210 * Check group membership...
11213 if (cupsdCheckGroup(username
, pw
, name
+ 1))
11216 else if (name
[0] == '#')
11222 if (cupsdCheckGroup(username
, pw
, name
))
11225 else if (!_cups_strcasecmp(username
, name
))
11229 return ((name
!= NULL
) != p
->deny_users
);
11234 * 'validate_job()' - Validate printer options and destination.
11238 validate_job(cupsd_client_t
*con
, /* I - Client connection */
11239 ipp_attribute_t
*uri
) /* I - Printer URI */
11241 http_status_t status
; /* Policy status */
11242 ipp_attribute_t
*attr
; /* Current attribute */
11244 ipp_attribute_t
*auth_info
; /* auth-info attribute */
11245 #endif /* HAVE_SSL */
11246 ipp_attribute_t
*format
, /* Document-format attribute */
11247 *name
; /* Job-name attribute */
11248 cups_ptype_t dtype
; /* Destination type (printer/class) */
11249 char super
[MIME_MAX_SUPER
],
11250 /* Supertype of file */
11251 type
[MIME_MAX_TYPE
];
11252 /* Subtype of file */
11253 cupsd_printer_t
*printer
; /* Printer */
11256 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_job(%p[%d], %s)", con
,
11257 con
->number
, uri
->values
[0].string
.text
);
11260 * OK, see if the client is sending the document compressed - CUPS
11261 * doesn't support compression yet...
11264 if ((attr
= ippFindAttribute(con
->request
, "compression",
11265 IPP_TAG_KEYWORD
)) != NULL
)
11267 if (strcmp(attr
->values
[0].string
.text
, "none")
11269 && strcmp(attr
->values
[0].string
.text
, "gzip")
11270 #endif /* HAVE_LIBZ */
11273 send_ipp_status(con
, IPP_ATTRIBUTES
,
11274 _("Unsupported 'compression' value \"%s\"."),
11275 attr
->values
[0].string
.text
);
11276 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
11277 "compression", NULL
, attr
->values
[0].string
.text
);
11283 * Is it a format we support?
11286 if ((format
= ippFindAttribute(con
->request
, "document-format",
11287 IPP_TAG_MIMETYPE
)) != NULL
)
11289 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%255[^;]",
11292 send_ipp_status(con
, IPP_BAD_REQUEST
,
11293 _("Bad 'document-format' value \"%s\"."),
11294 format
->values
[0].string
.text
);
11298 if ((strcmp(super
, "application") || strcmp(type
, "octet-stream")) &&
11299 !mimeType(MimeDatabase
, super
, type
))
11301 cupsdLogMessage(CUPSD_LOG_INFO
,
11302 "Hint: Do you have the raw file printing rules enabled?");
11303 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
11304 _("Unsupported 'document-format' value \"%s\"."),
11305 format
->values
[0].string
.text
);
11306 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
11307 "document-format", NULL
, format
->values
[0].string
.text
);
11313 * Is the job-hold-until value valid?
11316 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
)))
11318 send_ipp_status(con
, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES
, _("Unsupported 'job-hold-until' value."));
11319 ippCopyAttribute(con
->response
, attr
, 0);
11324 * Is the job-name valid?
11327 if ((name
= ippFindAttribute(con
->request
, "job-name", IPP_TAG_ZERO
)) != NULL
)
11329 if ((name
->value_tag
!= IPP_TAG_NAME
&& name
->value_tag
!= IPP_TAG_NAMELANG
) ||
11330 name
->num_values
!= 1 || !ippValidateAttribute(name
))
11332 if (StrictConformance
)
11334 send_ipp_status(con
, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES
, _("Unsupported 'job-name' value."));
11335 ippCopyAttribute(con
->response
, name
, 0);
11340 cupsdLogMessage(CUPSD_LOG_WARN
, "Unsupported 'job-name' value, deleting from request.");
11341 ippDeleteAttribute(con
->request
, name
);
11347 * Is the destination valid?
11350 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11356 send_ipp_status(con
, IPP_NOT_FOUND
,
11357 _("The printer or class does not exist."));
11366 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
11367 #endif /* HAVE_SSL */
11369 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11371 send_http_error(con
, status
, printer
);
11374 else if (printer
->num_auth_info_required
== 1 &&
11375 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
11378 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
11382 else if (auth_info
&& !con
->http
->tls
&&
11383 !httpAddrLocalhost(con
->http
->hostaddr
))
11386 * Require encryption of auth-info over non-local connections...
11389 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
11392 #endif /* HAVE_SSL */
11395 * Everything was ok, so return OK status...
11398 con
->response
->request
.status
.status_code
= IPP_OK
;
11403 * 'validate_name()' - Make sure the printer name only contains valid chars.
11406 static int /* O - 0 if name is no good, 1 if good */
11407 validate_name(const char *name
) /* I - Name to check */
11409 const char *ptr
; /* Pointer into name */
11413 * Scan the whole name...
11416 for (ptr
= name
; *ptr
; ptr
++)
11417 if ((*ptr
> 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
11421 * All the characters are good; validate the length, too...
11424 return ((ptr
- name
) < 128);
11429 * 'validate_user()' - Validate the user for the request.
11432 static int /* O - 1 if permitted, 0 otherwise */
11433 validate_user(cupsd_job_t
*job
, /* I - Job */
11434 cupsd_client_t
*con
, /* I - Client connection */
11435 const char *owner
, /* I - Owner of job/resource */
11436 char *username
, /* O - Authenticated username */
11437 size_t userlen
) /* I - Length of username */
11439 cupsd_printer_t
*printer
; /* Printer for job */
11442 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
);
11445 * Validate input...
11448 if (!con
|| !owner
|| !username
|| userlen
<= 0)
11452 * Get the best authenticated username that is available.
11455 strlcpy(username
, get_username(con
), userlen
);
11458 * Check the username against the owner...
11461 printer
= cupsdFindDest(job
->dest
);
11463 return (cupsdCheckPolicy(printer
? printer
->op_policy_ptr
: DefaultPolicyPtr
,
11464 con
, owner
) == HTTP_OK
);