2 * IPP routines for the CUPS scheduler.
4 * Copyright © 2007-2018 by Apple Inc.
5 * Copyright © 1997-2007 by Easy Software Products, all rights reserved.
7 * This file contains Kerberos support code, copyright 2006 by
10 * These coded instructions, statements, and computer programs are the
11 * property of Apple Inc. and are protected by Federal copyright
12 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
13 * which should have been included with this file. If this file is
14 * missing or damaged, see the license at "http://www.cups.org/".
18 * Include necessary headers...
22 #include <cups/ppd-private.h>
25 /*# include <ApplicationServices/ApplicationServices.h>
26 extern CFUUIDRef ColorSyncCreateUUIDFromUInt32(unsigned id);
27 # include <CoreFoundation/CoreFoundation.h>*/
28 # ifdef HAVE_MEMBERSHIP_H
29 # include <membership.h>
30 # endif /* HAVE_MEMBERSHIP_H */
31 # ifdef HAVE_MEMBERSHIPPRIV_H
32 # include <membershipPriv.h>
34 extern int mbr_user_name_to_uuid(const char* name
, uuid_t uu
);
35 extern int mbr_group_name_to_uuid(const char* name
, uuid_t uu
);
36 extern int mbr_check_membership_by_id(uuid_t user
, gid_t group
, int* ismember
);
37 # endif /* HAVE_MEMBERSHIPPRIV_H */
38 #endif /* __APPLE__ */
45 static void accept_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
46 static void add_class(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
47 static int add_file(cupsd_client_t
*con
, cupsd_job_t
*job
,
48 mime_type_t
*filetype
, int compression
);
49 static cupsd_job_t
*add_job(cupsd_client_t
*con
, cupsd_printer_t
*printer
,
50 mime_type_t
*filetype
);
51 static void add_job_subscriptions(cupsd_client_t
*con
, cupsd_job_t
*job
);
52 static void add_job_uuid(cupsd_job_t
*job
);
53 static void add_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
54 static void add_printer_state_reasons(cupsd_client_t
*con
,
56 static void add_queued_job_count(cupsd_client_t
*con
, cupsd_printer_t
*p
);
57 static void apply_printer_defaults(cupsd_printer_t
*printer
,
59 static void authenticate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
60 static void cancel_all_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
61 static void cancel_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
62 static void cancel_subscription(cupsd_client_t
*con
, int id
);
63 static int check_rss_recipient(const char *recipient
);
64 static int check_quotas(cupsd_client_t
*con
, cupsd_printer_t
*p
);
65 static void close_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
66 static void copy_attrs(ipp_t
*to
, ipp_t
*from
, cups_array_t
*ra
,
67 ipp_tag_t group
, int quickcopy
,
68 cups_array_t
*exclude
);
69 static int copy_banner(cupsd_client_t
*con
, cupsd_job_t
*job
,
71 static int copy_file(const char *from
, const char *to
, mode_t mode
);
72 static int copy_model(cupsd_client_t
*con
, const char *from
,
74 static void copy_job_attrs(cupsd_client_t
*con
,
76 cups_array_t
*ra
, cups_array_t
*exclude
);
77 static void copy_printer_attrs(cupsd_client_t
*con
,
78 cupsd_printer_t
*printer
,
80 static void copy_subscription_attrs(cupsd_client_t
*con
,
81 cupsd_subscription_t
*sub
,
83 cups_array_t
*exclude
);
84 static void create_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
85 static void create_local_printer(cupsd_client_t
*con
);
86 static cups_array_t
*create_requested_array(ipp_t
*request
);
87 static void create_subscriptions(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
88 static void delete_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
89 static void get_default(cupsd_client_t
*con
);
90 static void get_devices(cupsd_client_t
*con
);
91 static void get_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
92 static void get_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
93 static void get_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
94 static void get_notifications(cupsd_client_t
*con
);
95 static void get_ppd(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
96 static void get_ppds(cupsd_client_t
*con
);
97 static void get_printers(cupsd_client_t
*con
, int type
);
98 static void get_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
99 static void get_printer_supported(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
100 static void get_subscription_attrs(cupsd_client_t
*con
, int sub_id
);
101 static void get_subscriptions(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
102 static const char *get_username(cupsd_client_t
*con
);
103 static void hold_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
104 static void hold_new_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
105 static void move_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
106 static int ppd_parse_line(const char *line
, char *option
, int olen
,
107 char *choice
, int clen
);
108 static void print_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
109 static void read_job_ticket(cupsd_client_t
*con
);
110 static void reject_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
111 static void release_held_new_jobs(cupsd_client_t
*con
,
112 ipp_attribute_t
*uri
);
113 static void release_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
114 static void renew_subscription(cupsd_client_t
*con
, int sub_id
);
115 static void restart_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
116 static void save_auth_info(cupsd_client_t
*con
, cupsd_job_t
*job
,
117 ipp_attribute_t
*auth_info
);
118 static void send_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
119 static void send_http_error(cupsd_client_t
*con
, http_status_t status
,
120 cupsd_printer_t
*printer
);
121 static void send_ipp_status(cupsd_client_t
*con
, ipp_status_t status
,
122 const char *message
, ...)
123 __attribute__((__format__(__printf__
, 3, 4)));
124 static void set_default(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
125 static void set_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
126 static void set_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
127 static int set_printer_defaults(cupsd_client_t
*con
, cupsd_printer_t
*printer
);
128 static void start_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
129 static void stop_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
130 static void url_encode_attr(ipp_attribute_t
*attr
, char *buffer
, size_t bufsize
);
131 static char *url_encode_string(const char *s
, char *buffer
, size_t bufsize
);
132 static int user_allowed(cupsd_printer_t
*p
, const char *username
);
133 static void validate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
134 static int validate_name(const char *name
);
135 static int validate_user(cupsd_job_t
*job
, cupsd_client_t
*con
, const char *owner
, char *username
, size_t userlen
);
139 * 'cupsdProcessIPPRequest()' - Process an incoming IPP request.
142 int /* O - 1 on success, 0 on failure */
143 cupsdProcessIPPRequest(
144 cupsd_client_t
*con
) /* I - Client connection */
146 ipp_tag_t group
; /* Current group tag */
147 ipp_attribute_t
*attr
; /* Current attribute */
148 ipp_attribute_t
*charset
; /* Character set attribute */
149 ipp_attribute_t
*language
; /* Language attribute */
150 ipp_attribute_t
*uri
= NULL
; /* Printer or job URI attribute */
151 ipp_attribute_t
*username
; /* requesting-user-name attr */
152 int sub_id
; /* Subscription ID */
153 int valid
= 1; /* Valid request? */
156 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
));
158 if (LogLevel
>= CUPSD_LOG_DEBUG2
)
160 for (group
= IPP_TAG_ZERO
, attr
= ippFirstAttribute(con
->request
); attr
; attr
= ippNextAttribute(con
->request
))
162 const char *name
; /* Attribute name */
163 char value
[1024]; /* Attribute value */
165 if (group
!= ippGetGroupTag(attr
))
167 group
= ippGetGroupTag(attr
);
168 if (group
!= IPP_TAG_ZERO
)
169 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdProcessIPPRequest: %s", ippTagString(group
));
172 if ((name
= ippGetName(attr
)) == NULL
)
175 ippAttributeString(attr
, value
, sizeof(value
));
177 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdProcessIPPRequest: %s %s%s '%s'", name
, ippGetCount(attr
) > 1 ? "1setOf " : "", ippTagString(ippGetValueTag(attr
)), value
);
182 * First build an empty response message for this request...
185 con
->response
= ippNew();
187 con
->response
->request
.status
.version
[0] = con
->request
->request
.op
.version
[0];
188 con
->response
->request
.status
.version
[1] = con
->request
->request
.op
.version
[1];
189 con
->response
->request
.status
.request_id
= con
->request
->request
.op
.request_id
;
192 * Then validate the request header and required attributes...
195 if (con
->request
->request
.any
.version
[0] != 1 && con
->request
->request
.any
.version
[0] != 2)
198 * Return an error, since we only support IPP 1.x and 2.x.
201 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]);
203 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]);
205 else if (con
->request
->request
.any
.request_id
< 1)
208 * Return an error, since request IDs must be between 1 and 2^31-1
211 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
);
213 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Bad request ID %d."), con
->request
->request
.any
.request_id
);
215 else if (!con
->request
->attrs
)
217 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
, "%04X %s No attributes in request.", IPP_STATUS_ERROR_BAD_REQUEST
, con
->http
->hostname
);
219 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("No attributes in request."));
224 * Make sure that the attributes are provided in the correct order and
225 * don't repeat groups...
228 for (attr
= con
->request
->attrs
, group
= attr
->group_tag
;
231 if (attr
->group_tag
< group
&& attr
->group_tag
!= IPP_TAG_ZERO
)
234 * Out of order; return an error...
237 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
, "%04X %s Attribute groups are out of order", IPP_STATUS_ERROR_BAD_REQUEST
, con
->http
->hostname
);
239 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Attribute groups are out of order (%x < %x)."), attr
->group_tag
, group
);
243 group
= attr
->group_tag
;
248 * Then make sure that the first three attributes are:
251 * attributes-natural-language
252 * printer-uri/job-uri
255 attr
= con
->request
->attrs
;
256 if (attr
&& attr
->name
&& !strcmp(attr
->name
, "attributes-charset") && (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_CHARSET
)
264 if (attr
&& attr
->name
&& !strcmp(attr
->name
, "attributes-natural-language") && (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_LANGUAGE
)
269 * Reset language for this request if different from Accept-Language.
272 if (!con
->language
||
273 strcmp(attr
->values
[0].string
.text
, con
->language
->language
))
275 cupsLangFree(con
->language
);
276 con
->language
= cupsLangGet(attr
->values
[0].string
.text
);
282 if ((attr
= ippFindAttribute(con
->request
, "printer-uri", IPP_TAG_URI
)) != NULL
)
284 else if ((attr
= ippFindAttribute(con
->request
, "job-uri", IPP_TAG_URI
)) != NULL
)
286 else if (con
->request
->request
.op
.operation_id
== CUPS_GET_PPD
)
287 uri
= ippFindAttribute(con
->request
, "ppd-name", IPP_TAG_NAME
);
292 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
, "attributes-charset", NULL
, charset
->values
[0].string
.text
);
294 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
, "attributes-charset", NULL
, "utf-8");
297 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
, "attributes-natural-language", NULL
, language
->values
[0].string
.text
);
299 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
, "attributes-natural-language", NULL
, DefaultLanguage
);
301 if (charset
&& _cups_strcasecmp(charset
->values
[0].string
.text
, "us-ascii") && _cups_strcasecmp(charset
->values
[0].string
.text
, "utf-8"))
304 * Bad character set...
307 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unsupported character set \"%s\"",
308 charset
->values
[0].string
.text
);
309 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
);
310 send_ipp_status(con
, IPP_STATUS_ERROR_CHARSET
, _("Unsupported character set \"%s\"."), charset
->values
[0].string
.text
);
312 else if (!charset
|| !language
||
314 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEFAULT
&&
315 con
->request
->request
.op
.operation_id
!= CUPS_GET_PRINTERS
&&
316 con
->request
->request
.op
.operation_id
!= CUPS_GET_CLASSES
&&
317 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEVICES
&&
318 con
->request
->request
.op
.operation_id
!= CUPS_GET_PPDS
))
321 * Return an error, since attributes-charset,
322 * attributes-natural-language, and printer-uri/job-uri are required
323 * for all operations.
328 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing attributes-charset attribute.");
330 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
, "%04X %s Missing attributes-charset attribute.", IPP_STATUS_ERROR_BAD_REQUEST
, con
->http
->hostname
);
335 cupsdLogMessage(CUPSD_LOG_ERROR
,
336 "Missing attributes-natural-language attribute.");
338 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
, "%04X %s Missing attributes-natural-language attribute.", IPP_STATUS_ERROR_BAD_REQUEST
, con
->http
->hostname
);
343 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing printer-uri, job-uri, or ppd-name attribute.");
345 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
);
348 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Request attributes follow...");
350 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
351 cupsdLogMessage(CUPSD_LOG_DEBUG
,
352 "attr \"%s\": group_tag = %x, value_tag = %x",
353 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
356 cupsdLogMessage(CUPSD_LOG_DEBUG
, "End of attributes...");
358 send_ipp_status(con
, IPP_BAD_REQUEST
,
359 _("Missing required attributes."));
364 * OK, all the checks pass so far; validate "requesting-user-name"
368 if ((username
= ippFindAttribute(con
->request
, "requesting-user-name", IPP_TAG_ZERO
)) != NULL
)
371 * Validate "requesting-user-name"...
374 if (username
->group_tag
!= IPP_TAG_OPERATION
&& StrictConformance
)
376 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
, "%04X %s \"requesting-user-name\" attribute in wrong group.", IPP_STATUS_ERROR_BAD_REQUEST
, con
->http
->hostname
);
377 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("\"requesting-user-name\" attribute in wrong group."));
380 else if (username
->value_tag
!= IPP_TAG_NAME
&& username
->value_tag
!= IPP_TAG_NAMELANG
)
382 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
);
383 send_ipp_status(con
, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES
, _("\"requesting-user-name\" attribute with wrong syntax."));
384 if ((attr
= ippCopyAttribute(con
->response
, username
, 0)) != NULL
)
385 attr
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
388 else if (!ippValidateAttribute(username
))
390 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
);
392 if (StrictConformance
)
398 send_ipp_status(con
, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES
, _("\"requesting-user-name\" attribute with wrong syntax."));
399 if ((attr
= ippCopyAttribute(con
->response
, username
, 0)) != NULL
)
400 attr
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
406 * Map bad "requesting-user-name" to 'anonymous'...
409 ippSetString(con
->request
, &username
, 0, "anonymous");
412 else if (!strcmp(username
->values
[0].string
.text
, "root") && _cups_strcasecmp(con
->http
->hostname
, "localhost") && strcmp(con
->username
, "root"))
415 * Remote unauthenticated user masquerading as local root...
418 ippSetString(con
->request
, &username
, 0, RemoteRoot
);
422 if ((attr
= ippFindAttribute(con
->request
, "notify-subscription-id", IPP_TAG_INTEGER
)) != NULL
)
423 sub_id
= attr
->values
[0].integer
;
430 * Try processing the operation...
434 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s", ippOpString(con
->request
->request
.op
.operation_id
), uri
->values
[0].string
.text
);
436 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s", ippOpString(con
->request
->request
.op
.operation_id
));
438 switch (con
->request
->request
.op
.operation_id
)
440 case IPP_OP_PRINT_JOB
:
444 case IPP_OP_VALIDATE_JOB
:
445 validate_job(con
, uri
);
448 case IPP_OP_CREATE_JOB
:
449 create_job(con
, uri
);
452 case IPP_OP_SEND_DOCUMENT
:
453 send_document(con
, uri
);
456 case IPP_OP_CANCEL_JOB
:
457 cancel_job(con
, uri
);
460 case IPP_OP_GET_JOB_ATTRIBUTES
:
461 get_job_attrs(con
, uri
);
464 case IPP_OP_GET_JOBS
:
468 case IPP_OP_GET_PRINTER_ATTRIBUTES
:
469 get_printer_attrs(con
, uri
);
472 case IPP_OP_GET_PRINTER_SUPPORTED_VALUES
:
473 get_printer_supported(con
, uri
);
476 case IPP_OP_HOLD_JOB
:
480 case IPP_OP_RELEASE_JOB
:
481 release_job(con
, uri
);
484 case IPP_OP_RESTART_JOB
:
485 restart_job(con
, uri
);
488 case IPP_OP_PAUSE_PRINTER
:
489 stop_printer(con
, uri
);
492 case IPP_OP_RESUME_PRINTER
:
493 start_printer(con
, uri
);
496 case IPP_OP_PURGE_JOBS
:
497 case IPP_OP_CANCEL_JOBS
:
498 case IPP_OP_CANCEL_MY_JOBS
:
499 cancel_all_jobs(con
, uri
);
502 case IPP_OP_SET_JOB_ATTRIBUTES
:
503 set_job_attrs(con
, uri
);
506 case IPP_OP_SET_PRINTER_ATTRIBUTES
:
507 set_printer_attrs(con
, uri
);
510 case IPP_OP_HOLD_NEW_JOBS
:
511 hold_new_jobs(con
, uri
);
514 case IPP_OP_RELEASE_HELD_NEW_JOBS
:
515 release_held_new_jobs(con
, uri
);
518 case IPP_OP_CLOSE_JOB
:
522 case IPP_OP_CUPS_GET_DEFAULT
:
526 case IPP_OP_CUPS_GET_PRINTERS
:
527 get_printers(con
, 0);
530 case IPP_OP_CUPS_GET_CLASSES
:
531 get_printers(con
, CUPS_PRINTER_CLASS
);
534 case IPP_OP_CUPS_ADD_MODIFY_PRINTER
:
535 add_printer(con
, uri
);
538 case IPP_OP_CUPS_DELETE_PRINTER
:
539 delete_printer(con
, uri
);
542 case IPP_OP_CUPS_ADD_MODIFY_CLASS
:
546 case IPP_OP_CUPS_DELETE_CLASS
:
547 delete_printer(con
, uri
);
550 case IPP_OP_CUPS_ACCEPT_JOBS
:
551 case IPP_OP_ENABLE_PRINTER
:
552 accept_jobs(con
, uri
);
555 case IPP_OP_CUPS_REJECT_JOBS
:
556 case IPP_OP_DISABLE_PRINTER
:
557 reject_jobs(con
, uri
);
560 case IPP_OP_CUPS_SET_DEFAULT
:
561 set_default(con
, uri
);
564 case IPP_OP_CUPS_GET_DEVICES
:
568 case IPP_OP_CUPS_GET_DOCUMENT
:
569 get_document(con
, uri
);
572 case IPP_OP_CUPS_GET_PPD
:
576 case IPP_OP_CUPS_GET_PPDS
:
580 case IPP_OP_CUPS_MOVE_JOB
:
584 case IPP_OP_CUPS_AUTHENTICATE_JOB
:
585 authenticate_job(con
, uri
);
588 case IPP_OP_CREATE_PRINTER_SUBSCRIPTIONS
:
589 case IPP_OP_CREATE_JOB_SUBSCRIPTIONS
:
590 create_subscriptions(con
, uri
);
593 case IPP_OP_GET_SUBSCRIPTION_ATTRIBUTES
:
594 get_subscription_attrs(con
, sub_id
);
597 case IPP_OP_GET_SUBSCRIPTIONS
:
598 get_subscriptions(con
, uri
);
601 case IPP_OP_RENEW_SUBSCRIPTION
:
602 renew_subscription(con
, sub_id
);
605 case IPP_OP_CANCEL_SUBSCRIPTION
:
606 cancel_subscription(con
, sub_id
);
609 case IPP_OP_GET_NOTIFICATIONS
:
610 get_notifications(con
);
613 case IPP_OP_CUPS_CREATE_LOCAL_PRINTER
:
614 create_local_printer(con
);
618 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
));
620 send_ipp_status(con
, IPP_STATUS_ERROR_OPERATION_NOT_SUPPORTED
, _("%s not supported."), ippOpString(con
->request
->request
.op
.operation_id
));
631 * Sending data from the scheduler...
634 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
);
636 httpClearFields(con
->http
);
638 #ifdef CUPSD_USE_CHUNKING
640 * Because older versions of CUPS (1.1.17 and older) and some IPP
641 * clients do not implement chunking properly, we cannot use
642 * chunking by default. This may become the default in future
643 * CUPS releases, or we might add a configuration directive for
647 if (con
->http
->version
== HTTP_1_1
)
649 cupsdLogClient(con
, CUPSD_LOG_DEBUG
, "Transfer-Encoding: chunked");
650 cupsdSetLength(con
->http
, 0);
653 #endif /* CUPSD_USE_CHUNKING */
655 size_t length
; /* Length of response */
658 length
= ippLength(con
->response
);
660 if (con
->file
>= 0 && !con
->pipe_pid
)
662 struct stat fileinfo
; /* File information */
664 if (!fstat(con
->file
, &fileinfo
))
665 length
+= (size_t)fileinfo
.st_size
;
668 cupsdLogClient(con
, CUPSD_LOG_DEBUG
, "Content-Length: " CUPS_LLFMT
, CUPS_LLCAST length
);
669 httpSetLength(con
->http
, length
);
672 if (cupsdSendHeader(con
, HTTP_OK
, "application/ipp", CUPSD_AUTH_NONE
))
675 * Tell the caller the response header was sent successfully...
678 cupsdAddSelect(httpGetFd(con
->http
), (cupsd_selfunc_t
)cupsdReadClient
, (cupsd_selfunc_t
)cupsdWriteClient
, con
);
685 * Tell the caller the response header could not be sent...
694 * Sending data from a subprocess like cups-deviced; tell the caller
695 * everything is A-OK so far...
704 * 'cupsdTimeoutJob()' - Timeout a job waiting on job files.
707 int /* O - 0 on success, -1 on error */
708 cupsdTimeoutJob(cupsd_job_t
*job
) /* I - Job to timeout */
710 cupsd_printer_t
*printer
; /* Destination printer or class */
711 ipp_attribute_t
*attr
; /* job-sheets attribute */
712 int kbytes
; /* Kilobytes in banner */
715 job
->pending_timeout
= 0;
718 * See if we need to add the ending sheet...
721 if (!cupsdLoadJob(job
))
724 printer
= cupsdFindDest(job
->dest
);
725 attr
= ippFindAttribute(job
->attrs
, "job-sheets", IPP_TAG_NAME
);
727 if (printer
&& !(printer
->type
& CUPS_PRINTER_REMOTE
) &&
728 attr
&& attr
->num_values
> 1)
734 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding end banner page \"%s\".",
735 attr
->values
[1].string
.text
);
737 if ((kbytes
= copy_banner(NULL
, job
, attr
->values
[1].string
.text
)) < 0)
740 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
748 * 'accept_jobs()' - Accept print jobs to a printer.
752 accept_jobs(cupsd_client_t
*con
, /* I - Client connection */
753 ipp_attribute_t
*uri
) /* I - Printer or class URI */
755 http_status_t status
; /* Policy status */
756 cups_ptype_t dtype
; /* Destination type (printer/class) */
757 cupsd_printer_t
*printer
; /* Printer data */
760 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "accept_jobs(%p[%d], %s)", con
,
761 con
->number
, uri
->values
[0].string
.text
);
764 * Is the destination valid?
767 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
773 send_ipp_status(con
, IPP_NOT_FOUND
,
774 _("The printer or class does not exist."));
782 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
784 send_http_error(con
, status
, printer
);
789 * Accept jobs sent to the printer...
792 printer
->accepting
= 1;
793 printer
->state_message
[0] = '\0';
795 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
796 "Now accepting jobs.");
798 if (dtype
& CUPS_PRINTER_CLASS
)
800 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
802 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" now accepting jobs (\"%s\").",
803 printer
->name
, get_username(con
));
807 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
809 cupsdLogMessage(CUPSD_LOG_INFO
,
810 "Printer \"%s\" now accepting jobs (\"%s\").",
811 printer
->name
, get_username(con
));
815 * Everything was ok, so return OK status...
818 con
->response
->request
.status
.status_code
= IPP_OK
;
823 * 'add_class()' - Add a class to the system.
827 add_class(cupsd_client_t
*con
, /* I - Client connection */
828 ipp_attribute_t
*uri
) /* I - URI of class */
830 http_status_t status
; /* Policy status */
831 int i
; /* Looping var */
832 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
833 username
[HTTP_MAX_URI
], /* Username portion of URI */
834 host
[HTTP_MAX_URI
], /* Host portion of URI */
835 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
836 int port
; /* Port portion of URI */
837 cupsd_printer_t
*pclass
, /* Class */
838 *member
; /* Member printer/class */
839 cups_ptype_t dtype
; /* Destination type */
840 ipp_attribute_t
*attr
; /* Printer attribute */
841 int modify
; /* Non-zero if we just modified */
842 int need_restart_job
; /* Need to restart job? */
845 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_class(%p[%d], %s)", con
,
846 con
->number
, uri
->values
[0].string
.text
);
849 * Do we have a valid URI?
852 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
853 sizeof(scheme
), username
, sizeof(username
), host
,
854 sizeof(host
), &port
, resource
, sizeof(resource
));
857 if (strncmp(resource
, "/classes/", 9) || strlen(resource
) == 9)
860 * No, return an error...
863 send_ipp_status(con
, IPP_BAD_REQUEST
,
864 _("The printer-uri must be of the form "
865 "\"ipp://HOSTNAME/classes/CLASSNAME\"."));
870 * Do we have a valid printer name?
873 if (!validate_name(resource
+ 9))
876 * No, return an error...
879 send_ipp_status(con
, IPP_BAD_REQUEST
,
880 _("The printer-uri \"%s\" contains invalid characters."),
881 uri
->values
[0].string
.text
);
886 * See if the class already exists; if not, create a new class...
889 if ((pclass
= cupsdFindClass(resource
+ 9)) == NULL
)
892 * Class doesn't exist; see if we have a printer of the same name...
895 if ((pclass
= cupsdFindPrinter(resource
+ 9)) != NULL
)
898 * Yes, return an error...
901 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
902 _("A printer named \"%s\" already exists."),
908 * No, check the default policy and then add the class...
911 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
913 send_http_error(con
, status
, NULL
);
917 pclass
= cupsdAddClass(resource
+ 9);
920 else if ((status
= cupsdCheckPolicy(pclass
->op_policy_ptr
, con
,
923 send_http_error(con
, status
, pclass
);
930 * Look for attributes and copy them over as needed...
933 need_restart_job
= 0;
935 if ((attr
= ippFindAttribute(con
->request
, "printer-location", IPP_TAG_TEXT
)) != NULL
)
936 cupsdSetString(&pclass
->location
, attr
->values
[0].string
.text
);
938 if ((attr
= ippFindAttribute(con
->request
, "printer-geo-location", IPP_TAG_URI
)) != NULL
&& !strncmp(attr
->values
[0].string
.text
, "geo:", 4))
939 cupsdSetString(&pclass
->geo_location
, attr
->values
[0].string
.text
);
941 if ((attr
= ippFindAttribute(con
->request
, "printer-organization", IPP_TAG_TEXT
)) != NULL
)
942 cupsdSetString(&pclass
->organization
, attr
->values
[0].string
.text
);
944 if ((attr
= ippFindAttribute(con
->request
, "printer-organizational-unit", IPP_TAG_TEXT
)) != NULL
)
945 cupsdSetString(&pclass
->organizational_unit
, attr
->values
[0].string
.text
);
947 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
948 IPP_TAG_TEXT
)) != NULL
)
949 cupsdSetString(&pclass
->info
, attr
->values
[0].string
.text
);
951 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
952 IPP_TAG_BOOLEAN
)) != NULL
&&
953 attr
->values
[0].boolean
!= pclass
->accepting
)
955 cupsdLogMessage(CUPSD_LOG_INFO
,
956 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
957 pclass
->name
, attr
->values
[0].boolean
, pclass
->accepting
);
959 pclass
->accepting
= attr
->values
[0].boolean
;
961 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s accepting jobs.",
962 pclass
->accepting
? "Now" : "No longer");
965 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared", IPP_TAG_BOOLEAN
)) != NULL
)
967 if (pclass
->type
& CUPS_PRINTER_REMOTE
)
970 * Cannot re-share remote printers.
973 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Cannot change printer-is-shared for remote queues."));
975 cupsdDeletePrinter(pclass
, 0);
980 if (pclass
->shared
&& !ippGetBoolean(attr
, 0))
981 cupsdDeregisterPrinter(pclass
, 1);
983 cupsdLogMessage(CUPSD_LOG_INFO
,
984 "Setting %s printer-is-shared to %d (was %d.)",
985 pclass
->name
, attr
->values
[0].boolean
, pclass
->shared
);
987 pclass
->shared
= ippGetBoolean(attr
, 0);
990 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
991 IPP_TAG_ENUM
)) != NULL
)
993 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
994 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
996 send_ipp_status(con
, IPP_BAD_REQUEST
,
997 _("Attempt to set %s printer-state to bad value %d."),
998 pclass
->name
, attr
->values
[0].integer
);
1000 cupsdDeletePrinter(pclass
, 0);
1005 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
1006 pclass
->name
, attr
->values
[0].integer
, pclass
->state
);
1008 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
1009 cupsdStopPrinter(pclass
, 0);
1012 cupsdSetPrinterState(pclass
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
1013 need_restart_job
= 1;
1016 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
1017 IPP_TAG_TEXT
)) != NULL
)
1019 strlcpy(pclass
->state_message
, attr
->values
[0].string
.text
,
1020 sizeof(pclass
->state_message
));
1022 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s",
1023 pclass
->state_message
);
1025 if ((attr
= ippFindAttribute(con
->request
, "member-uris",
1026 IPP_TAG_URI
)) != NULL
)
1029 * Clear the printer array as needed...
1032 need_restart_job
= 1;
1034 if (pclass
->num_printers
> 0)
1036 free(pclass
->printers
);
1037 pclass
->num_printers
= 0;
1041 * Add each printer or class that is listed...
1044 for (i
= 0; i
< attr
->num_values
; i
++)
1047 * Search for the printer or class URI...
1050 if (!cupsdValidateDest(attr
->values
[i
].string
.text
, &dtype
, &member
))
1056 send_ipp_status(con
, IPP_NOT_FOUND
,
1057 _("The printer or class does not exist."));
1059 cupsdDeletePrinter(pclass
, 0);
1063 else if (dtype
& CUPS_PRINTER_CLASS
)
1065 send_ipp_status(con
, IPP_BAD_REQUEST
,
1066 _("Nested classes are not allowed."));
1068 cupsdDeletePrinter(pclass
, 0);
1074 * Add it to the class...
1077 cupsdAddPrinterToClass(pclass
, member
);
1081 if (!set_printer_defaults(con
, pclass
))
1084 cupsdDeletePrinter(pclass
, 0);
1089 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
1090 IPP_TAG_KEYWORD
)) != NULL
)
1091 cupsdSetAuthInfoRequired(pclass
, NULL
, attr
);
1093 pclass
->config_time
= time(NULL
);
1096 * Update the printer class attributes and return...
1099 cupsdSetPrinterAttrs(pclass
);
1100 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
1102 if (need_restart_job
&& pclass
->job
)
1105 * Reset the current job to a "pending" status...
1108 cupsdSetJobState(pclass
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
1109 "Job restarted because the class was modified.");
1112 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1116 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
1117 pclass
, NULL
, "Class \"%s\" modified by \"%s\".",
1118 pclass
->name
, get_username(con
));
1120 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" modified by \"%s\".",
1121 pclass
->name
, get_username(con
));
1125 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
1126 pclass
, NULL
, "New class \"%s\" added by \"%s\".",
1127 pclass
->name
, get_username(con
));
1129 cupsdLogMessage(CUPSD_LOG_INFO
, "New class \"%s\" added by \"%s\".",
1130 pclass
->name
, get_username(con
));
1133 con
->response
->request
.status
.status_code
= IPP_OK
;
1138 * 'add_file()' - Add a file to a job.
1141 static int /* O - 0 on success, -1 on error */
1142 add_file(cupsd_client_t
*con
, /* I - Connection to client */
1143 cupsd_job_t
*job
, /* I - Job to add to */
1144 mime_type_t
*filetype
, /* I - Type of file */
1145 int compression
) /* I - Compression */
1147 mime_type_t
**filetypes
; /* New filetypes array... */
1148 int *compressions
; /* New compressions array... */
1151 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1152 "add_file(con=%p[%d], job=%d, filetype=%s/%s, "
1153 "compression=%d)", con
, con
? con
->number
: -1, job
->id
,
1154 filetype
->super
, filetype
->type
, compression
);
1157 * Add the file to the job...
1160 if (job
->num_files
== 0)
1162 compressions
= (int *)malloc(sizeof(int));
1163 filetypes
= (mime_type_t
**)malloc(sizeof(mime_type_t
*));
1167 compressions
= (int *)realloc(job
->compressions
,
1168 (size_t)(job
->num_files
+ 1) * sizeof(int));
1169 filetypes
= (mime_type_t
**)realloc(job
->filetypes
,
1170 (size_t)(job
->num_files
+ 1) *
1171 sizeof(mime_type_t
*));
1175 job
->compressions
= compressions
;
1178 job
->filetypes
= filetypes
;
1180 if (!compressions
|| !filetypes
)
1182 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1183 "Job aborted because the scheduler ran out of memory.");
1186 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1187 _("Unable to allocate memory for file types."));
1192 job
->compressions
[job
->num_files
] = compression
;
1193 job
->filetypes
[job
->num_files
] = filetype
;
1198 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1205 * 'add_job()' - Add a job to a print queue.
1208 static cupsd_job_t
* /* O - Job object */
1209 add_job(cupsd_client_t
*con
, /* I - Client connection */
1210 cupsd_printer_t
*printer
, /* I - Destination printer */
1211 mime_type_t
*filetype
) /* I - First print file type, if any */
1213 http_status_t status
; /* Policy status */
1214 ipp_attribute_t
*attr
, /* Current attribute */
1215 *auth_info
; /* auth-info attribute */
1216 const char *mandatory
; /* Current mandatory job attribute */
1217 const char *val
; /* Default option value */
1218 int priority
; /* Job priority */
1219 cupsd_job_t
*job
; /* Current job */
1220 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
1221 int kbytes
; /* Size of print file */
1222 int i
; /* Looping var */
1223 int lowerpagerange
; /* Page range bound */
1224 int exact
; /* Did we have an exact match? */
1225 ipp_attribute_t
*media_col
, /* media-col attribute */
1226 *media_margin
; /* media-*-margin attribute */
1227 ipp_t
*unsup_col
; /* media-col in unsupported response */
1228 static const char * const readonly
[] =/* List of read-only attributes */
1230 "date-time-at-completed",
1231 "date-time-at-creation",
1232 "date-time-at-processing",
1233 "job-detailed-status-messages",
1234 "job-document-access-errors",
1236 "job-impressions-completed",
1237 "job-k-octets-completed",
1238 "job-media-sheets-completed",
1239 "job-pages-completed",
1240 "job-printer-up-time",
1243 "job-state-message",
1244 "job-state-reasons",
1246 "number-of-documents",
1247 "number-of-intervening-jobs",
1248 "output-device-assigned",
1249 "time-at-completed",
1251 "time-at-processing"
1255 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job(%p[%d], %p(%s), %p(%s/%s))",
1256 con
, con
->number
, printer
, printer
->name
,
1257 filetype
, filetype
? filetype
->super
: "none",
1258 filetype
? filetype
->type
: "none");
1261 * Check remote printing to non-shared printer...
1264 if (!printer
->shared
&&
1265 _cups_strcasecmp(con
->http
->hostname
, "localhost") &&
1266 _cups_strcasecmp(con
->http
->hostname
, ServerName
))
1268 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
1269 _("The printer or class is not shared."));
1277 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
1279 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
1281 send_http_error(con
, status
, printer
);
1284 else if (printer
->num_auth_info_required
== 1 &&
1285 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
1288 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
1292 else if (auth_info
&& !con
->http
->tls
&&
1293 !httpAddrLocalhost(con
->http
->hostaddr
))
1296 * Require encryption of auth-info over non-local connections...
1299 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
1302 #endif /* HAVE_SSL */
1305 * See if the printer is accepting jobs...
1308 if (!printer
->accepting
)
1310 send_ipp_status(con
, IPP_NOT_ACCEPTING
,
1311 _("Destination \"%s\" is not accepting jobs."),
1317 * Validate job template attributes; for now just document-format,
1318 * copies, job-sheets, number-up, page-ranges, mandatory attributes, and
1322 for (i
= 0; i
< (int)(sizeof(readonly
) / sizeof(readonly
[0])); i
++)
1324 if ((attr
= ippFindAttribute(con
->request
, readonly
[i
], IPP_TAG_ZERO
)) != NULL
)
1326 ippDeleteAttribute(con
->request
, attr
);
1328 if (StrictConformance
)
1330 send_ipp_status(con
, IPP_BAD_REQUEST
, _("The '%s' Job Status attribute cannot be supplied in a job creation request."), readonly
[i
]);
1334 cupsdLogMessage(CUPSD_LOG_INFO
, "Unexpected '%s' Job Status attribute in a job creation request.", readonly
[i
]);
1340 for (mandatory
= (char *)cupsArrayFirst(printer
->pc
->mandatory
);
1342 mandatory
= (char *)cupsArrayNext(printer
->pc
->mandatory
))
1344 if (!ippFindAttribute(con
->request
, mandatory
, IPP_TAG_ZERO
))
1347 * Missing a required attribute...
1350 send_ipp_status(con
, IPP_CONFLICT
,
1351 _("The \"%s\" attribute is required for print jobs."),
1358 if (filetype
&& printer
->filetypes
&&
1359 !cupsArrayFind(printer
->filetypes
, filetype
))
1361 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
1362 /* MIME media type string */
1365 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
1368 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
1369 _("Unsupported format \"%s\"."), mimetype
);
1371 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
1372 "document-format", NULL
, mimetype
);
1377 if ((attr
= ippFindAttribute(con
->request
, "copies",
1378 IPP_TAG_INTEGER
)) != NULL
)
1380 if (attr
->values
[0].integer
< 1 || attr
->values
[0].integer
> MaxCopies
)
1382 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad copies value %d."),
1383 attr
->values
[0].integer
);
1384 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1385 "copies", attr
->values
[0].integer
);
1390 if ((attr
= ippFindAttribute(con
->request
, "job-sheets",
1391 IPP_TAG_ZERO
)) != NULL
)
1393 if (attr
->value_tag
!= IPP_TAG_KEYWORD
&&
1394 attr
->value_tag
!= IPP_TAG_NAME
)
1396 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value type."));
1400 if (attr
->num_values
> 2)
1402 send_ipp_status(con
, IPP_BAD_REQUEST
,
1403 _("Too many job-sheets values (%d > 2)."),
1408 for (i
= 0; i
< attr
->num_values
; i
++)
1409 if (strcmp(attr
->values
[i
].string
.text
, "none") &&
1410 !cupsdFindBanner(attr
->values
[i
].string
.text
))
1412 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value \"%s\"."),
1413 attr
->values
[i
].string
.text
);
1418 if ((attr
= ippFindAttribute(con
->request
, "number-up",
1419 IPP_TAG_INTEGER
)) != NULL
)
1421 if (attr
->values
[0].integer
!= 1 &&
1422 attr
->values
[0].integer
!= 2 &&
1423 attr
->values
[0].integer
!= 4 &&
1424 attr
->values
[0].integer
!= 6 &&
1425 attr
->values
[0].integer
!= 9 &&
1426 attr
->values
[0].integer
!= 16)
1428 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad number-up value %d."),
1429 attr
->values
[0].integer
);
1430 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1431 "number-up", attr
->values
[0].integer
);
1436 if ((attr
= ippFindAttribute(con
->request
, "page-ranges",
1437 IPP_TAG_RANGE
)) != NULL
)
1439 for (i
= 0, lowerpagerange
= 1; i
< attr
->num_values
; i
++)
1441 if (attr
->values
[i
].range
.lower
< lowerpagerange
||
1442 attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
1444 send_ipp_status(con
, IPP_BAD_REQUEST
,
1445 _("Bad page-ranges values %d-%d."),
1446 attr
->values
[i
].range
.lower
,
1447 attr
->values
[i
].range
.upper
);
1451 lowerpagerange
= attr
->values
[i
].range
.upper
+ 1;
1456 * Do media selection as needed...
1459 if (!ippFindAttribute(con
->request
, "PageRegion", IPP_TAG_ZERO
) &&
1460 !ippFindAttribute(con
->request
, "PageSize", IPP_TAG_ZERO
) &&
1461 _ppdCacheGetPageSize(printer
->pc
, con
->request
, NULL
, &exact
))
1464 (media_col
= ippFindAttribute(con
->request
, "media-col",
1465 IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
1467 send_ipp_status(con
, IPP_OK_SUBST
, _("Unsupported margins."));
1469 unsup_col
= ippNew();
1470 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1471 "media-bottom-margin",
1472 IPP_TAG_INTEGER
)) != NULL
)
1473 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1474 "media-bottom-margin", media_margin
->values
[0].integer
);
1476 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1477 "media-left-margin",
1478 IPP_TAG_INTEGER
)) != NULL
)
1479 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1480 "media-left-margin", media_margin
->values
[0].integer
);
1482 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1483 "media-right-margin",
1484 IPP_TAG_INTEGER
)) != NULL
)
1485 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1486 "media-right-margin", media_margin
->values
[0].integer
);
1488 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1490 IPP_TAG_INTEGER
)) != NULL
)
1491 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1492 "media-top-margin", media_margin
->values
[0].integer
);
1494 ippAddCollection(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, "media-col",
1496 ippDelete(unsup_col
);
1501 * Make sure we aren't over our limit...
1504 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1507 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1509 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Too many active jobs."));
1513 if ((i
= check_quotas(con
, printer
)) < 0)
1515 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
1520 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
1525 * Create the job and set things up...
1528 if ((attr
= ippFindAttribute(con
->request
, "job-priority",
1529 IPP_TAG_INTEGER
)) != NULL
)
1530 priority
= attr
->values
[0].integer
;
1533 if ((val
= cupsGetOption("job-priority", printer
->num_options
,
1534 printer
->options
)) != NULL
)
1535 priority
= atoi(val
);
1539 ippAddInteger(con
->request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-priority",
1543 if ((attr
= ippFindAttribute(con
->request
, "job-name", IPP_TAG_ZERO
)) == NULL
)
1544 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
, "Untitled");
1545 else if ((attr
->value_tag
!= IPP_TAG_NAME
&&
1546 attr
->value_tag
!= IPP_TAG_NAMELANG
) ||
1547 attr
->num_values
!= 1)
1549 send_ipp_status(con
, IPP_ATTRIBUTES
,
1550 _("Bad job-name value: Wrong type or count."));
1551 if ((attr
= ippCopyAttribute(con
->response
, attr
, 0)) != NULL
)
1552 attr
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
1554 if (StrictConformance
)
1557 /* Don't use invalid attribute */
1558 ippDeleteAttribute(con
->request
, attr
);
1560 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
, "Untitled");
1562 else if (!ippValidateAttribute(attr
))
1564 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad job-name value: %s"),
1565 cupsLastErrorString());
1567 if ((attr
= ippCopyAttribute(con
->response
, attr
, 0)) != NULL
)
1568 attr
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
1570 if (StrictConformance
)
1573 /* Don't use invalid attribute */
1574 ippDeleteAttribute(con
->request
, attr
);
1576 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
, "Untitled");
1579 attr
= ippFindAttribute(con
->request
, "requesting-user-name", IPP_TAG_NAME
);
1581 if ((job
= cupsdAddJob(priority
, printer
->name
)) == NULL
)
1583 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1584 _("Unable to add job for destination \"%s\"."),
1589 job
->dtype
= printer
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
1590 job
->attrs
= con
->request
;
1592 con
->request
= ippNewRequest(job
->attrs
->request
.op
.operation_id
);
1594 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1597 apply_printer_defaults(printer
, job
);
1599 if (con
->username
[0])
1601 cupsdSetString(&job
->username
, con
->username
);
1604 ippSetString(job
->attrs
, &attr
, 0, con
->username
);
1608 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1609 "add_job: requesting-user-name=\"%s\"",
1610 attr
->values
[0].string
.text
);
1612 cupsdSetString(&job
->username
, attr
->values
[0].string
.text
);
1615 cupsdSetString(&job
->username
, "anonymous");
1618 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1619 "job-originating-user-name", NULL
, job
->username
);
1622 ippSetGroupTag(job
->attrs
, &attr
, IPP_TAG_JOB
);
1623 ippSetName(job
->attrs
, &attr
, "job-originating-user-name");
1626 if (con
->username
[0] || auth_info
)
1628 save_auth_info(con
, job
, auth_info
);
1631 * Remove the auth-info attribute from the attribute data...
1635 ippDeleteAttribute(job
->attrs
, auth_info
);
1638 if ((attr
= ippFindAttribute(con
->request
, "job-name", IPP_TAG_NAME
)) != NULL
)
1639 cupsdSetString(&(job
->name
), attr
->values
[0].string
.text
);
1641 if ((attr
= ippFindAttribute(job
->attrs
, "job-originating-host-name",
1642 IPP_TAG_ZERO
)) != NULL
)
1645 * Request contains a job-originating-host-name attribute; validate it...
1648 if (attr
->value_tag
!= IPP_TAG_NAME
||
1649 attr
->num_values
!= 1 ||
1650 strcmp(con
->http
->hostname
, "localhost"))
1653 * Can't override the value if we aren't connected via localhost.
1654 * Also, we can only have 1 value and it must be a name value.
1657 ippDeleteAttribute(job
->attrs
, attr
);
1658 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-originating-host-name", NULL
, con
->http
->hostname
);
1661 ippSetGroupTag(job
->attrs
, &attr
, IPP_TAG_JOB
);
1666 * No job-originating-host-name attribute, so use the hostname from
1670 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1671 "job-originating-host-name", NULL
, con
->http
->hostname
);
1674 ippAddOutOfBand(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NOVALUE
, "date-time-at-completed");
1675 ippAddDate(job
->attrs
, IPP_TAG_JOB
, "date-time-at-creation", ippTimeToDate(time(NULL
)));
1676 ippAddOutOfBand(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NOVALUE
, "date-time-at-processing");
1677 ippAddOutOfBand(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NOVALUE
, "time-at-completed");
1678 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation", time(NULL
));
1679 ippAddOutOfBand(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NOVALUE
, "time-at-processing");
1682 * Add remaining job attributes...
1685 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1686 job
->state
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_ENUM
,
1687 "job-state", IPP_JOB_STOPPED
);
1688 job
->state_value
= (ipp_jstate_t
)job
->state
->values
[0].integer
;
1689 job
->reasons
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1690 "job-state-reasons", NULL
, "job-incoming");
1691 job
->impressions
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-impressions-completed", 0);
1692 job
->sheets
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1693 "job-media-sheets-completed", 0);
1694 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-printer-uri", NULL
,
1697 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets", IPP_TAG_INTEGER
)) != NULL
)
1698 attr
->values
[0].integer
= 0;
1700 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-k-octets", 0);
1702 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
1703 IPP_TAG_KEYWORD
)) == NULL
)
1704 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
1707 if ((val
= cupsGetOption("job-hold-until", printer
->num_options
,
1708 printer
->options
)) == NULL
)
1711 attr
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1712 "job-hold-until", NULL
, val
);
1715 if (printer
->holding_new_jobs
)
1718 * Hold all new jobs on this printer...
1721 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
1722 cupsdSetJobHoldUntil(job
, ippGetString(attr
, 0, NULL
), 0);
1724 cupsdSetJobHoldUntil(job
, "indefinite", 0);
1726 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1727 job
->state_value
= IPP_JOB_HELD
;
1729 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-held-on-create");
1731 else if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
1734 * Hold job until specified time...
1737 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
1739 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1740 job
->state_value
= IPP_JOB_HELD
;
1742 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-hold-until-specified");
1744 else if (job
->attrs
->request
.op
.operation_id
== IPP_CREATE_JOB
)
1746 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
1747 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1748 job
->state_value
= IPP_JOB_HELD
;
1752 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1753 job
->state_value
= IPP_JOB_PENDING
;
1755 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
1758 if (!(printer
->type
& CUPS_PRINTER_REMOTE
) || Classification
)
1761 * Add job sheets options...
1764 if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1765 IPP_TAG_ZERO
)) == NULL
)
1767 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1768 "Adding default job-sheets values \"%s,%s\"...",
1769 printer
->job_sheets
[0], printer
->job_sheets
[1]);
1771 attr
= ippAddStrings(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-sheets",
1773 ippSetString(job
->attrs
, &attr
, 0, printer
->job_sheets
[0]);
1774 ippSetString(job
->attrs
, &attr
, 1, printer
->job_sheets
[1]);
1777 job
->job_sheets
= attr
;
1780 * Enforce classification level if set...
1785 cupsdLogMessage(CUPSD_LOG_INFO
,
1786 "Classification=\"%s\", ClassifyOverride=%d",
1787 Classification
? Classification
: "(null)",
1790 if (ClassifyOverride
)
1792 if (!strcmp(attr
->values
[0].string
.text
, "none") &&
1793 (attr
->num_values
== 1 ||
1794 !strcmp(attr
->values
[1].string
.text
, "none")))
1797 * Force the leading banner to have the classification on it...
1800 ippSetString(job
->attrs
, &attr
, 0, Classification
);
1802 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1803 "job-sheets=\"%s,none\", "
1804 "job-originating-user-name=\"%s\"",
1805 Classification
, job
->username
);
1807 else if (attr
->num_values
== 2 &&
1808 strcmp(attr
->values
[0].string
.text
,
1809 attr
->values
[1].string
.text
) &&
1810 strcmp(attr
->values
[0].string
.text
, "none") &&
1811 strcmp(attr
->values
[1].string
.text
, "none"))
1814 * Can't put two different security markings on the same document!
1817 ippSetString(job
->attrs
, &attr
, 1, attr
->values
[0].string
.text
);
1819 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1820 "job-sheets=\"%s,%s\", "
1821 "job-originating-user-name=\"%s\"",
1822 attr
->values
[0].string
.text
,
1823 attr
->values
[1].string
.text
, job
->username
);
1825 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1826 strcmp(attr
->values
[0].string
.text
, "none") &&
1827 (attr
->num_values
== 1 ||
1828 (strcmp(attr
->values
[1].string
.text
, Classification
) &&
1829 strcmp(attr
->values
[1].string
.text
, "none"))))
1831 if (attr
->num_values
== 1)
1832 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1833 "CLASSIFICATION OVERRIDDEN "
1834 "job-sheets=\"%s\", "
1835 "job-originating-user-name=\"%s\"",
1836 attr
->values
[0].string
.text
, job
->username
);
1838 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1839 "CLASSIFICATION OVERRIDDEN "
1840 "job-sheets=\"%s,%s\",fffff "
1841 "job-originating-user-name=\"%s\"",
1842 attr
->values
[0].string
.text
,
1843 attr
->values
[1].string
.text
, job
->username
);
1846 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1847 (attr
->num_values
== 1 ||
1848 strcmp(attr
->values
[1].string
.text
, Classification
)))
1851 * Force the banner to have the classification on it...
1854 if (attr
->num_values
> 1 &&
1855 !strcmp(attr
->values
[0].string
.text
, attr
->values
[1].string
.text
))
1857 ippSetString(job
->attrs
, &attr
, 0, Classification
);
1858 ippSetString(job
->attrs
, &attr
, 1, Classification
);
1862 if (attr
->num_values
== 1 ||
1863 strcmp(attr
->values
[0].string
.text
, "none"))
1864 ippSetString(job
->attrs
, &attr
, 0, Classification
);
1866 if (attr
->num_values
> 1 &&
1867 strcmp(attr
->values
[1].string
.text
, "none"))
1868 ippSetString(job
->attrs
, &attr
, 1, Classification
);
1871 if (attr
->num_values
> 1)
1872 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1873 "CLASSIFICATION FORCED "
1874 "job-sheets=\"%s,%s\", "
1875 "job-originating-user-name=\"%s\"",
1876 attr
->values
[0].string
.text
,
1877 attr
->values
[1].string
.text
, job
->username
);
1879 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1880 "CLASSIFICATION FORCED "
1881 "job-sheets=\"%s\", "
1882 "job-originating-user-name=\"%s\"",
1883 Classification
, job
->username
);
1888 * See if we need to add the starting sheet...
1891 if (!(printer
->type
& CUPS_PRINTER_REMOTE
))
1893 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding start banner page \"%s\".",
1894 attr
->values
[0].string
.text
);
1896 if ((kbytes
= copy_banner(con
, job
, attr
->values
[0].string
.text
)) < 0)
1898 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1899 "Aborting job because the start banner could not be "
1904 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
1907 else if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1908 IPP_TAG_ZERO
)) != NULL
)
1909 job
->job_sheets
= attr
;
1912 * Fill in the response info...
1915 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
1916 con
->clientname
, con
->clientport
, "/jobs/%d", job
->id
);
1917 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
1920 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1922 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
1924 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_TEXT
, "job-state-message", NULL
, "");
1925 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons",
1926 NULL
, job
->reasons
->values
[0].string
.text
);
1928 con
->response
->request
.status
.status_code
= IPP_OK
;
1931 * Add any job subscriptions...
1934 add_job_subscriptions(con
, job
);
1937 * Set all but the first two attributes to the job attributes group...
1940 for (attr
= job
->attrs
->attrs
->next
->next
; attr
; attr
= attr
->next
)
1941 attr
->group_tag
= IPP_TAG_JOB
;
1944 * Fire the "job created" event...
1947 cupsdAddEvent(CUPSD_EVENT_JOB_CREATED
, printer
, job
, "Job created.");
1950 * Return the new job...
1958 * 'add_job_subscriptions()' - Add any subscriptions for a job.
1962 add_job_subscriptions(
1963 cupsd_client_t
*con
, /* I - Client connection */
1964 cupsd_job_t
*job
) /* I - Newly created job */
1966 int i
; /* Looping var */
1967 ipp_attribute_t
*prev
, /* Previous attribute */
1968 *next
, /* Next attribute */
1969 *attr
; /* Current attribute */
1970 cupsd_subscription_t
*sub
; /* Subscription object */
1971 const char *recipient
, /* notify-recipient-uri */
1972 *pullmethod
; /* notify-pull-method */
1973 ipp_attribute_t
*user_data
; /* notify-user-data */
1974 int interval
; /* notify-time-interval */
1975 unsigned mask
; /* notify-events */
1979 * Find the first subscription group attribute; return if we have
1983 for (attr
= job
->attrs
->attrs
; attr
; attr
= attr
->next
)
1984 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
1991 * Process the subscription attributes in the request...
2000 mask
= CUPSD_EVENT_NONE
;
2002 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
2004 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
2005 attr
->value_tag
== IPP_TAG_URI
)
2008 * Validate the recipient scheme against the ServerBin/notifier
2012 char notifier
[1024], /* Notifier filename */
2013 scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
2014 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
2015 host
[HTTP_MAX_URI
], /* Host portion of URI */
2016 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2017 int port
; /* Port portion of URI */
2020 recipient
= attr
->values
[0].string
.text
;
2022 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
2023 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
2024 host
, sizeof(host
), &port
,
2025 resource
, sizeof(resource
)) < HTTP_URI_OK
)
2027 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2028 _("Bad notify-recipient-uri \"%s\"."), recipient
);
2029 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2030 "notify-status-code", IPP_URI_SCHEME
);
2034 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
2036 if (access(notifier
, X_OK
))
2038 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2039 _("notify-recipient-uri URI \"%s\" uses unknown "
2040 "scheme."), recipient
);
2041 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2042 "notify-status-code", IPP_URI_SCHEME
);
2046 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
2048 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2049 _("notify-recipient-uri URI \"%s\" is already used."),
2051 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2052 "notify-status-code", IPP_ATTRIBUTES
);
2056 else if (!strcmp(attr
->name
, "notify-pull-method") &&
2057 attr
->value_tag
== IPP_TAG_KEYWORD
)
2059 pullmethod
= attr
->values
[0].string
.text
;
2061 if (strcmp(pullmethod
, "ippget"))
2063 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2064 _("Bad notify-pull-method \"%s\"."), pullmethod
);
2065 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2066 "notify-status-code", IPP_ATTRIBUTES
);
2070 else if (!strcmp(attr
->name
, "notify-charset") &&
2071 attr
->value_tag
== IPP_TAG_CHARSET
&&
2072 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
2073 strcmp(attr
->values
[0].string
.text
, "utf-8"))
2075 send_ipp_status(con
, IPP_CHARSET
,
2076 _("Character set \"%s\" not supported."),
2077 attr
->values
[0].string
.text
);
2080 else if (!strcmp(attr
->name
, "notify-natural-language") &&
2081 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
2082 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
2084 send_ipp_status(con
, IPP_CHARSET
,
2085 _("Language \"%s\" not supported."),
2086 attr
->values
[0].string
.text
);
2089 else if (!strcmp(attr
->name
, "notify-user-data") &&
2090 attr
->value_tag
== IPP_TAG_STRING
)
2092 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
2094 send_ipp_status(con
, IPP_REQUEST_VALUE
,
2095 _("The notify-user-data value is too large "
2096 "(%d > 63 octets)."),
2097 attr
->values
[0].unknown
.length
);
2103 else if (!strcmp(attr
->name
, "notify-events") &&
2104 attr
->value_tag
== IPP_TAG_KEYWORD
)
2106 for (i
= 0; i
< attr
->num_values
; i
++)
2107 mask
|= cupsdEventValue(attr
->values
[i
].string
.text
);
2109 else if (!strcmp(attr
->name
, "notify-lease-duration"))
2111 send_ipp_status(con
, IPP_BAD_REQUEST
,
2112 _("The notify-lease-duration attribute cannot be "
2113 "used with job subscriptions."));
2116 else if (!strcmp(attr
->name
, "notify-time-interval") &&
2117 attr
->value_tag
== IPP_TAG_INTEGER
)
2118 interval
= attr
->values
[0].integer
;
2123 if (!recipient
&& !pullmethod
)
2126 if (mask
== CUPSD_EVENT_NONE
)
2127 mask
= CUPSD_EVENT_JOB_COMPLETED
;
2129 if ((sub
= cupsdAddSubscription(mask
, cupsdFindDest(job
->dest
), job
,
2130 recipient
, 0)) != NULL
)
2132 sub
->interval
= interval
;
2134 cupsdSetString(&sub
->owner
, job
->username
);
2138 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
2139 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
2140 (size_t)sub
->user_data_len
);
2143 ippAddSeparator(con
->response
);
2144 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
2145 "notify-subscription-id", sub
->id
);
2147 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
2155 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
2158 * Remove all of the subscription attributes from the job request...
2160 * TODO: Optimize this since subscription groups have to come at the
2161 * end of the request...
2164 for (attr
= job
->attrs
->attrs
, prev
= NULL
; attr
; attr
= next
)
2168 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
||
2169 attr
->group_tag
== IPP_TAG_ZERO
)
2172 * Free and remove this attribute...
2175 ippDeleteAttribute(NULL
, attr
);
2180 job
->attrs
->attrs
= next
;
2186 job
->attrs
->last
= prev
;
2187 job
->attrs
->current
= prev
;
2192 * 'add_job_uuid()' - Add job-uuid attribute to a job.
2194 * See RFC 4122 for the definition of UUIDs and the format.
2198 add_job_uuid(cupsd_job_t
*job
) /* I - Job */
2200 char uuid
[64]; /* job-uuid string */
2204 * Add a job-uuid attribute if none exists...
2207 if (!ippFindAttribute(job
->attrs
, "job-uuid", IPP_TAG_URI
))
2208 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uuid", NULL
,
2209 httpAssembleUUID(ServerName
, RemotePort
, job
->dest
, job
->id
,
2210 uuid
, sizeof(uuid
)));
2215 * 'add_printer()' - Add a printer to the system.
2219 add_printer(cupsd_client_t
*con
, /* I - Client connection */
2220 ipp_attribute_t
*uri
) /* I - URI of printer */
2222 http_status_t status
; /* Policy status */
2223 int i
; /* Looping var */
2224 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
2225 username
[HTTP_MAX_URI
], /* Username portion of URI */
2226 host
[HTTP_MAX_URI
], /* Host portion of URI */
2227 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2228 int port
; /* Port portion of URI */
2229 cupsd_printer_t
*printer
; /* Printer/class */
2230 ipp_attribute_t
*attr
; /* Printer attribute */
2231 cups_file_t
*fp
; /* Script/PPD file */
2232 char line
[1024]; /* Line from file... */
2233 char srcfile
[1024], /* Source Script/PPD file */
2234 dstfile
[1024]; /* Destination Script/PPD file */
2235 int modify
; /* Non-zero if we are modifying */
2236 int changed_driver
, /* Changed the PPD? */
2237 need_restart_job
, /* Need to restart job? */
2238 set_device_uri
, /* Did we set the device URI? */
2239 set_port_monitor
; /* Did we set the port monitor? */
2242 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer(%p[%d], %s)", con
,
2243 con
->number
, uri
->values
[0].string
.text
);
2246 * Do we have a valid URI?
2249 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
2250 sizeof(scheme
), username
, sizeof(username
), host
,
2251 sizeof(host
), &port
, resource
, sizeof(resource
));
2253 if (strncmp(resource
, "/printers/", 10) || strlen(resource
) == 10)
2256 * No, return an error...
2259 send_ipp_status(con
, IPP_BAD_REQUEST
,
2260 _("The printer-uri must be of the form "
2261 "\"ipp://HOSTNAME/printers/PRINTERNAME\"."));
2266 * Do we have a valid printer name?
2269 if (!validate_name(resource
+ 10))
2272 * No, return an error...
2275 send_ipp_status(con
, IPP_BAD_REQUEST
,
2276 _("The printer-uri \"%s\" contains invalid characters."),
2277 uri
->values
[0].string
.text
);
2282 * See if the printer already exists; if not, create a new printer...
2285 if ((printer
= cupsdFindPrinter(resource
+ 10)) == NULL
)
2288 * Printer doesn't exist; see if we have a class of the same name...
2291 if ((printer
= cupsdFindClass(resource
+ 10)) != NULL
)
2294 * Yes, return an error...
2297 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2298 _("A class named \"%s\" already exists."),
2304 * No, check the default policy then add the printer...
2307 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2309 send_http_error(con
, status
, NULL
);
2313 printer
= cupsdAddPrinter(resource
+ 10);
2316 else if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
2319 send_http_error(con
, status
, printer
);
2326 * Look for attributes and copy them over as needed...
2330 need_restart_job
= 0;
2332 if ((attr
= ippFindAttribute(con
->request
, "printer-is-temporary", IPP_TAG_BOOLEAN
)) != NULL
)
2333 printer
->temporary
= ippGetBoolean(attr
, 0);
2335 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
2336 IPP_TAG_TEXT
)) != NULL
)
2337 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
2339 if ((attr
= ippFindAttribute(con
->request
, "printer-geo-location", IPP_TAG_URI
)) != NULL
&& !strncmp(attr
->values
[0].string
.text
, "geo:", 4))
2340 cupsdSetString(&printer
->geo_location
, attr
->values
[0].string
.text
);
2342 if ((attr
= ippFindAttribute(con
->request
, "printer-organization", IPP_TAG_TEXT
)) != NULL
)
2343 cupsdSetString(&printer
->organization
, attr
->values
[0].string
.text
);
2345 if ((attr
= ippFindAttribute(con
->request
, "printer-organizational-unit", IPP_TAG_TEXT
)) != NULL
)
2346 cupsdSetString(&printer
->organizational_unit
, attr
->values
[0].string
.text
);
2348 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
2349 IPP_TAG_TEXT
)) != NULL
)
2350 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
2354 if ((attr
= ippFindAttribute(con
->request
, "device-uri",
2355 IPP_TAG_URI
)) != NULL
)
2358 * Do we have a valid device URI?
2361 http_uri_status_t uri_status
; /* URI separation status */
2362 char old_device_uri
[1024];
2363 /* Old device URI */
2365 need_restart_job
= 1;
2367 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
,
2368 attr
->values
[0].string
.text
,
2369 scheme
, sizeof(scheme
),
2370 username
, sizeof(username
),
2371 host
, sizeof(host
), &port
,
2372 resource
, sizeof(resource
));
2374 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s device-uri: %s", printer
->name
, httpURIStatusString(uri_status
));
2376 if (uri_status
< HTTP_URI_OK
)
2378 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri \"%s\"."),
2379 attr
->values
[0].string
.text
);
2381 cupsdDeletePrinter(printer
, 0);
2386 if (!strcmp(scheme
, "file"))
2389 * See if the administrator has enabled file devices...
2392 if (!FileDevice
&& strcmp(resource
, "/dev/null"))
2395 * File devices are disabled and the URL is not file:/dev/null...
2398 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2399 _("File device URIs have been disabled. "
2400 "To enable, see the FileDevice directive in "
2401 "\"%s/cups-files.conf\"."),
2404 cupsdDeletePrinter(printer
, 0);
2412 * See if the backend exists and is executable...
2415 snprintf(srcfile
, sizeof(srcfile
), "%s/backend/%s", ServerBin
, scheme
);
2416 if (access(srcfile
, X_OK
))
2419 * Could not find device in list!
2422 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2423 _("Bad device-uri scheme \"%s\"."), scheme
);
2425 cupsdDeletePrinter(printer
, 0);
2431 if (printer
->sanitized_device_uri
)
2432 strlcpy(old_device_uri
, printer
->sanitized_device_uri
,
2433 sizeof(old_device_uri
));
2435 old_device_uri
[0] = '\0';
2437 cupsdSetDeviceURI(printer
, attr
->values
[0].string
.text
);
2439 cupsdLogMessage(CUPSD_LOG_INFO
,
2440 "Setting %s device-uri to \"%s\" (was \"%s\".)",
2441 printer
->name
, printer
->sanitized_device_uri
,
2447 set_port_monitor
= 0;
2449 if ((attr
= ippFindAttribute(con
->request
, "port-monitor",
2450 IPP_TAG_NAME
)) != NULL
)
2452 ipp_attribute_t
*supported
; /* port-monitor-supported attribute */
2455 need_restart_job
= 1;
2457 supported
= ippFindAttribute(printer
->ppd_attrs
, "port-monitor-supported",
2461 for (i
= 0; i
< supported
->num_values
; i
++)
2462 if (!strcmp(supported
->values
[i
].string
.text
,
2463 attr
->values
[0].string
.text
))
2467 if (!supported
|| i
>= supported
->num_values
)
2469 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad port-monitor \"%s\"."),
2470 attr
->values
[0].string
.text
);
2472 cupsdDeletePrinter(printer
, 0);
2477 cupsdLogMessage(CUPSD_LOG_INFO
,
2478 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2479 printer
->name
, attr
->values
[0].string
.text
,
2480 printer
->port_monitor
? printer
->port_monitor
: "none");
2482 if (strcmp(attr
->values
[0].string
.text
, "none"))
2483 cupsdSetString(&printer
->port_monitor
, attr
->values
[0].string
.text
);
2485 cupsdClearString(&printer
->port_monitor
);
2487 set_port_monitor
= 1;
2490 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
2491 IPP_TAG_BOOLEAN
)) != NULL
&&
2492 attr
->values
[0].boolean
!= printer
->accepting
)
2494 cupsdLogMessage(CUPSD_LOG_INFO
,
2495 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
2496 printer
->name
, attr
->values
[0].boolean
, printer
->accepting
);
2498 printer
->accepting
= attr
->values
[0].boolean
;
2500 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2501 "%s accepting jobs.",
2502 printer
->accepting
? "Now" : "No longer");
2505 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared", IPP_TAG_BOOLEAN
)) != NULL
)
2507 if (ippGetBoolean(attr
, 0) &&
2508 printer
->num_auth_info_required
== 1 &&
2509 !strcmp(printer
->auth_info_required
[0], "negotiate"))
2511 send_ipp_status(con
, IPP_BAD_REQUEST
,
2512 _("Cannot share a remote Kerberized printer."));
2514 cupsdDeletePrinter(printer
, 0);
2519 if (printer
->type
& CUPS_PRINTER_REMOTE
)
2522 * Cannot re-share remote printers.
2525 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Cannot change printer-is-shared for remote queues."));
2527 cupsdDeletePrinter(printer
, 0);
2532 if (printer
->shared
&& !ippGetBoolean(attr
, 0))
2533 cupsdDeregisterPrinter(printer
, 1);
2535 cupsdLogMessage(CUPSD_LOG_INFO
,
2536 "Setting %s printer-is-shared to %d (was %d.)",
2537 printer
->name
, attr
->values
[0].boolean
, printer
->shared
);
2539 printer
->shared
= ippGetBoolean(attr
, 0);
2540 if (printer
->shared
&& printer
->temporary
)
2541 printer
->temporary
= 0;
2544 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
2545 IPP_TAG_ENUM
)) != NULL
)
2547 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
2548 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
2550 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad printer-state value %d."),
2551 attr
->values
[0].integer
);
2553 cupsdDeletePrinter(printer
, 0);
2558 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
2559 printer
->name
, attr
->values
[0].integer
, printer
->state
);
2561 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
2562 cupsdStopPrinter(printer
, 0);
2565 need_restart_job
= 1;
2566 cupsdSetPrinterState(printer
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
2570 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
2571 IPP_TAG_TEXT
)) != NULL
)
2573 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
2574 sizeof(printer
->state_message
));
2576 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
, "%s",
2577 printer
->state_message
);
2580 if ((attr
= ippFindAttribute(con
->request
, "printer-state-reasons",
2581 IPP_TAG_KEYWORD
)) != NULL
)
2583 if (attr
->num_values
>
2584 (int)(sizeof(printer
->reasons
) / sizeof(printer
->reasons
[0])))
2586 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2587 _("Too many printer-state-reasons values (%d > %d)."),
2589 (int)(sizeof(printer
->reasons
) /
2590 sizeof(printer
->reasons
[0])));
2592 cupsdDeletePrinter(printer
, 0);
2597 for (i
= 0; i
< printer
->num_reasons
; i
++)
2598 _cupsStrFree(printer
->reasons
[i
]);
2600 printer
->num_reasons
= 0;
2601 for (i
= 0; i
< attr
->num_values
; i
++)
2603 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
2606 printer
->reasons
[printer
->num_reasons
] =
2607 _cupsStrRetain(attr
->values
[i
].string
.text
);
2608 printer
->num_reasons
++;
2610 if (!strcmp(attr
->values
[i
].string
.text
, "paused") &&
2611 printer
->state
!= IPP_PRINTER_STOPPED
)
2613 cupsdLogMessage(CUPSD_LOG_INFO
,
2614 "Setting %s printer-state to %d (was %d.)",
2615 printer
->name
, IPP_PRINTER_STOPPED
, printer
->state
);
2616 cupsdStopPrinter(printer
, 0);
2620 if (PrintcapFormat
== PRINTCAP_PLIST
)
2621 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2623 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2624 "Printer \"%s\" state changed.", printer
->name
);
2627 if (!set_printer_defaults(con
, printer
))
2630 cupsdDeletePrinter(printer
, 0);
2635 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
2636 IPP_TAG_KEYWORD
)) != NULL
)
2637 cupsdSetAuthInfoRequired(printer
, NULL
, attr
);
2640 * See if we have all required attributes...
2643 if (!printer
->device_uri
)
2644 cupsdSetString(&printer
->device_uri
, "file:///dev/null");
2647 * See if we have a PPD file attached to the request...
2652 need_restart_job
= 1;
2655 strlcpy(srcfile
, con
->filename
, sizeof(srcfile
));
2657 if ((fp
= cupsFileOpen(srcfile
, "rb")))
2660 * Yes; get the first line from it...
2664 cupsFileGets(fp
, line
, sizeof(line
));
2668 * Then see what kind of file it is...
2671 if (strncmp(line
, "*PPD-Adobe", 10))
2673 send_ipp_status(con
, IPP_STATUS_ERROR_DOCUMENT_FORMAT_NOT_SUPPORTED
, _("Bad PPD file."));
2675 cupsdDeletePrinter(printer
, 0);
2680 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2684 * The new file is a PPD file, so move the file over to the ppd
2688 if (copy_file(srcfile
, dstfile
, ConfigFilePerm
))
2690 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file - %s"), strerror(errno
));
2692 cupsdDeletePrinter(printer
, 0);
2697 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Copied PPD file successfully");
2700 else if ((attr
= ippFindAttribute(con
->request
, "ppd-name", IPP_TAG_NAME
)) != NULL
)
2702 const char *ppd_name
= ippGetString(attr
, 0, NULL
);
2703 /* ppd-name value */
2705 need_restart_job
= 1;
2708 if (!strcmp(ppd_name
, "raw"))
2711 * Raw driver, remove any existing PPD file.
2714 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
, printer
->name
);
2717 else if (strstr(ppd_name
, "../"))
2719 send_ipp_status(con
, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES
, _("Invalid ppd-name value."));
2721 cupsdDeletePrinter(printer
, 0);
2731 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
, printer
->name
);
2733 if (copy_model(con
, ppd_name
, dstfile
))
2735 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file."));
2737 cupsdDeletePrinter(printer
, 0);
2742 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Copied PPD file successfully");
2749 * If we changed the PPD, then remove the printer's cache file and clear the
2750 * printer-state-reasons...
2753 char cache_name
[1024]; /* Cache filename for printer attrs */
2755 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.data", CacheDir
, printer
->name
);
2758 cupsdSetPrinterReasons(printer
, "none");
2761 * (Re)register color profiles...
2764 cupsdRegisterColor(printer
);
2768 * If we set the device URI but not the port monitor, check which port
2769 * monitor to use by default...
2772 if (set_device_uri
&& !set_port_monitor
)
2774 ppd_file_t
*ppd
; /* PPD file */
2775 ppd_attr_t
*ppdattr
; /* cupsPortMonitor attribute */
2778 httpSeparateURI(HTTP_URI_CODING_ALL
, printer
->device_uri
, scheme
,
2779 sizeof(scheme
), username
, sizeof(username
), host
,
2780 sizeof(host
), &port
, resource
, sizeof(resource
));
2782 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
,
2784 if ((ppd
= _ppdOpenFile(srcfile
, _PPD_LOCALIZATION_NONE
)) != NULL
)
2786 for (ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2788 ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
2789 if (!strcmp(scheme
, ppdattr
->spec
))
2791 cupsdLogMessage(CUPSD_LOG_INFO
,
2792 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2793 printer
->name
, ppdattr
->value
,
2794 printer
->port_monitor
? printer
->port_monitor
2797 if (strcmp(ppdattr
->value
, "none"))
2798 cupsdSetString(&printer
->port_monitor
, ppdattr
->value
);
2800 cupsdClearString(&printer
->port_monitor
);
2809 printer
->config_time
= time(NULL
);
2812 * Update the printer attributes and return...
2815 cupsdSetPrinterAttrs(printer
);
2816 if (!printer
->temporary
)
2817 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2819 if (need_restart_job
&& printer
->job
)
2822 * Restart the current job...
2825 cupsdSetJobState(printer
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
2826 "Job restarted because the printer was modified.");
2829 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2833 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
2834 printer
, NULL
, "Printer \"%s\" modified by \"%s\".",
2835 printer
->name
, get_username(con
));
2837 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" modified by \"%s\".",
2838 printer
->name
, get_username(con
));
2842 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
2843 printer
, NULL
, "New printer \"%s\" added by \"%s\".",
2844 printer
->name
, get_username(con
));
2846 cupsdLogMessage(CUPSD_LOG_INFO
, "New printer \"%s\" added by \"%s\".",
2847 printer
->name
, get_username(con
));
2850 con
->response
->request
.status
.status_code
= IPP_OK
;
2855 * 'add_printer_state_reasons()' - Add the "printer-state-reasons" attribute
2856 * based upon the printer state...
2860 add_printer_state_reasons(
2861 cupsd_client_t
*con
, /* I - Client connection */
2862 cupsd_printer_t
*p
) /* I - Printer info */
2864 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2865 "add_printer_state_reasons(%p[%d], %p[%s])",
2866 con
, con
->number
, p
, p
->name
);
2868 if (p
->num_reasons
== 0)
2869 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2870 "printer-state-reasons", NULL
, "none");
2872 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2873 "printer-state-reasons", p
->num_reasons
, NULL
,
2874 (const char * const *)p
->reasons
);
2879 * 'add_queued_job_count()' - Add the "queued-job-count" attribute for
2880 * the specified printer or class.
2884 add_queued_job_count(
2885 cupsd_client_t
*con
, /* I - Client connection */
2886 cupsd_printer_t
*p
) /* I - Printer or class */
2888 int count
; /* Number of jobs on destination */
2891 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_queued_job_count(%p[%d], %p[%s])",
2892 con
, con
->number
, p
, p
->name
);
2894 count
= cupsdGetPrinterJobCount(p
->name
);
2896 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2897 "queued-job-count", count
);
2902 * 'apply_printer_defaults()' - Apply printer default options to a job.
2906 apply_printer_defaults(
2907 cupsd_printer_t
*printer
, /* I - Printer */
2908 cupsd_job_t
*job
) /* I - Job */
2910 int i
, /* Looping var */
2911 num_options
; /* Number of default options */
2912 cups_option_t
*options
, /* Default options */
2913 *option
; /* Current option */
2916 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Applying default options...");
2919 * Collect all of the default options and add the missing ones to the
2923 for (i
= printer
->num_options
, num_options
= 0, options
= NULL
,
2924 option
= printer
->options
;
2927 if (!ippFindAttribute(job
->attrs
, option
->name
, IPP_TAG_ZERO
))
2929 if (!strcmp(option
->name
, "print-quality") && ippFindAttribute(job
->attrs
, "cupsPrintQuality", IPP_TAG_NAME
))
2930 continue; /* Don't override cupsPrintQuality */
2932 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Adding default %s=%s", option
->name
, option
->value
);
2934 num_options
= cupsAddOption(option
->name
, option
->value
, num_options
, &options
);
2938 * Encode these options as attributes in the job object...
2941 cupsEncodeOptions2(job
->attrs
, num_options
, options
, IPP_TAG_JOB
);
2942 cupsFreeOptions(num_options
, options
);
2947 * 'authenticate_job()' - Set job authentication info.
2951 authenticate_job(cupsd_client_t
*con
, /* I - Client connection */
2952 ipp_attribute_t
*uri
) /* I - Job URI */
2954 ipp_attribute_t
*attr
, /* job-id attribute */
2955 *auth_info
; /* auth-info attribute */
2956 int jobid
; /* Job ID */
2957 cupsd_job_t
*job
; /* Current job */
2958 char scheme
[HTTP_MAX_URI
],
2959 /* Method portion of URI */
2960 username
[HTTP_MAX_URI
],
2961 /* Username portion of URI */
2963 /* Host portion of URI */
2964 resource
[HTTP_MAX_URI
];
2965 /* Resource portion of URI */
2966 int port
; /* Port portion of URI */
2969 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "authenticate_job(%p[%d], %s)",
2970 con
, con
->number
, uri
->values
[0].string
.text
);
2973 * Start with "everything is OK" status...
2976 con
->response
->request
.status
.status_code
= IPP_OK
;
2979 * See if we have a job URI or a printer URI...
2982 if (!strcmp(uri
->name
, "printer-uri"))
2985 * Got a printer URI; see if we also have a job-id attribute...
2988 if ((attr
= ippFindAttribute(con
->request
, "job-id",
2989 IPP_TAG_INTEGER
)) == NULL
)
2991 send_ipp_status(con
, IPP_BAD_REQUEST
,
2992 _("Got a printer-uri attribute but no job-id."));
2996 jobid
= attr
->values
[0].integer
;
3001 * Got a job URI; parse it to get the job ID...
3004 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
3005 sizeof(scheme
), username
, sizeof(username
), host
,
3006 sizeof(host
), &port
, resource
, sizeof(resource
));
3008 if (strncmp(resource
, "/jobs/", 6))
3014 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
3015 uri
->values
[0].string
.text
);
3019 jobid
= atoi(resource
+ 6);
3023 * See if the job exists...
3026 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3029 * Nope - return a "not found" error...
3032 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
3037 * See if the job has been completed...
3040 if (job
->state_value
!= IPP_JOB_HELD
)
3043 * Return a "not-possible" error...
3046 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3047 _("Job #%d is not held for authentication."),
3053 * See if we have already authenticated...
3056 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
3058 if (!con
->username
[0] && !auth_info
)
3060 cupsd_printer_t
*printer
; /* Job destination */
3063 * No auth data. If we need to authenticate via Kerberos, send a
3064 * HTTP auth challenge, otherwise just return an IPP error...
3067 printer
= cupsdFindDest(job
->dest
);
3069 if (printer
&& printer
->num_auth_info_required
> 0 &&
3070 !strcmp(printer
->auth_info_required
[0], "negotiate"))
3071 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
3073 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
3074 _("No authentication information provided."));
3079 * See if the job is owned by the requesting user...
3082 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3084 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3085 cupsdFindDest(job
->dest
));
3090 * Save the authentication information for this job...
3093 save_auth_info(con
, job
, auth_info
);
3096 * Reset the job-hold-until value to "no-hold"...
3099 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
3100 IPP_TAG_KEYWORD
)) == NULL
)
3101 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
3105 ippSetValueTag(job
->attrs
, &attr
, IPP_TAG_KEYWORD
);
3106 ippSetString(job
->attrs
, &attr
, 0, "no-hold");
3110 * Release the job and return...
3113 cupsdReleaseJob(job
);
3115 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, NULL
, job
, "Job authenticated by user");
3117 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Authenticated by \"%s\".", con
->username
);
3124 * 'cancel_all_jobs()' - Cancel all or selected print jobs.
3128 cancel_all_jobs(cupsd_client_t
*con
, /* I - Client connection */
3129 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3131 int i
; /* Looping var */
3132 http_status_t status
; /* Policy status */
3133 cups_ptype_t dtype
; /* Destination type */
3134 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3135 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
3136 hostname
[HTTP_MAX_URI
], /* Host portion of URI */
3137 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3138 int port
; /* Port portion of URI */
3139 ipp_attribute_t
*attr
; /* Attribute in request */
3140 const char *username
= NULL
; /* Username */
3141 cupsd_jobaction_t purge
= CUPSD_JOB_DEFAULT
;
3143 cupsd_printer_t
*printer
; /* Printer */
3144 ipp_attribute_t
*job_ids
; /* job-ids attribute */
3145 cupsd_job_t
*job
; /* Job */
3148 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_all_jobs(%p[%d], %s)", con
,
3149 con
->number
, uri
->values
[0].string
.text
);
3152 * Get the jobs to cancel/purge...
3155 switch (con
->request
->request
.op
.operation_id
)
3157 case IPP_PURGE_JOBS
:
3159 * Get the username (if any) for the jobs we want to cancel (only if
3160 * "my-jobs" is specified...
3163 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
3164 IPP_TAG_BOOLEAN
)) != NULL
&&
3165 attr
->values
[0].boolean
)
3167 if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3168 IPP_TAG_NAME
)) != NULL
)
3169 username
= attr
->values
[0].string
.text
;
3172 send_ipp_status(con
, IPP_BAD_REQUEST
,
3173 _("Missing requesting-user-name attribute."));
3179 * Look for the "purge-jobs" attribute...
3182 if ((attr
= ippFindAttribute(con
->request
, "purge-jobs",
3183 IPP_TAG_BOOLEAN
)) != NULL
)
3184 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
3186 purge
= CUPSD_JOB_PURGE
;
3189 case IPP_CANCEL_MY_JOBS
:
3190 if (con
->username
[0])
3191 username
= con
->username
;
3192 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3193 IPP_TAG_NAME
)) != NULL
)
3194 username
= attr
->values
[0].string
.text
;
3197 send_ipp_status(con
, IPP_BAD_REQUEST
,
3198 _("Missing requesting-user-name attribute."));
3206 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
3209 * See if we have a printer URI...
3212 if (strcmp(uri
->name
, "printer-uri"))
3214 send_ipp_status(con
, IPP_BAD_REQUEST
,
3215 _("The printer-uri attribute is required."));
3220 * And if the destination is valid...
3223 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3229 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
,
3230 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
3231 hostname
, sizeof(hostname
), &port
,
3232 resource
, sizeof(resource
));
3234 if ((!strncmp(resource
, "/printers/", 10) && resource
[10]) ||
3235 (!strncmp(resource
, "/classes/", 9) && resource
[9]))
3237 send_ipp_status(con
, IPP_NOT_FOUND
,
3238 _("The printer or class does not exist."));
3246 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
3248 send_http_error(con
, status
, NULL
);
3254 for (i
= 0; i
< job_ids
->num_values
; i
++)
3256 if ((job
= cupsdFindJob(job_ids
->values
[i
].integer
)) == NULL
)
3259 if (con
->request
->request
.op
.operation_id
== IPP_CANCEL_MY_JOBS
&&
3260 _cups_strcasecmp(job
->username
, username
))
3264 if (i
< job_ids
->num_values
)
3266 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3267 job_ids
->values
[i
].integer
);
3271 for (i
= 0; i
< job_ids
->num_values
; i
++)
3273 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
3275 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3276 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
3277 "Job canceled by user.");
3280 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
3281 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3287 * Cancel all jobs on all printers...
3290 cupsdCancelJobs(NULL
, username
, purge
);
3292 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs were %s by \"%s\".",
3293 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3303 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
3306 send_http_error(con
, status
, printer
);
3312 for (i
= 0; i
< job_ids
->num_values
; i
++)
3314 if ((job
= cupsdFindJob(job_ids
->values
[i
].integer
)) == NULL
||
3315 _cups_strcasecmp(job
->dest
, printer
->name
))
3318 if (con
->request
->request
.op
.operation_id
== IPP_CANCEL_MY_JOBS
&&
3319 _cups_strcasecmp(job
->username
, username
))
3323 if (i
< job_ids
->num_values
)
3325 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3326 job_ids
->values
[i
].integer
);
3330 for (i
= 0; i
< job_ids
->num_values
; i
++)
3332 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
3334 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3335 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
3336 "Job canceled by user.");
3339 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
3340 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3346 * Cancel all of the jobs on the named printer...
3349 cupsdCancelJobs(printer
->name
, username
, purge
);
3351 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs on \"%s\" were %s by \"%s\".",
3353 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3358 con
->response
->request
.status
.status_code
= IPP_OK
;
3365 * 'cancel_job()' - Cancel a print job.
3369 cancel_job(cupsd_client_t
*con
, /* I - Client connection */
3370 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3372 ipp_attribute_t
*attr
; /* Current attribute */
3373 int jobid
; /* Job ID */
3374 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3375 username
[HTTP_MAX_URI
], /* Username portion of URI */
3376 host
[HTTP_MAX_URI
], /* Host portion of URI */
3377 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3378 int port
; /* Port portion of URI */
3379 cupsd_job_t
*job
; /* Job information */
3380 cups_ptype_t dtype
; /* Destination type (printer/class) */
3381 cupsd_printer_t
*printer
; /* Printer data */
3382 cupsd_jobaction_t purge
; /* Purge the job? */
3385 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_job(%p[%d], %s)", con
,
3386 con
->number
, uri
->values
[0].string
.text
);
3389 * See if we have a job URI or a printer URI...
3392 if (!strcmp(uri
->name
, "printer-uri"))
3395 * Got a printer URI; see if we also have a job-id attribute...
3398 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3399 IPP_TAG_INTEGER
)) == NULL
)
3401 send_ipp_status(con
, IPP_BAD_REQUEST
,
3402 _("Got a printer-uri attribute but no job-id."));
3406 if ((jobid
= attr
->values
[0].integer
) == 0)
3409 * Find the current job on the specified printer...
3412 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3418 send_ipp_status(con
, IPP_NOT_FOUND
,
3419 _("The printer or class does not exist."));
3424 * See if there are any pending jobs...
3427 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3429 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3430 if (job
->state_value
<= IPP_JOB_PROCESSING
&&
3431 !_cups_strcasecmp(job
->dest
, printer
->name
))
3439 * No, try stopped jobs...
3442 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3444 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3445 if (job
->state_value
== IPP_JOB_STOPPED
&&
3446 !_cups_strcasecmp(job
->dest
, printer
->name
))
3453 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("No active jobs on %s."),
3463 * Got a job URI; parse it to get the job ID...
3466 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
3467 sizeof(scheme
), username
, sizeof(username
), host
,
3468 sizeof(host
), &port
, resource
, sizeof(resource
));
3470 if (strncmp(resource
, "/jobs/", 6))
3476 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
3477 uri
->values
[0].string
.text
);
3481 jobid
= atoi(resource
+ 6);
3485 * Look for the "purge-job" attribute...
3488 if ((attr
= ippFindAttribute(con
->request
, "purge-job",
3489 IPP_TAG_BOOLEAN
)) != NULL
)
3490 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
3492 purge
= CUPSD_JOB_DEFAULT
;
3495 * See if the job exists...
3498 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3501 * Nope - return a "not found" error...
3504 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
3509 * See if the job is owned by the requesting user...
3512 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3514 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3515 cupsdFindDest(job
->dest
));
3520 * See if the job is already completed, canceled, or aborted; if so,
3521 * we can't cancel...
3524 if (job
->state_value
>= IPP_JOB_CANCELED
&& purge
!= CUPSD_JOB_PURGE
)
3526 switch (job
->state_value
)
3528 case IPP_JOB_CANCELED
:
3529 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3530 _("Job #%d is already canceled - can\'t cancel."),
3534 case IPP_JOB_ABORTED
:
3535 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3536 _("Job #%d is already aborted - can\'t cancel."),
3541 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3542 _("Job #%d is already completed - can\'t cancel."),
3551 * Cancel the job and return...
3554 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3555 purge
== CUPSD_JOB_PURGE
? "Job purged by \"%s\"" :
3556 "Job canceled by \"%s\"",
3560 if (purge
== CUPSD_JOB_PURGE
)
3561 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Purged by \"%s\".", jobid
,
3564 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Canceled by \"%s\".", jobid
,
3567 con
->response
->request
.status
.status_code
= IPP_OK
;
3572 * 'cancel_subscription()' - Cancel a subscription.
3576 cancel_subscription(
3577 cupsd_client_t
*con
, /* I - Client connection */
3578 int sub_id
) /* I - Subscription ID */
3580 http_status_t status
; /* Policy status */
3581 cupsd_subscription_t
*sub
; /* Subscription */
3584 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3585 "cancel_subscription(con=%p[%d], sub_id=%d)",
3586 con
, con
->number
, sub_id
);
3589 * Is the subscription ID valid?
3592 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
3595 * Bad subscription ID...
3598 send_ipp_status(con
, IPP_NOT_FOUND
,
3599 _("Subscription #%d does not exist."), sub_id
);
3607 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
3609 con
, sub
->owner
)) != HTTP_OK
)
3611 send_http_error(con
, status
, sub
->dest
);
3616 * Cancel the subscription...
3619 cupsdDeleteSubscription(sub
, 1);
3621 con
->response
->request
.status
.status_code
= IPP_OK
;
3626 * 'check_rss_recipient()' - Check that we do not have a duplicate RSS feed URI.
3629 static int /* O - 1 if OK, 0 if not */
3630 check_rss_recipient(
3631 const char *recipient
) /* I - Recipient URI */
3633 cupsd_subscription_t
*sub
; /* Current subscription */
3636 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
);
3638 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
3642 * Compare the URIs up to the first ?...
3645 const char *r1
, *r2
;
3647 for (r1
= recipient
, r2
= sub
->recipient
;
3648 *r1
== *r2
&& *r1
&& *r1
!= '?' && *r2
&& *r2
!= '?';
3660 * 'check_quotas()' - Check quotas for a printer and user.
3663 static int /* O - 1 if OK, 0 if forbidden,
3664 -1 if limit reached */
3665 check_quotas(cupsd_client_t
*con
, /* I - Client connection */
3666 cupsd_printer_t
*p
) /* I - Printer or class */
3668 char username
[33], /* Username */
3669 *name
; /* Current user name */
3670 cupsd_quota_t
*q
; /* Quota data */
3671 #ifdef HAVE_MBR_UID_TO_UUID
3673 * Use Apple membership APIs which require that all names represent
3674 * valid user account or group records accessible by the server.
3677 uuid_t usr_uuid
; /* UUID for job requesting user */
3678 uuid_t usr2_uuid
; /* UUID for ACL user name entry */
3679 uuid_t grp_uuid
; /* UUID for ACL group name entry */
3680 int mbr_err
; /* Error from membership function */
3681 int is_member
; /* Is this user a member? */
3684 * Use standard POSIX APIs for checking users and groups...
3687 struct passwd
*pw
; /* User password data */
3688 #endif /* HAVE_MBR_UID_TO_UUID */
3691 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "check_quotas(%p[%d], %p[%s])",
3692 con
, con
->number
, p
, p
->name
);
3695 * Figure out who is printing...
3698 strlcpy(username
, get_username(con
), sizeof(username
));
3700 if ((name
= strchr(username
, '@')) != NULL
)
3701 *name
= '\0'; /* Strip @REALM */
3704 * Check global active job limits for printers and users...
3707 if (MaxJobsPerPrinter
)
3710 * Check if there are too many pending jobs on this printer...
3713 if (cupsdGetPrinterJobCount(p
->name
) >= MaxJobsPerPrinter
)
3715 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for printer \"%s\"...",
3724 * Check if there are too many pending jobs for this user...
3727 if (cupsdGetUserJobCount(username
) >= MaxJobsPerUser
)
3729 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for user \"%s\"...",
3736 * Check against users...
3739 if (cupsArrayCount(p
->users
) == 0 && p
->k_limit
== 0 && p
->page_limit
== 0)
3742 if (cupsArrayCount(p
->users
))
3744 #ifdef HAVE_MBR_UID_TO_UUID
3746 * Get UUID for job requesting user...
3749 if (mbr_user_name_to_uuid((char *)username
, usr_uuid
))
3755 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3756 "check_quotas: UUID lookup failed for user \"%s\"",
3758 cupsdLogMessage(CUPSD_LOG_INFO
,
3759 "Denying user \"%s\" access to printer \"%s\" "
3760 "(unknown user)...",
3766 * Get UID and GID of requesting user...
3769 pw
= getpwnam(username
);
3771 #endif /* HAVE_MBR_UID_TO_UUID */
3773 for (name
= (char *)cupsArrayFirst(p
->users
);
3775 name
= (char *)cupsArrayNext(p
->users
))
3779 * Check group membership...
3782 #ifdef HAVE_MBR_UID_TO_UUID
3785 if (uuid_parse(name
+ 2, grp_uuid
))
3786 uuid_clear(grp_uuid
);
3788 else if ((mbr_err
= mbr_group_name_to_uuid(name
+ 1, grp_uuid
)) != 0)
3791 * Invalid ACL entries are ignored for matching; just record a
3792 * warning in the log...
3795 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3796 "check_quotas: UUID lookup failed for ACL entry "
3797 "\"%s\" (err=%d)", name
, mbr_err
);
3798 cupsdLogMessage(CUPSD_LOG_WARN
,
3799 "Access control entry \"%s\" not a valid group name; "
3800 "entry ignored", name
);
3803 if ((mbr_err
= mbr_check_membership(usr_uuid
, grp_uuid
,
3807 * At this point, there should be no errors, but check anyways...
3810 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3811 "check_quotas: group \"%s\" membership check "
3812 "failed (err=%d)", name
+ 1, mbr_err
);
3817 * Stop if we found a match...
3824 if (cupsdCheckGroup(username
, pw
, name
+ 1))
3826 #endif /* HAVE_MBR_UID_TO_UUID */
3828 #ifdef HAVE_MBR_UID_TO_UUID
3833 if (uuid_parse(name
+ 1, usr2_uuid
))
3834 uuid_clear(usr2_uuid
);
3836 else if ((mbr_err
= mbr_user_name_to_uuid(name
, usr2_uuid
)) != 0)
3839 * Invalid ACL entries are ignored for matching; just record a
3840 * warning in the log...
3843 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3844 "check_quotas: UUID lookup failed for ACL entry "
3845 "\"%s\" (err=%d)", name
, mbr_err
);
3846 cupsdLogMessage(CUPSD_LOG_WARN
,
3847 "Access control entry \"%s\" not a valid user name; "
3848 "entry ignored", name
);
3851 if (!uuid_compare(usr_uuid
, usr2_uuid
))
3855 else if (!_cups_strcasecmp(username
, name
))
3857 #endif /* HAVE_MBR_UID_TO_UUID */
3859 if ((name
!= NULL
) == p
->deny_users
)
3861 cupsdLogMessage(CUPSD_LOG_INFO
,
3862 "Denying user \"%s\" access to printer \"%s\"...",
3872 if (p
->k_limit
|| p
->page_limit
)
3874 if ((q
= cupsdUpdateQuota(p
, username
, 0, 0)) == NULL
)
3876 cupsdLogMessage(CUPSD_LOG_ERROR
,
3877 "Unable to allocate quota data for user \"%s\"",
3882 if ((q
->k_count
>= p
->k_limit
&& p
->k_limit
) ||
3883 (q
->page_count
>= p
->page_limit
&& p
->page_limit
))
3885 cupsdLogMessage(CUPSD_LOG_INFO
, "User \"%s\" is over the quota limit...",
3892 * If we have gotten this far, we're done!
3900 * 'close_job()' - Close a multi-file job.
3904 close_job(cupsd_client_t
*con
, /* I - Client connection */
3905 ipp_attribute_t
*uri
) /* I - Printer URI */
3907 cupsd_job_t
*job
; /* Job */
3908 ipp_attribute_t
*attr
; /* Attribute */
3909 char job_uri
[HTTP_MAX_URI
],
3911 username
[256]; /* User name */
3914 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "close_job(%p[%d], %s)", con
,
3915 con
->number
, uri
->values
[0].string
.text
);
3918 * See if we have a job URI or a printer URI...
3921 if (strcmp(uri
->name
, "printer-uri"))
3924 * job-uri is not supported by Close-Job!
3927 send_ipp_status(con
, IPP_BAD_REQUEST
,
3928 _("Close-Job doesn't support the job-uri attribute."));
3933 * Got a printer URI; see if we also have a job-id attribute...
3936 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3937 IPP_TAG_INTEGER
)) == NULL
)
3939 send_ipp_status(con
, IPP_BAD_REQUEST
,
3940 _("Got a printer-uri attribute but no job-id."));
3944 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
3947 * Nope - return a "not found" error...
3950 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3951 attr
->values
[0].integer
);
3956 * See if the job is owned by the requesting user...
3959 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3961 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3962 cupsdFindDest(job
->dest
));
3967 * Add any ending sheet...
3970 if (cupsdTimeoutJob(job
))
3973 if (job
->state_value
== IPP_JOB_STOPPED
)
3975 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
3976 job
->state_value
= IPP_JOB_PENDING
;
3978 else if (job
->state_value
== IPP_JOB_HELD
)
3980 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
3981 IPP_TAG_KEYWORD
)) == NULL
)
3982 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
3984 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
3986 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
3987 job
->state_value
= IPP_JOB_PENDING
;
3992 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
3995 * Fill in the response info...
3998 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
3999 con
->clientname
, con
->clientport
, "/jobs/%d", job
->id
);
4000 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
4003 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
4005 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
4008 con
->response
->request
.status
.status_code
= IPP_OK
;
4011 * Start the job if necessary...
4019 * 'copy_attrs()' - Copy attributes from one request to another.
4023 copy_attrs(ipp_t
*to
, /* I - Destination request */
4024 ipp_t
*from
, /* I - Source request */
4025 cups_array_t
*ra
, /* I - Requested attributes */
4026 ipp_tag_t group
, /* I - Group to copy */
4027 int quickcopy
, /* I - Do a quick copy? */
4028 cups_array_t
*exclude
) /* I - Attributes to exclude? */
4030 ipp_attribute_t
*fromattr
; /* Source attribute */
4033 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4034 "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)",
4035 to
, from
, ra
, group
, quickcopy
);
4040 for (fromattr
= from
->attrs
; fromattr
; fromattr
= fromattr
->next
)
4043 * Filter attributes as needed...
4046 if ((group
!= IPP_TAG_ZERO
&& fromattr
->group_tag
!= group
&&
4047 fromattr
->group_tag
!= IPP_TAG_ZERO
) || !fromattr
->name
)
4050 if (!strcmp(fromattr
->name
, "document-password") ||
4051 !strcmp(fromattr
->name
, "job-authorization-uri") ||
4052 !strcmp(fromattr
->name
, "job-password") ||
4053 !strcmp(fromattr
->name
, "job-password-encryption") ||
4054 !strcmp(fromattr
->name
, "job-printer-uri"))
4058 (cupsArrayFind(exclude
, fromattr
->name
) ||
4059 cupsArrayFind(exclude
, "all")))
4062 * We need to exclude this attribute for security reasons; we require the
4063 * job-id attribute regardless of the security settings for IPP
4066 * The job-printer-uri attribute is handled by copy_job_attrs().
4068 * Subscription attribute security is handled by copy_subscription_attrs().
4071 if (strcmp(fromattr
->name
, "job-id"))
4075 if (!ra
|| cupsArrayFind(ra
, fromattr
->name
))
4078 * Don't send collection attributes by default to IPP/1.x clients
4079 * since many do not support collections. Also don't send
4080 * media-col-database unless specifically requested by the client.
4083 if (fromattr
->value_tag
== IPP_TAG_BEGIN_COLLECTION
&&
4085 (to
->request
.status
.version
[0] == 1 ||
4086 !strcmp(fromattr
->name
, "media-col-database")))
4089 ippCopyAttribute(to
, fromattr
, quickcopy
);
4096 * 'copy_banner()' - Copy a banner file to the requests directory for the
4100 static int /* O - Size of banner file in kbytes */
4101 copy_banner(cupsd_client_t
*con
, /* I - Client connection */
4102 cupsd_job_t
*job
, /* I - Job information */
4103 const char *name
) /* I - Name of banner */
4105 int i
; /* Looping var */
4106 int kbytes
; /* Size of banner file in kbytes */
4107 char filename
[1024]; /* Job filename */
4108 cupsd_banner_t
*banner
; /* Pointer to banner */
4109 cups_file_t
*in
; /* Input file */
4110 cups_file_t
*out
; /* Output file */
4111 int ch
; /* Character from file */
4112 char attrname
[255], /* Name of attribute */
4113 *s
; /* Pointer into name */
4114 ipp_attribute_t
*attr
; /* Attribute */
4117 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4118 "copy_banner(con=%p[%d], job=%p[%d], name=\"%s\")",
4119 con
, con
? con
->number
: -1, job
, job
->id
,
4120 name
? name
: "(null)");
4123 * Find the banner; return if not found or "none"...
4126 if (!name
|| !strcmp(name
, "none") ||
4127 (banner
= cupsdFindBanner(name
)) == NULL
)
4131 * Open the banner and job files...
4134 if (add_file(con
, job
, banner
->filetype
, 0))
4137 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
4139 if ((out
= cupsFileOpen(filename
, "w")) == NULL
)
4141 cupsdLogMessage(CUPSD_LOG_ERROR
,
4142 "Unable to create banner job file %s - %s",
4143 filename
, strerror(errno
));
4148 fchmod(cupsFileNumber(out
), 0640);
4149 fchown(cupsFileNumber(out
), RunUser
, Group
);
4152 * Try the localized banner file under the subdirectory...
4155 strlcpy(attrname
, job
->attrs
->attrs
->next
->values
[0].string
.text
,
4157 if (strlen(attrname
) > 2 && attrname
[2] == '-')
4160 * Convert ll-cc to ll_CC...
4164 attrname
[3] = (char)toupper(attrname
[3] & 255);
4165 attrname
[4] = (char)toupper(attrname
[4] & 255);
4168 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4171 if (access(filename
, 0) && strlen(attrname
) > 2)
4174 * Wasn't able to find "ll_CC" locale file; try the non-national
4175 * localization banner directory.
4180 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4184 if (access(filename
, 0))
4187 * Use the non-localized banner file.
4190 snprintf(filename
, sizeof(filename
), "%s/banners/%s", DataDir
, name
);
4193 if ((in
= cupsFileOpen(filename
, "r")) == NULL
)
4197 cupsdLogMessage(CUPSD_LOG_ERROR
,
4198 "Unable to open banner template file %s - %s",
4199 filename
, strerror(errno
));
4205 * Parse the file to the end...
4208 while ((ch
= cupsFileGetChar(in
)) != EOF
)
4212 * Get an attribute name...
4215 for (s
= attrname
; (ch
= cupsFileGetChar(in
)) != EOF
;)
4216 if (!isalpha(ch
& 255) && ch
!= '-' && ch
!= '?')
4218 else if (s
< (attrname
+ sizeof(attrname
) - 1))
4228 * Ignore { followed by stuff that is not an attribute name...
4231 cupsFilePrintf(out
, "{%s%c", attrname
, ch
);
4236 * See if it is defined...
4239 if (attrname
[0] == '?')
4244 if (!strcmp(s
, "printer-name"))
4246 cupsFilePuts(out
, job
->dest
);
4249 else if ((attr
= ippFindAttribute(job
->attrs
, s
, IPP_TAG_ZERO
)) == NULL
)
4252 * See if we have a leading question mark...
4255 if (attrname
[0] != '?')
4258 * Nope, write to file as-is; probably a PostScript procedure...
4261 cupsFilePrintf(out
, "{%s}", attrname
);
4268 * Output value(s)...
4271 for (i
= 0; i
< attr
->num_values
; i
++)
4274 cupsFilePutChar(out
, ',');
4276 switch (attr
->value_tag
)
4278 case IPP_TAG_INTEGER
:
4280 if (!strncmp(s
, "time-at-", 8))
4282 struct timeval tv
; /* Time value */
4284 tv
.tv_sec
= attr
->values
[i
].integer
;
4287 cupsFilePuts(out
, cupsdGetDateTime(&tv
, CUPSD_TIME_STANDARD
));
4290 cupsFilePrintf(out
, "%d", attr
->values
[i
].integer
);
4293 case IPP_TAG_BOOLEAN
:
4294 cupsFilePrintf(out
, "%d", attr
->values
[i
].boolean
);
4297 case IPP_TAG_NOVALUE
:
4298 cupsFilePuts(out
, "novalue");
4301 case IPP_TAG_RANGE
:
4302 cupsFilePrintf(out
, "%d-%d", attr
->values
[i
].range
.lower
,
4303 attr
->values
[i
].range
.upper
);
4306 case IPP_TAG_RESOLUTION
:
4307 cupsFilePrintf(out
, "%dx%d%s", attr
->values
[i
].resolution
.xres
,
4308 attr
->values
[i
].resolution
.yres
,
4309 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
4314 case IPP_TAG_STRING
:
4317 case IPP_TAG_KEYWORD
:
4318 case IPP_TAG_CHARSET
:
4319 case IPP_TAG_LANGUAGE
:
4320 if (!_cups_strcasecmp(banner
->filetype
->type
, "postscript"))
4323 * Need to quote strings for PS banners...
4328 for (p
= attr
->values
[i
].string
.text
; *p
; p
++)
4330 if (*p
== '(' || *p
== ')' || *p
== '\\')
4332 cupsFilePutChar(out
, '\\');
4333 cupsFilePutChar(out
, *p
);
4335 else if (*p
< 32 || *p
> 126)
4336 cupsFilePrintf(out
, "\\%03o", *p
& 255);
4338 cupsFilePutChar(out
, *p
);
4342 cupsFilePuts(out
, attr
->values
[i
].string
.text
);
4346 break; /* anti-compiler-warning-code */
4350 else if (ch
== '\\') /* Quoted char */
4352 ch
= cupsFileGetChar(in
);
4354 if (ch
!= '{') /* Only do special handling for \{ */
4355 cupsFilePutChar(out
, '\\');
4357 cupsFilePutChar(out
, ch
);
4360 cupsFilePutChar(out
, ch
);
4364 kbytes
= (cupsFileTell(out
) + 1023) / 1024;
4366 job
->koctets
+= kbytes
;
4368 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets", IPP_TAG_INTEGER
)) != NULL
)
4369 attr
->values
[0].integer
+= kbytes
;
4378 * 'copy_file()' - Copy a PPD file...
4381 static int /* O - 0 = success, -1 = error */
4382 copy_file(const char *from
, /* I - Source file */
4383 const char *to
, /* I - Destination file */
4384 mode_t mode
) /* I - Permissions */
4386 cups_file_t
*src
, /* Source file */
4387 *dst
; /* Destination file */
4388 int bytes
; /* Bytes to read/write */
4389 char buffer
[2048]; /* Copy buffer */
4392 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_file(\"%s\", \"%s\")", from
, to
);
4395 * Open the source and destination file for a copy...
4398 if ((src
= cupsFileOpen(from
, "rb")) == NULL
)
4401 if ((dst
= cupsdCreateConfFile(to
, mode
)) == NULL
)
4408 * Copy the source file to the destination...
4411 while ((bytes
= cupsFileRead(src
, buffer
, sizeof(buffer
))) > 0)
4412 if (cupsFileWrite(dst
, buffer
, (size_t)bytes
) < bytes
)
4420 * Close both files and return...
4425 return (cupsdCloseCreatedConfFile(dst
, to
));
4430 * 'copy_model()' - Copy a PPD model file, substituting default values
4434 static int /* O - 0 = success, -1 = error */
4435 copy_model(cupsd_client_t
*con
, /* I - Client connection */
4436 const char *from
, /* I - Source file */
4437 const char *to
) /* I - Destination file */
4439 fd_set input
; /* select() input set */
4440 struct timeval timeout
; /* select() timeout */
4441 int maxfd
; /* Max file descriptor for select() */
4442 char tempfile
[1024]; /* Temporary PPD file */
4443 int tempfd
; /* Temporary PPD file descriptor */
4444 int temppid
; /* Process ID of cups-driverd */
4445 int temppipe
[2]; /* Temporary pipes */
4446 char *argv
[4], /* Command-line arguments */
4447 *envp
[MAX_ENV
]; /* Environment */
4448 cups_file_t
*src
, /* Source file */
4449 *dst
; /* Destination file */
4450 ppd_file_t
*ppd
; /* PPD file */
4451 int bytes
, /* Bytes from pipe */
4452 total
; /* Total bytes from pipe */
4453 char buffer
[2048]; /* Copy buffer */
4454 int i
; /* Looping var */
4455 char option
[PPD_MAX_NAME
], /* Option name */
4456 choice
[PPD_MAX_NAME
]; /* Choice name */
4457 ppd_size_t
*size
; /* Default size */
4458 int num_defaults
; /* Number of default options */
4459 cups_option_t
*defaults
; /* Default options */
4460 char cups_protocol
[PPD_MAX_LINE
];
4461 /* cupsProtocol attribute */
4464 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_model(con=%p, from=\"%s\", to=\"%s\")", con
, from
, to
);
4467 * Run cups-driverd to get the PPD file...
4470 argv
[0] = "cups-driverd";
4472 argv
[2] = (char *)from
;
4475 cupsdLoadEnv(envp
, (int)(sizeof(envp
) / sizeof(envp
[0])));
4477 snprintf(buffer
, sizeof(buffer
), "%s/daemon/cups-driverd", ServerBin
);
4478 snprintf(tempfile
, sizeof(tempfile
), "%s/%d.ppd", TempDir
, con
->number
);
4479 tempfd
= open(tempfile
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
4480 if (tempfd
< 0 || cupsdOpenPipe(temppipe
))
4483 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4484 "copy_model: Running \"cups-driverd cat %s\"...", from
);
4486 if (!cupsdStartProcess(buffer
, argv
, envp
, -1, temppipe
[1], CGIPipes
[1],
4487 -1, -1, 0, DefaultProfile
, NULL
, &temppid
))
4498 * Wait up to 30 seconds for the PPD file to be copied...
4503 if (temppipe
[0] > CGIPipes
[0])
4504 maxfd
= temppipe
[0] + 1;
4506 maxfd
= CGIPipes
[0] + 1;
4511 * See if we have data ready...
4515 FD_SET(temppipe
[0], &input
);
4516 FD_SET(CGIPipes
[0], &input
);
4518 timeout
.tv_sec
= 30;
4519 timeout
.tv_usec
= 0;
4521 if ((i
= select(maxfd
, &input
, NULL
, NULL
, &timeout
)) < 0)
4531 * We have timed out...
4537 if (FD_ISSET(temppipe
[0], &input
))
4540 * Read the PPD file from the pipe, and write it to the PPD file.
4543 if ((bytes
= read(temppipe
[0], buffer
, sizeof(buffer
))) > 0)
4545 if (write(tempfd
, buffer
, (size_t)bytes
) < bytes
)
4554 if (FD_ISSET(CGIPipes
[0], &input
))
4564 * No data from cups-deviced...
4567 cupsdLogMessage(CUPSD_LOG_ERROR
, "copy_model: empty PPD file");
4573 * Open the source file for a copy...
4576 if ((src
= cupsFileOpen(tempfile
, "rb")) == NULL
)
4583 * Read the source file and see what page sizes are supported...
4586 if ((ppd
= _ppdOpen(src
, _PPD_LOCALIZATION_NONE
)) == NULL
)
4594 * Open the destination (if possible) and set the default options...
4599 cups_protocol
[0] = '\0';
4601 if ((dst
= cupsFileOpen(to
, "rb")) != NULL
)
4604 * Read all of the default lines from the old PPD...
4607 while (cupsFileGets(dst
, buffer
, sizeof(buffer
)))
4608 if (!strncmp(buffer
, "*Default", 8))
4611 * Add the default option...
4614 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
4615 choice
, sizeof(choice
)))
4617 ppd_option_t
*ppdo
; /* PPD option */
4621 * Only add the default if the default hasn't already been
4622 * set and the choice exists in the new PPD...
4625 if (!cupsGetOption(option
, num_defaults
, defaults
) &&
4626 (ppdo
= ppdFindOption(ppd
, option
)) != NULL
&&
4627 ppdFindChoice(ppdo
, choice
))
4628 num_defaults
= cupsAddOption(option
, choice
, num_defaults
,
4632 else if (!strncmp(buffer
, "*cupsProtocol:", 14))
4633 strlcpy(cups_protocol
, buffer
, sizeof(cups_protocol
));
4637 else if ((size
= ppdPageSize(ppd
, DefaultPaperSize
)) != NULL
)
4640 * Add the default media sizes...
4643 num_defaults
= cupsAddOption("PageSize", size
->name
,
4644 num_defaults
, &defaults
);
4645 num_defaults
= cupsAddOption("PageRegion", size
->name
,
4646 num_defaults
, &defaults
);
4647 num_defaults
= cupsAddOption("PaperDimension", size
->name
,
4648 num_defaults
, &defaults
);
4649 num_defaults
= cupsAddOption("ImageableArea", size
->name
,
4650 num_defaults
, &defaults
);
4656 * Open the destination file for a copy...
4659 if ((dst
= cupsdCreateConfFile(to
, ConfigFilePerm
)) == NULL
)
4661 cupsFreeOptions(num_defaults
, defaults
);
4668 * Copy the source file to the destination...
4671 cupsFileRewind(src
);
4673 while (cupsFileGets(src
, buffer
, sizeof(buffer
)))
4675 if (!strncmp(buffer
, "*Default", 8))
4678 * Check for an previous default option choice...
4681 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
4682 choice
, sizeof(choice
)))
4684 const char *val
; /* Default option value */
4687 if ((val
= cupsGetOption(option
, num_defaults
, defaults
)) != NULL
)
4690 * Substitute the previous choice...
4693 snprintf(buffer
, sizeof(buffer
), "*Default%s: %s", option
, val
);
4698 cupsFilePrintf(dst
, "%s\n", buffer
);
4701 if (cups_protocol
[0])
4702 cupsFilePrintf(dst
, "%s\n", cups_protocol
);
4704 cupsFreeOptions(num_defaults
, defaults
);
4707 * Close both files and return...
4714 return (cupsdCloseCreatedConfFile(dst
, to
));
4719 * 'copy_job_attrs()' - Copy job attributes.
4723 copy_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
4724 cupsd_job_t
*job
, /* I - Job */
4725 cups_array_t
*ra
, /* I - Requested attributes array */
4726 cups_array_t
*exclude
) /* I - Private attributes array */
4728 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
4732 * Send the requested attributes for each job...
4735 if (!cupsArrayFind(exclude
, "all"))
4737 if ((!exclude
|| !cupsArrayFind(exclude
, "number-of-documents")) &&
4738 (!ra
|| cupsArrayFind(ra
, "number-of-documents")))
4739 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4740 "number-of-documents", job
->num_files
);
4742 if ((!exclude
|| !cupsArrayFind(exclude
, "job-media-progress")) &&
4743 (!ra
|| cupsArrayFind(ra
, "job-media-progress")))
4744 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4745 "job-media-progress", job
->progress
);
4747 if ((!exclude
|| !cupsArrayFind(exclude
, "job-more-info")) &&
4748 (!ra
|| cupsArrayFind(ra
, "job-more-info")))
4750 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "http",
4751 NULL
, con
->clientname
, con
->clientport
, "/jobs/%d",
4753 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4754 "job-more-info", NULL
, job_uri
);
4757 if (job
->state_value
> IPP_JOB_PROCESSING
&&
4758 (!exclude
|| !cupsArrayFind(exclude
, "job-preserved")) &&
4759 (!ra
|| cupsArrayFind(ra
, "job-preserved")))
4760 ippAddBoolean(con
->response
, IPP_TAG_JOB
, "job-preserved",
4761 job
->num_files
> 0);
4763 if ((!exclude
|| !cupsArrayFind(exclude
, "job-printer-up-time")) &&
4764 (!ra
|| cupsArrayFind(ra
, "job-printer-up-time")))
4765 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4766 "job-printer-up-time", time(NULL
));
4769 if (!ra
|| cupsArrayFind(ra
, "job-printer-uri"))
4771 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
4772 con
->clientname
, con
->clientport
,
4773 (job
->dtype
& CUPS_PRINTER_CLASS
) ? "/classes/%s" :
4776 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4777 "job-printer-uri", NULL
, job_uri
);
4780 if (!ra
|| cupsArrayFind(ra
, "job-uri"))
4782 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
4783 con
->clientname
, con
->clientport
, "/jobs/%d",
4785 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4786 "job-uri", NULL
, job_uri
);
4791 copy_attrs(con
->response
, job
->attrs
, ra
, IPP_TAG_JOB
, 0, exclude
);
4796 * Generate attributes from the job structure...
4799 if (job
->completed_time
&& (!ra
|| cupsArrayFind(ra
, "date-time-at-completed")))
4800 ippAddDate(con
->response
, IPP_TAG_JOB
, "date-time-at-completed", ippTimeToDate(job
->completed_time
));
4802 if (job
->creation_time
&& (!ra
|| cupsArrayFind(ra
, "date-time-at-creation")))
4803 ippAddDate(con
->response
, IPP_TAG_JOB
, "date-time-at-creation", ippTimeToDate(job
->creation_time
));
4805 if (!ra
|| cupsArrayFind(ra
, "job-id"))
4806 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
4808 if (!ra
|| cupsArrayFind(ra
, "job-k-octets"))
4809 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-k-octets", job
->koctets
);
4811 if (job
->name
&& (!ra
|| cupsArrayFind(ra
, "job-name")))
4812 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_CONST_TAG(IPP_TAG_NAME
), "job-name", NULL
, job
->name
);
4814 if (job
->username
&& (!ra
|| cupsArrayFind(ra
, "job-originating-user-name")))
4815 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_CONST_TAG(IPP_TAG_NAME
), "job-originating-user-name", NULL
, job
->username
);
4817 if (!ra
|| cupsArrayFind(ra
, "job-state"))
4818 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state", (int)job
->state_value
);
4820 if (!ra
|| cupsArrayFind(ra
, "job-state-reasons"))
4822 switch (job
->state_value
)
4824 default : /* Should never get here for processing, pending, held, or stopped jobs since they don't get unloaded... */
4826 case IPP_JSTATE_ABORTED
:
4827 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons", NULL
, "job-aborted-by-system");
4829 case IPP_JSTATE_CANCELED
:
4830 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons", NULL
, "job-canceled-by-user");
4832 case IPP_JSTATE_COMPLETED
:
4833 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons", NULL
, "job-completed-successfully");
4838 if (job
->completed_time
&& (!ra
|| cupsArrayFind(ra
, "time-at-completed")))
4839 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-completed", (int)job
->completed_time
);
4841 if (job
->creation_time
&& (!ra
|| cupsArrayFind(ra
, "time-at-creation")))
4842 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation", (int)job
->creation_time
);
4848 * 'copy_printer_attrs()' - Copy printer attributes.
4853 cupsd_client_t
*con
, /* I - Client connection */
4854 cupsd_printer_t
*printer
, /* I - Printer */
4855 cups_array_t
*ra
) /* I - Requested attributes array */
4857 char printer_uri
[HTTP_MAX_URI
];
4859 char printer_icons
[HTTP_MAX_URI
];
4861 time_t curtime
; /* Current time */
4862 int i
; /* Looping var */
4866 * Copy the printer attributes to the response using requested-attributes
4867 * and document-format attributes that may be provided by the client.
4870 _cupsRWLockRead(&printer
->lock
);
4872 curtime
= time(NULL
);
4874 if (!ra
|| cupsArrayFind(ra
, "marker-change-time"))
4875 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4876 "marker-change-time", printer
->marker_time
);
4878 if (printer
->num_printers
> 0 &&
4879 (!ra
|| cupsArrayFind(ra
, "member-uris")))
4881 ipp_attribute_t
*member_uris
; /* member-uris attribute */
4882 cupsd_printer_t
*p2
; /* Printer in class */
4883 ipp_attribute_t
*p2_uri
; /* printer-uri-supported for class printer */
4886 if ((member_uris
= ippAddStrings(con
->response
, IPP_TAG_PRINTER
,
4887 IPP_TAG_URI
, "member-uris",
4888 printer
->num_printers
, NULL
,
4891 for (i
= 0; i
< printer
->num_printers
; i
++)
4893 p2
= printer
->printers
[i
];
4895 if ((p2_uri
= ippFindAttribute(p2
->attrs
, "printer-uri-supported",
4896 IPP_TAG_URI
)) != NULL
)
4897 member_uris
->values
[i
].string
.text
=
4898 _cupsStrRetain(p2_uri
->values
[0].string
.text
);
4901 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
,
4902 sizeof(printer_uri
), "ipp", NULL
, con
->clientname
,
4904 (p2
->type
& CUPS_PRINTER_CLASS
) ?
4905 "/classes/%s" : "/printers/%s", p2
->name
);
4906 member_uris
->values
[i
].string
.text
= _cupsStrAlloc(printer_uri
);
4912 if (printer
->alert
&& (!ra
|| cupsArrayFind(ra
, "printer-alert")))
4913 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_STRING
,
4914 "printer-alert", NULL
, printer
->alert
);
4916 if (printer
->alert_description
&&
4917 (!ra
|| cupsArrayFind(ra
, "printer-alert-description")))
4918 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4919 "printer-alert-description", NULL
,
4920 printer
->alert_description
);
4922 if (!ra
|| cupsArrayFind(ra
, "printer-config-change-date-time"))
4923 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-config-change-date-time", ippTimeToDate(printer
->config_time
));
4925 if (!ra
|| cupsArrayFind(ra
, "printer-config-change-time"))
4926 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4927 "printer-config-change-time", printer
->config_time
);
4929 if (!ra
|| cupsArrayFind(ra
, "printer-current-time"))
4930 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-current-time",
4931 ippTimeToDate(curtime
));
4933 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
4934 if (!ra
|| cupsArrayFind(ra
, "printer-dns-sd-name"))
4936 if (printer
->reg_name
)
4937 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4938 "printer-dns-sd-name", NULL
, printer
->reg_name
);
4940 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
4941 "printer-dns-sd-name", 0);
4943 #endif /* HAVE_DNSSD || HAVE_AVAHI */
4945 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy"))
4946 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4947 "printer-error-policy", NULL
, printer
->error_policy
);
4949 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy-supported"))
4951 static const char * const errors
[] =/* printer-error-policy-supported values */
4954 "retry-current-job",
4959 if (printer
->type
& CUPS_PRINTER_CLASS
)
4960 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
4961 "printer-error-policy-supported", NULL
, "retry-current-job");
4963 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
4964 "printer-error-policy-supported",
4965 sizeof(errors
) / sizeof(errors
[0]), NULL
, errors
);
4968 if (!ra
|| cupsArrayFind(ra
, "printer-icons"))
4970 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_icons
, sizeof(printer_icons
),
4971 "http", NULL
, con
->clientname
, con
->clientport
,
4972 "/icons/%s.png", printer
->name
);
4973 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-icons",
4974 NULL
, printer_icons
);
4975 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-icons=\"%s\"", printer_icons
);
4978 if (!ra
|| cupsArrayFind(ra
, "printer-is-accepting-jobs"))
4979 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs", (char)printer
->accepting
);
4981 if (!ra
|| cupsArrayFind(ra
, "printer-is-shared"))
4982 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-shared", (char)printer
->shared
);
4984 if (!ra
|| cupsArrayFind(ra
, "printer-is-temporary"))
4985 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-temporary", (char)printer
->temporary
);
4987 if (!ra
|| cupsArrayFind(ra
, "printer-more-info"))
4989 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
4990 "http", NULL
, con
->clientname
, con
->clientport
,
4991 (printer
->type
& CUPS_PRINTER_CLASS
) ?
4992 "/classes/%s" : "/printers/%s", printer
->name
);
4993 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
4994 "printer-more-info", NULL
, printer_uri
);
4997 if (!ra
|| cupsArrayFind(ra
, "printer-op-policy"))
4998 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4999 "printer-op-policy", NULL
, printer
->op_policy
);
5001 if (!ra
|| cupsArrayFind(ra
, "printer-state"))
5002 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
5005 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-date-time"))
5006 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-state-change-date-time", ippTimeToDate(printer
->state_time
));
5008 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-time"))
5009 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5010 "printer-state-change-time", printer
->state_time
);
5012 if (!ra
|| cupsArrayFind(ra
, "printer-state-message"))
5013 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5014 "printer-state-message", NULL
, printer
->state_message
);
5016 if (!ra
|| cupsArrayFind(ra
, "printer-state-reasons"))
5017 add_printer_state_reasons(con
, printer
);
5019 if (!ra
|| cupsArrayFind(ra
, "printer-type"))
5021 cups_ptype_t type
; /* printer-type value */
5024 * Add the CUPS-specific printer-type attribute...
5027 type
= printer
->type
;
5029 if (printer
== DefaultPrinter
)
5030 type
|= CUPS_PRINTER_DEFAULT
;
5032 if (!printer
->accepting
)
5033 type
|= CUPS_PRINTER_REJECTING
;
5035 if (!printer
->shared
)
5036 type
|= CUPS_PRINTER_NOT_SHARED
;
5038 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-type", (int)type
);
5041 if (!ra
|| cupsArrayFind(ra
, "printer-up-time"))
5042 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5043 "printer-up-time", curtime
);
5045 if (!ra
|| cupsArrayFind(ra
, "printer-uri-supported"))
5047 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5048 "ipp", NULL
, con
->clientname
, con
->clientport
,
5049 (printer
->type
& CUPS_PRINTER_CLASS
) ?
5050 "/classes/%s" : "/printers/%s", printer
->name
);
5051 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5052 "printer-uri-supported", NULL
, printer_uri
);
5053 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-uri-supported=\"%s\"",
5057 if (!ra
|| cupsArrayFind(ra
, "queued-job-count"))
5058 add_queued_job_count(con
, printer
);
5060 copy_attrs(con
->response
, printer
->attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
5061 if (printer
->ppd_attrs
)
5062 copy_attrs(con
->response
, printer
->ppd_attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
5063 copy_attrs(con
->response
, CommonData
, ra
, IPP_TAG_ZERO
, IPP_TAG_COPY
, NULL
);
5065 _cupsRWUnlock(&printer
->lock
);
5070 * 'copy_subscription_attrs()' - Copy subscription attributes.
5074 copy_subscription_attrs(
5075 cupsd_client_t
*con
, /* I - Client connection */
5076 cupsd_subscription_t
*sub
, /* I - Subscription */
5077 cups_array_t
*ra
, /* I - Requested attributes array */
5078 cups_array_t
*exclude
) /* I - Private attributes array */
5080 ipp_attribute_t
*attr
; /* Current attribute */
5081 char printer_uri
[HTTP_MAX_URI
];
5083 int count
; /* Number of events */
5084 unsigned mask
; /* Current event mask */
5085 const char *name
; /* Current event name */
5088 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5089 "copy_subscription_attrs(con=%p, sub=%p, ra=%p, exclude=%p)",
5090 con
, sub
, ra
, exclude
);
5093 * Copy the subscription attributes to the response using the
5094 * requested-attributes attribute that may be provided by the client.
5097 if (!exclude
|| !cupsArrayFind(exclude
, "all"))
5099 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-events")) &&
5100 (!ra
|| cupsArrayFind(ra
, "notify-events")))
5102 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_subscription_attrs: notify-events");
5104 if ((name
= cupsdEventName((cupsd_eventmask_t
)sub
->mask
)) != NULL
)
5107 * Simple event list...
5110 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
,
5111 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5112 "notify-events", NULL
, name
);
5117 * Complex event list...
5120 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5121 if (sub
->mask
& mask
)
5124 attr
= ippAddStrings(con
->response
, IPP_TAG_SUBSCRIPTION
,
5125 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5126 "notify-events", count
, NULL
, NULL
);
5128 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5129 if (sub
->mask
& mask
)
5131 attr
->values
[count
].string
.text
=
5132 (char *)cupsdEventName((cupsd_eventmask_t
)mask
);
5139 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-lease-duration")) &&
5140 (!sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-lease-duration"))))
5141 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5142 "notify-lease-duration", sub
->lease
);
5144 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-recipient-uri")) &&
5145 (sub
->recipient
&& (!ra
|| cupsArrayFind(ra
, "notify-recipient-uri"))))
5146 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5147 "notify-recipient-uri", NULL
, sub
->recipient
);
5148 else if ((!exclude
|| !cupsArrayFind(exclude
, "notify-pull-method")) &&
5149 (!ra
|| cupsArrayFind(ra
, "notify-pull-method")))
5150 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_KEYWORD
,
5151 "notify-pull-method", NULL
, "ippget");
5153 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-subscriber-user-name")) &&
5154 (!ra
|| cupsArrayFind(ra
, "notify-subscriber-user-name")))
5155 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_NAME
,
5156 "notify-subscriber-user-name", NULL
, sub
->owner
);
5158 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-time-interval")) &&
5159 (!ra
|| cupsArrayFind(ra
, "notify-time-interval")))
5160 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5161 "notify-time-interval", sub
->interval
);
5163 if (sub
->user_data_len
> 0 &&
5164 (!exclude
|| !cupsArrayFind(exclude
, "notify-user-data")) &&
5165 (!ra
|| cupsArrayFind(ra
, "notify-user-data")))
5166 ippAddOctetString(con
->response
, IPP_TAG_SUBSCRIPTION
, "notify-user-data",
5167 sub
->user_data
, sub
->user_data_len
);
5170 if (sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-job-id")))
5171 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5172 "notify-job-id", sub
->job
->id
);
5174 if (sub
->dest
&& (!ra
|| cupsArrayFind(ra
, "notify-printer-uri")))
5176 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5177 "ipp", NULL
, con
->clientname
, con
->clientport
,
5178 "/printers/%s", sub
->dest
->name
);
5179 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5180 "notify-printer-uri", NULL
, printer_uri
);
5183 if (!ra
|| cupsArrayFind(ra
, "notify-subscription-id"))
5184 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5185 "notify-subscription-id", sub
->id
);
5190 * 'create_job()' - Print a file to a printer or class.
5194 create_job(cupsd_client_t
*con
, /* I - Client connection */
5195 ipp_attribute_t
*uri
) /* I - Printer URI */
5197 int i
; /* Looping var */
5198 cupsd_printer_t
*printer
; /* Printer */
5199 cupsd_job_t
*job
; /* New job */
5200 static const char * const forbidden_attrs
[] =
5201 { /* List of forbidden attributes */
5205 "document-natural-language"
5209 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "create_job(%p[%d], %s)", con
,
5210 con
->number
, uri
->values
[0].string
.text
);
5213 * Is the destination valid?
5216 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
5222 send_ipp_status(con
, IPP_NOT_FOUND
,
5223 _("The printer or class does not exist."));
5228 * Check for invalid Create-Job attributes and log a warning or error depending
5229 * on whether cupsd is running in "strict conformance" mode...
5233 i
< (int)(sizeof(forbidden_attrs
) / sizeof(forbidden_attrs
[0]));
5235 if (ippFindAttribute(con
->request
, forbidden_attrs
[i
], IPP_TAG_ZERO
))
5237 if (StrictConformance
)
5239 send_ipp_status(con
, IPP_BAD_REQUEST
,
5240 _("The '%s' operation attribute cannot be supplied in a "
5241 "Create-Job request."), forbidden_attrs
[i
]);
5245 cupsdLogMessage(CUPSD_LOG_WARN
,
5246 "Unexpected '%s' operation attribute in a Create-Job "
5247 "request.", forbidden_attrs
[i
]);
5251 * Create the job object...
5254 if ((job
= add_job(con
, printer
, NULL
)) == NULL
)
5257 job
->pending_timeout
= 1;
5260 * Save and log the job...
5263 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
5264 job
->dest
, job
->username
);
5269 * 'create_local_bg_thread()' - Background thread for creating a local print queue.
5272 static void * /* O - Exit status */
5273 create_local_bg_thread(
5274 cupsd_printer_t
*printer
) /* I - Printer */
5276 cups_file_t
*from
, /* Source file */
5277 *to
; /* Destination file */
5278 char fromppd
[1024], /* Source PPD */
5279 toppd
[1024], /* Destination PPD */
5280 scheme
[32], /* URI scheme */
5281 userpass
[256], /* User:pass */
5282 host
[256], /* Hostname */
5283 resource
[1024], /* Resource path */
5284 line
[1024]; /* Line from PPD */
5285 int port
; /* Port number */
5286 http_encryption_t encryption
; /* Type of encryption to use */
5287 http_t
*http
; /* Connection to printer */
5288 ipp_t
*request
, /* Request to printer */
5289 *response
; /* Response from printer */
5290 ipp_attribute_t
*attr
; /* Attribute in response */
5291 ipp_status_t status
; /* Status code */
5295 * Try connecting to the printer...
5298 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s: Generating PPD file from \"%s\"...", printer
->name
, printer
->device_uri
);
5300 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
)
5302 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: Bad device URI \"%s\".", printer
->name
, printer
->device_uri
);
5306 if (!strcmp(scheme
, "ipps") || port
== 443)
5307 encryption
= HTTP_ENCRYPTION_ALWAYS
;
5309 encryption
= HTTP_ENCRYPTION_IF_REQUESTED
;
5311 if ((http
= httpConnect2(host
, port
, NULL
, AF_UNSPEC
, encryption
, 1, 30000, NULL
)) == NULL
)
5313 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: Unable to connect to %s:%d: %s", printer
->name
, host
, port
, cupsLastErrorString());
5318 * Query the printer for its capabilities...
5321 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s: Connected to %s:%d, sending Get-Printer-Attributes request...", printer
->name
, host
, port
);
5323 request
= ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES
);
5324 ippSetVersion(request
, 2, 0);
5325 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
, printer
->device_uri
);
5326 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
, "requested-attributes", NULL
, "all");
5328 response
= cupsDoRequest(http
, request
, resource
);
5329 status
= cupsLastError();
5331 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s: Get-Printer-Attributes returned %s (%s)", printer
->name
, ippErrorString(cupsLastError()), cupsLastErrorString());
5333 if (status
== IPP_STATUS_ERROR_BAD_REQUEST
|| status
== IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED
)
5336 * Try request using IPP/1.1, in case we are talking to an old CUPS server or
5340 ippDelete(response
);
5342 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s: Re-sending Get-Printer-Attributes request using IPP/1.1...", printer
->name
);
5344 request
= ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES
);
5345 ippSetVersion(request
, 1, 1);
5346 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
, printer
->device_uri
);
5347 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
, "requested-attributes", NULL
, "all");
5349 response
= cupsDoRequest(http
, request
, resource
);
5351 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s: IPP/1.1 Get-Printer-Attributes returned %s (%s)", printer
->name
, ippErrorString(cupsLastError()), cupsLastErrorString());
5354 // TODO: Grab printer icon file...
5358 * Write the PPD for the queue...
5361 if (_ppdCreateFromIPP(fromppd
, sizeof(fromppd
), response
))
5363 if ((!printer
->info
|| !*(printer
->info
)) && (attr
= ippFindAttribute(response
, "printer-info", IPP_TAG_TEXT
)) != NULL
)
5364 cupsdSetString(&printer
->info
, ippGetString(attr
, 0, NULL
));
5366 if ((!printer
->location
|| !*(printer
->location
)) && (attr
= ippFindAttribute(response
, "printer-location", IPP_TAG_TEXT
)) != NULL
)
5367 cupsdSetString(&printer
->location
, ippGetString(attr
, 0, NULL
));
5369 if ((!printer
->geo_location
|| !*(printer
->geo_location
)) && (attr
= ippFindAttribute(response
, "printer-geo-location", IPP_TAG_URI
)) != NULL
)
5370 cupsdSetString(&printer
->geo_location
, ippGetString(attr
, 0, NULL
));
5372 if ((from
= cupsFileOpen(fromppd
, "r")) == NULL
)
5374 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: Unable to read generated PPD: %s", printer
->name
, strerror(errno
));
5378 snprintf(toppd
, sizeof(toppd
), "%s/ppd/%s.ppd", ServerRoot
, printer
->name
);
5379 if ((to
= cupsdCreateConfFile(toppd
, ConfigFilePerm
)) == NULL
)
5381 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: Unable to create PPD for printer: %s", printer
->name
, strerror(errno
));
5382 cupsFileClose(from
);
5386 while (cupsFileGets(from
, line
, sizeof(line
)))
5387 cupsFilePrintf(to
, "%s\n", line
);
5389 cupsFileClose(from
);
5390 if (!cupsdCloseCreatedConfFile(to
, toppd
))
5392 printer
->config_time
= time(NULL
);
5393 printer
->state
= IPP_PSTATE_IDLE
;
5394 printer
->accepting
= 1;
5396 cupsdSetPrinterAttrs(printer
);
5398 cupsdAddEvent(CUPSD_EVENT_PRINTER_CONFIG
, printer
, NULL
, "Printer \"%s\" is now available.", printer
->name
);
5399 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" is now available.", printer
->name
);
5403 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: PPD creation failed: %s", printer
->name
, cupsLastErrorString());
5410 * 'create_local_printer()' - Create a local (temporary) print queue.
5414 create_local_printer(
5415 cupsd_client_t
*con
) /* I - Client connection */
5417 ipp_attribute_t
*device_uri
, /* device-uri attribute */
5418 *printer_geo_location
, /* printer-geo-location attribute */
5419 *printer_info
, /* printer-info attribute */
5420 *printer_location
, /* printer-location attribute */
5421 *printer_name
; /* printer-name attribute */
5422 cupsd_printer_t
*printer
; /* New printer */
5423 http_status_t status
; /* Policy status */
5424 char name
[128], /* Sanitized printer name */
5425 *nameptr
, /* Pointer into name */
5426 uri
[1024]; /* printer-uri-supported value */
5427 const char *ptr
; /* Pointer into attribute value */
5431 * Require local access to create a local printer...
5434 if (!httpAddrLocalhost(httpGetAddress(con
->http
)))
5436 send_ipp_status(con
, IPP_STATUS_ERROR_FORBIDDEN
, _("Only local users can create a local printer."));
5441 * Check any other policy limits...
5444 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5446 send_http_error(con
, status
, NULL
);
5451 * Grab needed attributes...
5454 if ((printer_name
= ippFindAttribute(con
->request
, "printer-name", IPP_TAG_ZERO
)) == NULL
|| ippGetGroupTag(printer_name
) != IPP_TAG_PRINTER
|| ippGetValueTag(printer_name
) != IPP_TAG_NAME
)
5457 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Missing required attribute \"%s\"."), "printer-name");
5458 else if (ippGetGroupTag(printer_name
) != IPP_TAG_PRINTER
)
5459 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Attribute \"%s\" is in the wrong group."), "printer-name");
5461 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Attribute \"%s\" is the wrong value type."), "printer-name");
5466 for (nameptr
= name
, ptr
= ippGetString(printer_name
, 0, NULL
); *ptr
&& nameptr
< (name
+ sizeof(name
) - 1); ptr
++)
5469 * Sanitize the printer name...
5472 if (_cups_isalnum(*ptr
))
5474 else if (nameptr
== name
|| nameptr
[-1] != '_')
5480 if ((device_uri
= ippFindAttribute(con
->request
, "device-uri", IPP_TAG_ZERO
)) == NULL
|| ippGetGroupTag(device_uri
) != IPP_TAG_PRINTER
|| ippGetValueTag(device_uri
) != IPP_TAG_URI
)
5483 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Missing required attribute \"%s\"."), "device-uri");
5484 else if (ippGetGroupTag(device_uri
) != IPP_TAG_PRINTER
)
5485 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Attribute \"%s\" is in the wrong group."), "device-uri");
5487 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Attribute \"%s\" is the wrong value type."), "device-uri");
5492 printer_geo_location
= ippFindAttribute(con
->request
, "printer-geo-location", IPP_TAG_URI
);
5493 printer_info
= ippFindAttribute(con
->request
, "printer-info", IPP_TAG_TEXT
);
5494 printer_location
= ippFindAttribute(con
->request
, "printer-location", IPP_TAG_TEXT
);
5497 * See if the printer already exists...
5500 if ((printer
= cupsdFindDest(name
)) != NULL
)
5502 send_ipp_status(con
, IPP_STATUS_ERROR_NOT_POSSIBLE
, _("Printer \"%s\" already exists."), name
);
5503 goto add_printer_attributes
;
5507 * Create the printer...
5510 if ((printer
= cupsdAddPrinter(name
)) == NULL
)
5512 send_ipp_status(con
, IPP_STATUS_ERROR_INTERNAL
, _("Unable to create printer."));
5516 printer
->shared
= 0;
5517 printer
->temporary
= 1;
5519 cupsdSetDeviceURI(printer
, ippGetString(device_uri
, 0, NULL
));
5521 if (printer_geo_location
)
5522 cupsdSetString(&printer
->geo_location
, ippGetString(printer_geo_location
, 0, NULL
));
5524 cupsdSetString(&printer
->info
, ippGetString(printer_info
, 0, NULL
));
5525 if (printer_location
)
5526 cupsdSetString(&printer
->location
, ippGetString(printer_location
, 0, NULL
));
5528 cupsdSetPrinterAttrs(printer
);
5531 * Run a background thread to create the PPD...
5534 _cupsThreadCreate((_cups_thread_func_t
)create_local_bg_thread
, printer
);
5537 * Return printer attributes...
5540 send_ipp_status(con
, IPP_STATUS_OK
, _("Local printer created."));
5542 add_printer_attributes
:
5544 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs", (char)printer
->accepting
);
5545 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state", printer
->state
);
5546 add_printer_state_reasons(con
, printer
);
5548 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), httpIsEncrypted(con
->http
) ? "ipps" : "ipp", NULL
, con
->clientname
, con
->clientport
, "/printers/%s", printer
->name
);
5549 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-uri-supported", NULL
, uri
);
5554 * 'create_requested_array()' - Create an array for the requested-attributes.
5557 static cups_array_t
* /* O - Array of attributes or NULL */
5558 create_requested_array(ipp_t
*request
) /* I - IPP request */
5560 cups_array_t
*ra
; /* Requested attributes array */
5564 * Create the array for standard attributes...
5567 ra
= ippCreateRequestedArray(request
);
5570 * Add CUPS defaults as needed...
5573 if (cupsArrayFind(ra
, "printer-defaults"))
5576 * Include user-set defaults...
5579 char *name
; /* Option name */
5581 cupsArrayRemove(ra
, "printer-defaults");
5583 for (name
= (char *)cupsArrayFirst(CommonDefaults
);
5585 name
= (char *)cupsArrayNext(CommonDefaults
))
5586 if (!cupsArrayFind(ra
, name
))
5587 cupsArrayAdd(ra
, name
);
5595 * 'create_subscriptions()' - Create one or more notification subscriptions.
5599 create_subscriptions(
5600 cupsd_client_t
*con
, /* I - Client connection */
5601 ipp_attribute_t
*uri
) /* I - Printer URI */
5603 http_status_t status
; /* Policy status */
5604 int i
; /* Looping var */
5605 ipp_attribute_t
*attr
; /* Current attribute */
5606 cups_ptype_t dtype
; /* Destination type (printer/class) */
5607 char scheme
[HTTP_MAX_URI
],
5608 /* Scheme portion of URI */
5609 userpass
[HTTP_MAX_URI
],
5610 /* Username portion of URI */
5612 /* Host portion of URI */
5613 resource
[HTTP_MAX_URI
];
5614 /* Resource portion of URI */
5615 int port
; /* Port portion of URI */
5616 cupsd_printer_t
*printer
; /* Printer/class */
5617 cupsd_job_t
*job
; /* Job */
5618 int jobid
; /* Job ID */
5619 cupsd_subscription_t
*sub
; /* Subscription object */
5620 const char *username
, /* requesting-user-name or
5621 authenticated username */
5622 *recipient
, /* notify-recipient-uri */
5623 *pullmethod
; /* notify-pull-method */
5624 ipp_attribute_t
*user_data
; /* notify-user-data */
5625 int interval
, /* notify-time-interval */
5626 lease
; /* notify-lease-duration */
5627 unsigned mask
; /* notify-events */
5628 ipp_attribute_t
*notify_events
,/* notify-events(-default) */
5629 *notify_lease
; /* notify-lease-duration(-default) */
5633 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
5635 if (attr
->group_tag
!= IPP_TAG_ZERO
)
5636 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "g%04x v%04x %s", attr
->group_tag
,
5637 attr
->value_tag
, attr
->name
);
5639 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "----SEP----");
5644 * Is the destination valid?
5647 cupsdLogMessage(CUPSD_LOG_DEBUG
, "create_subscriptions(con=%p(%d), uri=\"%s\")", con
, con
->number
, uri
->values
[0].string
.text
);
5649 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
5650 sizeof(scheme
), userpass
, sizeof(userpass
), host
,
5651 sizeof(host
), &port
, resource
, sizeof(resource
));
5653 if (!strcmp(resource
, "/"))
5655 dtype
= (cups_ptype_t
)0;
5658 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
5660 dtype
= (cups_ptype_t
)0;
5663 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
5665 dtype
= CUPS_PRINTER_CLASS
;
5668 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
5674 send_ipp_status(con
, IPP_NOT_FOUND
,
5675 _("The printer or class does not exist."));
5685 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
5688 send_http_error(con
, status
, printer
);
5692 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5694 send_http_error(con
, status
, NULL
);
5699 * Get the user that is requesting the subscription...
5702 username
= get_username(con
);
5705 * Find the first subscription group attribute; return if we have
5709 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
5710 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
5715 send_ipp_status(con
, IPP_BAD_REQUEST
,
5716 _("No subscription attributes in request."));
5721 * Process the subscription attributes in the request...
5724 con
->response
->request
.status
.status_code
= IPP_BAD_REQUEST
;
5732 lease
= DefaultLeaseDuration
;
5734 mask
= CUPSD_EVENT_NONE
;
5738 notify_events
= ippFindAttribute(printer
->attrs
, "notify-events-default",
5740 notify_lease
= ippFindAttribute(printer
->attrs
,
5741 "notify-lease-duration-default",
5745 lease
= notify_lease
->values
[0].integer
;
5749 notify_events
= NULL
;
5750 notify_lease
= NULL
;
5753 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
5755 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
5756 attr
->value_tag
== IPP_TAG_URI
)
5759 * Validate the recipient scheme against the ServerBin/notifier
5763 char notifier
[1024]; /* Notifier filename */
5766 recipient
= attr
->values
[0].string
.text
;
5768 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
5769 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
5770 host
, sizeof(host
), &port
,
5771 resource
, sizeof(resource
)) < HTTP_URI_OK
)
5773 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5774 _("Bad notify-recipient-uri \"%s\"."), recipient
);
5775 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5776 "notify-status-code", IPP_URI_SCHEME
);
5780 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
5782 if (access(notifier
, X_OK
))
5784 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5785 _("notify-recipient-uri URI \"%s\" uses unknown "
5786 "scheme."), recipient
);
5787 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5788 "notify-status-code", IPP_URI_SCHEME
);
5792 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
5794 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5795 _("notify-recipient-uri URI \"%s\" is already used."),
5797 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5798 "notify-status-code", IPP_ATTRIBUTES
);
5802 else if (!strcmp(attr
->name
, "notify-pull-method") &&
5803 attr
->value_tag
== IPP_TAG_KEYWORD
)
5805 pullmethod
= attr
->values
[0].string
.text
;
5807 if (strcmp(pullmethod
, "ippget"))
5809 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5810 _("Bad notify-pull-method \"%s\"."), pullmethod
);
5811 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5812 "notify-status-code", IPP_ATTRIBUTES
);
5816 else if (!strcmp(attr
->name
, "notify-charset") &&
5817 attr
->value_tag
== IPP_TAG_CHARSET
&&
5818 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
5819 strcmp(attr
->values
[0].string
.text
, "utf-8"))
5821 send_ipp_status(con
, IPP_CHARSET
,
5822 _("Character set \"%s\" not supported."),
5823 attr
->values
[0].string
.text
);
5826 else if (!strcmp(attr
->name
, "notify-natural-language") &&
5827 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
5828 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
5830 send_ipp_status(con
, IPP_CHARSET
,
5831 _("Language \"%s\" not supported."),
5832 attr
->values
[0].string
.text
);
5835 else if (!strcmp(attr
->name
, "notify-user-data") &&
5836 attr
->value_tag
== IPP_TAG_STRING
)
5838 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
5840 send_ipp_status(con
, IPP_REQUEST_VALUE
,
5841 _("The notify-user-data value is too large "
5842 "(%d > 63 octets)."),
5843 attr
->values
[0].unknown
.length
);
5849 else if (!strcmp(attr
->name
, "notify-events") &&
5850 attr
->value_tag
== IPP_TAG_KEYWORD
)
5851 notify_events
= attr
;
5852 else if (!strcmp(attr
->name
, "notify-lease-duration") &&
5853 attr
->value_tag
== IPP_TAG_INTEGER
)
5854 lease
= attr
->values
[0].integer
;
5855 else if (!strcmp(attr
->name
, "notify-time-interval") &&
5856 attr
->value_tag
== IPP_TAG_INTEGER
)
5857 interval
= attr
->values
[0].integer
;
5858 else if (!strcmp(attr
->name
, "notify-job-id") &&
5859 attr
->value_tag
== IPP_TAG_INTEGER
)
5860 jobid
= attr
->values
[0].integer
;
5867 for (i
= 0; i
< notify_events
->num_values
; i
++)
5868 mask
|= cupsdEventValue(notify_events
->values
[i
].string
.text
);
5872 cupsdLogMessage(CUPSD_LOG_DEBUG
, "recipient=\"%s\"", recipient
);
5874 cupsdLogMessage(CUPSD_LOG_DEBUG
, "pullmethod=\"%s\"", pullmethod
);
5875 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-lease-duration=%d", lease
);
5876 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-time-interval=%d", interval
);
5878 if (!recipient
&& !pullmethod
)
5881 if (mask
== CUPSD_EVENT_NONE
)
5884 mask
= CUPSD_EVENT_JOB_COMPLETED
;
5886 mask
= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
5889 send_ipp_status(con
, IPP_BAD_REQUEST
,
5890 _("notify-events not specified."));
5895 if (MaxLeaseDuration
&& (lease
== 0 || lease
> MaxLeaseDuration
))
5897 cupsdLogMessage(CUPSD_LOG_INFO
,
5898 "create_subscriptions: Limiting notify-lease-duration to "
5901 lease
= MaxLeaseDuration
;
5906 if ((job
= cupsdFindJob(jobid
)) == NULL
)
5908 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
5916 if ((sub
= cupsdAddSubscription(mask
, printer
, job
, recipient
, 0)) == NULL
)
5918 send_ipp_status(con
, IPP_TOO_MANY_SUBSCRIPTIONS
,
5919 _("There are too many subscriptions."));
5924 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription #%d for job %d.",
5927 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5928 "Added subscription #%d for printer \"%s\".",
5929 sub
->id
, printer
->name
);
5931 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription #%d for server.",
5934 sub
->interval
= interval
;
5936 sub
->expire
= lease
? time(NULL
) + lease
: 0;
5938 cupsdSetString(&sub
->owner
, username
);
5942 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
5943 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
5944 (size_t)sub
->user_data_len
);
5947 ippAddSeparator(con
->response
);
5948 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5949 "notify-subscription-id", sub
->id
);
5951 con
->response
->request
.status
.status_code
= IPP_OK
;
5957 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
5962 * 'delete_printer()' - Remove a printer or class from the system.
5966 delete_printer(cupsd_client_t
*con
, /* I - Client connection */
5967 ipp_attribute_t
*uri
) /* I - URI of printer or class */
5969 http_status_t status
; /* Policy status */
5970 cups_ptype_t dtype
; /* Destination type (printer/class) */
5971 cupsd_printer_t
*printer
; /* Printer/class */
5972 char filename
[1024]; /* Script/PPD filename */
5973 int temporary
; /* Temporary queue? */
5976 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "delete_printer(%p[%d], %s)", con
,
5977 con
->number
, uri
->values
[0].string
.text
);
5980 * Do we have a valid URI?
5983 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
5989 send_ipp_status(con
, IPP_NOT_FOUND
,
5990 _("The printer or class does not exist."));
5998 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6000 send_http_error(con
, status
, NULL
);
6005 * Remove old jobs...
6008 cupsdCancelJobs(printer
->name
, NULL
, 1);
6011 * Remove old subscriptions and send a "deleted printer" event...
6014 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED
, printer
, NULL
,
6015 "%s \"%s\" deleted by \"%s\".",
6016 (dtype
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
6017 printer
->name
, get_username(con
));
6019 cupsdExpireSubscriptions(printer
, NULL
);
6022 * Remove any old PPD or script files...
6025 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
6028 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd.O", ServerRoot
,
6032 snprintf(filename
, sizeof(filename
), "%s/%s.png", CacheDir
, printer
->name
);
6035 snprintf(filename
, sizeof(filename
), "%s/%s.data", CacheDir
, printer
->name
);
6039 * Unregister color profiles...
6042 cupsdUnregisterColor(printer
);
6044 temporary
= printer
->temporary
;
6046 if (dtype
& CUPS_PRINTER_CLASS
)
6048 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" deleted by \"%s\".",
6049 printer
->name
, get_username(con
));
6051 cupsdDeletePrinter(printer
, 0);
6053 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
6057 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" deleted by \"%s\".",
6058 printer
->name
, get_username(con
));
6060 if (cupsdDeletePrinter(printer
, 0) && !temporary
)
6061 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
6064 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
6068 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
6071 * Return with no errors...
6074 con
->response
->request
.status
.status_code
= IPP_OK
;
6079 * 'get_default()' - Get the default destination.
6083 get_default(cupsd_client_t
*con
) /* I - Client connection */
6085 http_status_t status
; /* Policy status */
6086 cups_array_t
*ra
; /* Requested attributes array */
6089 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_default(%p[%d])", con
, con
->number
);
6095 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6097 send_http_error(con
, status
, NULL
);
6103 ra
= create_requested_array(con
->request
);
6105 copy_printer_attrs(con
, DefaultPrinter
, ra
);
6107 cupsArrayDelete(ra
);
6109 con
->response
->request
.status
.status_code
= IPP_OK
;
6112 send_ipp_status(con
, IPP_NOT_FOUND
, _("No default printer."));
6117 * 'get_devices()' - Get the list of available devices on the local system.
6121 get_devices(cupsd_client_t
*con
) /* I - Client connection */
6123 http_status_t status
; /* Policy status */
6124 ipp_attribute_t
*limit
, /* limit attribute */
6125 *timeout
, /* timeout attribute */
6126 *requested
, /* requested-attributes attribute */
6127 *exclude
, /* exclude-schemes attribute */
6128 *include
; /* include-schemes attribute */
6129 char command
[1024], /* cups-deviced command */
6130 options
[2048], /* Options to pass to command */
6132 /* String for requested attributes */
6134 /* String for excluded schemes */
6136 /* String for included schemes */
6139 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_devices(%p[%d])", con
, con
->number
);
6145 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6147 send_http_error(con
, status
, NULL
);
6152 * Run cups-deviced command with the given options...
6155 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
6156 timeout
= ippFindAttribute(con
->request
, "timeout", IPP_TAG_INTEGER
);
6157 requested
= ippFindAttribute(con
->request
, "requested-attributes",
6159 exclude
= ippFindAttribute(con
->request
, "exclude-schemes", IPP_TAG_NAME
);
6160 include
= ippFindAttribute(con
->request
, "include-schemes", IPP_TAG_NAME
);
6163 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
6165 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
6168 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
6170 exclude_str
[0] = '\0';
6173 url_encode_attr(include
, include_str
, sizeof(include_str
));
6175 include_str
[0] = '\0';
6177 snprintf(command
, sizeof(command
), "%s/daemon/cups-deviced", ServerBin
);
6178 snprintf(options
, sizeof(options
),
6179 "%d+%d+%d+%d+%s%s%s%s%s",
6180 con
->request
->request
.op
.request_id
,
6181 limit
? limit
->values
[0].integer
: 0,
6182 timeout
? timeout
->values
[0].integer
: 15,
6185 exclude_str
[0] ? "%20" : "", exclude_str
,
6186 include_str
[0] ? "%20" : "", include_str
);
6188 if (cupsdSendCommand(con
, command
, options
, 1))
6191 * Command started successfully, don't send an IPP response here...
6194 ippDelete(con
->response
);
6195 con
->response
= NULL
;
6200 * Command failed, return "internal error" so the user knows something
6204 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
6205 _("cups-deviced failed to execute."));
6211 * 'get_document()' - Get a copy of a job file.
6215 get_document(cupsd_client_t
*con
, /* I - Client connection */
6216 ipp_attribute_t
*uri
) /* I - Job URI */
6218 http_status_t status
; /* Policy status */
6219 ipp_attribute_t
*attr
; /* Current attribute */
6220 int jobid
; /* Job ID */
6221 int docnum
; /* Document number */
6222 cupsd_job_t
*job
; /* Current job */
6223 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
6224 username
[HTTP_MAX_URI
], /* Username portion of URI */
6225 host
[HTTP_MAX_URI
], /* Host portion of URI */
6226 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6227 int port
; /* Port portion of URI */
6228 char filename
[1024], /* Filename for document */
6229 format
[1024]; /* Format for document */
6232 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_document(%p[%d], %s)", con
,
6233 con
->number
, uri
->values
[0].string
.text
);
6236 * See if we have a job URI or a printer URI...
6239 if (!strcmp(uri
->name
, "printer-uri"))
6242 * Got a printer URI; see if we also have a job-id attribute...
6245 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6246 IPP_TAG_INTEGER
)) == NULL
)
6248 send_ipp_status(con
, IPP_BAD_REQUEST
,
6249 _("Got a printer-uri attribute but no job-id."));
6253 jobid
= attr
->values
[0].integer
;
6258 * Got a job URI; parse it to get the job ID...
6261 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6262 sizeof(scheme
), username
, sizeof(username
), host
,
6263 sizeof(host
), &port
, resource
, sizeof(resource
));
6265 if (strncmp(resource
, "/jobs/", 6))
6271 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
6272 uri
->values
[0].string
.text
);
6276 jobid
= atoi(resource
+ 6);
6280 * See if the job exists...
6283 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6286 * Nope - return a "not found" error...
6289 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
6297 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
,
6298 job
->username
)) != HTTP_OK
)
6300 send_http_error(con
, status
, NULL
);
6305 * Get the document number...
6308 if ((attr
= ippFindAttribute(con
->request
, "document-number",
6309 IPP_TAG_INTEGER
)) == NULL
)
6311 send_ipp_status(con
, IPP_BAD_REQUEST
,
6312 _("Missing document-number attribute."));
6316 if ((docnum
= attr
->values
[0].integer
) < 1 || docnum
> job
->num_files
||
6317 attr
->num_values
> 1)
6319 send_ipp_status(con
, IPP_NOT_FOUND
,
6320 _("Document #%d does not exist in job #%d."), docnum
,
6325 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, jobid
,
6327 if ((con
->file
= open(filename
, O_RDONLY
)) == -1)
6329 cupsdLogMessage(CUPSD_LOG_ERROR
,
6330 "Unable to open document %d in job %d - %s", docnum
, jobid
,
6332 send_ipp_status(con
, IPP_NOT_FOUND
,
6333 _("Unable to open document #%d in job #%d."), docnum
,
6338 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
6342 snprintf(format
, sizeof(format
), "%s/%s", job
->filetypes
[docnum
- 1]->super
,
6343 job
->filetypes
[docnum
- 1]->type
);
6345 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format",
6347 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "document-number",
6349 if ((attr
= ippFindAttribute(job
->attrs
, "document-name",
6350 IPP_TAG_NAME
)) != NULL
)
6351 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name",
6352 NULL
, attr
->values
[0].string
.text
);
6357 * 'get_job_attrs()' - Get job attributes.
6361 get_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
6362 ipp_attribute_t
*uri
) /* I - Job URI */
6364 http_status_t status
; /* Policy status */
6365 ipp_attribute_t
*attr
; /* Current attribute */
6366 int jobid
; /* Job ID */
6367 cupsd_job_t
*job
; /* Current job */
6368 cupsd_printer_t
*printer
; /* Current printer */
6369 cupsd_policy_t
*policy
; /* Current security policy */
6370 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6371 username
[HTTP_MAX_URI
], /* Username portion of URI */
6372 host
[HTTP_MAX_URI
], /* Host portion of URI */
6373 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6374 int port
; /* Port portion of URI */
6375 cups_array_t
*ra
, /* Requested attributes array */
6376 *exclude
; /* Private attributes array */
6379 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_job_attrs(%p[%d], %s)", con
,
6380 con
->number
, uri
->values
[0].string
.text
);
6383 * See if we have a job URI or a printer URI...
6386 if (!strcmp(uri
->name
, "printer-uri"))
6389 * Got a printer URI; see if we also have a job-id attribute...
6392 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6393 IPP_TAG_INTEGER
)) == NULL
)
6395 send_ipp_status(con
, IPP_BAD_REQUEST
,
6396 _("Got a printer-uri attribute but no job-id."));
6400 jobid
= attr
->values
[0].integer
;
6405 * Got a job URI; parse it to get the job ID...
6408 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6409 sizeof(scheme
), username
, sizeof(username
), host
,
6410 sizeof(host
), &port
, resource
, sizeof(resource
));
6412 if (strncmp(resource
, "/jobs/", 6))
6418 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
6419 uri
->values
[0].string
.text
);
6423 jobid
= atoi(resource
+ 6);
6427 * See if the job exists...
6430 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6433 * Nope - return a "not found" error...
6436 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
6444 if ((printer
= job
->printer
) == NULL
)
6445 printer
= cupsdFindDest(job
->dest
);
6448 policy
= printer
->op_policy_ptr
;
6450 policy
= DefaultPolicyPtr
;
6452 if ((status
= cupsdCheckPolicy(policy
, con
, job
->username
)) != HTTP_OK
)
6454 send_http_error(con
, status
, NULL
);
6458 exclude
= cupsdGetPrivateAttrs(policy
, con
, printer
, job
->username
);
6461 * Copy attributes...
6466 ra
= create_requested_array(con
->request
);
6467 copy_job_attrs(con
, job
, ra
, exclude
);
6468 cupsArrayDelete(ra
);
6470 con
->response
->request
.status
.status_code
= IPP_OK
;
6475 * 'get_jobs()' - Get a list of jobs for the specified printer.
6479 get_jobs(cupsd_client_t
*con
, /* I - Client connection */
6480 ipp_attribute_t
*uri
) /* I - Printer URI */
6482 http_status_t status
; /* Policy status */
6483 ipp_attribute_t
*attr
; /* Current attribute */
6484 const char *dest
; /* Destination */
6485 cups_ptype_t dtype
; /* Destination type (printer/class) */
6486 cups_ptype_t dmask
; /* Destination type mask */
6487 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6488 username
[HTTP_MAX_URI
], /* Username portion of URI */
6489 host
[HTTP_MAX_URI
], /* Host portion of URI */
6490 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6491 int port
; /* Port portion of URI */
6492 int job_comparison
; /* Job comparison */
6493 ipp_jstate_t job_state
; /* job-state value */
6494 int first_job_id
= 1, /* First job ID */
6495 first_index
= 1, /* First index */
6496 limit
= 0, /* Maximum number of jobs to return */
6497 count
, /* Number of jobs that match */
6498 need_load_job
= 0; /* Do we need to load the job? */
6499 const char *job_attr
; /* Job attribute requested */
6500 ipp_attribute_t
*job_ids
; /* job-ids attribute */
6501 cupsd_job_t
*job
; /* Current job pointer */
6502 cupsd_printer_t
*printer
; /* Printer */
6503 cups_array_t
*list
; /* Which job list... */
6504 int delete_list
= 0; /* Delete the list afterwards? */
6505 cups_array_t
*ra
, /* Requested attributes array */
6506 *exclude
; /* Private attributes array */
6507 cupsd_policy_t
*policy
; /* Current policy */
6510 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs(%p[%d], %s)", con
, con
->number
,
6511 uri
->values
[0].string
.text
);
6514 * Is the destination valid?
6517 if (strcmp(uri
->name
, "printer-uri"))
6519 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No printer-uri in request."));
6523 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6524 sizeof(scheme
), username
, sizeof(username
), host
,
6525 sizeof(host
), &port
, resource
, sizeof(resource
));
6527 if (!strcmp(resource
, "/") || !strcmp(resource
, "/jobs"))
6530 dtype
= (cups_ptype_t
)0;
6531 dmask
= (cups_ptype_t
)0;
6534 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6537 dtype
= (cups_ptype_t
)0;
6538 dmask
= CUPS_PRINTER_CLASS
;
6541 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6544 dtype
= CUPS_PRINTER_CLASS
;
6545 dmask
= CUPS_PRINTER_CLASS
;
6548 else if ((dest
= cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
,
6555 send_ipp_status(con
, IPP_NOT_FOUND
,
6556 _("The printer or class does not exist."));
6561 dtype
&= CUPS_PRINTER_CLASS
;
6562 dmask
= CUPS_PRINTER_CLASS
;
6570 policy
= printer
->op_policy_ptr
;
6572 policy
= DefaultPolicyPtr
;
6574 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
6576 send_http_error(con
, status
, NULL
);
6580 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
6583 * See if the "which-jobs" attribute have been specified...
6586 if ((attr
= ippFindAttribute(con
->request
, "which-jobs",
6587 IPP_TAG_KEYWORD
)) != NULL
&& job_ids
)
6589 send_ipp_status(con
, IPP_CONFLICT
,
6590 _("The %s attribute cannot be provided with job-ids."),
6594 else if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "not-completed"))
6596 job_comparison
= -1;
6597 job_state
= IPP_JOB_STOPPED
;
6600 else if (!strcmp(attr
->values
[0].string
.text
, "completed"))
6603 job_state
= IPP_JOB_CANCELED
;
6604 list
= cupsdGetCompletedJobs(printer
);
6607 else if (!strcmp(attr
->values
[0].string
.text
, "aborted"))
6610 job_state
= IPP_JOB_ABORTED
;
6611 list
= cupsdGetCompletedJobs(printer
);
6614 else if (!strcmp(attr
->values
[0].string
.text
, "all"))
6617 job_state
= IPP_JOB_PENDING
;
6620 else if (!strcmp(attr
->values
[0].string
.text
, "canceled"))
6623 job_state
= IPP_JOB_CANCELED
;
6624 list
= cupsdGetCompletedJobs(printer
);
6627 else if (!strcmp(attr
->values
[0].string
.text
, "pending"))
6630 job_state
= IPP_JOB_PENDING
;
6633 else if (!strcmp(attr
->values
[0].string
.text
, "pending-held"))
6636 job_state
= IPP_JOB_HELD
;
6639 else if (!strcmp(attr
->values
[0].string
.text
, "processing"))
6642 job_state
= IPP_JOB_PROCESSING
;
6643 list
= PrintingJobs
;
6645 else if (!strcmp(attr
->values
[0].string
.text
, "processing-stopped"))
6648 job_state
= IPP_JOB_STOPPED
;
6653 send_ipp_status(con
, IPP_ATTRIBUTES
,
6654 _("The which-jobs value \"%s\" is not supported."),
6655 attr
->values
[0].string
.text
);
6656 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
6657 "which-jobs", NULL
, attr
->values
[0].string
.text
);
6662 * See if they want to limit the number of jobs reported...
6665 if ((attr
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
)) != NULL
)
6669 send_ipp_status(con
, IPP_CONFLICT
,
6670 _("The %s attribute cannot be provided with job-ids."),
6675 limit
= attr
->values
[0].integer
;
6678 if ((attr
= ippFindAttribute(con
->request
, "first-index", IPP_TAG_INTEGER
)) != NULL
)
6682 send_ipp_status(con
, IPP_CONFLICT
,
6683 _("The %s attribute cannot be provided with job-ids."),
6688 first_index
= attr
->values
[0].integer
;
6690 else if ((attr
= ippFindAttribute(con
->request
, "first-job-id", IPP_TAG_INTEGER
)) != NULL
)
6694 send_ipp_status(con
, IPP_CONFLICT
,
6695 _("The %s attribute cannot be provided with job-ids."),
6700 first_job_id
= attr
->values
[0].integer
;
6704 * See if we only want to see jobs for a specific user...
6707 if ((attr
= ippFindAttribute(con
->request
, "my-jobs", IPP_TAG_BOOLEAN
)) != NULL
&& job_ids
)
6709 send_ipp_status(con
, IPP_CONFLICT
,
6710 _("The %s attribute cannot be provided with job-ids."),
6714 else if (attr
&& attr
->values
[0].boolean
)
6715 strlcpy(username
, get_username(con
), sizeof(username
));
6719 ra
= create_requested_array(con
->request
);
6720 for (job_attr
= (char *)cupsArrayFirst(ra
); job_attr
; job_attr
= (char *)cupsArrayNext(ra
))
6721 if (strcmp(job_attr
, "job-id") &&
6722 strcmp(job_attr
, "job-k-octets") &&
6723 strcmp(job_attr
, "job-media-progress") &&
6724 strcmp(job_attr
, "job-more-info") &&
6725 strcmp(job_attr
, "job-name") &&
6726 strcmp(job_attr
, "job-originating-user-name") &&
6727 strcmp(job_attr
, "job-preserved") &&
6728 strcmp(job_attr
, "job-printer-up-time") &&
6729 strcmp(job_attr
, "job-printer-uri") &&
6730 strcmp(job_attr
, "job-state") &&
6731 strcmp(job_attr
, "job-state-reasons") &&
6732 strcmp(job_attr
, "job-uri") &&
6733 strcmp(job_attr
, "time-at-completed") &&
6734 strcmp(job_attr
, "time-at-creation") &&
6735 strcmp(job_attr
, "number-of-documents"))
6741 if (need_load_job
&& (limit
== 0 || limit
> 500) && (list
== Jobs
|| delete_list
))
6744 * Limit expensive Get-Jobs for job history to 500 jobs...
6747 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
, "limit", 500);
6750 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
, "limit", limit
);
6754 cupsdLogClient(con
, CUPSD_LOG_INFO
, "Limiting Get-Jobs response to %d jobs.", limit
);
6758 * OK, build a list of jobs for this printer...
6763 int i
; /* Looping var */
6765 for (i
= 0; i
< job_ids
->num_values
; i
++)
6767 if (!cupsdFindJob(job_ids
->values
[i
].integer
))
6771 if (i
< job_ids
->num_values
)
6773 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
6774 job_ids
->values
[i
].integer
);
6778 for (i
= 0; i
< job_ids
->num_values
; i
++)
6780 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
6782 if (need_load_job
&& !job
->attrs
)
6788 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d", job
->id
);
6794 ippAddSeparator(con
->response
);
6796 exclude
= cupsdGetPrivateAttrs(job
->printer
?
6797 job
->printer
->op_policy_ptr
:
6798 policy
, con
, job
->printer
,
6801 copy_job_attrs(con
, job
, ra
, exclude
);
6806 if (first_index
> 1)
6807 job
= (cupsd_job_t
*)cupsArrayIndex(list
, first_index
- 1);
6809 job
= (cupsd_job_t
*)cupsArrayFirst(list
);
6811 for (count
= 0; (limit
<= 0 || count
< limit
) && job
; job
= (cupsd_job_t
*)cupsArrayNext(list
))
6814 * Filter out jobs that don't match...
6817 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
6818 "get_jobs: job->id=%d, dest=\"%s\", username=\"%s\", "
6819 "state_value=%d, attrs=%p", job
->id
, job
->dest
,
6820 job
->username
, job
->state_value
, job
->attrs
);
6822 if (!job
->dest
|| !job
->username
)
6825 if (!job
->dest
|| !job
->username
)
6828 if ((dest
&& strcmp(job
->dest
, dest
)) &&
6829 (!job
->printer
|| !dest
|| strcmp(job
->printer
->name
, dest
)))
6831 if ((job
->dtype
& dmask
) != dtype
&&
6832 (!job
->printer
|| (job
->printer
->type
& dmask
) != dtype
))
6835 if ((job_comparison
< 0 && job
->state_value
> job_state
) ||
6836 (job_comparison
== 0 && job
->state_value
!= job_state
) ||
6837 (job_comparison
> 0 && job
->state_value
< job_state
))
6840 if (job
->id
< first_job_id
)
6843 if (need_load_job
&& !job
->attrs
)
6849 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d", job
->id
);
6854 if (username
[0] && _cups_strcasecmp(username
, job
->username
))
6858 ippAddSeparator(con
->response
);
6862 exclude
= cupsdGetPrivateAttrs(job
->printer
?
6863 job
->printer
->op_policy_ptr
:
6864 policy
, con
, job
->printer
,
6867 copy_job_attrs(con
, job
, ra
, exclude
);
6870 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: count=%d", count
);
6873 cupsArrayDelete(ra
);
6876 cupsArrayDelete(list
);
6878 con
->response
->request
.status
.status_code
= IPP_OK
;
6883 * 'get_notifications()' - Get events for a subscription.
6887 get_notifications(cupsd_client_t
*con
) /* I - Client connection */
6889 int i
, j
; /* Looping vars */
6890 http_status_t status
; /* Policy status */
6891 cupsd_subscription_t
*sub
; /* Subscription */
6892 ipp_attribute_t
*ids
, /* notify-subscription-ids */
6893 *sequences
; /* notify-sequence-numbers */
6894 int min_seq
; /* Minimum sequence number */
6895 int interval
; /* Poll interval */
6898 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_notifications(con=%p[%d])",
6902 * Get subscription attributes...
6905 ids
= ippFindAttribute(con
->request
, "notify-subscription-ids",
6907 sequences
= ippFindAttribute(con
->request
, "notify-sequence-numbers",
6912 send_ipp_status(con
, IPP_BAD_REQUEST
,
6913 _("Missing notify-subscription-ids attribute."));
6918 * Are the subscription IDs valid?
6921 for (i
= 0, interval
= 60; i
< ids
->num_values
; i
++)
6923 if ((sub
= cupsdFindSubscription(ids
->values
[i
].integer
)) == NULL
)
6926 * Bad subscription ID...
6929 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
6930 ids
->values
[i
].integer
);
6938 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
6940 con
, sub
->owner
)) != HTTP_OK
)
6942 send_http_error(con
, status
, sub
->dest
);
6947 * Check the subscription type and update the interval accordingly.
6950 if (sub
->job
&& sub
->job
->state_value
== IPP_JOB_PROCESSING
&&
6953 else if (sub
->job
&& sub
->job
->state_value
>= IPP_JOB_STOPPED
)
6955 else if (sub
->dest
&& sub
->dest
->state
== IPP_PRINTER_PROCESSING
&&
6961 * Tell the client to poll again in N seconds...
6965 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
6966 "notify-get-interval", interval
);
6968 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
6969 "printer-up-time", time(NULL
));
6972 * Copy the subscription event attributes to the response.
6975 con
->response
->request
.status
.status_code
=
6976 interval
? IPP_OK
: IPP_OK_EVENTS_COMPLETE
;
6978 for (i
= 0; i
< ids
->num_values
; i
++)
6981 * Get the subscription and sequence number...
6984 sub
= cupsdFindSubscription(ids
->values
[i
].integer
);
6986 if (sequences
&& i
< sequences
->num_values
)
6987 min_seq
= sequences
->values
[i
].integer
;
6992 * If we don't have any new events, nothing to do here...
6995 if (min_seq
> (sub
->first_event_id
+ cupsArrayCount(sub
->events
)))
6999 * Otherwise copy all of the new events...
7002 if (sub
->first_event_id
> min_seq
)
7005 j
= min_seq
- sub
->first_event_id
;
7007 for (; j
< cupsArrayCount(sub
->events
); j
++)
7009 ippAddSeparator(con
->response
);
7011 copy_attrs(con
->response
,
7012 ((cupsd_event_t
*)cupsArrayIndex(sub
->events
, j
))->attrs
, NULL
,
7013 IPP_TAG_EVENT_NOTIFICATION
, 0, NULL
);
7020 * 'get_ppd()' - Get a named PPD from the local system.
7024 get_ppd(cupsd_client_t
*con
, /* I - Client connection */
7025 ipp_attribute_t
*uri
) /* I - Printer URI or PPD name */
7027 http_status_t status
; /* Policy status */
7028 cupsd_printer_t
*dest
; /* Destination */
7029 cups_ptype_t dtype
; /* Destination type */
7032 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppd(%p[%d], %p[%s=%s])", con
,
7033 con
->number
, uri
, uri
->name
, uri
->values
[0].string
.text
);
7035 if (!strcmp(ippGetName(uri
), "ppd-name"))
7038 * Return a PPD file from cups-driverd...
7041 const char *ppd_name
= ippGetString(uri
, 0, NULL
);
7042 /* ppd-name value */
7043 char command
[1024], /* cups-driverd command */
7044 options
[1024], /* Options to pass to command */
7045 oppd_name
[1024]; /* Escaped ppd-name */
7051 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7053 send_http_error(con
, status
, NULL
);
7058 * Check ppd-name value...
7061 if (strstr(ppd_name
, "../"))
7063 send_ipp_status(con
, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES
, _("Invalid ppd-name value."));
7068 * Run cups-driverd command with the given options...
7071 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7072 url_encode_string(ppd_name
, oppd_name
, sizeof(oppd_name
));
7073 snprintf(options
, sizeof(options
), "get+%d+%s", ippGetRequestId(con
->request
), oppd_name
);
7075 if (cupsdSendCommand(con
, command
, options
, 0))
7078 * Command started successfully, don't send an IPP response here...
7081 ippDelete(con
->response
);
7082 con
->response
= NULL
;
7087 * Command failed, return "internal error" so the user knows something
7091 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("cups-driverd failed to execute."));
7094 else if (!strcmp(ippGetName(uri
), "printer-uri") && cupsdValidateDest(ippGetString(uri
, 0, NULL
), &dtype
, &dest
))
7096 int i
; /* Looping var */
7097 char filename
[1024]; /* PPD filename */
7103 if ((status
= cupsdCheckPolicy(dest
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7105 send_http_error(con
, status
, dest
);
7110 * See if we need the PPD for a class or remote printer...
7113 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
, dest
->name
);
7115 if ((dtype
& CUPS_PRINTER_REMOTE
) && access(filename
, 0))
7117 send_ipp_status(con
, IPP_STATUS_CUPS_SEE_OTHER
, _("See remote printer."));
7118 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
, dest
->uri
);
7121 else if (dtype
& CUPS_PRINTER_CLASS
)
7123 for (i
= 0; i
< dest
->num_printers
; i
++)
7124 if (!(dest
->printers
[i
]->type
& CUPS_PRINTER_CLASS
))
7126 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
, dest
->printers
[i
]->name
);
7128 if (!access(filename
, 0))
7132 if (i
< dest
->num_printers
)
7133 dest
= dest
->printers
[i
];
7136 send_ipp_status(con
, IPP_STATUS_CUPS_SEE_OTHER
, _("See remote printer."));
7137 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
, dest
->printers
[0]->uri
);
7143 * Found the printer with the PPD file, now see if there is one...
7146 if ((con
->file
= open(filename
, O_RDONLY
)) < 0)
7148 send_ipp_status(con
, IPP_STATUS_ERROR_NOT_FOUND
, _("The PPD file \"%s\" could not be opened: %s"), ippGetString(uri
, 0, NULL
), strerror(errno
));
7152 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
7156 ippSetStatusCode(con
->response
, IPP_STATUS_OK
);
7159 send_ipp_status(con
, IPP_STATUS_ERROR_NOT_FOUND
, _("The PPD file \"%s\" could not be found."), ippGetString(uri
, 0, NULL
));
7164 * 'get_ppds()' - Get the list of PPD files on the local system.
7168 get_ppds(cupsd_client_t
*con
) /* I - Client connection */
7170 http_status_t status
; /* Policy status */
7171 ipp_attribute_t
*limit
, /* Limit attribute */
7172 *device
, /* ppd-device-id attribute */
7173 *language
, /* ppd-natural-language attribute */
7174 *make
, /* ppd-make attribute */
7175 *model
, /* ppd-make-and-model attribute */
7176 *model_number
, /* ppd-model-number attribute */
7177 *product
, /* ppd-product attribute */
7178 *psversion
, /* ppd-psverion attribute */
7179 *type
, /* ppd-type attribute */
7180 *requested
, /* requested-attributes attribute */
7181 *exclude
, /* exclude-schemes attribute */
7182 *include
; /* include-schemes attribute */
7183 char command
[1024], /* cups-driverd command */
7184 options
[4096], /* Options to pass to command */
7185 device_str
[256],/* Escaped ppd-device-id string */
7187 /* Escaped ppd-natural-language */
7188 make_str
[256], /* Escaped ppd-make string */
7189 model_str
[256], /* Escaped ppd-make-and-model string */
7190 model_number_str
[256],
7191 /* ppd-model-number string */
7193 /* Escaped ppd-product string */
7195 /* Escaped ppd-psversion string */
7196 type_str
[256], /* Escaped ppd-type string */
7198 /* String for requested attributes */
7200 /* String for excluded schemes */
7202 /* String for included schemes */
7205 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppds(%p[%d])", con
, con
->number
);
7211 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7213 send_http_error(con
, status
, NULL
);
7218 * Run cups-driverd command with the given options...
7221 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
7222 device
= ippFindAttribute(con
->request
, "ppd-device-id", IPP_TAG_TEXT
);
7223 language
= ippFindAttribute(con
->request
, "ppd-natural-language",
7225 make
= ippFindAttribute(con
->request
, "ppd-make", IPP_TAG_TEXT
);
7226 model
= ippFindAttribute(con
->request
, "ppd-make-and-model",
7228 model_number
= ippFindAttribute(con
->request
, "ppd-model-number",
7230 product
= ippFindAttribute(con
->request
, "ppd-product", IPP_TAG_TEXT
);
7231 psversion
= ippFindAttribute(con
->request
, "ppd-psversion", IPP_TAG_TEXT
);
7232 type
= ippFindAttribute(con
->request
, "ppd-type", IPP_TAG_KEYWORD
);
7233 requested
= ippFindAttribute(con
->request
, "requested-attributes",
7235 exclude
= ippFindAttribute(con
->request
, "exclude-schemes",
7237 include
= ippFindAttribute(con
->request
, "include-schemes",
7241 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
7243 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
7246 url_encode_attr(device
, device_str
, sizeof(device_str
));
7248 device_str
[0] = '\0';
7251 url_encode_attr(language
, language_str
, sizeof(language_str
));
7253 language_str
[0] = '\0';
7256 url_encode_attr(make
, make_str
, sizeof(make_str
));
7261 url_encode_attr(model
, model_str
, sizeof(model_str
));
7263 model_str
[0] = '\0';
7266 snprintf(model_number_str
, sizeof(model_number_str
), "ppd-model-number=%d",
7267 model_number
->values
[0].integer
);
7269 model_number_str
[0] = '\0';
7272 url_encode_attr(product
, product_str
, sizeof(product_str
));
7274 product_str
[0] = '\0';
7277 url_encode_attr(psversion
, psversion_str
, sizeof(psversion_str
));
7279 psversion_str
[0] = '\0';
7282 url_encode_attr(type
, type_str
, sizeof(type_str
));
7287 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
7289 exclude_str
[0] = '\0';
7292 url_encode_attr(include
, include_str
, sizeof(include_str
));
7294 include_str
[0] = '\0';
7296 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7297 snprintf(options
, sizeof(options
),
7298 "list+%d+%d+%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
7299 con
->request
->request
.op
.request_id
,
7300 limit
? limit
->values
[0].integer
: 0,
7302 device
? "%20" : "", device_str
,
7303 language
? "%20" : "", language_str
,
7304 make
? "%20" : "", make_str
,
7305 model
? "%20" : "", model_str
,
7306 model_number
? "%20" : "", model_number_str
,
7307 product
? "%20" : "", product_str
,
7308 psversion
? "%20" : "", psversion_str
,
7309 type
? "%20" : "", type_str
,
7310 exclude_str
[0] ? "%20" : "", exclude_str
,
7311 include_str
[0] ? "%20" : "", include_str
);
7313 if (cupsdSendCommand(con
, command
, options
, 0))
7316 * Command started successfully, don't send an IPP response here...
7319 ippDelete(con
->response
);
7320 con
->response
= NULL
;
7325 * Command failed, return "internal error" so the user knows something
7329 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7330 _("cups-driverd failed to execute."));
7336 * 'get_printer_attrs()' - Get printer attributes.
7340 get_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
7341 ipp_attribute_t
*uri
) /* I - Printer URI */
7343 http_status_t status
; /* Policy status */
7344 cups_ptype_t dtype
; /* Destination type (printer/class) */
7345 cupsd_printer_t
*printer
; /* Printer/class */
7346 cups_array_t
*ra
; /* Requested attributes array */
7349 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_attrs(%p[%d], %s)", con
,
7350 con
->number
, uri
->values
[0].string
.text
);
7353 * Is the destination valid?
7356 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7362 send_ipp_status(con
, IPP_NOT_FOUND
,
7363 _("The printer or class does not exist."));
7371 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7373 send_http_error(con
, status
, printer
);
7378 * Send the attributes...
7381 ra
= create_requested_array(con
->request
);
7383 copy_printer_attrs(con
, printer
, ra
);
7385 cupsArrayDelete(ra
);
7387 con
->response
->request
.status
.status_code
= IPP_OK
;
7392 * 'get_printer_supported()' - Get printer supported values.
7396 get_printer_supported(
7397 cupsd_client_t
*con
, /* I - Client connection */
7398 ipp_attribute_t
*uri
) /* I - Printer URI */
7400 http_status_t status
; /* Policy status */
7401 cups_ptype_t dtype
; /* Destination type (printer/class) */
7402 cupsd_printer_t
*printer
; /* Printer/class */
7405 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_supported(%p[%d], %s)", con
,
7406 con
->number
, uri
->values
[0].string
.text
);
7409 * Is the destination valid?
7412 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7418 send_ipp_status(con
, IPP_NOT_FOUND
,
7419 _("The printer or class does not exist."));
7427 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7429 send_http_error(con
, status
, printer
);
7434 * Return a list of attributes that can be set via Set-Printer-Attributes.
7437 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7438 "printer-geo-location", 0);
7439 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7441 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7442 "printer-location", 0);
7443 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7444 "printer-organization", 0);
7445 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7446 "printer-organizational-unit", 0);
7448 con
->response
->request
.status
.status_code
= IPP_OK
;
7453 * 'get_printers()' - Get a list of printers or classes.
7457 get_printers(cupsd_client_t
*con
, /* I - Client connection */
7458 int type
) /* I - 0 or CUPS_PRINTER_CLASS */
7460 http_status_t status
; /* Policy status */
7461 ipp_attribute_t
*attr
; /* Current attribute */
7462 int limit
; /* Max number of printers to return */
7463 int count
; /* Number of printers that match */
7464 cupsd_printer_t
*printer
; /* Current printer pointer */
7465 cups_ptype_t printer_type
, /* printer-type attribute */
7466 printer_mask
; /* printer-type-mask attribute */
7467 char *location
; /* Location string */
7468 const char *username
; /* Current user */
7469 char *first_printer_name
; /* first-printer-name attribute */
7470 cups_array_t
*ra
; /* Requested attributes array */
7471 int local
; /* Local connection? */
7474 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printers(%p[%d], %x)", con
,
7481 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7483 send_http_error(con
, status
, NULL
);
7488 * Check for printers...
7491 if (!Printers
|| !cupsArrayCount(Printers
))
7493 send_ipp_status(con
, IPP_NOT_FOUND
, _("No destinations added."));
7498 * See if they want to limit the number of printers reported...
7501 if ((attr
= ippFindAttribute(con
->request
, "limit",
7502 IPP_TAG_INTEGER
)) != NULL
)
7503 limit
= attr
->values
[0].integer
;
7507 if ((attr
= ippFindAttribute(con
->request
, "first-printer-name",
7508 IPP_TAG_NAME
)) != NULL
)
7509 first_printer_name
= attr
->values
[0].string
.text
;
7511 first_printer_name
= NULL
;
7514 * Support filtering...
7517 if ((attr
= ippFindAttribute(con
->request
, "printer-type",
7518 IPP_TAG_ENUM
)) != NULL
)
7519 printer_type
= (cups_ptype_t
)attr
->values
[0].integer
;
7521 printer_type
= (cups_ptype_t
)0;
7523 if ((attr
= ippFindAttribute(con
->request
, "printer-type-mask",
7524 IPP_TAG_ENUM
)) != NULL
)
7525 printer_mask
= (cups_ptype_t
)attr
->values
[0].integer
;
7527 printer_mask
= (cups_ptype_t
)0;
7529 local
= httpAddrLocalhost(&(con
->clientaddr
));
7531 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
7532 IPP_TAG_TEXT
)) != NULL
)
7533 location
= attr
->values
[0].string
.text
;
7537 if (con
->username
[0])
7538 username
= con
->username
;
7539 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7540 IPP_TAG_NAME
)) != NULL
)
7541 username
= attr
->values
[0].string
.text
;
7545 ra
= create_requested_array(con
->request
);
7548 * OK, build a list of printers for this printer...
7551 if (first_printer_name
)
7553 if ((printer
= cupsdFindDest(first_printer_name
)) == NULL
)
7554 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7557 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7560 count
< limit
&& printer
;
7561 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
7563 if (!local
&& !printer
->shared
)
7566 if ((!type
|| (printer
->type
& CUPS_PRINTER_CLASS
) == type
) &&
7567 (printer
->type
& printer_mask
) == printer_type
&&
7569 (printer
->location
&& !_cups_strcasecmp(printer
->location
, location
))))
7572 * If a username is specified, see if it is allowed or denied
7576 if (cupsArrayCount(printer
->users
) && username
&&
7577 !user_allowed(printer
, username
))
7581 * Add the group separator as needed...
7585 ippAddSeparator(con
->response
);
7590 * Send the attributes...
7593 copy_printer_attrs(con
, printer
, ra
);
7597 cupsArrayDelete(ra
);
7599 con
->response
->request
.status
.status_code
= IPP_OK
;
7604 * 'get_subscription_attrs()' - Get subscription attributes.
7608 get_subscription_attrs(
7609 cupsd_client_t
*con
, /* I - Client connection */
7610 int sub_id
) /* I - Subscription ID */
7612 http_status_t status
; /* Policy status */
7613 cupsd_subscription_t
*sub
; /* Subscription */
7614 cupsd_policy_t
*policy
; /* Current security policy */
7615 cups_array_t
*ra
, /* Requested attributes array */
7616 *exclude
; /* Private attributes array */
7619 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7620 "get_subscription_attrs(con=%p[%d], sub_id=%d)",
7621 con
, con
->number
, sub_id
);
7624 * Expire subscriptions as needed...
7627 cupsdExpireSubscriptions(NULL
, NULL
);
7630 * Is the subscription ID valid?
7633 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
7636 * Bad subscription ID...
7639 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
7649 policy
= sub
->dest
->op_policy_ptr
;
7651 policy
= DefaultPolicyPtr
;
7653 if ((status
= cupsdCheckPolicy(policy
, con
, sub
->owner
)) != HTTP_OK
)
7655 send_http_error(con
, status
, sub
->dest
);
7659 exclude
= cupsdGetPrivateAttrs(policy
, con
, sub
->dest
, sub
->owner
);
7662 * Copy the subscription attributes to the response using the
7663 * requested-attributes attribute that may be provided by the client.
7666 ra
= create_requested_array(con
->request
);
7668 copy_subscription_attrs(con
, sub
, ra
, exclude
);
7670 cupsArrayDelete(ra
);
7672 con
->response
->request
.status
.status_code
= IPP_OK
;
7677 * 'get_subscriptions()' - Get subscriptions.
7681 get_subscriptions(cupsd_client_t
*con
, /* I - Client connection */
7682 ipp_attribute_t
*uri
) /* I - Printer/job URI */
7684 http_status_t status
; /* Policy status */
7685 int count
; /* Number of subscriptions */
7686 int limit
; /* Limit */
7687 cupsd_subscription_t
*sub
; /* Subscription */
7688 cups_array_t
*ra
; /* Requested attributes array */
7689 ipp_attribute_t
*attr
; /* Attribute */
7690 cups_ptype_t dtype
; /* Destination type (printer/class) */
7691 char scheme
[HTTP_MAX_URI
],
7692 /* Scheme portion of URI */
7693 username
[HTTP_MAX_URI
],
7694 /* Username portion of URI */
7696 /* Host portion of URI */
7697 resource
[HTTP_MAX_URI
];
7698 /* Resource portion of URI */
7699 int port
; /* Port portion of URI */
7700 cupsd_job_t
*job
; /* Job pointer */
7701 cupsd_printer_t
*printer
; /* Printer */
7702 cupsd_policy_t
*policy
; /* Policy */
7703 cups_array_t
*exclude
; /* Private attributes array */
7706 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7707 "get_subscriptions(con=%p[%d], uri=%s)",
7708 con
, con
->number
, uri
->values
[0].string
.text
);
7711 * Is the destination valid?
7714 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7715 sizeof(scheme
), username
, sizeof(username
), host
,
7716 sizeof(host
), &port
, resource
, sizeof(resource
));
7718 if (!strcmp(resource
, "/") ||
7719 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6) ||
7720 (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10) ||
7721 (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9))
7726 else if (!strncmp(resource
, "/jobs/", 6) && resource
[6])
7729 job
= cupsdFindJob(atoi(resource
+ 6));
7733 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
7734 atoi(resource
+ 6));
7738 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7744 send_ipp_status(con
, IPP_NOT_FOUND
,
7745 _("The printer or class does not exist."));
7748 else if ((attr
= ippFindAttribute(con
->request
, "notify-job-id",
7749 IPP_TAG_INTEGER
)) != NULL
)
7751 job
= cupsdFindJob(attr
->values
[0].integer
);
7755 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
7756 attr
->values
[0].integer
);
7768 policy
= printer
->op_policy_ptr
;
7770 policy
= DefaultPolicyPtr
;
7772 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
7774 send_http_error(con
, status
, printer
);
7779 * Expire subscriptions as needed...
7782 cupsdExpireSubscriptions(NULL
, NULL
);
7785 * Copy the subscription attributes to the response using the
7786 * requested-attributes attribute that may be provided by the client.
7789 ra
= create_requested_array(con
->request
);
7791 if ((attr
= ippFindAttribute(con
->request
, "limit",
7792 IPP_TAG_INTEGER
)) != NULL
)
7793 limit
= attr
->values
[0].integer
;
7798 * See if we only want to see subscriptions for a specific user...
7801 if ((attr
= ippFindAttribute(con
->request
, "my-subscriptions",
7802 IPP_TAG_BOOLEAN
)) != NULL
&&
7803 attr
->values
[0].boolean
)
7804 strlcpy(username
, get_username(con
), sizeof(username
));
7808 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
), count
= 0;
7810 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
7811 if ((!printer
|| sub
->dest
== printer
) && (!job
|| sub
->job
== job
) &&
7812 (!username
[0] || !_cups_strcasecmp(username
, sub
->owner
)))
7814 ippAddSeparator(con
->response
);
7816 exclude
= cupsdGetPrivateAttrs(sub
->dest
? sub
->dest
->op_policy_ptr
:
7817 policy
, con
, sub
->dest
,
7820 copy_subscription_attrs(con
, sub
, ra
, exclude
);
7823 if (limit
&& count
>= limit
)
7827 cupsArrayDelete(ra
);
7830 con
->response
->request
.status
.status_code
= IPP_OK
;
7832 send_ipp_status(con
, IPP_NOT_FOUND
, _("No subscriptions found."));
7837 * 'get_username()' - Get the username associated with a request.
7840 static const char * /* O - Username */
7841 get_username(cupsd_client_t
*con
) /* I - Connection */
7843 ipp_attribute_t
*attr
; /* Attribute */
7846 if (con
->username
[0])
7847 return (con
->username
);
7848 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7849 IPP_TAG_NAME
)) != NULL
)
7850 return (attr
->values
[0].string
.text
);
7852 return ("anonymous");
7857 * 'hold_job()' - Hold a print job.
7861 hold_job(cupsd_client_t
*con
, /* I - Client connection */
7862 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
7864 ipp_attribute_t
*attr
; /* Current job-hold-until */
7865 const char *when
; /* New value */
7866 int jobid
; /* Job ID */
7867 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
7868 username
[HTTP_MAX_URI
], /* Username portion of URI */
7869 host
[HTTP_MAX_URI
], /* Host portion of URI */
7870 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7871 int port
; /* Port portion of URI */
7872 cupsd_job_t
*job
; /* Job information */
7875 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_job(%p[%d], %s)", con
, con
->number
,
7876 uri
->values
[0].string
.text
);
7879 * See if we have a job URI or a printer URI...
7882 if (!strcmp(uri
->name
, "printer-uri"))
7885 * Got a printer URI; see if we also have a job-id attribute...
7888 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7889 IPP_TAG_INTEGER
)) == NULL
)
7891 send_ipp_status(con
, IPP_BAD_REQUEST
,
7892 _("Got a printer-uri attribute but no job-id."));
7896 jobid
= attr
->values
[0].integer
;
7901 * Got a job URI; parse it to get the job ID...
7904 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7905 sizeof(scheme
), username
, sizeof(username
), host
,
7906 sizeof(host
), &port
, resource
, sizeof(resource
));
7908 if (strncmp(resource
, "/jobs/", 6))
7914 send_ipp_status(con
, IPP_BAD_REQUEST
,
7915 _("Bad job-uri \"%s\"."),
7916 uri
->values
[0].string
.text
);
7920 jobid
= atoi(resource
+ 6);
7924 * See if the job exists...
7927 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7930 * Nope - return a "not found" error...
7933 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
7938 * See if the job is owned by the requesting user...
7941 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7943 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
7944 cupsdFindDest(job
->dest
));
7949 * See if the job is in a state that allows holding...
7952 if (job
->state_value
> IPP_JOB_STOPPED
)
7955 * Return a "not-possible" error...
7958 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
7959 _("Job #%d is finished and cannot be altered."),
7965 * Hold the job and return...
7968 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
7969 IPP_TAG_KEYWORD
)) == NULL
)
7970 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
7974 when
= attr
->values
[0].string
.text
;
7976 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
7977 "Job job-hold-until value changed by user.");
7980 when
= "indefinite";
7982 cupsdSetJobHoldUntil(job
, when
, 1);
7983 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
, "Job held by \"%s\".",
7986 con
->response
->request
.status
.status_code
= IPP_OK
;
7991 * 'hold_new_jobs()' - Hold pending/new jobs on a printer or class.
7995 hold_new_jobs(cupsd_client_t
*con
, /* I - Connection */
7996 ipp_attribute_t
*uri
) /* I - Printer URI */
7998 http_status_t status
; /* Policy status */
7999 cups_ptype_t dtype
; /* Destination type (printer/class) */
8000 cupsd_printer_t
*printer
; /* Printer data */
8003 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_new_jobs(%p[%d], %s)", con
,
8004 con
->number
, uri
->values
[0].string
.text
);
8007 * Is the destination valid?
8010 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8016 send_ipp_status(con
, IPP_NOT_FOUND
,
8017 _("The printer or class does not exist."));
8025 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8027 send_http_error(con
, status
, printer
);
8032 * Hold pending/new jobs sent to the printer...
8035 printer
->holding_new_jobs
= 1;
8037 cupsdSetPrinterReasons(printer
, "+hold-new-jobs");
8039 if (dtype
& CUPS_PRINTER_CLASS
)
8040 cupsdLogMessage(CUPSD_LOG_INFO
,
8041 "Class \"%s\" now holding pending/new jobs (\"%s\").",
8042 printer
->name
, get_username(con
));
8044 cupsdLogMessage(CUPSD_LOG_INFO
,
8045 "Printer \"%s\" now holding pending/new jobs (\"%s\").",
8046 printer
->name
, get_username(con
));
8049 * Everything was ok, so return OK status...
8052 con
->response
->request
.status
.status_code
= IPP_OK
;
8057 * 'move_job()' - Move a job to a new destination.
8061 move_job(cupsd_client_t
*con
, /* I - Client connection */
8062 ipp_attribute_t
*uri
) /* I - Job URI */
8064 http_status_t status
; /* Policy status */
8065 ipp_attribute_t
*attr
; /* Current attribute */
8066 int jobid
; /* Job ID */
8067 cupsd_job_t
*job
; /* Current job */
8068 const char *src
; /* Source printer/class */
8069 cups_ptype_t stype
, /* Source type (printer or class) */
8070 dtype
; /* Destination type (printer/class) */
8071 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
8072 username
[HTTP_MAX_URI
], /* Username portion of URI */
8073 host
[HTTP_MAX_URI
], /* Host portion of URI */
8074 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8075 int port
; /* Port portion of URI */
8076 cupsd_printer_t
*sprinter
, /* Source printer */
8077 *dprinter
; /* Destination printer */
8080 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "move_job(%p[%d], %s)", con
, con
->number
,
8081 uri
->values
[0].string
.text
);
8084 * Get the new printer or class...
8087 if ((attr
= ippFindAttribute(con
->request
, "job-printer-uri",
8088 IPP_TAG_URI
)) == NULL
)
8091 * Need job-printer-uri...
8094 send_ipp_status(con
, IPP_BAD_REQUEST
,
8095 _("job-printer-uri attribute missing."));
8099 if (!cupsdValidateDest(attr
->values
[0].string
.text
, &dtype
, &dprinter
))
8105 send_ipp_status(con
, IPP_NOT_FOUND
,
8106 _("The printer or class does not exist."));
8111 * See if we have a job URI or a printer URI...
8114 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8115 sizeof(scheme
), username
, sizeof(username
), host
,
8116 sizeof(host
), &port
, resource
, sizeof(resource
));
8118 if (!strcmp(uri
->name
, "printer-uri"))
8121 * Got a printer URI; see if we also have a job-id attribute...
8124 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8125 IPP_TAG_INTEGER
)) == NULL
)
8131 if ((src
= cupsdValidateDest(uri
->values
[0].string
.text
, &stype
,
8132 &sprinter
)) == NULL
)
8138 send_ipp_status(con
, IPP_NOT_FOUND
,
8139 _("The printer or class does not exist."));
8148 * Otherwise, just move a single job...
8151 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
8154 * Nope - return a "not found" error...
8157 send_ipp_status(con
, IPP_NOT_FOUND
,
8158 _("Job #%d does not exist."), attr
->values
[0].integer
);
8164 * Job found, initialize source pointers...
8175 * Got a job URI; parse it to get the job ID...
8178 if (strncmp(resource
, "/jobs/", 6))
8184 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
8185 uri
->values
[0].string
.text
);
8190 * See if the job exists...
8193 jobid
= atoi(resource
+ 6);
8195 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8198 * Nope - return a "not found" error...
8201 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
8207 * Job found, initialize source pointers...
8216 * Check the policy of the destination printer...
8219 if ((status
= cupsdCheckPolicy(dprinter
->op_policy_ptr
, con
,
8220 job
? job
->username
: NULL
)) != HTTP_OK
)
8222 send_http_error(con
, status
, dprinter
);
8227 * Now move the job or jobs...
8233 * See if the job has been completed...
8236 if (job
->state_value
> IPP_JOB_STOPPED
)
8239 * Return a "not-possible" error...
8242 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8243 _("Job #%d is finished and cannot be altered."),
8249 * See if the job is owned by the requesting user...
8252 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8254 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8255 cupsdFindDest(job
->dest
));
8260 * Move the job to a different printer or class...
8263 cupsdMoveJob(job
, dprinter
);
8268 * Got the source printer, now look through the jobs...
8271 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
8273 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
8276 * See if the job is pointing at the source printer or has not been
8280 if (_cups_strcasecmp(job
->dest
, src
) ||
8281 job
->state_value
> IPP_JOB_STOPPED
)
8285 * See if the job can be moved by the requesting user...
8288 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8292 * Move the job to a different printer or class...
8295 cupsdMoveJob(job
, dprinter
);
8300 * Start jobs if possible...
8306 * Return with "everything is OK" status...
8309 con
->response
->request
.status
.status_code
= IPP_OK
;
8314 * 'ppd_parse_line()' - Parse a PPD default line.
8317 static int /* O - 0 on success, -1 on failure */
8318 ppd_parse_line(const char *line
, /* I - Line */
8319 char *option
, /* O - Option name */
8320 int olen
, /* I - Size of option name */
8321 char *choice
, /* O - Choice name */
8322 int clen
) /* I - Size of choice name */
8325 * Verify this is a default option line...
8328 if (strncmp(line
, "*Default", 8))
8332 * Read the option name...
8335 for (line
+= 8, olen
--;
8336 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
8347 * Skip everything else up to the colon (:)...
8350 while (*line
&& *line
!= ':')
8359 * Now grab the option choice, skipping leading whitespace...
8362 while (isspace(*line
& 255))
8366 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
8377 * Return with no errors...
8385 * 'print_job()' - Print a file to a printer or class.
8389 print_job(cupsd_client_t
*con
, /* I - Client connection */
8390 ipp_attribute_t
*uri
) /* I - Printer URI */
8392 ipp_attribute_t
*attr
; /* Current attribute */
8393 ipp_attribute_t
*doc_name
; /* document-name attribute */
8394 ipp_attribute_t
*format
; /* Document-format attribute */
8395 const char *default_format
; /* document-format-default value */
8396 cupsd_job_t
*job
; /* New job */
8397 char filename
[1024]; /* Job filename */
8398 mime_type_t
*filetype
; /* Type of file */
8399 char super
[MIME_MAX_SUPER
], /* Supertype of file */
8400 type
[MIME_MAX_TYPE
], /* Subtype of file */
8401 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
8402 /* Textual name of mime type */
8403 cupsd_printer_t
*printer
; /* Printer data */
8404 struct stat fileinfo
; /* File information */
8405 int kbytes
; /* Size of file */
8406 int compression
; /* Document compression */
8409 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "print_job(%p[%d], %s)", con
, con
->number
,
8410 uri
->values
[0].string
.text
);
8413 * Validate print file attributes, for now just document-format and
8414 * compression (CUPS only supports "none" and "gzip")...
8417 compression
= CUPS_FILE_NONE
;
8419 if ((attr
= ippFindAttribute(con
->request
, "compression",
8420 IPP_TAG_KEYWORD
)) != NULL
)
8422 if (strcmp(attr
->values
[0].string
.text
, "none")
8424 && strcmp(attr
->values
[0].string
.text
, "gzip")
8425 #endif /* HAVE_LIBZ */
8428 send_ipp_status(con
, IPP_ATTRIBUTES
,
8429 _("Unsupported compression \"%s\"."),
8430 attr
->values
[0].string
.text
);
8431 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
8432 "compression", NULL
, attr
->values
[0].string
.text
);
8437 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
8438 compression
= CUPS_FILE_GZIP
;
8439 #endif /* HAVE_LIBZ */
8443 * Do we have a file to print?
8448 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file in print request."));
8453 * Is the destination valid?
8456 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
8462 send_ipp_status(con
, IPP_NOT_FOUND
,
8463 _("The printer or class does not exist."));
8468 * Is it a format we support?
8471 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
8473 ippSetName(con
->request
, &doc_name
, "document-name-supplied");
8475 if ((format
= ippFindAttribute(con
->request
, "document-format",
8476 IPP_TAG_MIMETYPE
)) != NULL
)
8479 * Grab format from client...
8482 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%255[^;]", super
,
8485 send_ipp_status(con
, IPP_BAD_REQUEST
,
8486 _("Bad document-format \"%s\"."),
8487 format
->values
[0].string
.text
);
8491 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format-supplied", NULL
, ippGetString(format
, 0, NULL
));
8493 else if ((default_format
= cupsGetOption("document-format",
8494 printer
->num_options
,
8495 printer
->options
)) != NULL
)
8498 * Use default document format...
8501 if (sscanf(default_format
, "%15[^/]/%255[^;]", super
, type
) != 2)
8503 send_ipp_status(con
, IPP_BAD_REQUEST
,
8504 _("Bad document-format \"%s\"."),
8515 strlcpy(super
, "application", sizeof(super
));
8516 strlcpy(type
, "octet-stream", sizeof(type
));
8519 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
8522 * Auto-type the file...
8525 cupsdLogMessage(CUPSD_LOG_DEBUG
, "[Job ???] Auto-typing file...");
8528 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
8529 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
8533 filetype
= mimeType(MimeDatabase
, super
, type
);
8535 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job ???] Request file type is %s/%s.",
8536 filetype
->super
, filetype
->type
);
8538 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
, filetype
->type
);
8539 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format-detected", NULL
, mimetype
);
8542 filetype
= mimeType(MimeDatabase
, super
, type
);
8546 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
8549 * Replace the document-format attribute value with the auto-typed or
8553 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
8557 ippSetString(con
->request
, &format
, 0, mimetype
);
8559 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
8560 "document-format", NULL
, mimetype
);
8564 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
8565 _("Unsupported document-format \"%s\"."),
8566 format
? format
->values
[0].string
.text
:
8567 "application/octet-stream");
8568 cupsdLogMessage(CUPSD_LOG_INFO
,
8569 "Hint: Do you have the raw file printing rules enabled?");
8572 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
8573 "document-format", NULL
, format
->values
[0].string
.text
);
8579 * Read any embedded job ticket info from PS files...
8582 if (!_cups_strcasecmp(filetype
->super
, "application") &&
8583 (!_cups_strcasecmp(filetype
->type
, "postscript") ||
8584 !_cups_strcasecmp(filetype
->type
, "pdf")))
8585 read_job_ticket(con
);
8588 * Create the job object...
8591 if ((job
= add_job(con
, printer
, filetype
)) == NULL
)
8595 * Update quota data...
8598 if (stat(con
->filename
, &fileinfo
))
8601 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
8603 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
8605 job
->koctets
+= kbytes
;
8607 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets", IPP_TAG_INTEGER
)) != NULL
)
8608 attr
->values
[0].integer
+= kbytes
;
8611 * Add the job file...
8614 if (add_file(con
, job
, filetype
, compression
))
8617 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
, job
->num_files
);
8618 if (rename(con
->filename
, filename
))
8620 cupsdLogJob(job
, CUPSD_LOG_ERROR
, "Unable to rename job document file \"%s\": %s", filename
, strerror(errno
));
8622 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to rename job document file."));
8626 cupsdClearString(&con
->filename
);
8629 * See if we need to add the ending sheet...
8632 if (cupsdTimeoutJob(job
))
8636 * Log and save the job...
8639 cupsdLogJob(job
, CUPSD_LOG_INFO
,
8640 "File of type %s/%s queued by \"%s\".",
8641 filetype
->super
, filetype
->type
, job
->username
);
8642 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "hold_until=%d", (int)job
->hold_until
);
8643 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
8644 job
->dest
, job
->username
);
8647 * Start the job if possible...
8655 * 'read_job_ticket()' - Read a job ticket embedded in a print file.
8657 * This function only gets called when printing a single PDF or PostScript
8658 * file using the Print-Job operation. It doesn't work for Create-Job +
8659 * Send-File, since the job attributes need to be set at job creation
8660 * time for banners to work. The embedded job ticket stuff is here
8661 * primarily to allow the Windows printer driver for CUPS to pass in JCL
8662 * options and IPP attributes which otherwise would be lost.
8664 * The format of a job ticket is simple:
8666 * %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
8668 * %cupsJobTicket: attr1=value1
8669 * %cupsJobTicket: attr2=value2
8671 * %cupsJobTicket: attrN=valueN
8673 * Job ticket lines must appear immediately after the first line that
8674 * specifies PostScript (%!PS-Adobe-3.0) or PDF (%PDF) format, and CUPS
8675 * stops looking for job ticket info when it finds a line that does not begin
8676 * with "%cupsJobTicket:".
8678 * The maximum length of a job ticket line, including the prefix, is
8679 * 255 characters to conform with the Adobe DSC.
8681 * Read-only attributes are rejected with a notice to the error log in
8682 * case a malicious user tries anything. Since the job ticket is read
8683 * prior to attribute validation in print_job(), job ticket attributes
8684 * will go through the same validation as IPP attributes...
8688 read_job_ticket(cupsd_client_t
*con
) /* I - Client connection */
8690 cups_file_t
*fp
; /* File to read from */
8691 char line
[256]; /* Line data */
8692 int num_options
; /* Number of options */
8693 cups_option_t
*options
; /* Options */
8694 ipp_t
*ticket
; /* New attributes */
8695 ipp_attribute_t
*attr
, /* Current attribute */
8696 *attr2
, /* Job attribute */
8697 *prev2
; /* Previous job attribute */
8701 * First open the print file...
8704 if ((fp
= cupsFileOpen(con
->filename
, "rb")) == NULL
)
8706 cupsdLogMessage(CUPSD_LOG_ERROR
,
8707 "Unable to open print file for job ticket - %s",
8713 * Skip the first line...
8716 if (cupsFileGets(fp
, line
, sizeof(line
)) == NULL
)
8718 cupsdLogMessage(CUPSD_LOG_ERROR
,
8719 "Unable to read from print file for job ticket - %s",
8725 if (strncmp(line
, "%!PS-Adobe-", 11) && strncmp(line
, "%PDF-", 5))
8728 * Not a DSC-compliant file, so no job ticket info will be available...
8736 * Read job ticket info from the file...
8742 while (cupsFileGets(fp
, line
, sizeof(line
)))
8745 * Stop at the first non-ticket line...
8748 if (strncmp(line
, "%cupsJobTicket:", 15))
8752 * Add the options to the option array...
8755 num_options
= cupsParseOptions(line
+ 15, num_options
, &options
);
8759 * Done with the file; see if we have any options...
8764 if (num_options
== 0)
8768 * OK, convert the options to an attribute list, and apply them to
8773 cupsEncodeOptions(ticket
, num_options
, options
);
8776 * See what the user wants to change.
8779 for (attr
= ticket
->attrs
; attr
; attr
= attr
->next
)
8781 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
8784 if (!strncmp(attr
->name
, "date-time-at-", 13) ||
8785 !strcmp(attr
->name
, "job-impressions-completed") ||
8786 !strcmp(attr
->name
, "job-media-sheets-completed") ||
8787 !strncmp(attr
->name
, "job-k-octets", 12) ||
8788 !strcmp(attr
->name
, "job-id") ||
8789 !strcmp(attr
->name
, "job-originating-host-name") ||
8790 !strcmp(attr
->name
, "job-originating-user-name") ||
8791 !strcmp(attr
->name
, "job-pages-completed") ||
8792 !strcmp(attr
->name
, "job-printer-uri") ||
8793 !strncmp(attr
->name
, "job-state", 9) ||
8794 !strcmp(attr
->name
, "job-uri") ||
8795 !strncmp(attr
->name
, "time-at-", 8))
8796 continue; /* Read-only attrs */
8798 if ((attr2
= ippFindAttribute(con
->request
, attr
->name
,
8799 IPP_TAG_ZERO
)) != NULL
)
8802 * Some other value; first free the old value...
8805 if (con
->request
->attrs
== attr2
)
8807 con
->request
->attrs
= attr2
->next
;
8812 for (prev2
= con
->request
->attrs
; prev2
; prev2
= prev2
->next
)
8813 if (prev2
->next
== attr2
)
8815 prev2
->next
= attr2
->next
;
8820 if (con
->request
->last
== attr2
)
8821 con
->request
->last
= prev2
;
8823 ippDeleteAttribute(NULL
, attr2
);
8827 * Add new option by copying it...
8830 ippCopyAttribute(con
->request
, attr
, 0);
8834 * Then free the attribute list and option array...
8838 cupsFreeOptions(num_options
, options
);
8843 * 'reject_jobs()' - Reject print jobs to a printer.
8847 reject_jobs(cupsd_client_t
*con
, /* I - Client connection */
8848 ipp_attribute_t
*uri
) /* I - Printer or class URI */
8850 http_status_t status
; /* Policy status */
8851 cups_ptype_t dtype
; /* Destination type (printer/class) */
8852 cupsd_printer_t
*printer
; /* Printer data */
8853 ipp_attribute_t
*attr
; /* printer-state-message text */
8856 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "reject_jobs(%p[%d], %s)", con
,
8857 con
->number
, uri
->values
[0].string
.text
);
8860 * Is the destination valid?
8863 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8869 send_ipp_status(con
, IPP_NOT_FOUND
,
8870 _("The printer or class does not exist."));
8878 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8880 send_http_error(con
, status
, printer
);
8885 * Reject jobs sent to the printer...
8888 printer
->accepting
= 0;
8890 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
8891 IPP_TAG_TEXT
)) == NULL
)
8892 strlcpy(printer
->state_message
, "Rejecting Jobs",
8893 sizeof(printer
->state_message
));
8895 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
8896 sizeof(printer
->state_message
));
8898 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
8899 "No longer accepting jobs.");
8901 if (dtype
& CUPS_PRINTER_CLASS
)
8903 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
8905 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" rejecting jobs (\"%s\").",
8906 printer
->name
, get_username(con
));
8910 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
8912 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" rejecting jobs (\"%s\").",
8913 printer
->name
, get_username(con
));
8917 * Everything was ok, so return OK status...
8920 con
->response
->request
.status
.status_code
= IPP_OK
;
8925 * 'release_held_new_jobs()' - Release pending/new jobs on a printer or class.
8929 release_held_new_jobs(
8930 cupsd_client_t
*con
, /* I - Connection */
8931 ipp_attribute_t
*uri
) /* I - Printer URI */
8933 http_status_t status
; /* Policy status */
8934 cups_ptype_t dtype
; /* Destination type (printer/class) */
8935 cupsd_printer_t
*printer
; /* Printer data */
8938 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_held_new_jobs(%p[%d], %s)", con
,
8939 con
->number
, uri
->values
[0].string
.text
);
8942 * Is the destination valid?
8945 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8951 send_ipp_status(con
, IPP_NOT_FOUND
,
8952 _("The printer or class does not exist."));
8960 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8962 send_http_error(con
, status
, printer
);
8967 * Hold pending/new jobs sent to the printer...
8970 printer
->holding_new_jobs
= 0;
8972 cupsdSetPrinterReasons(printer
, "-hold-new-jobs");
8974 if (dtype
& CUPS_PRINTER_CLASS
)
8975 cupsdLogMessage(CUPSD_LOG_INFO
,
8976 "Class \"%s\" now printing pending/new jobs (\"%s\").",
8977 printer
->name
, get_username(con
));
8979 cupsdLogMessage(CUPSD_LOG_INFO
,
8980 "Printer \"%s\" now printing pending/new jobs (\"%s\").",
8981 printer
->name
, get_username(con
));
8986 * Everything was ok, so return OK status...
8989 con
->response
->request
.status
.status_code
= IPP_OK
;
8994 * 'release_job()' - Release a held print job.
8998 release_job(cupsd_client_t
*con
, /* I - Client connection */
8999 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9001 ipp_attribute_t
*attr
; /* Current attribute */
9002 int jobid
; /* Job ID */
9003 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9004 username
[HTTP_MAX_URI
], /* Username portion of URI */
9005 host
[HTTP_MAX_URI
], /* Host portion of URI */
9006 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9007 int port
; /* Port portion of URI */
9008 cupsd_job_t
*job
; /* Job information */
9011 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_job(%p[%d], %s)", con
,
9012 con
->number
, uri
->values
[0].string
.text
);
9015 * See if we have a job URI or a printer URI...
9018 if (!strcmp(uri
->name
, "printer-uri"))
9021 * Got a printer URI; see if we also have a job-id attribute...
9024 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9025 IPP_TAG_INTEGER
)) == NULL
)
9027 send_ipp_status(con
, IPP_BAD_REQUEST
,
9028 _("Got a printer-uri attribute but no job-id."));
9032 jobid
= attr
->values
[0].integer
;
9037 * Got a job URI; parse it to get the job ID...
9040 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9041 sizeof(scheme
), username
, sizeof(username
), host
,
9042 sizeof(host
), &port
, resource
, sizeof(resource
));
9044 if (strncmp(resource
, "/jobs/", 6))
9050 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9051 uri
->values
[0].string
.text
);
9055 jobid
= atoi(resource
+ 6);
9059 * See if the job exists...
9062 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9065 * Nope - return a "not found" error...
9068 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9073 * See if job is "held"...
9076 if (job
->state_value
!= IPP_JOB_HELD
)
9079 * Nope - return a "not possible" error...
9082 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not held."), jobid
);
9087 * See if the job is owned by the requesting user...
9090 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9092 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9093 cupsdFindDest(job
->dest
));
9098 * Reset the job-hold-until value to "no-hold"...
9101 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9102 IPP_TAG_KEYWORD
)) == NULL
)
9103 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9107 ippSetValueTag(job
->attrs
, &attr
, IPP_TAG_KEYWORD
);
9108 ippSetString(job
->attrs
, &attr
, 0, "no-hold");
9110 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
9111 "Job job-hold-until value changed by user.");
9112 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
9116 * Release the job and return...
9119 cupsdReleaseJob(job
);
9121 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
9122 "Job released by user.");
9124 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Released by \"%s\".", username
);
9126 con
->response
->request
.status
.status_code
= IPP_OK
;
9133 * 'renew_subscription()' - Renew an existing subscription...
9138 cupsd_client_t
*con
, /* I - Client connection */
9139 int sub_id
) /* I - Subscription ID */
9141 http_status_t status
; /* Policy status */
9142 cupsd_subscription_t
*sub
; /* Subscription */
9143 ipp_attribute_t
*lease
; /* notify-lease-duration */
9146 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
9147 "renew_subscription(con=%p[%d], sub_id=%d)",
9148 con
, con
->number
, sub_id
);
9151 * Is the subscription ID valid?
9154 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
9157 * Bad subscription ID...
9160 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
9168 * Job subscriptions cannot be renewed...
9171 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9172 _("Job subscriptions cannot be renewed."));
9180 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
9182 con
, sub
->owner
)) != HTTP_OK
)
9184 send_http_error(con
, status
, sub
->dest
);
9189 * Renew the subscription...
9192 lease
= ippFindAttribute(con
->request
, "notify-lease-duration",
9195 sub
->lease
= lease
? lease
->values
[0].integer
: DefaultLeaseDuration
;
9197 if (MaxLeaseDuration
&& (sub
->lease
== 0 || sub
->lease
> MaxLeaseDuration
))
9199 cupsdLogMessage(CUPSD_LOG_INFO
,
9200 "renew_subscription: Limiting notify-lease-duration to "
9203 sub
->lease
= MaxLeaseDuration
;
9206 sub
->expire
= sub
->lease
? time(NULL
) + sub
->lease
: 0;
9208 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
9210 con
->response
->request
.status
.status_code
= IPP_OK
;
9212 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
9213 "notify-lease-duration", sub
->lease
);
9218 * 'restart_job()' - Restart an old print job.
9222 restart_job(cupsd_client_t
*con
, /* I - Client connection */
9223 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9225 ipp_attribute_t
*attr
; /* Current attribute */
9226 int jobid
; /* Job ID */
9227 cupsd_job_t
*job
; /* Job information */
9228 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9229 username
[HTTP_MAX_URI
], /* Username portion of URI */
9230 host
[HTTP_MAX_URI
], /* Host portion of URI */
9231 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9232 int port
; /* Port portion of URI */
9235 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "restart_job(%p[%d], %s)", con
,
9236 con
->number
, uri
->values
[0].string
.text
);
9239 * See if we have a job URI or a printer URI...
9242 if (!strcmp(uri
->name
, "printer-uri"))
9245 * Got a printer URI; see if we also have a job-id attribute...
9248 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9249 IPP_TAG_INTEGER
)) == NULL
)
9251 send_ipp_status(con
, IPP_BAD_REQUEST
,
9252 _("Got a printer-uri attribute but no job-id."));
9256 jobid
= attr
->values
[0].integer
;
9261 * Got a job URI; parse it to get the job ID...
9264 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9265 sizeof(scheme
), username
, sizeof(username
), host
,
9266 sizeof(host
), &port
, resource
, sizeof(resource
));
9268 if (strncmp(resource
, "/jobs/", 6))
9274 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9275 uri
->values
[0].string
.text
);
9279 jobid
= atoi(resource
+ 6);
9283 * See if the job exists...
9286 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9289 * Nope - return a "not found" error...
9292 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9297 * See if job is in any of the "completed" states...
9300 if (job
->state_value
<= IPP_JOB_PROCESSING
)
9303 * Nope - return a "not possible" error...
9306 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not complete."),
9312 * See if we have retained the job files...
9317 if (!job
->attrs
|| job
->num_files
== 0)
9320 * Nope - return a "not possible" error...
9323 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9324 _("Job #%d cannot be restarted - no files."), jobid
);
9329 * See if the job is owned by the requesting user...
9332 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9334 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9335 cupsdFindDest(job
->dest
));
9340 * See if the job-hold-until attribute is specified...
9343 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
9344 IPP_TAG_KEYWORD
)) == NULL
)
9345 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
9347 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
9350 * Return the job to a held state...
9353 cupsdLogJob(job
, CUPSD_LOG_DEBUG
,
9354 "Restarted by \"%s\" with job-hold-until=%s.",
9355 username
, attr
->values
[0].string
.text
);
9356 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
9358 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
,
9359 NULL
, job
, "Job restarted by user with job-hold-until=%s",
9360 attr
->values
[0].string
.text
);
9365 * Restart the job...
9368 cupsdRestartJob(job
);
9372 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Restarted by \"%s\".", username
);
9374 con
->response
->request
.status
.status_code
= IPP_OK
;
9379 * 'save_auth_info()' - Save authentication information for a job.
9384 cupsd_client_t
*con
, /* I - Client connection */
9385 cupsd_job_t
*job
, /* I - Job */
9386 ipp_attribute_t
*auth_info
) /* I - auth-info attribute, if any */
9388 int i
; /* Looping var */
9389 char filename
[1024]; /* Job authentication filename */
9390 cups_file_t
*fp
; /* Job authentication file */
9391 char line
[65536]; /* Line for file */
9392 cupsd_printer_t
*dest
; /* Destination printer/class */
9396 * This function saves the in-memory authentication information for
9397 * a job so that it can be used to authenticate with a remote host.
9398 * The information is stored in a file that is readable only by the
9399 * root user. The fields are Base-64 encoded, each on a separate line,
9400 * followed by random number (up to 1024) of newlines to limit the
9401 * amount of information that is exposed.
9403 * Because of the potential for exposing of authentication information,
9404 * this functionality is only enabled when running cupsd as root.
9406 * This caching only works for the Basic and BasicDigest authentication
9407 * types. Digest authentication cannot be cached this way, and in
9408 * the future Kerberos authentication may make all of this obsolete.
9410 * Authentication information is saved whenever an authenticated
9411 * Print-Job, Create-Job, or CUPS-Authenticate-Job operation is
9414 * This information is deleted after a job is completed or canceled,
9415 * so reprints may require subsequent re-authentication.
9421 if ((dest
= cupsdFindDest(job
->dest
)) == NULL
)
9425 * Create the authentication file and change permissions...
9428 snprintf(filename
, sizeof(filename
), "%s/a%05d", RequestRoot
, job
->id
);
9429 if ((fp
= cupsFileOpen(filename
, "w")) == NULL
)
9431 cupsdLogMessage(CUPSD_LOG_ERROR
,
9432 "Unable to save authentication info to \"%s\" - %s",
9433 filename
, strerror(errno
));
9437 fchown(cupsFileNumber(fp
), 0, 0);
9438 fchmod(cupsFileNumber(fp
), 0400);
9440 cupsFilePuts(fp
, "CUPSD-AUTH-V3\n");
9443 i
< (int)(sizeof(job
->auth_env
) / sizeof(job
->auth_env
[0]));
9445 cupsdClearString(job
->auth_env
+ i
);
9447 if (auth_info
&& auth_info
->num_values
== dest
->num_auth_info_required
)
9450 * Write 1 to 3 auth values...
9454 i
< auth_info
->num_values
&&
9455 i
< (int)(sizeof(job
->auth_env
) / sizeof(job
->auth_env
[0]));
9458 if (strcmp(dest
->auth_info_required
[i
], "negotiate"))
9460 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[i
].string
.text
, (int)strlen(auth_info
->values
[i
].string
.text
));
9461 cupsFilePutConf(fp
, dest
->auth_info_required
[i
], line
);
9464 cupsFilePutConf(fp
, dest
->auth_info_required
[i
],
9465 auth_info
->values
[i
].string
.text
);
9467 if (!strcmp(dest
->auth_info_required
[i
], "username"))
9468 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_USERNAME=%s",
9469 auth_info
->values
[i
].string
.text
);
9470 else if (!strcmp(dest
->auth_info_required
[i
], "domain"))
9471 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_DOMAIN=%s",
9472 auth_info
->values
[i
].string
.text
);
9473 else if (!strcmp(dest
->auth_info_required
[i
], "password"))
9474 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_PASSWORD=%s",
9475 auth_info
->values
[i
].string
.text
);
9476 else if (!strcmp(dest
->auth_info_required
[i
], "negotiate"))
9477 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_NEGOTIATE=%s",
9478 auth_info
->values
[i
].string
.text
);
9483 else if (auth_info
&& auth_info
->num_values
== 2 &&
9484 dest
->num_auth_info_required
== 1 &&
9485 !strcmp(dest
->auth_info_required
[0], "negotiate"))
9488 * Allow fallback to username+password for Kerberized queues...
9491 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[0].string
.text
, (int)strlen(auth_info
->values
[0].string
.text
));
9492 cupsFilePutConf(fp
, "username", line
);
9494 cupsdSetStringf(job
->auth_env
+ 0, "AUTH_USERNAME=%s",
9495 auth_info
->values
[0].string
.text
);
9497 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[1].string
.text
, (int)strlen(auth_info
->values
[1].string
.text
));
9498 cupsFilePutConf(fp
, "password", line
);
9500 cupsdSetStringf(job
->auth_env
+ 1, "AUTH_PASSWORD=%s",
9501 auth_info
->values
[1].string
.text
);
9503 else if (con
->username
[0])
9506 * Write the authenticated username...
9509 httpEncode64_2(line
, sizeof(line
), con
->username
, (int)strlen(con
->username
));
9510 cupsFilePutConf(fp
, "username", line
);
9512 cupsdSetStringf(job
->auth_env
+ 0, "AUTH_USERNAME=%s", con
->username
);
9515 * Write the authenticated password...
9518 httpEncode64_2(line
, sizeof(line
), con
->password
, (int)strlen(con
->password
));
9519 cupsFilePutConf(fp
, "password", line
);
9521 cupsdSetStringf(job
->auth_env
+ 1, "AUTH_PASSWORD=%s", con
->password
);
9525 if (con
->gss_uid
> 0)
9527 cupsFilePrintf(fp
, "uid %d\n", (int)con
->gss_uid
);
9528 cupsdSetStringf(&job
->auth_uid
, "AUTH_UID=%d", (int)con
->gss_uid
);
9530 #endif /* HAVE_GSSAPI */
9533 * Write a random number of newlines to the end of the file...
9536 for (i
= (CUPS_RAND() % 1024); i
>= 0; i
--)
9537 cupsFilePutChar(fp
, '\n');
9540 * Close the file and return...
9548 * 'send_document()' - Send a file to a printer or class.
9552 send_document(cupsd_client_t
*con
, /* I - Client connection */
9553 ipp_attribute_t
*uri
) /* I - Printer URI */
9555 ipp_attribute_t
*attr
; /* Current attribute */
9556 ipp_attribute_t
*format
; /* Request's document-format attribute */
9557 ipp_attribute_t
*jformat
; /* Job's document-format attribute */
9558 const char *default_format
;/* document-format-default value */
9559 int jobid
; /* Job ID number */
9560 cupsd_job_t
*job
; /* Current job */
9561 char job_uri
[HTTP_MAX_URI
],
9563 scheme
[HTTP_MAX_URI
],
9564 /* Method portion of URI */
9565 username
[HTTP_MAX_URI
],
9566 /* Username portion of URI */
9568 /* Host portion of URI */
9569 resource
[HTTP_MAX_URI
];
9570 /* Resource portion of URI */
9571 int port
; /* Port portion of URI */
9572 mime_type_t
*filetype
; /* Type of file */
9573 char super
[MIME_MAX_SUPER
],
9574 /* Supertype of file */
9575 type
[MIME_MAX_TYPE
],
9576 /* Subtype of file */
9577 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
9578 /* Textual name of mime type */
9579 char filename
[1024]; /* Job filename */
9580 cupsd_printer_t
*printer
; /* Current printer */
9581 struct stat fileinfo
; /* File information */
9582 int kbytes
; /* Size of file */
9583 int compression
; /* Type of compression */
9584 int start_job
; /* Start the job? */
9587 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "send_document(%p[%d], %s)", con
,
9588 con
->number
, uri
->values
[0].string
.text
);
9591 * See if we have a job URI or a printer URI...
9594 if (!strcmp(uri
->name
, "printer-uri"))
9597 * Got a printer URI; see if we also have a job-id attribute...
9600 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9601 IPP_TAG_INTEGER
)) == NULL
)
9603 send_ipp_status(con
, IPP_BAD_REQUEST
,
9604 _("Got a printer-uri attribute but no job-id."));
9608 jobid
= attr
->values
[0].integer
;
9613 * Got a job URI; parse it to get the job ID...
9616 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9617 sizeof(scheme
), username
, sizeof(username
), host
,
9618 sizeof(host
), &port
, resource
, sizeof(resource
));
9620 if (strncmp(resource
, "/jobs/", 6))
9626 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9627 uri
->values
[0].string
.text
);
9631 jobid
= atoi(resource
+ 6);
9635 * See if the job exists...
9638 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9641 * Nope - return a "not found" error...
9644 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9648 printer
= cupsdFindDest(job
->dest
);
9651 * See if the job is owned by the requesting user...
9654 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9656 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9657 cupsdFindDest(job
->dest
));
9662 * OK, see if the client is sending the document compressed - CUPS
9663 * only supports "none" and "gzip".
9666 compression
= CUPS_FILE_NONE
;
9668 if ((attr
= ippFindAttribute(con
->request
, "compression",
9669 IPP_TAG_KEYWORD
)) != NULL
)
9671 if (strcmp(attr
->values
[0].string
.text
, "none")
9673 && strcmp(attr
->values
[0].string
.text
, "gzip")
9674 #endif /* HAVE_LIBZ */
9677 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Unsupported compression \"%s\"."),
9678 attr
->values
[0].string
.text
);
9679 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
9680 "compression", NULL
, attr
->values
[0].string
.text
);
9685 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
9686 compression
= CUPS_FILE_GZIP
;
9687 #endif /* HAVE_LIBZ */
9691 * Do we have a file to print?
9694 if ((attr
= ippFindAttribute(con
->request
, "last-document",
9695 IPP_TAG_BOOLEAN
)) == NULL
)
9697 send_ipp_status(con
, IPP_BAD_REQUEST
,
9698 _("Missing last-document attribute in request."));
9705 * Check for an empty request with "last-document" set to true, which is
9706 * used to close an "open" job by RFC 2911, section 3.3.2.
9709 if (job
->num_files
> 0 && attr
->values
[0].boolean
)
9712 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file in print request."));
9717 * Is it a format we support?
9722 if ((format
= ippFindAttribute(con
->request
, "document-format",
9723 IPP_TAG_MIMETYPE
)) != NULL
)
9726 * Grab format from client...
9729 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%255[^;]",
9732 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"."),
9733 format
->values
[0].string
.text
);
9737 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format-supplied", NULL
, ippGetString(format
, 0, NULL
));
9739 else if ((default_format
= cupsGetOption("document-format",
9740 printer
->num_options
,
9741 printer
->options
)) != NULL
)
9744 * Use default document format...
9747 if (sscanf(default_format
, "%15[^/]/%255[^;]", super
, type
) != 2)
9749 send_ipp_status(con
, IPP_BAD_REQUEST
,
9750 _("Bad document-format-default \"%s\"."), default_format
);
9757 * No document format attribute? Auto-type it!
9760 strlcpy(super
, "application", sizeof(super
));
9761 strlcpy(type
, "octet-stream", sizeof(type
));
9764 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
9767 * Auto-type the file...
9770 ipp_attribute_t
*doc_name
; /* document-name attribute */
9773 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Auto-typing file...");
9775 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
9776 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
9777 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
9781 filetype
= mimeType(MimeDatabase
, super
, type
);
9784 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Request file type is %s/%s.",
9785 filetype
->super
, filetype
->type
);
9787 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
, filetype
->type
);
9788 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format-detected", NULL
, mimetype
);
9791 filetype
= mimeType(MimeDatabase
, super
, type
);
9796 * Replace the document-format attribute value with the auto-typed or
9800 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9803 if ((jformat
= ippFindAttribute(job
->attrs
, "document-format",
9804 IPP_TAG_MIMETYPE
)) != NULL
)
9805 ippSetString(job
->attrs
, &jformat
, 0, mimetype
);
9807 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
9808 "document-format", NULL
, mimetype
);
9812 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9813 _("Unsupported document-format \"%s/%s\"."), super
, type
);
9814 cupsdLogMessage(CUPSD_LOG_INFO
,
9815 "Hint: Do you have the raw file printing rules enabled?");
9818 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9819 "document-format", NULL
, format
->values
[0].string
.text
);
9824 if (printer
->filetypes
&& !cupsArrayFind(printer
->filetypes
, filetype
))
9826 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9829 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9830 _("Unsupported document-format \"%s\"."), mimetype
);
9832 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9833 "document-format", NULL
, mimetype
);
9839 * Add the file to the job...
9842 if (add_file(con
, job
, filetype
, compression
))
9845 if ((attr
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
)) != NULL
)
9846 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name-supplied", NULL
, ippGetString(attr
, 0, NULL
));
9848 if (stat(con
->filename
, &fileinfo
))
9851 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
9853 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
9855 job
->koctets
+= kbytes
;
9857 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets", IPP_TAG_INTEGER
)) != NULL
)
9858 attr
->values
[0].integer
+= kbytes
;
9860 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
, job
->num_files
);
9861 if (rename(con
->filename
, filename
))
9863 cupsdLogJob(job
, CUPSD_LOG_ERROR
, "Unable to rename job document file \"%s\": %s", filename
, strerror(errno
));
9865 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to rename job document file."));
9869 cupsdClearString(&con
->filename
);
9871 cupsdLogJob(job
, CUPSD_LOG_INFO
, "File of type %s/%s queued by \"%s\".",
9872 filetype
->super
, filetype
->type
, job
->username
);
9875 * Start the job if this is the last document...
9880 if ((attr
= ippFindAttribute(con
->request
, "last-document",
9881 IPP_TAG_BOOLEAN
)) != NULL
&&
9882 attr
->values
[0].boolean
)
9885 * See if we need to add the ending sheet...
9888 if (cupsdTimeoutJob(job
))
9891 if (job
->state_value
== IPP_JOB_STOPPED
)
9893 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9894 job
->state_value
= IPP_JOB_PENDING
;
9896 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
9898 else if (job
->state_value
== IPP_JOB_HELD
)
9900 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9901 IPP_TAG_KEYWORD
)) == NULL
)
9902 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9904 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9906 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9907 job
->state_value
= IPP_JOB_PENDING
;
9909 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
9912 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-hold-until-specified");
9916 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
9922 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9923 IPP_TAG_KEYWORD
)) == NULL
)
9924 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9926 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9928 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
9929 job
->state_value
= IPP_JOB_HELD
;
9930 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
9932 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-incoming");
9935 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
9942 * Fill in the response info...
9945 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
9946 con
->clientname
, con
->clientport
, "/jobs/%d", jobid
);
9947 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
9950 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", jobid
);
9952 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
9954 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons",
9955 NULL
, job
->reasons
->values
[0].string
.text
);
9957 con
->response
->request
.status
.status_code
= IPP_OK
;
9960 * Start the job if necessary...
9969 * 'send_http_error()' - Send a HTTP error back to the IPP client.
9974 cupsd_client_t
*con
, /* I - Client connection */
9975 http_status_t status
, /* I - HTTP status code */
9976 cupsd_printer_t
*printer
) /* I - Printer, if any */
9978 ipp_attribute_t
*uri
; /* Request URI, if any */
9981 if ((uri
= ippFindAttribute(con
->request
, "printer-uri",
9982 IPP_TAG_URI
)) == NULL
)
9983 uri
= ippFindAttribute(con
->request
, "job-uri", IPP_TAG_URI
);
9985 cupsdLogMessage(status
== HTTP_FORBIDDEN
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
9986 "[Client %d] Returning HTTP %s for %s (%s) from %s",
9987 con
->number
, httpStatus(status
),
9989 ippOpString(con
->request
->request
.op
.operation_id
) :
9991 uri
? uri
->values
[0].string
.text
: "no URI",
9992 con
->http
->hostname
);
9996 int auth_type
; /* Type of authentication required */
9999 auth_type
= CUPSD_AUTH_NONE
;
10001 if (status
== HTTP_UNAUTHORIZED
&&
10002 printer
->num_auth_info_required
> 0 &&
10003 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
10005 (con
->request
->request
.op
.operation_id
== IPP_PRINT_JOB
||
10006 con
->request
->request
.op
.operation_id
== IPP_CREATE_JOB
||
10007 con
->request
->request
.op
.operation_id
== CUPS_AUTHENTICATE_JOB
))
10010 * Creating and authenticating jobs requires Kerberos...
10013 auth_type
= CUPSD_AUTH_NEGOTIATE
;
10018 * Use policy/location-defined authentication requirements...
10021 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
10022 cupsd_location_t
*auth
; /* Pointer to authentication element */
10025 if (printer
->type
& CUPS_PRINTER_CLASS
)
10026 snprintf(resource
, sizeof(resource
), "/classes/%s", printer
->name
);
10028 snprintf(resource
, sizeof(resource
), "/printers/%s", printer
->name
);
10030 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
10031 auth
->type
== CUPSD_AUTH_NONE
)
10032 auth
= cupsdFindPolicyOp(printer
->op_policy_ptr
,
10034 con
->request
->request
.op
.operation_id
:
10039 if (auth
->type
== CUPSD_AUTH_DEFAULT
)
10040 auth_type
= cupsdDefaultAuthType();
10042 auth_type
= auth
->type
;
10046 cupsdSendError(con
, status
, auth_type
);
10049 cupsdSendError(con
, status
, CUPSD_AUTH_NONE
);
10051 ippDelete(con
->response
);
10052 con
->response
= NULL
;
10059 * 'send_ipp_status()' - Send a status back to the IPP client.
10063 send_ipp_status(cupsd_client_t
*con
, /* I - Client connection */
10064 ipp_status_t status
, /* I - IPP status code */
10065 const char *message
,/* I - Status message */
10066 ...) /* I - Additional args as needed */
10068 va_list ap
; /* Pointer to additional args */
10069 char formatted
[1024]; /* Formatted errror message */
10072 va_start(ap
, message
);
10073 vsnprintf(formatted
, sizeof(formatted
),
10074 _cupsLangString(con
->language
, message
), ap
);
10077 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s: %s",
10078 ippOpString(con
->request
->request
.op
.operation_id
),
10079 ippErrorString(status
), formatted
);
10081 con
->response
->request
.status
.status_code
= status
;
10083 if (ippFindAttribute(con
->response
, "attributes-charset",
10084 IPP_TAG_ZERO
) == NULL
)
10085 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
10086 "attributes-charset", NULL
, "utf-8");
10088 if (ippFindAttribute(con
->response
, "attributes-natural-language",
10089 IPP_TAG_ZERO
) == NULL
)
10090 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
10091 "attributes-natural-language", NULL
, DefaultLanguage
);
10093 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
10094 "status-message", NULL
, formatted
);
10099 * 'set_default()' - Set the default destination...
10103 set_default(cupsd_client_t
*con
, /* I - Client connection */
10104 ipp_attribute_t
*uri
) /* I - Printer URI */
10106 http_status_t status
; /* Policy status */
10107 cups_ptype_t dtype
; /* Destination type (printer/class) */
10108 cupsd_printer_t
*printer
, /* Printer */
10109 *oldprinter
; /* Old default printer */
10112 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_default(%p[%d], %s)", con
,
10113 con
->number
, uri
->values
[0].string
.text
);
10116 * Is the destination valid?
10119 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10125 send_ipp_status(con
, IPP_NOT_FOUND
,
10126 _("The printer or class does not exist."));
10134 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
10136 send_http_error(con
, status
, NULL
);
10141 * Set it as the default...
10144 oldprinter
= DefaultPrinter
;
10145 DefaultPrinter
= printer
;
10148 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, oldprinter
, NULL
,
10149 "%s is no longer the default printer.", oldprinter
->name
);
10151 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
10152 "%s is now the default printer.", printer
->name
);
10154 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
| CUPSD_DIRTY_CLASSES
|
10155 CUPSD_DIRTY_PRINTCAP
);
10157 cupsdLogMessage(CUPSD_LOG_INFO
,
10158 "Default destination set to \"%s\" by \"%s\".",
10159 printer
->name
, get_username(con
));
10162 * Everything was ok, so return OK status...
10165 con
->response
->request
.status
.status_code
= IPP_OK
;
10170 * 'set_job_attrs()' - Set job attributes.
10174 set_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
10175 ipp_attribute_t
*uri
) /* I - Job URI */
10177 ipp_attribute_t
*attr
, /* Current attribute */
10178 *attr2
; /* Job attribute */
10179 int jobid
; /* Job ID */
10180 cupsd_job_t
*job
; /* Current job */
10181 char scheme
[HTTP_MAX_URI
],
10182 /* Method portion of URI */
10183 username
[HTTP_MAX_URI
],
10184 /* Username portion of URI */
10185 host
[HTTP_MAX_URI
],
10186 /* Host portion of URI */
10187 resource
[HTTP_MAX_URI
];
10188 /* Resource portion of URI */
10189 int port
; /* Port portion of URI */
10190 int event
; /* Events? */
10191 int check_jobs
; /* Check jobs? */
10194 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_job_attrs(%p[%d], %s)", con
,
10195 con
->number
, uri
->values
[0].string
.text
);
10198 * Start with "everything is OK" status...
10201 con
->response
->request
.status
.status_code
= IPP_OK
;
10204 * See if we have a job URI or a printer URI...
10207 if (!strcmp(uri
->name
, "printer-uri"))
10210 * Got a printer URI; see if we also have a job-id attribute...
10213 if ((attr
= ippFindAttribute(con
->request
, "job-id",
10214 IPP_TAG_INTEGER
)) == NULL
)
10216 send_ipp_status(con
, IPP_BAD_REQUEST
,
10217 _("Got a printer-uri attribute but no job-id."));
10221 jobid
= attr
->values
[0].integer
;
10226 * Got a job URI; parse it to get the job ID...
10229 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
10230 sizeof(scheme
), username
, sizeof(username
), host
,
10231 sizeof(host
), &port
, resource
, sizeof(resource
));
10233 if (strncmp(resource
, "/jobs/", 6))
10239 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
10240 uri
->values
[0].string
.text
);
10244 jobid
= atoi(resource
+ 6);
10248 * See if the job exists...
10251 if ((job
= cupsdFindJob(jobid
)) == NULL
)
10254 * Nope - return a "not found" error...
10257 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
10262 * See if the job has been completed...
10265 if (job
->state_value
> IPP_JOB_STOPPED
)
10268 * Return a "not-possible" error...
10271 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10272 _("Job #%d is finished and cannot be altered."), jobid
);
10277 * See if the job is owned by the requesting user...
10280 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10282 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
10283 cupsdFindDest(job
->dest
));
10288 * See what the user wants to change.
10296 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10298 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
10301 if (!strcmp(attr
->name
, "attributes-charset") ||
10302 !strcmp(attr
->name
, "attributes-natural-language") ||
10303 !strncmp(attr
->name
, "date-time-at-", 13) ||
10304 !strncmp(attr
->name
, "document-compression", 20) ||
10305 !strncmp(attr
->name
, "document-format", 15) ||
10306 !strcmp(attr
->name
, "job-detailed-status-messages") ||
10307 !strcmp(attr
->name
, "job-document-access-errors") ||
10308 !strcmp(attr
->name
, "job-id") ||
10309 !strcmp(attr
->name
, "job-impressions-completed") ||
10310 !strcmp(attr
->name
, "job-k-octets-completed") ||
10311 !strcmp(attr
->name
, "job-media-sheets-completed") ||
10312 !strcmp(attr
->name
, "job-originating-host-name") ||
10313 !strcmp(attr
->name
, "job-originating-user-name") ||
10314 !strcmp(attr
->name
, "job-pages-completed") ||
10315 !strcmp(attr
->name
, "job-printer-up-time") ||
10316 !strcmp(attr
->name
, "job-printer-uri") ||
10317 !strcmp(attr
->name
, "job-sheets") ||
10318 !strcmp(attr
->name
, "job-state-message") ||
10319 !strcmp(attr
->name
, "job-state-reasons") ||
10320 !strcmp(attr
->name
, "job-uri") ||
10321 !strcmp(attr
->name
, "number-of-documents") ||
10322 !strcmp(attr
->name
, "number-of-intervening-jobs") ||
10323 !strcmp(attr
->name
, "output-device-assigned") ||
10324 !strncmp(attr
->name
, "time-at-", 8))
10330 send_ipp_status(con
, IPP_ATTRIBUTES_NOT_SETTABLE
,
10331 _("%s cannot be changed."), attr
->name
);
10333 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
10334 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
10338 if (!strcmp(attr
->name
, "job-priority"))
10341 * Change the job priority...
10344 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10346 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-priority value."));
10348 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
10349 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
10351 else if (job
->state_value
>= IPP_JOB_PROCESSING
)
10353 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10354 _("Job is completed and cannot be changed."));
10357 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10359 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-priority to %d",
10360 attr
->values
[0].integer
);
10361 cupsdSetJobPriority(job
, attr
->values
[0].integer
);
10364 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
|
10365 CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
;
10368 else if (!strcmp(attr
->name
, "job-state"))
10371 * Change the job state...
10374 if (attr
->value_tag
!= IPP_TAG_ENUM
)
10376 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-state value."));
10378 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
10379 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
10383 switch (attr
->values
[0].integer
)
10385 case IPP_JOB_PENDING
:
10386 case IPP_JOB_HELD
:
10387 if (job
->state_value
> IPP_JOB_HELD
)
10389 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10390 _("Job state cannot be changed."));
10393 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10395 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10396 attr
->values
[0].integer
);
10397 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
, CUPSD_JOB_DEFAULT
, "Job state changed by \"%s\"", username
);
10402 case IPP_JOB_PROCESSING
:
10403 case IPP_JOB_STOPPED
:
10404 if (job
->state_value
!= attr
->values
[0].integer
)
10406 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10407 _("Job state cannot be changed."));
10412 case IPP_JOB_CANCELED
:
10413 case IPP_JOB_ABORTED
:
10414 case IPP_JOB_COMPLETED
:
10415 if (job
->state_value
> IPP_JOB_PROCESSING
)
10417 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10418 _("Job state cannot be changed."));
10421 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10423 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10424 attr
->values
[0].integer
);
10425 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
,
10427 "Job state changed by \"%s\"", username
);
10434 else if (con
->response
->request
.status
.status_code
!= IPP_OK
)
10436 else if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10437 IPP_TAG_ZERO
)) != NULL
)
10440 * Some other value; first free the old value...
10443 if (job
->attrs
->prev
)
10444 job
->attrs
->prev
->next
= attr2
->next
;
10446 job
->attrs
->attrs
= attr2
->next
;
10448 if (job
->attrs
->last
== attr2
)
10449 job
->attrs
->last
= job
->attrs
->prev
;
10451 ippDeleteAttribute(NULL
, attr2
);
10454 * Then copy the attribute...
10457 ippCopyAttribute(job
->attrs
, attr
, 0);
10460 * See if the job-name or job-hold-until is being changed.
10463 if (!strcmp(attr
->name
, "job-hold-until"))
10465 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-hold-until to %s",
10466 attr
->values
[0].string
.text
);
10467 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
10469 if (!strcmp(attr
->values
[0].string
.text
, "no-hold"))
10471 cupsdReleaseJob(job
);
10475 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
,
10476 "Job held by \"%s\".", username
);
10478 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
;
10481 else if (attr
->value_tag
== IPP_TAG_DELETEATTR
)
10484 * Delete the attribute...
10487 if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10488 IPP_TAG_ZERO
)) != NULL
)
10490 if (job
->attrs
->prev
)
10491 job
->attrs
->prev
->next
= attr2
->next
;
10493 job
->attrs
->attrs
= attr2
->next
;
10495 if (attr2
== job
->attrs
->last
)
10496 job
->attrs
->last
= job
->attrs
->prev
;
10498 ippDeleteAttribute(NULL
, attr2
);
10500 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10506 * Add new option by copying it...
10509 ippCopyAttribute(job
->attrs
, attr
, 0);
10511 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10520 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10523 * Send events as needed...
10526 if (event
& CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
)
10527 cupsdAddEvent(CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
,
10528 cupsdFindDest(job
->dest
), job
,
10529 "Job priority changed by user.");
10531 if (event
& CUPSD_EVENT_JOB_STATE
)
10532 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
10533 job
->state_value
== IPP_JOB_HELD
?
10534 "Job held by user." : "Job restarted by user.");
10536 if (event
& CUPSD_EVENT_JOB_CONFIG_CHANGED
)
10537 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
10538 "Job options changed by user.");
10541 * Start jobs if possible...
10550 * 'set_printer_attrs()' - Set printer attributes.
10554 set_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
10555 ipp_attribute_t
*uri
) /* I - Printer */
10557 http_status_t status
; /* Policy status */
10558 cups_ptype_t dtype
; /* Destination type (printer/class) */
10559 cupsd_printer_t
*printer
; /* Printer/class */
10560 ipp_attribute_t
*attr
; /* Printer attribute */
10561 int changed
= 0; /* Was anything changed? */
10564 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_attrs(%p[%d], %s)", con
,
10565 con
->number
, uri
->values
[0].string
.text
);
10568 * Is the destination valid?
10571 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10577 send_ipp_status(con
, IPP_NOT_FOUND
,
10578 _("The printer or class does not exist."));
10586 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10588 send_http_error(con
, status
, printer
);
10593 * Return a list of attributes that can be set via Set-Printer-Attributes.
10596 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
10597 IPP_TAG_TEXT
)) != NULL
)
10599 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
10603 if ((attr
= ippFindAttribute(con
->request
, "printer-geo-location", IPP_TAG_URI
)) != NULL
&& !strncmp(attr
->values
[0].string
.text
, "geo:", 4))
10605 cupsdSetString(&printer
->geo_location
, attr
->values
[0].string
.text
);
10609 if ((attr
= ippFindAttribute(con
->request
, "printer-organization", IPP_TAG_TEXT
)) != NULL
)
10611 cupsdSetString(&printer
->organization
, attr
->values
[0].string
.text
);
10615 if ((attr
= ippFindAttribute(con
->request
, "printer-organizational-unit", IPP_TAG_TEXT
)) != NULL
)
10617 cupsdSetString(&printer
->organizational_unit
, attr
->values
[0].string
.text
);
10621 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
10622 IPP_TAG_TEXT
)) != NULL
)
10624 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
10629 * Update the printer attributes and return...
10634 printer
->config_time
= time(NULL
);
10636 cupsdSetPrinterAttrs(printer
);
10637 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
10639 cupsdAddEvent(CUPSD_EVENT_PRINTER_CONFIG
, printer
, NULL
,
10640 "Printer \"%s\" description or location changed by \"%s\".",
10641 printer
->name
, get_username(con
));
10643 cupsdLogMessage(CUPSD_LOG_INFO
,
10644 "Printer \"%s\" description or location changed by \"%s\".",
10645 printer
->name
, get_username(con
));
10648 con
->response
->request
.status
.status_code
= IPP_OK
;
10653 * 'set_printer_defaults()' - Set printer default options from a request.
10656 static int /* O - 1 on success, 0 on failure */
10657 set_printer_defaults(
10658 cupsd_client_t
*con
, /* I - Client connection */
10659 cupsd_printer_t
*printer
) /* I - Printer */
10661 int i
; /* Looping var */
10662 ipp_attribute_t
*attr
; /* Current attribute */
10663 size_t namelen
; /* Length of attribute name */
10664 char name
[256], /* New attribute name */
10665 value
[256]; /* String version of integer attrs */
10668 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10671 * Skip non-printer attributes...
10674 if (attr
->group_tag
!= IPP_TAG_PRINTER
|| !attr
->name
)
10677 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_defaults: %s", attr
->name
);
10679 if (!strcmp(attr
->name
, "job-sheets-default"))
10682 * Only allow keywords and names...
10685 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10689 * Only allow job-sheets-default to be set when running without a
10690 * system high classification level...
10693 if (Classification
)
10696 cupsdSetString(&printer
->job_sheets
[0], attr
->values
[0].string
.text
);
10698 if (attr
->num_values
> 1)
10699 cupsdSetString(&printer
->job_sheets
[1], attr
->values
[1].string
.text
);
10701 cupsdSetString(&printer
->job_sheets
[1], "none");
10703 else if (!strcmp(attr
->name
, "requesting-user-name-allowed"))
10705 cupsdFreeStrings(&(printer
->users
));
10707 printer
->deny_users
= 0;
10709 if (attr
->value_tag
== IPP_TAG_NAME
&&
10710 (attr
->num_values
> 1 ||
10711 strcmp(attr
->values
[0].string
.text
, "all")))
10713 for (i
= 0; i
< attr
->num_values
; i
++)
10714 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
10717 else if (!strcmp(attr
->name
, "requesting-user-name-denied"))
10719 cupsdFreeStrings(&(printer
->users
));
10721 printer
->deny_users
= 1;
10723 if (attr
->value_tag
== IPP_TAG_NAME
&&
10724 (attr
->num_values
> 1 ||
10725 strcmp(attr
->values
[0].string
.text
, "none")))
10727 for (i
= 0; i
< attr
->num_values
; i
++)
10728 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
10731 else if (!strcmp(attr
->name
, "job-quota-period"))
10733 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10736 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-quota-period to %d...",
10737 attr
->values
[0].integer
);
10738 cupsdFreeQuotas(printer
);
10740 printer
->quota_period
= attr
->values
[0].integer
;
10742 else if (!strcmp(attr
->name
, "job-k-limit"))
10744 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10747 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-k-limit to %d...",
10748 attr
->values
[0].integer
);
10749 cupsdFreeQuotas(printer
);
10751 printer
->k_limit
= attr
->values
[0].integer
;
10753 else if (!strcmp(attr
->name
, "job-page-limit"))
10755 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10758 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-page-limit to %d...",
10759 attr
->values
[0].integer
);
10760 cupsdFreeQuotas(printer
);
10762 printer
->page_limit
= attr
->values
[0].integer
;
10764 else if (!strcmp(attr
->name
, "printer-op-policy"))
10766 cupsd_policy_t
*p
; /* Policy */
10769 if (attr
->value_tag
!= IPP_TAG_NAME
)
10772 if ((p
= cupsdFindPolicy(attr
->values
[0].string
.text
)) != NULL
)
10774 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10775 "Setting printer-op-policy to \"%s\"...",
10776 attr
->values
[0].string
.text
);
10777 cupsdSetString(&printer
->op_policy
, attr
->values
[0].string
.text
);
10778 printer
->op_policy_ptr
= p
;
10782 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10783 _("Unknown printer-op-policy \"%s\"."),
10784 attr
->values
[0].string
.text
);
10788 else if (!strcmp(attr
->name
, "printer-error-policy"))
10790 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10793 if (strcmp(attr
->values
[0].string
.text
, "retry-current-job") &&
10794 ((printer
->type
& CUPS_PRINTER_CLASS
) ||
10795 (strcmp(attr
->values
[0].string
.text
, "abort-job") &&
10796 strcmp(attr
->values
[0].string
.text
, "retry-job") &&
10797 strcmp(attr
->values
[0].string
.text
, "stop-printer"))))
10799 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10800 _("Unknown printer-error-policy \"%s\"."),
10801 attr
->values
[0].string
.text
);
10805 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10806 "Setting printer-error-policy to \"%s\"...",
10807 attr
->values
[0].string
.text
);
10808 cupsdSetString(&printer
->error_policy
, attr
->values
[0].string
.text
);
10812 * Skip any other non-default attributes...
10815 namelen
= strlen(attr
->name
);
10816 if (namelen
< 9 || strcmp(attr
->name
+ namelen
- 8, "-default") ||
10817 namelen
> (sizeof(name
) - 1) || attr
->num_values
!= 1)
10821 * OK, anything else must be a user-defined default...
10824 strlcpy(name
, attr
->name
, sizeof(name
));
10825 name
[namelen
- 8] = '\0'; /* Strip "-default" */
10827 switch (attr
->value_tag
)
10829 case IPP_TAG_DELETEATTR
:
10830 printer
->num_options
= cupsRemoveOption(name
,
10831 printer
->num_options
,
10832 &(printer
->options
));
10833 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10834 "Deleting %s", attr
->name
);
10837 case IPP_TAG_NAME
:
10838 case IPP_TAG_TEXT
:
10839 case IPP_TAG_KEYWORD
:
10841 printer
->num_options
= cupsAddOption(name
,
10842 attr
->values
[0].string
.text
,
10843 printer
->num_options
,
10844 &(printer
->options
));
10845 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10846 "Setting %s to \"%s\"...", attr
->name
,
10847 attr
->values
[0].string
.text
);
10850 case IPP_TAG_BOOLEAN
:
10851 printer
->num_options
= cupsAddOption(name
,
10852 attr
->values
[0].boolean
?
10854 printer
->num_options
,
10855 &(printer
->options
));
10856 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10857 "Setting %s to %s...", attr
->name
,
10858 attr
->values
[0].boolean
? "true" : "false");
10861 case IPP_TAG_INTEGER
:
10862 case IPP_TAG_ENUM
:
10863 sprintf(value
, "%d", attr
->values
[0].integer
);
10864 printer
->num_options
= cupsAddOption(name
, value
,
10865 printer
->num_options
,
10866 &(printer
->options
));
10867 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10868 "Setting %s to %s...", attr
->name
, value
);
10871 case IPP_TAG_RANGE
:
10872 sprintf(value
, "%d-%d", attr
->values
[0].range
.lower
,
10873 attr
->values
[0].range
.upper
);
10874 printer
->num_options
= cupsAddOption(name
, value
,
10875 printer
->num_options
,
10876 &(printer
->options
));
10877 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10878 "Setting %s to %s...", attr
->name
, value
);
10881 case IPP_TAG_RESOLUTION
:
10882 sprintf(value
, "%dx%d%s", attr
->values
[0].resolution
.xres
,
10883 attr
->values
[0].resolution
.yres
,
10884 attr
->values
[0].resolution
.units
== IPP_RES_PER_INCH
?
10886 printer
->num_options
= cupsAddOption(name
, value
,
10887 printer
->num_options
,
10888 &(printer
->options
));
10889 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10890 "Setting %s to %s...", attr
->name
, value
);
10894 /* Do nothing for other values */
10904 * 'start_printer()' - Start a printer.
10908 start_printer(cupsd_client_t
*con
, /* I - Client connection */
10909 ipp_attribute_t
*uri
) /* I - Printer URI */
10911 int i
; /* Temporary variable */
10912 http_status_t status
; /* Policy status */
10913 cups_ptype_t dtype
; /* Destination type (printer/class) */
10914 cupsd_printer_t
*printer
; /* Printer data */
10917 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_printer(%p[%d], %s)", con
,
10918 con
->number
, uri
->values
[0].string
.text
);
10921 * Is the destination valid?
10924 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10930 send_ipp_status(con
, IPP_NOT_FOUND
,
10931 _("The printer or class does not exist."));
10939 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10941 send_http_error(con
, status
, printer
);
10946 * Start the printer...
10949 printer
->state_message
[0] = '\0';
10951 cupsdStartPrinter(printer
, 1);
10953 if (dtype
& CUPS_PRINTER_CLASS
)
10954 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" started by \"%s\".",
10955 printer
->name
, get_username(con
));
10957 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" started by \"%s\".",
10958 printer
->name
, get_username(con
));
10966 if ((i
= check_quotas(con
, printer
)) < 0)
10968 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
10973 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
10978 * Everything was ok, so return OK status...
10981 con
->response
->request
.status
.status_code
= IPP_OK
;
10986 * 'stop_printer()' - Stop a printer.
10990 stop_printer(cupsd_client_t
*con
, /* I - Client connection */
10991 ipp_attribute_t
*uri
) /* I - Printer URI */
10993 http_status_t status
; /* Policy status */
10994 cups_ptype_t dtype
; /* Destination type (printer/class) */
10995 cupsd_printer_t
*printer
; /* Printer data */
10996 ipp_attribute_t
*attr
; /* printer-state-message attribute */
10999 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "stop_printer(%p[%d], %s)", con
,
11000 con
->number
, uri
->values
[0].string
.text
);
11003 * Is the destination valid?
11006 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11012 send_ipp_status(con
, IPP_NOT_FOUND
,
11013 _("The printer or class does not exist."));
11021 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11023 send_http_error(con
, status
, printer
);
11028 * Stop the printer...
11031 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
11032 IPP_TAG_TEXT
)) == NULL
)
11033 strlcpy(printer
->state_message
, "Paused", sizeof(printer
->state_message
));
11036 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
11037 sizeof(printer
->state_message
));
11040 cupsdStopPrinter(printer
, 1);
11042 if (dtype
& CUPS_PRINTER_CLASS
)
11043 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" stopped by \"%s\".",
11044 printer
->name
, get_username(con
));
11046 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" stopped by \"%s\".",
11047 printer
->name
, get_username(con
));
11050 * Everything was ok, so return OK status...
11053 con
->response
->request
.status
.status_code
= IPP_OK
;
11058 * 'url_encode_attr()' - URL-encode a string attribute.
11062 url_encode_attr(ipp_attribute_t
*attr
, /* I - Attribute */
11063 char *buffer
,/* I - String buffer */
11064 size_t bufsize
)/* I - Size of buffer */
11066 int i
; /* Looping var */
11067 char *bufptr
, /* Pointer into buffer */
11068 *bufend
; /* End of buffer */
11071 strlcpy(buffer
, attr
->name
, bufsize
);
11072 bufptr
= buffer
+ strlen(buffer
);
11073 bufend
= buffer
+ bufsize
- 1;
11075 for (i
= 0; i
< attr
->num_values
; i
++)
11077 if (bufptr
>= bufend
)
11085 if (bufptr
>= bufend
)
11090 bufptr
= url_encode_string(attr
->values
[i
].string
.text
, bufptr
, (size_t)(bufend
- bufptr
+ 1));
11092 if (bufptr
>= bufend
)
11103 * 'url_encode_string()' - URL-encode a string.
11106 static char * /* O - End of string */
11107 url_encode_string(const char *s
, /* I - String */
11108 char *buffer
, /* I - String buffer */
11109 size_t bufsize
) /* I - Size of buffer */
11111 char *bufptr
, /* Pointer into buffer */
11112 *bufend
; /* End of buffer */
11113 static const char *hex
= "0123456789ABCDEF";
11118 bufend
= buffer
+ bufsize
- 1;
11120 while (*s
&& bufptr
< bufend
)
11122 if (*s
== ' ' || *s
== '%' || *s
== '+')
11124 if (bufptr
>= (bufend
- 2))
11128 *bufptr
++ = hex
[(*s
>> 4) & 15];
11129 *bufptr
++ = hex
[*s
& 15];
11133 else if (*s
== '\'' || *s
== '\\')
11135 if (bufptr
>= (bufend
- 1))
11152 * 'user_allowed()' - See if a user is allowed to print to a queue.
11155 static int /* O - 0 if not allowed, 1 if allowed */
11156 user_allowed(cupsd_printer_t
*p
, /* I - Printer or class */
11157 const char *username
) /* I - Username */
11159 struct passwd
*pw
; /* User password data */
11160 char baseuser
[256], /* Base username */
11161 *baseptr
, /* Pointer to "@" in base username */
11162 *name
; /* Current user name */
11165 if (cupsArrayCount(p
->users
) == 0)
11168 if (!strcmp(username
, "root"))
11171 if (strchr(username
, '@'))
11174 * Strip @REALM for username check...
11177 strlcpy(baseuser
, username
, sizeof(baseuser
));
11179 if ((baseptr
= strchr(baseuser
, '@')) != NULL
)
11182 username
= baseuser
;
11185 pw
= getpwnam(username
);
11188 for (name
= (char *)cupsArrayFirst(p
->users
);
11190 name
= (char *)cupsArrayNext(p
->users
))
11192 if (name
[0] == '@')
11195 * Check group membership...
11198 if (cupsdCheckGroup(username
, pw
, name
+ 1))
11201 else if (name
[0] == '#')
11207 if (cupsdCheckGroup(username
, pw
, name
))
11210 else if (!_cups_strcasecmp(username
, name
))
11214 return ((name
!= NULL
) != p
->deny_users
);
11219 * 'validate_job()' - Validate printer options and destination.
11223 validate_job(cupsd_client_t
*con
, /* I - Client connection */
11224 ipp_attribute_t
*uri
) /* I - Printer URI */
11226 http_status_t status
; /* Policy status */
11227 ipp_attribute_t
*attr
; /* Current attribute */
11229 ipp_attribute_t
*auth_info
; /* auth-info attribute */
11230 #endif /* HAVE_SSL */
11231 ipp_attribute_t
*format
, /* Document-format attribute */
11232 *name
; /* Job-name attribute */
11233 cups_ptype_t dtype
; /* Destination type (printer/class) */
11234 char super
[MIME_MAX_SUPER
],
11235 /* Supertype of file */
11236 type
[MIME_MAX_TYPE
];
11237 /* Subtype of file */
11238 cupsd_printer_t
*printer
; /* Printer */
11241 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_job(%p[%d], %s)", con
,
11242 con
->number
, uri
->values
[0].string
.text
);
11245 * OK, see if the client is sending the document compressed - CUPS
11246 * doesn't support compression yet...
11249 if ((attr
= ippFindAttribute(con
->request
, "compression",
11250 IPP_TAG_KEYWORD
)) != NULL
)
11252 if (strcmp(attr
->values
[0].string
.text
, "none")
11254 && strcmp(attr
->values
[0].string
.text
, "gzip")
11255 #endif /* HAVE_LIBZ */
11258 send_ipp_status(con
, IPP_ATTRIBUTES
,
11259 _("Unsupported 'compression' value \"%s\"."),
11260 attr
->values
[0].string
.text
);
11261 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
11262 "compression", NULL
, attr
->values
[0].string
.text
);
11268 * Is it a format we support?
11271 if ((format
= ippFindAttribute(con
->request
, "document-format",
11272 IPP_TAG_MIMETYPE
)) != NULL
)
11274 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%255[^;]",
11277 send_ipp_status(con
, IPP_BAD_REQUEST
,
11278 _("Bad 'document-format' value \"%s\"."),
11279 format
->values
[0].string
.text
);
11283 if ((strcmp(super
, "application") || strcmp(type
, "octet-stream")) &&
11284 !mimeType(MimeDatabase
, super
, type
))
11286 cupsdLogMessage(CUPSD_LOG_INFO
,
11287 "Hint: Do you have the raw file printing rules enabled?");
11288 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
11289 _("Unsupported 'document-format' value \"%s\"."),
11290 format
->values
[0].string
.text
);
11291 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
11292 "document-format", NULL
, format
->values
[0].string
.text
);
11298 * Is the job-name valid?
11301 if ((name
= ippFindAttribute(con
->request
, "job-name", IPP_TAG_ZERO
)) != NULL
)
11303 int bad_name
= 0; /* Is the job-name value bad? */
11305 if ((name
->value_tag
!= IPP_TAG_NAME
&& name
->value_tag
!= IPP_TAG_NAMELANG
) ||
11306 name
->num_values
!= 1)
11313 * Validate that job-name conforms to RFC 5198 (Network Unicode) and
11314 * IPP Everywhere requirements for "name" values...
11317 const unsigned char *nameptr
; /* Pointer into "job-name" attribute */
11319 for (nameptr
= (unsigned char *)name
->values
[0].string
.text
;
11323 if (*nameptr
< ' ' && *nameptr
!= '\t')
11325 else if (*nameptr
== 0x7f)
11327 else if ((*nameptr
& 0xe0) == 0xc0)
11329 if ((nameptr
[1] & 0xc0) != 0x80)
11334 else if ((*nameptr
& 0xf0) == 0xe0)
11336 if ((nameptr
[1] & 0xc0) != 0x80 ||
11337 (nameptr
[2] & 0xc0) != 0x80)
11342 else if ((*nameptr
& 0xf8) == 0xf0)
11344 if ((nameptr
[1] & 0xc0) != 0x80 ||
11345 (nameptr
[2] & 0xc0) != 0x80 ||
11346 (nameptr
[3] & 0xc0) != 0x80)
11351 else if (*nameptr
& 0x80)
11361 if (StrictConformance
)
11363 send_ipp_status(con
, IPP_ATTRIBUTES
,
11364 _("Unsupported 'job-name' value."));
11365 ippCopyAttribute(con
->response
, name
, 0);
11370 cupsdLogMessage(CUPSD_LOG_WARN
,
11371 "Unsupported 'job-name' value, deleting from request.");
11372 ippDeleteAttribute(con
->request
, name
);
11378 * Is the destination valid?
11381 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11387 send_ipp_status(con
, IPP_NOT_FOUND
,
11388 _("The printer or class does not exist."));
11397 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
11398 #endif /* HAVE_SSL */
11400 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11402 send_http_error(con
, status
, printer
);
11405 else if (printer
->num_auth_info_required
== 1 &&
11406 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
11409 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
11413 else if (auth_info
&& !con
->http
->tls
&&
11414 !httpAddrLocalhost(con
->http
->hostaddr
))
11417 * Require encryption of auth-info over non-local connections...
11420 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
11423 #endif /* HAVE_SSL */
11426 * Everything was ok, so return OK status...
11429 con
->response
->request
.status
.status_code
= IPP_OK
;
11434 * 'validate_name()' - Make sure the printer name only contains valid chars.
11437 static int /* O - 0 if name is no good, 1 if good */
11438 validate_name(const char *name
) /* I - Name to check */
11440 const char *ptr
; /* Pointer into name */
11444 * Scan the whole name...
11447 for (ptr
= name
; *ptr
; ptr
++)
11448 if ((*ptr
> 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
11452 * All the characters are good; validate the length, too...
11455 return ((ptr
- name
) < 128);
11460 * 'validate_user()' - Validate the user for the request.
11463 static int /* O - 1 if permitted, 0 otherwise */
11464 validate_user(cupsd_job_t
*job
, /* I - Job */
11465 cupsd_client_t
*con
, /* I - Client connection */
11466 const char *owner
, /* I - Owner of job/resource */
11467 char *username
, /* O - Authenticated username */
11468 size_t userlen
) /* I - Length of username */
11470 cupsd_printer_t
*printer
; /* Printer for job */
11473 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
);
11476 * Validate input...
11479 if (!con
|| !owner
|| !username
|| userlen
<= 0)
11483 * Get the best authenticated username that is available.
11486 strlcpy(username
, get_username(con
), userlen
);
11489 * Check the username against the owner...
11492 printer
= cupsdFindDest(job
->dest
);
11494 return (cupsdCheckPolicy(printer
? printer
->op_policy_ptr
: DefaultPolicyPtr
,
11495 con
, owner
) == HTTP_OK
);