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 _cupsRWLockWrite(&printer
->lock
);
5365 if ((!printer
->info
|| !*(printer
->info
)) && (attr
= ippFindAttribute(response
, "printer-info", IPP_TAG_TEXT
)) != NULL
)
5366 cupsdSetString(&printer
->info
, ippGetString(attr
, 0, NULL
));
5368 if ((!printer
->location
|| !*(printer
->location
)) && (attr
= ippFindAttribute(response
, "printer-location", IPP_TAG_TEXT
)) != NULL
)
5369 cupsdSetString(&printer
->location
, ippGetString(attr
, 0, NULL
));
5371 if ((!printer
->geo_location
|| !*(printer
->geo_location
)) && (attr
= ippFindAttribute(response
, "printer-geo-location", IPP_TAG_URI
)) != NULL
)
5372 cupsdSetString(&printer
->geo_location
, ippGetString(attr
, 0, NULL
));
5374 _cupsRWUnlock(&printer
->lock
);
5376 if ((from
= cupsFileOpen(fromppd
, "r")) == NULL
)
5378 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: Unable to read generated PPD: %s", printer
->name
, strerror(errno
));
5382 snprintf(toppd
, sizeof(toppd
), "%s/ppd/%s.ppd", ServerRoot
, printer
->name
);
5383 if ((to
= cupsdCreateConfFile(toppd
, ConfigFilePerm
)) == NULL
)
5385 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: Unable to create PPD for printer: %s", printer
->name
, strerror(errno
));
5386 cupsFileClose(from
);
5390 while (cupsFileGets(from
, line
, sizeof(line
)))
5391 cupsFilePrintf(to
, "%s\n", line
);
5393 cupsFileClose(from
);
5394 if (!cupsdCloseCreatedConfFile(to
, toppd
))
5396 printer
->config_time
= time(NULL
);
5397 printer
->state
= IPP_PSTATE_IDLE
;
5398 printer
->accepting
= 1;
5400 cupsdSetPrinterAttrs(printer
);
5402 cupsdAddEvent(CUPSD_EVENT_PRINTER_CONFIG
, printer
, NULL
, "Printer \"%s\" is now available.", printer
->name
);
5403 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" is now available.", printer
->name
);
5407 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: PPD creation failed: %s", printer
->name
, cupsLastErrorString());
5414 * 'create_local_printer()' - Create a local (temporary) print queue.
5418 create_local_printer(
5419 cupsd_client_t
*con
) /* I - Client connection */
5421 ipp_attribute_t
*device_uri
, /* device-uri attribute */
5422 *printer_geo_location
, /* printer-geo-location attribute */
5423 *printer_info
, /* printer-info attribute */
5424 *printer_location
, /* printer-location attribute */
5425 *printer_name
; /* printer-name attribute */
5426 cupsd_printer_t
*printer
; /* New printer */
5427 http_status_t status
; /* Policy status */
5428 char name
[128], /* Sanitized printer name */
5429 *nameptr
, /* Pointer into name */
5430 uri
[1024]; /* printer-uri-supported value */
5431 const char *ptr
; /* Pointer into attribute value */
5435 * Require local access to create a local printer...
5438 if (!httpAddrLocalhost(httpGetAddress(con
->http
)))
5440 send_ipp_status(con
, IPP_STATUS_ERROR_FORBIDDEN
, _("Only local users can create a local printer."));
5445 * Check any other policy limits...
5448 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5450 send_http_error(con
, status
, NULL
);
5455 * Grab needed attributes...
5458 if ((printer_name
= ippFindAttribute(con
->request
, "printer-name", IPP_TAG_ZERO
)) == NULL
|| ippGetGroupTag(printer_name
) != IPP_TAG_PRINTER
|| ippGetValueTag(printer_name
) != IPP_TAG_NAME
)
5461 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Missing required attribute \"%s\"."), "printer-name");
5462 else if (ippGetGroupTag(printer_name
) != IPP_TAG_PRINTER
)
5463 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Attribute \"%s\" is in the wrong group."), "printer-name");
5465 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Attribute \"%s\" is the wrong value type."), "printer-name");
5470 for (nameptr
= name
, ptr
= ippGetString(printer_name
, 0, NULL
); *ptr
&& nameptr
< (name
+ sizeof(name
) - 1); ptr
++)
5473 * Sanitize the printer name...
5476 if (_cups_isalnum(*ptr
))
5478 else if (nameptr
== name
|| nameptr
[-1] != '_')
5484 if ((device_uri
= ippFindAttribute(con
->request
, "device-uri", IPP_TAG_ZERO
)) == NULL
|| ippGetGroupTag(device_uri
) != IPP_TAG_PRINTER
|| ippGetValueTag(device_uri
) != IPP_TAG_URI
)
5487 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Missing required attribute \"%s\"."), "device-uri");
5488 else if (ippGetGroupTag(device_uri
) != IPP_TAG_PRINTER
)
5489 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Attribute \"%s\" is in the wrong group."), "device-uri");
5491 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Attribute \"%s\" is the wrong value type."), "device-uri");
5496 printer_geo_location
= ippFindAttribute(con
->request
, "printer-geo-location", IPP_TAG_URI
);
5497 printer_info
= ippFindAttribute(con
->request
, "printer-info", IPP_TAG_TEXT
);
5498 printer_location
= ippFindAttribute(con
->request
, "printer-location", IPP_TAG_TEXT
);
5501 * See if the printer already exists...
5504 if ((printer
= cupsdFindDest(name
)) != NULL
)
5506 send_ipp_status(con
, IPP_STATUS_ERROR_NOT_POSSIBLE
, _("Printer \"%s\" already exists."), name
);
5507 goto add_printer_attributes
;
5511 * Create the printer...
5514 if ((printer
= cupsdAddPrinter(name
)) == NULL
)
5516 send_ipp_status(con
, IPP_STATUS_ERROR_INTERNAL
, _("Unable to create printer."));
5520 printer
->shared
= 0;
5521 printer
->temporary
= 1;
5523 cupsdSetDeviceURI(printer
, ippGetString(device_uri
, 0, NULL
));
5525 if (printer_geo_location
)
5526 cupsdSetString(&printer
->geo_location
, ippGetString(printer_geo_location
, 0, NULL
));
5528 cupsdSetString(&printer
->info
, ippGetString(printer_info
, 0, NULL
));
5529 if (printer_location
)
5530 cupsdSetString(&printer
->location
, ippGetString(printer_location
, 0, NULL
));
5532 cupsdSetPrinterAttrs(printer
);
5535 * Run a background thread to create the PPD...
5538 _cupsThreadCreate((_cups_thread_func_t
)create_local_bg_thread
, printer
);
5541 * Return printer attributes...
5544 send_ipp_status(con
, IPP_STATUS_OK
, _("Local printer created."));
5546 add_printer_attributes
:
5548 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs", (char)printer
->accepting
);
5549 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state", printer
->state
);
5550 add_printer_state_reasons(con
, printer
);
5552 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), httpIsEncrypted(con
->http
) ? "ipps" : "ipp", NULL
, con
->clientname
, con
->clientport
, "/printers/%s", printer
->name
);
5553 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-uri-supported", NULL
, uri
);
5558 * 'create_requested_array()' - Create an array for the requested-attributes.
5561 static cups_array_t
* /* O - Array of attributes or NULL */
5562 create_requested_array(ipp_t
*request
) /* I - IPP request */
5564 cups_array_t
*ra
; /* Requested attributes array */
5568 * Create the array for standard attributes...
5571 ra
= ippCreateRequestedArray(request
);
5574 * Add CUPS defaults as needed...
5577 if (cupsArrayFind(ra
, "printer-defaults"))
5580 * Include user-set defaults...
5583 char *name
; /* Option name */
5585 cupsArrayRemove(ra
, "printer-defaults");
5587 for (name
= (char *)cupsArrayFirst(CommonDefaults
);
5589 name
= (char *)cupsArrayNext(CommonDefaults
))
5590 if (!cupsArrayFind(ra
, name
))
5591 cupsArrayAdd(ra
, name
);
5599 * 'create_subscriptions()' - Create one or more notification subscriptions.
5603 create_subscriptions(
5604 cupsd_client_t
*con
, /* I - Client connection */
5605 ipp_attribute_t
*uri
) /* I - Printer URI */
5607 http_status_t status
; /* Policy status */
5608 int i
; /* Looping var */
5609 ipp_attribute_t
*attr
; /* Current attribute */
5610 cups_ptype_t dtype
; /* Destination type (printer/class) */
5611 char scheme
[HTTP_MAX_URI
],
5612 /* Scheme portion of URI */
5613 userpass
[HTTP_MAX_URI
],
5614 /* Username portion of URI */
5616 /* Host portion of URI */
5617 resource
[HTTP_MAX_URI
];
5618 /* Resource portion of URI */
5619 int port
; /* Port portion of URI */
5620 cupsd_printer_t
*printer
; /* Printer/class */
5621 cupsd_job_t
*job
; /* Job */
5622 int jobid
; /* Job ID */
5623 cupsd_subscription_t
*sub
; /* Subscription object */
5624 const char *username
, /* requesting-user-name or
5625 authenticated username */
5626 *recipient
, /* notify-recipient-uri */
5627 *pullmethod
; /* notify-pull-method */
5628 ipp_attribute_t
*user_data
; /* notify-user-data */
5629 int interval
, /* notify-time-interval */
5630 lease
; /* notify-lease-duration */
5631 unsigned mask
; /* notify-events */
5632 ipp_attribute_t
*notify_events
,/* notify-events(-default) */
5633 *notify_lease
; /* notify-lease-duration(-default) */
5637 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
5639 if (attr
->group_tag
!= IPP_TAG_ZERO
)
5640 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "g%04x v%04x %s", attr
->group_tag
,
5641 attr
->value_tag
, attr
->name
);
5643 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "----SEP----");
5648 * Is the destination valid?
5651 cupsdLogMessage(CUPSD_LOG_DEBUG
, "create_subscriptions(con=%p(%d), uri=\"%s\")", con
, con
->number
, uri
->values
[0].string
.text
);
5653 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
5654 sizeof(scheme
), userpass
, sizeof(userpass
), host
,
5655 sizeof(host
), &port
, resource
, sizeof(resource
));
5657 if (!strcmp(resource
, "/"))
5659 dtype
= (cups_ptype_t
)0;
5662 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
5664 dtype
= (cups_ptype_t
)0;
5667 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
5669 dtype
= CUPS_PRINTER_CLASS
;
5672 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
5678 send_ipp_status(con
, IPP_NOT_FOUND
,
5679 _("The printer or class does not exist."));
5689 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
5692 send_http_error(con
, status
, printer
);
5696 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5698 send_http_error(con
, status
, NULL
);
5703 * Get the user that is requesting the subscription...
5706 username
= get_username(con
);
5709 * Find the first subscription group attribute; return if we have
5713 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
5714 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
5719 send_ipp_status(con
, IPP_BAD_REQUEST
,
5720 _("No subscription attributes in request."));
5725 * Process the subscription attributes in the request...
5728 con
->response
->request
.status
.status_code
= IPP_BAD_REQUEST
;
5736 lease
= DefaultLeaseDuration
;
5738 mask
= CUPSD_EVENT_NONE
;
5742 notify_events
= ippFindAttribute(printer
->attrs
, "notify-events-default",
5744 notify_lease
= ippFindAttribute(printer
->attrs
,
5745 "notify-lease-duration-default",
5749 lease
= notify_lease
->values
[0].integer
;
5753 notify_events
= NULL
;
5754 notify_lease
= NULL
;
5757 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
5759 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
5760 attr
->value_tag
== IPP_TAG_URI
)
5763 * Validate the recipient scheme against the ServerBin/notifier
5767 char notifier
[1024]; /* Notifier filename */
5770 recipient
= attr
->values
[0].string
.text
;
5772 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
5773 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
5774 host
, sizeof(host
), &port
,
5775 resource
, sizeof(resource
)) < HTTP_URI_OK
)
5777 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5778 _("Bad notify-recipient-uri \"%s\"."), recipient
);
5779 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5780 "notify-status-code", IPP_URI_SCHEME
);
5784 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
5786 if (access(notifier
, X_OK
))
5788 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5789 _("notify-recipient-uri URI \"%s\" uses unknown "
5790 "scheme."), recipient
);
5791 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5792 "notify-status-code", IPP_URI_SCHEME
);
5796 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
5798 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5799 _("notify-recipient-uri URI \"%s\" is already used."),
5801 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5802 "notify-status-code", IPP_ATTRIBUTES
);
5806 else if (!strcmp(attr
->name
, "notify-pull-method") &&
5807 attr
->value_tag
== IPP_TAG_KEYWORD
)
5809 pullmethod
= attr
->values
[0].string
.text
;
5811 if (strcmp(pullmethod
, "ippget"))
5813 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5814 _("Bad notify-pull-method \"%s\"."), pullmethod
);
5815 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5816 "notify-status-code", IPP_ATTRIBUTES
);
5820 else if (!strcmp(attr
->name
, "notify-charset") &&
5821 attr
->value_tag
== IPP_TAG_CHARSET
&&
5822 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
5823 strcmp(attr
->values
[0].string
.text
, "utf-8"))
5825 send_ipp_status(con
, IPP_CHARSET
,
5826 _("Character set \"%s\" not supported."),
5827 attr
->values
[0].string
.text
);
5830 else if (!strcmp(attr
->name
, "notify-natural-language") &&
5831 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
5832 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
5834 send_ipp_status(con
, IPP_CHARSET
,
5835 _("Language \"%s\" not supported."),
5836 attr
->values
[0].string
.text
);
5839 else if (!strcmp(attr
->name
, "notify-user-data") &&
5840 attr
->value_tag
== IPP_TAG_STRING
)
5842 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
5844 send_ipp_status(con
, IPP_REQUEST_VALUE
,
5845 _("The notify-user-data value is too large "
5846 "(%d > 63 octets)."),
5847 attr
->values
[0].unknown
.length
);
5853 else if (!strcmp(attr
->name
, "notify-events") &&
5854 attr
->value_tag
== IPP_TAG_KEYWORD
)
5855 notify_events
= attr
;
5856 else if (!strcmp(attr
->name
, "notify-lease-duration") &&
5857 attr
->value_tag
== IPP_TAG_INTEGER
)
5858 lease
= attr
->values
[0].integer
;
5859 else if (!strcmp(attr
->name
, "notify-time-interval") &&
5860 attr
->value_tag
== IPP_TAG_INTEGER
)
5861 interval
= attr
->values
[0].integer
;
5862 else if (!strcmp(attr
->name
, "notify-job-id") &&
5863 attr
->value_tag
== IPP_TAG_INTEGER
)
5864 jobid
= attr
->values
[0].integer
;
5871 for (i
= 0; i
< notify_events
->num_values
; i
++)
5872 mask
|= cupsdEventValue(notify_events
->values
[i
].string
.text
);
5876 cupsdLogMessage(CUPSD_LOG_DEBUG
, "recipient=\"%s\"", recipient
);
5878 cupsdLogMessage(CUPSD_LOG_DEBUG
, "pullmethod=\"%s\"", pullmethod
);
5879 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-lease-duration=%d", lease
);
5880 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-time-interval=%d", interval
);
5882 if (!recipient
&& !pullmethod
)
5885 if (mask
== CUPSD_EVENT_NONE
)
5888 mask
= CUPSD_EVENT_JOB_COMPLETED
;
5890 mask
= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
5893 send_ipp_status(con
, IPP_BAD_REQUEST
,
5894 _("notify-events not specified."));
5899 if (MaxLeaseDuration
&& (lease
== 0 || lease
> MaxLeaseDuration
))
5901 cupsdLogMessage(CUPSD_LOG_INFO
,
5902 "create_subscriptions: Limiting notify-lease-duration to "
5905 lease
= MaxLeaseDuration
;
5910 if ((job
= cupsdFindJob(jobid
)) == NULL
)
5912 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
5920 if ((sub
= cupsdAddSubscription(mask
, printer
, job
, recipient
, 0)) == NULL
)
5922 send_ipp_status(con
, IPP_TOO_MANY_SUBSCRIPTIONS
,
5923 _("There are too many subscriptions."));
5928 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription #%d for job %d.",
5931 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5932 "Added subscription #%d for printer \"%s\".",
5933 sub
->id
, printer
->name
);
5935 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription #%d for server.",
5938 sub
->interval
= interval
;
5940 sub
->expire
= lease
? time(NULL
) + lease
: 0;
5942 cupsdSetString(&sub
->owner
, username
);
5946 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
5947 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
5948 (size_t)sub
->user_data_len
);
5951 ippAddSeparator(con
->response
);
5952 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5953 "notify-subscription-id", sub
->id
);
5955 con
->response
->request
.status
.status_code
= IPP_OK
;
5961 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
5966 * 'delete_printer()' - Remove a printer or class from the system.
5970 delete_printer(cupsd_client_t
*con
, /* I - Client connection */
5971 ipp_attribute_t
*uri
) /* I - URI of printer or class */
5973 http_status_t status
; /* Policy status */
5974 cups_ptype_t dtype
; /* Destination type (printer/class) */
5975 cupsd_printer_t
*printer
; /* Printer/class */
5976 char filename
[1024]; /* Script/PPD filename */
5977 int temporary
; /* Temporary queue? */
5980 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "delete_printer(%p[%d], %s)", con
,
5981 con
->number
, uri
->values
[0].string
.text
);
5984 * Do we have a valid URI?
5987 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
5993 send_ipp_status(con
, IPP_NOT_FOUND
,
5994 _("The printer or class does not exist."));
6002 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6004 send_http_error(con
, status
, NULL
);
6009 * Remove old jobs...
6012 cupsdCancelJobs(printer
->name
, NULL
, 1);
6015 * Remove old subscriptions and send a "deleted printer" event...
6018 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED
, printer
, NULL
,
6019 "%s \"%s\" deleted by \"%s\".",
6020 (dtype
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
6021 printer
->name
, get_username(con
));
6023 cupsdExpireSubscriptions(printer
, NULL
);
6026 * Remove any old PPD or script files...
6029 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
6032 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd.O", ServerRoot
,
6036 snprintf(filename
, sizeof(filename
), "%s/%s.png", CacheDir
, printer
->name
);
6039 snprintf(filename
, sizeof(filename
), "%s/%s.data", CacheDir
, printer
->name
);
6043 * Unregister color profiles...
6046 cupsdUnregisterColor(printer
);
6048 temporary
= printer
->temporary
;
6050 if (dtype
& CUPS_PRINTER_CLASS
)
6052 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" deleted by \"%s\".",
6053 printer
->name
, get_username(con
));
6055 cupsdDeletePrinter(printer
, 0);
6057 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
6061 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" deleted by \"%s\".",
6062 printer
->name
, get_username(con
));
6064 if (cupsdDeletePrinter(printer
, 0) && !temporary
)
6065 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
6068 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
6072 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
6075 * Return with no errors...
6078 con
->response
->request
.status
.status_code
= IPP_OK
;
6083 * 'get_default()' - Get the default destination.
6087 get_default(cupsd_client_t
*con
) /* I - Client connection */
6089 http_status_t status
; /* Policy status */
6090 cups_array_t
*ra
; /* Requested attributes array */
6093 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_default(%p[%d])", con
, con
->number
);
6099 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6101 send_http_error(con
, status
, NULL
);
6107 ra
= create_requested_array(con
->request
);
6109 copy_printer_attrs(con
, DefaultPrinter
, ra
);
6111 cupsArrayDelete(ra
);
6113 con
->response
->request
.status
.status_code
= IPP_OK
;
6116 send_ipp_status(con
, IPP_NOT_FOUND
, _("No default printer."));
6121 * 'get_devices()' - Get the list of available devices on the local system.
6125 get_devices(cupsd_client_t
*con
) /* I - Client connection */
6127 http_status_t status
; /* Policy status */
6128 ipp_attribute_t
*limit
, /* limit attribute */
6129 *timeout
, /* timeout attribute */
6130 *requested
, /* requested-attributes attribute */
6131 *exclude
, /* exclude-schemes attribute */
6132 *include
; /* include-schemes attribute */
6133 char command
[1024], /* cups-deviced command */
6134 options
[2048], /* Options to pass to command */
6136 /* String for requested attributes */
6138 /* String for excluded schemes */
6140 /* String for included schemes */
6143 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_devices(%p[%d])", con
, con
->number
);
6149 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6151 send_http_error(con
, status
, NULL
);
6156 * Run cups-deviced command with the given options...
6159 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
6160 timeout
= ippFindAttribute(con
->request
, "timeout", IPP_TAG_INTEGER
);
6161 requested
= ippFindAttribute(con
->request
, "requested-attributes",
6163 exclude
= ippFindAttribute(con
->request
, "exclude-schemes", IPP_TAG_NAME
);
6164 include
= ippFindAttribute(con
->request
, "include-schemes", IPP_TAG_NAME
);
6167 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
6169 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
6172 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
6174 exclude_str
[0] = '\0';
6177 url_encode_attr(include
, include_str
, sizeof(include_str
));
6179 include_str
[0] = '\0';
6181 snprintf(command
, sizeof(command
), "%s/daemon/cups-deviced", ServerBin
);
6182 snprintf(options
, sizeof(options
),
6183 "%d+%d+%d+%d+%s%s%s%s%s",
6184 con
->request
->request
.op
.request_id
,
6185 limit
? limit
->values
[0].integer
: 0,
6186 timeout
? timeout
->values
[0].integer
: 15,
6189 exclude_str
[0] ? "%20" : "", exclude_str
,
6190 include_str
[0] ? "%20" : "", include_str
);
6192 if (cupsdSendCommand(con
, command
, options
, 1))
6195 * Command started successfully, don't send an IPP response here...
6198 ippDelete(con
->response
);
6199 con
->response
= NULL
;
6204 * Command failed, return "internal error" so the user knows something
6208 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
6209 _("cups-deviced failed to execute."));
6215 * 'get_document()' - Get a copy of a job file.
6219 get_document(cupsd_client_t
*con
, /* I - Client connection */
6220 ipp_attribute_t
*uri
) /* I - Job URI */
6222 http_status_t status
; /* Policy status */
6223 ipp_attribute_t
*attr
; /* Current attribute */
6224 int jobid
; /* Job ID */
6225 int docnum
; /* Document number */
6226 cupsd_job_t
*job
; /* Current job */
6227 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
6228 username
[HTTP_MAX_URI
], /* Username portion of URI */
6229 host
[HTTP_MAX_URI
], /* Host portion of URI */
6230 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6231 int port
; /* Port portion of URI */
6232 char filename
[1024], /* Filename for document */
6233 format
[1024]; /* Format for document */
6236 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_document(%p[%d], %s)", con
,
6237 con
->number
, uri
->values
[0].string
.text
);
6240 * See if we have a job URI or a printer URI...
6243 if (!strcmp(uri
->name
, "printer-uri"))
6246 * Got a printer URI; see if we also have a job-id attribute...
6249 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6250 IPP_TAG_INTEGER
)) == NULL
)
6252 send_ipp_status(con
, IPP_BAD_REQUEST
,
6253 _("Got a printer-uri attribute but no job-id."));
6257 jobid
= attr
->values
[0].integer
;
6262 * Got a job URI; parse it to get the job ID...
6265 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6266 sizeof(scheme
), username
, sizeof(username
), host
,
6267 sizeof(host
), &port
, resource
, sizeof(resource
));
6269 if (strncmp(resource
, "/jobs/", 6))
6275 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
6276 uri
->values
[0].string
.text
);
6280 jobid
= atoi(resource
+ 6);
6284 * See if the job exists...
6287 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6290 * Nope - return a "not found" error...
6293 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
6301 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
,
6302 job
->username
)) != HTTP_OK
)
6304 send_http_error(con
, status
, NULL
);
6309 * Get the document number...
6312 if ((attr
= ippFindAttribute(con
->request
, "document-number",
6313 IPP_TAG_INTEGER
)) == NULL
)
6315 send_ipp_status(con
, IPP_BAD_REQUEST
,
6316 _("Missing document-number attribute."));
6320 if ((docnum
= attr
->values
[0].integer
) < 1 || docnum
> job
->num_files
||
6321 attr
->num_values
> 1)
6323 send_ipp_status(con
, IPP_NOT_FOUND
,
6324 _("Document #%d does not exist in job #%d."), docnum
,
6329 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, jobid
,
6331 if ((con
->file
= open(filename
, O_RDONLY
)) == -1)
6333 cupsdLogMessage(CUPSD_LOG_ERROR
,
6334 "Unable to open document %d in job %d - %s", docnum
, jobid
,
6336 send_ipp_status(con
, IPP_NOT_FOUND
,
6337 _("Unable to open document #%d in job #%d."), docnum
,
6342 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
6346 snprintf(format
, sizeof(format
), "%s/%s", job
->filetypes
[docnum
- 1]->super
,
6347 job
->filetypes
[docnum
- 1]->type
);
6349 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format",
6351 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "document-number",
6353 if ((attr
= ippFindAttribute(job
->attrs
, "document-name",
6354 IPP_TAG_NAME
)) != NULL
)
6355 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name",
6356 NULL
, attr
->values
[0].string
.text
);
6361 * 'get_job_attrs()' - Get job attributes.
6365 get_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
6366 ipp_attribute_t
*uri
) /* I - Job URI */
6368 http_status_t status
; /* Policy status */
6369 ipp_attribute_t
*attr
; /* Current attribute */
6370 int jobid
; /* Job ID */
6371 cupsd_job_t
*job
; /* Current job */
6372 cupsd_printer_t
*printer
; /* Current printer */
6373 cupsd_policy_t
*policy
; /* Current security policy */
6374 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6375 username
[HTTP_MAX_URI
], /* Username portion of URI */
6376 host
[HTTP_MAX_URI
], /* Host portion of URI */
6377 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6378 int port
; /* Port portion of URI */
6379 cups_array_t
*ra
, /* Requested attributes array */
6380 *exclude
; /* Private attributes array */
6383 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_job_attrs(%p[%d], %s)", con
,
6384 con
->number
, uri
->values
[0].string
.text
);
6387 * See if we have a job URI or a printer URI...
6390 if (!strcmp(uri
->name
, "printer-uri"))
6393 * Got a printer URI; see if we also have a job-id attribute...
6396 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6397 IPP_TAG_INTEGER
)) == NULL
)
6399 send_ipp_status(con
, IPP_BAD_REQUEST
,
6400 _("Got a printer-uri attribute but no job-id."));
6404 jobid
= attr
->values
[0].integer
;
6409 * Got a job URI; parse it to get the job ID...
6412 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6413 sizeof(scheme
), username
, sizeof(username
), host
,
6414 sizeof(host
), &port
, resource
, sizeof(resource
));
6416 if (strncmp(resource
, "/jobs/", 6))
6422 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
6423 uri
->values
[0].string
.text
);
6427 jobid
= atoi(resource
+ 6);
6431 * See if the job exists...
6434 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6437 * Nope - return a "not found" error...
6440 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
6448 if ((printer
= job
->printer
) == NULL
)
6449 printer
= cupsdFindDest(job
->dest
);
6452 policy
= printer
->op_policy_ptr
;
6454 policy
= DefaultPolicyPtr
;
6456 if ((status
= cupsdCheckPolicy(policy
, con
, job
->username
)) != HTTP_OK
)
6458 send_http_error(con
, status
, NULL
);
6462 exclude
= cupsdGetPrivateAttrs(policy
, con
, printer
, job
->username
);
6465 * Copy attributes...
6470 ra
= create_requested_array(con
->request
);
6471 copy_job_attrs(con
, job
, ra
, exclude
);
6472 cupsArrayDelete(ra
);
6474 con
->response
->request
.status
.status_code
= IPP_OK
;
6479 * 'get_jobs()' - Get a list of jobs for the specified printer.
6483 get_jobs(cupsd_client_t
*con
, /* I - Client connection */
6484 ipp_attribute_t
*uri
) /* I - Printer URI */
6486 http_status_t status
; /* Policy status */
6487 ipp_attribute_t
*attr
; /* Current attribute */
6488 const char *dest
; /* Destination */
6489 cups_ptype_t dtype
; /* Destination type (printer/class) */
6490 cups_ptype_t dmask
; /* Destination type mask */
6491 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6492 username
[HTTP_MAX_URI
], /* Username portion of URI */
6493 host
[HTTP_MAX_URI
], /* Host portion of URI */
6494 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6495 int port
; /* Port portion of URI */
6496 int job_comparison
; /* Job comparison */
6497 ipp_jstate_t job_state
; /* job-state value */
6498 int first_job_id
= 1, /* First job ID */
6499 first_index
= 1, /* First index */
6500 limit
= 0, /* Maximum number of jobs to return */
6501 count
, /* Number of jobs that match */
6502 need_load_job
= 0; /* Do we need to load the job? */
6503 const char *job_attr
; /* Job attribute requested */
6504 ipp_attribute_t
*job_ids
; /* job-ids attribute */
6505 cupsd_job_t
*job
; /* Current job pointer */
6506 cupsd_printer_t
*printer
; /* Printer */
6507 cups_array_t
*list
; /* Which job list... */
6508 int delete_list
= 0; /* Delete the list afterwards? */
6509 cups_array_t
*ra
, /* Requested attributes array */
6510 *exclude
; /* Private attributes array */
6511 cupsd_policy_t
*policy
; /* Current policy */
6514 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs(%p[%d], %s)", con
, con
->number
,
6515 uri
->values
[0].string
.text
);
6518 * Is the destination valid?
6521 if (strcmp(uri
->name
, "printer-uri"))
6523 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No printer-uri in request."));
6527 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6528 sizeof(scheme
), username
, sizeof(username
), host
,
6529 sizeof(host
), &port
, resource
, sizeof(resource
));
6531 if (!strcmp(resource
, "/") || !strcmp(resource
, "/jobs"))
6534 dtype
= (cups_ptype_t
)0;
6535 dmask
= (cups_ptype_t
)0;
6538 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6541 dtype
= (cups_ptype_t
)0;
6542 dmask
= CUPS_PRINTER_CLASS
;
6545 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6548 dtype
= CUPS_PRINTER_CLASS
;
6549 dmask
= CUPS_PRINTER_CLASS
;
6552 else if ((dest
= cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
,
6559 send_ipp_status(con
, IPP_NOT_FOUND
,
6560 _("The printer or class does not exist."));
6565 dtype
&= CUPS_PRINTER_CLASS
;
6566 dmask
= CUPS_PRINTER_CLASS
;
6574 policy
= printer
->op_policy_ptr
;
6576 policy
= DefaultPolicyPtr
;
6578 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
6580 send_http_error(con
, status
, NULL
);
6584 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
6587 * See if the "which-jobs" attribute have been specified...
6590 if ((attr
= ippFindAttribute(con
->request
, "which-jobs",
6591 IPP_TAG_KEYWORD
)) != NULL
&& job_ids
)
6593 send_ipp_status(con
, IPP_CONFLICT
,
6594 _("The %s attribute cannot be provided with job-ids."),
6598 else if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "not-completed"))
6600 job_comparison
= -1;
6601 job_state
= IPP_JOB_STOPPED
;
6604 else if (!strcmp(attr
->values
[0].string
.text
, "completed"))
6607 job_state
= IPP_JOB_CANCELED
;
6608 list
= cupsdGetCompletedJobs(printer
);
6611 else if (!strcmp(attr
->values
[0].string
.text
, "aborted"))
6614 job_state
= IPP_JOB_ABORTED
;
6615 list
= cupsdGetCompletedJobs(printer
);
6618 else if (!strcmp(attr
->values
[0].string
.text
, "all"))
6621 job_state
= IPP_JOB_PENDING
;
6624 else if (!strcmp(attr
->values
[0].string
.text
, "canceled"))
6627 job_state
= IPP_JOB_CANCELED
;
6628 list
= cupsdGetCompletedJobs(printer
);
6631 else if (!strcmp(attr
->values
[0].string
.text
, "pending"))
6634 job_state
= IPP_JOB_PENDING
;
6637 else if (!strcmp(attr
->values
[0].string
.text
, "pending-held"))
6640 job_state
= IPP_JOB_HELD
;
6643 else if (!strcmp(attr
->values
[0].string
.text
, "processing"))
6646 job_state
= IPP_JOB_PROCESSING
;
6647 list
= PrintingJobs
;
6649 else if (!strcmp(attr
->values
[0].string
.text
, "processing-stopped"))
6652 job_state
= IPP_JOB_STOPPED
;
6657 send_ipp_status(con
, IPP_ATTRIBUTES
,
6658 _("The which-jobs value \"%s\" is not supported."),
6659 attr
->values
[0].string
.text
);
6660 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
6661 "which-jobs", NULL
, attr
->values
[0].string
.text
);
6666 * See if they want to limit the number of jobs reported...
6669 if ((attr
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
)) != NULL
)
6673 send_ipp_status(con
, IPP_CONFLICT
,
6674 _("The %s attribute cannot be provided with job-ids."),
6679 limit
= attr
->values
[0].integer
;
6682 if ((attr
= ippFindAttribute(con
->request
, "first-index", IPP_TAG_INTEGER
)) != NULL
)
6686 send_ipp_status(con
, IPP_CONFLICT
,
6687 _("The %s attribute cannot be provided with job-ids."),
6692 first_index
= attr
->values
[0].integer
;
6694 else if ((attr
= ippFindAttribute(con
->request
, "first-job-id", IPP_TAG_INTEGER
)) != NULL
)
6698 send_ipp_status(con
, IPP_CONFLICT
,
6699 _("The %s attribute cannot be provided with job-ids."),
6704 first_job_id
= attr
->values
[0].integer
;
6708 * See if we only want to see jobs for a specific user...
6711 if ((attr
= ippFindAttribute(con
->request
, "my-jobs", IPP_TAG_BOOLEAN
)) != NULL
&& job_ids
)
6713 send_ipp_status(con
, IPP_CONFLICT
,
6714 _("The %s attribute cannot be provided with job-ids."),
6718 else if (attr
&& attr
->values
[0].boolean
)
6719 strlcpy(username
, get_username(con
), sizeof(username
));
6723 ra
= create_requested_array(con
->request
);
6724 for (job_attr
= (char *)cupsArrayFirst(ra
); job_attr
; job_attr
= (char *)cupsArrayNext(ra
))
6725 if (strcmp(job_attr
, "job-id") &&
6726 strcmp(job_attr
, "job-k-octets") &&
6727 strcmp(job_attr
, "job-media-progress") &&
6728 strcmp(job_attr
, "job-more-info") &&
6729 strcmp(job_attr
, "job-name") &&
6730 strcmp(job_attr
, "job-originating-user-name") &&
6731 strcmp(job_attr
, "job-preserved") &&
6732 strcmp(job_attr
, "job-printer-up-time") &&
6733 strcmp(job_attr
, "job-printer-uri") &&
6734 strcmp(job_attr
, "job-state") &&
6735 strcmp(job_attr
, "job-state-reasons") &&
6736 strcmp(job_attr
, "job-uri") &&
6737 strcmp(job_attr
, "time-at-completed") &&
6738 strcmp(job_attr
, "time-at-creation") &&
6739 strcmp(job_attr
, "number-of-documents"))
6745 if (need_load_job
&& (limit
== 0 || limit
> 500) && (list
== Jobs
|| delete_list
))
6748 * Limit expensive Get-Jobs for job history to 500 jobs...
6751 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
, "limit", 500);
6754 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
, "limit", limit
);
6758 cupsdLogClient(con
, CUPSD_LOG_INFO
, "Limiting Get-Jobs response to %d jobs.", limit
);
6762 * OK, build a list of jobs for this printer...
6767 int i
; /* Looping var */
6769 for (i
= 0; i
< job_ids
->num_values
; i
++)
6771 if (!cupsdFindJob(job_ids
->values
[i
].integer
))
6775 if (i
< job_ids
->num_values
)
6777 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
6778 job_ids
->values
[i
].integer
);
6782 for (i
= 0; i
< job_ids
->num_values
; i
++)
6784 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
6786 if (need_load_job
&& !job
->attrs
)
6792 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d", job
->id
);
6798 ippAddSeparator(con
->response
);
6800 exclude
= cupsdGetPrivateAttrs(job
->printer
?
6801 job
->printer
->op_policy_ptr
:
6802 policy
, con
, job
->printer
,
6805 copy_job_attrs(con
, job
, ra
, exclude
);
6810 if (first_index
> 1)
6811 job
= (cupsd_job_t
*)cupsArrayIndex(list
, first_index
- 1);
6813 job
= (cupsd_job_t
*)cupsArrayFirst(list
);
6815 for (count
= 0; (limit
<= 0 || count
< limit
) && job
; job
= (cupsd_job_t
*)cupsArrayNext(list
))
6818 * Filter out jobs that don't match...
6821 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
6822 "get_jobs: job->id=%d, dest=\"%s\", username=\"%s\", "
6823 "state_value=%d, attrs=%p", job
->id
, job
->dest
,
6824 job
->username
, job
->state_value
, job
->attrs
);
6826 if (!job
->dest
|| !job
->username
)
6829 if (!job
->dest
|| !job
->username
)
6832 if ((dest
&& strcmp(job
->dest
, dest
)) &&
6833 (!job
->printer
|| !dest
|| strcmp(job
->printer
->name
, dest
)))
6835 if ((job
->dtype
& dmask
) != dtype
&&
6836 (!job
->printer
|| (job
->printer
->type
& dmask
) != dtype
))
6839 if ((job_comparison
< 0 && job
->state_value
> job_state
) ||
6840 (job_comparison
== 0 && job
->state_value
!= job_state
) ||
6841 (job_comparison
> 0 && job
->state_value
< job_state
))
6844 if (job
->id
< first_job_id
)
6847 if (need_load_job
&& !job
->attrs
)
6853 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d", job
->id
);
6858 if (username
[0] && _cups_strcasecmp(username
, job
->username
))
6862 ippAddSeparator(con
->response
);
6866 exclude
= cupsdGetPrivateAttrs(job
->printer
?
6867 job
->printer
->op_policy_ptr
:
6868 policy
, con
, job
->printer
,
6871 copy_job_attrs(con
, job
, ra
, exclude
);
6874 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: count=%d", count
);
6877 cupsArrayDelete(ra
);
6880 cupsArrayDelete(list
);
6882 con
->response
->request
.status
.status_code
= IPP_OK
;
6887 * 'get_notifications()' - Get events for a subscription.
6891 get_notifications(cupsd_client_t
*con
) /* I - Client connection */
6893 int i
, j
; /* Looping vars */
6894 http_status_t status
; /* Policy status */
6895 cupsd_subscription_t
*sub
; /* Subscription */
6896 ipp_attribute_t
*ids
, /* notify-subscription-ids */
6897 *sequences
; /* notify-sequence-numbers */
6898 int min_seq
; /* Minimum sequence number */
6899 int interval
; /* Poll interval */
6902 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_notifications(con=%p[%d])",
6906 * Get subscription attributes...
6909 ids
= ippFindAttribute(con
->request
, "notify-subscription-ids",
6911 sequences
= ippFindAttribute(con
->request
, "notify-sequence-numbers",
6916 send_ipp_status(con
, IPP_BAD_REQUEST
,
6917 _("Missing notify-subscription-ids attribute."));
6922 * Are the subscription IDs valid?
6925 for (i
= 0, interval
= 60; i
< ids
->num_values
; i
++)
6927 if ((sub
= cupsdFindSubscription(ids
->values
[i
].integer
)) == NULL
)
6930 * Bad subscription ID...
6933 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
6934 ids
->values
[i
].integer
);
6942 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
6944 con
, sub
->owner
)) != HTTP_OK
)
6946 send_http_error(con
, status
, sub
->dest
);
6951 * Check the subscription type and update the interval accordingly.
6954 if (sub
->job
&& sub
->job
->state_value
== IPP_JOB_PROCESSING
&&
6957 else if (sub
->job
&& sub
->job
->state_value
>= IPP_JOB_STOPPED
)
6959 else if (sub
->dest
&& sub
->dest
->state
== IPP_PRINTER_PROCESSING
&&
6965 * Tell the client to poll again in N seconds...
6969 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
6970 "notify-get-interval", interval
);
6972 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
6973 "printer-up-time", time(NULL
));
6976 * Copy the subscription event attributes to the response.
6979 con
->response
->request
.status
.status_code
=
6980 interval
? IPP_OK
: IPP_OK_EVENTS_COMPLETE
;
6982 for (i
= 0; i
< ids
->num_values
; i
++)
6985 * Get the subscription and sequence number...
6988 sub
= cupsdFindSubscription(ids
->values
[i
].integer
);
6990 if (sequences
&& i
< sequences
->num_values
)
6991 min_seq
= sequences
->values
[i
].integer
;
6996 * If we don't have any new events, nothing to do here...
6999 if (min_seq
> (sub
->first_event_id
+ cupsArrayCount(sub
->events
)))
7003 * Otherwise copy all of the new events...
7006 if (sub
->first_event_id
> min_seq
)
7009 j
= min_seq
- sub
->first_event_id
;
7011 for (; j
< cupsArrayCount(sub
->events
); j
++)
7013 ippAddSeparator(con
->response
);
7015 copy_attrs(con
->response
,
7016 ((cupsd_event_t
*)cupsArrayIndex(sub
->events
, j
))->attrs
, NULL
,
7017 IPP_TAG_EVENT_NOTIFICATION
, 0, NULL
);
7024 * 'get_ppd()' - Get a named PPD from the local system.
7028 get_ppd(cupsd_client_t
*con
, /* I - Client connection */
7029 ipp_attribute_t
*uri
) /* I - Printer URI or PPD name */
7031 http_status_t status
; /* Policy status */
7032 cupsd_printer_t
*dest
; /* Destination */
7033 cups_ptype_t dtype
; /* Destination type */
7036 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppd(%p[%d], %p[%s=%s])", con
,
7037 con
->number
, uri
, uri
->name
, uri
->values
[0].string
.text
);
7039 if (!strcmp(ippGetName(uri
), "ppd-name"))
7042 * Return a PPD file from cups-driverd...
7045 const char *ppd_name
= ippGetString(uri
, 0, NULL
);
7046 /* ppd-name value */
7047 char command
[1024], /* cups-driverd command */
7048 options
[1024], /* Options to pass to command */
7049 oppd_name
[1024]; /* Escaped ppd-name */
7055 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7057 send_http_error(con
, status
, NULL
);
7062 * Check ppd-name value...
7065 if (strstr(ppd_name
, "../"))
7067 send_ipp_status(con
, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES
, _("Invalid ppd-name value."));
7072 * Run cups-driverd command with the given options...
7075 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7076 url_encode_string(ppd_name
, oppd_name
, sizeof(oppd_name
));
7077 snprintf(options
, sizeof(options
), "get+%d+%s", ippGetRequestId(con
->request
), oppd_name
);
7079 if (cupsdSendCommand(con
, command
, options
, 0))
7082 * Command started successfully, don't send an IPP response here...
7085 ippDelete(con
->response
);
7086 con
->response
= NULL
;
7091 * Command failed, return "internal error" so the user knows something
7095 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("cups-driverd failed to execute."));
7098 else if (!strcmp(ippGetName(uri
), "printer-uri") && cupsdValidateDest(ippGetString(uri
, 0, NULL
), &dtype
, &dest
))
7100 int i
; /* Looping var */
7101 char filename
[1024]; /* PPD filename */
7107 if ((status
= cupsdCheckPolicy(dest
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7109 send_http_error(con
, status
, dest
);
7114 * See if we need the PPD for a class or remote printer...
7117 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
, dest
->name
);
7119 if ((dtype
& CUPS_PRINTER_REMOTE
) && access(filename
, 0))
7121 send_ipp_status(con
, IPP_STATUS_CUPS_SEE_OTHER
, _("See remote printer."));
7122 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
, dest
->uri
);
7125 else if (dtype
& CUPS_PRINTER_CLASS
)
7127 for (i
= 0; i
< dest
->num_printers
; i
++)
7128 if (!(dest
->printers
[i
]->type
& CUPS_PRINTER_CLASS
))
7130 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
, dest
->printers
[i
]->name
);
7132 if (!access(filename
, 0))
7136 if (i
< dest
->num_printers
)
7137 dest
= dest
->printers
[i
];
7140 send_ipp_status(con
, IPP_STATUS_CUPS_SEE_OTHER
, _("See remote printer."));
7141 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
, dest
->printers
[0]->uri
);
7147 * Found the printer with the PPD file, now see if there is one...
7150 if ((con
->file
= open(filename
, O_RDONLY
)) < 0)
7152 send_ipp_status(con
, IPP_STATUS_ERROR_NOT_FOUND
, _("The PPD file \"%s\" could not be opened: %s"), ippGetString(uri
, 0, NULL
), strerror(errno
));
7156 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
7160 ippSetStatusCode(con
->response
, IPP_STATUS_OK
);
7163 send_ipp_status(con
, IPP_STATUS_ERROR_NOT_FOUND
, _("The PPD file \"%s\" could not be found."), ippGetString(uri
, 0, NULL
));
7168 * 'get_ppds()' - Get the list of PPD files on the local system.
7172 get_ppds(cupsd_client_t
*con
) /* I - Client connection */
7174 http_status_t status
; /* Policy status */
7175 ipp_attribute_t
*limit
, /* Limit attribute */
7176 *device
, /* ppd-device-id attribute */
7177 *language
, /* ppd-natural-language attribute */
7178 *make
, /* ppd-make attribute */
7179 *model
, /* ppd-make-and-model attribute */
7180 *model_number
, /* ppd-model-number attribute */
7181 *product
, /* ppd-product attribute */
7182 *psversion
, /* ppd-psverion attribute */
7183 *type
, /* ppd-type attribute */
7184 *requested
, /* requested-attributes attribute */
7185 *exclude
, /* exclude-schemes attribute */
7186 *include
; /* include-schemes attribute */
7187 char command
[1024], /* cups-driverd command */
7188 options
[4096], /* Options to pass to command */
7189 device_str
[256],/* Escaped ppd-device-id string */
7191 /* Escaped ppd-natural-language */
7192 make_str
[256], /* Escaped ppd-make string */
7193 model_str
[256], /* Escaped ppd-make-and-model string */
7194 model_number_str
[256],
7195 /* ppd-model-number string */
7197 /* Escaped ppd-product string */
7199 /* Escaped ppd-psversion string */
7200 type_str
[256], /* Escaped ppd-type string */
7202 /* String for requested attributes */
7204 /* String for excluded schemes */
7206 /* String for included schemes */
7209 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppds(%p[%d])", con
, con
->number
);
7215 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7217 send_http_error(con
, status
, NULL
);
7222 * Run cups-driverd command with the given options...
7225 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
7226 device
= ippFindAttribute(con
->request
, "ppd-device-id", IPP_TAG_TEXT
);
7227 language
= ippFindAttribute(con
->request
, "ppd-natural-language",
7229 make
= ippFindAttribute(con
->request
, "ppd-make", IPP_TAG_TEXT
);
7230 model
= ippFindAttribute(con
->request
, "ppd-make-and-model",
7232 model_number
= ippFindAttribute(con
->request
, "ppd-model-number",
7234 product
= ippFindAttribute(con
->request
, "ppd-product", IPP_TAG_TEXT
);
7235 psversion
= ippFindAttribute(con
->request
, "ppd-psversion", IPP_TAG_TEXT
);
7236 type
= ippFindAttribute(con
->request
, "ppd-type", IPP_TAG_KEYWORD
);
7237 requested
= ippFindAttribute(con
->request
, "requested-attributes",
7239 exclude
= ippFindAttribute(con
->request
, "exclude-schemes",
7241 include
= ippFindAttribute(con
->request
, "include-schemes",
7245 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
7247 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
7250 url_encode_attr(device
, device_str
, sizeof(device_str
));
7252 device_str
[0] = '\0';
7255 url_encode_attr(language
, language_str
, sizeof(language_str
));
7257 language_str
[0] = '\0';
7260 url_encode_attr(make
, make_str
, sizeof(make_str
));
7265 url_encode_attr(model
, model_str
, sizeof(model_str
));
7267 model_str
[0] = '\0';
7270 snprintf(model_number_str
, sizeof(model_number_str
), "ppd-model-number=%d",
7271 model_number
->values
[0].integer
);
7273 model_number_str
[0] = '\0';
7276 url_encode_attr(product
, product_str
, sizeof(product_str
));
7278 product_str
[0] = '\0';
7281 url_encode_attr(psversion
, psversion_str
, sizeof(psversion_str
));
7283 psversion_str
[0] = '\0';
7286 url_encode_attr(type
, type_str
, sizeof(type_str
));
7291 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
7293 exclude_str
[0] = '\0';
7296 url_encode_attr(include
, include_str
, sizeof(include_str
));
7298 include_str
[0] = '\0';
7300 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7301 snprintf(options
, sizeof(options
),
7302 "list+%d+%d+%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
7303 con
->request
->request
.op
.request_id
,
7304 limit
? limit
->values
[0].integer
: 0,
7306 device
? "%20" : "", device_str
,
7307 language
? "%20" : "", language_str
,
7308 make
? "%20" : "", make_str
,
7309 model
? "%20" : "", model_str
,
7310 model_number
? "%20" : "", model_number_str
,
7311 product
? "%20" : "", product_str
,
7312 psversion
? "%20" : "", psversion_str
,
7313 type
? "%20" : "", type_str
,
7314 exclude_str
[0] ? "%20" : "", exclude_str
,
7315 include_str
[0] ? "%20" : "", include_str
);
7317 if (cupsdSendCommand(con
, command
, options
, 0))
7320 * Command started successfully, don't send an IPP response here...
7323 ippDelete(con
->response
);
7324 con
->response
= NULL
;
7329 * Command failed, return "internal error" so the user knows something
7333 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7334 _("cups-driverd failed to execute."));
7340 * 'get_printer_attrs()' - Get printer attributes.
7344 get_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
7345 ipp_attribute_t
*uri
) /* I - Printer URI */
7347 http_status_t status
; /* Policy status */
7348 cups_ptype_t dtype
; /* Destination type (printer/class) */
7349 cupsd_printer_t
*printer
; /* Printer/class */
7350 cups_array_t
*ra
; /* Requested attributes array */
7353 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_attrs(%p[%d], %s)", con
,
7354 con
->number
, uri
->values
[0].string
.text
);
7357 * Is the destination valid?
7360 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7366 send_ipp_status(con
, IPP_NOT_FOUND
,
7367 _("The printer or class does not exist."));
7375 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7377 send_http_error(con
, status
, printer
);
7382 * Send the attributes...
7385 ra
= create_requested_array(con
->request
);
7387 copy_printer_attrs(con
, printer
, ra
);
7389 cupsArrayDelete(ra
);
7391 con
->response
->request
.status
.status_code
= IPP_OK
;
7396 * 'get_printer_supported()' - Get printer supported values.
7400 get_printer_supported(
7401 cupsd_client_t
*con
, /* I - Client connection */
7402 ipp_attribute_t
*uri
) /* I - Printer URI */
7404 http_status_t status
; /* Policy status */
7405 cups_ptype_t dtype
; /* Destination type (printer/class) */
7406 cupsd_printer_t
*printer
; /* Printer/class */
7409 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_supported(%p[%d], %s)", con
,
7410 con
->number
, uri
->values
[0].string
.text
);
7413 * Is the destination valid?
7416 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7422 send_ipp_status(con
, IPP_NOT_FOUND
,
7423 _("The printer or class does not exist."));
7431 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7433 send_http_error(con
, status
, printer
);
7438 * Return a list of attributes that can be set via Set-Printer-Attributes.
7441 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7442 "printer-geo-location", 0);
7443 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7445 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7446 "printer-location", 0);
7447 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7448 "printer-organization", 0);
7449 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7450 "printer-organizational-unit", 0);
7452 con
->response
->request
.status
.status_code
= IPP_OK
;
7457 * 'get_printers()' - Get a list of printers or classes.
7461 get_printers(cupsd_client_t
*con
, /* I - Client connection */
7462 int type
) /* I - 0 or CUPS_PRINTER_CLASS */
7464 http_status_t status
; /* Policy status */
7465 ipp_attribute_t
*attr
; /* Current attribute */
7466 int limit
; /* Max number of printers to return */
7467 int count
; /* Number of printers that match */
7468 cupsd_printer_t
*printer
; /* Current printer pointer */
7469 cups_ptype_t printer_type
, /* printer-type attribute */
7470 printer_mask
; /* printer-type-mask attribute */
7471 char *location
; /* Location string */
7472 const char *username
; /* Current user */
7473 char *first_printer_name
; /* first-printer-name attribute */
7474 cups_array_t
*ra
; /* Requested attributes array */
7475 int local
; /* Local connection? */
7478 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printers(%p[%d], %x)", con
,
7485 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7487 send_http_error(con
, status
, NULL
);
7492 * Check for printers...
7495 if (!Printers
|| !cupsArrayCount(Printers
))
7497 send_ipp_status(con
, IPP_NOT_FOUND
, _("No destinations added."));
7502 * See if they want to limit the number of printers reported...
7505 if ((attr
= ippFindAttribute(con
->request
, "limit",
7506 IPP_TAG_INTEGER
)) != NULL
)
7507 limit
= attr
->values
[0].integer
;
7511 if ((attr
= ippFindAttribute(con
->request
, "first-printer-name",
7512 IPP_TAG_NAME
)) != NULL
)
7513 first_printer_name
= attr
->values
[0].string
.text
;
7515 first_printer_name
= NULL
;
7518 * Support filtering...
7521 if ((attr
= ippFindAttribute(con
->request
, "printer-type",
7522 IPP_TAG_ENUM
)) != NULL
)
7523 printer_type
= (cups_ptype_t
)attr
->values
[0].integer
;
7525 printer_type
= (cups_ptype_t
)0;
7527 if ((attr
= ippFindAttribute(con
->request
, "printer-type-mask",
7528 IPP_TAG_ENUM
)) != NULL
)
7529 printer_mask
= (cups_ptype_t
)attr
->values
[0].integer
;
7531 printer_mask
= (cups_ptype_t
)0;
7533 local
= httpAddrLocalhost(&(con
->clientaddr
));
7535 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
7536 IPP_TAG_TEXT
)) != NULL
)
7537 location
= attr
->values
[0].string
.text
;
7541 if (con
->username
[0])
7542 username
= con
->username
;
7543 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7544 IPP_TAG_NAME
)) != NULL
)
7545 username
= attr
->values
[0].string
.text
;
7549 ra
= create_requested_array(con
->request
);
7552 * OK, build a list of printers for this printer...
7555 if (first_printer_name
)
7557 if ((printer
= cupsdFindDest(first_printer_name
)) == NULL
)
7558 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7561 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7564 count
< limit
&& printer
;
7565 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
7567 if (!local
&& !printer
->shared
)
7570 if ((!type
|| (printer
->type
& CUPS_PRINTER_CLASS
) == type
) &&
7571 (printer
->type
& printer_mask
) == printer_type
&&
7573 (printer
->location
&& !_cups_strcasecmp(printer
->location
, location
))))
7576 * If a username is specified, see if it is allowed or denied
7580 if (cupsArrayCount(printer
->users
) && username
&&
7581 !user_allowed(printer
, username
))
7585 * Add the group separator as needed...
7589 ippAddSeparator(con
->response
);
7594 * Send the attributes...
7597 copy_printer_attrs(con
, printer
, ra
);
7601 cupsArrayDelete(ra
);
7603 con
->response
->request
.status
.status_code
= IPP_OK
;
7608 * 'get_subscription_attrs()' - Get subscription attributes.
7612 get_subscription_attrs(
7613 cupsd_client_t
*con
, /* I - Client connection */
7614 int sub_id
) /* I - Subscription ID */
7616 http_status_t status
; /* Policy status */
7617 cupsd_subscription_t
*sub
; /* Subscription */
7618 cupsd_policy_t
*policy
; /* Current security policy */
7619 cups_array_t
*ra
, /* Requested attributes array */
7620 *exclude
; /* Private attributes array */
7623 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7624 "get_subscription_attrs(con=%p[%d], sub_id=%d)",
7625 con
, con
->number
, sub_id
);
7628 * Expire subscriptions as needed...
7631 cupsdExpireSubscriptions(NULL
, NULL
);
7634 * Is the subscription ID valid?
7637 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
7640 * Bad subscription ID...
7643 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
7653 policy
= sub
->dest
->op_policy_ptr
;
7655 policy
= DefaultPolicyPtr
;
7657 if ((status
= cupsdCheckPolicy(policy
, con
, sub
->owner
)) != HTTP_OK
)
7659 send_http_error(con
, status
, sub
->dest
);
7663 exclude
= cupsdGetPrivateAttrs(policy
, con
, sub
->dest
, sub
->owner
);
7666 * Copy the subscription attributes to the response using the
7667 * requested-attributes attribute that may be provided by the client.
7670 ra
= create_requested_array(con
->request
);
7672 copy_subscription_attrs(con
, sub
, ra
, exclude
);
7674 cupsArrayDelete(ra
);
7676 con
->response
->request
.status
.status_code
= IPP_OK
;
7681 * 'get_subscriptions()' - Get subscriptions.
7685 get_subscriptions(cupsd_client_t
*con
, /* I - Client connection */
7686 ipp_attribute_t
*uri
) /* I - Printer/job URI */
7688 http_status_t status
; /* Policy status */
7689 int count
; /* Number of subscriptions */
7690 int limit
; /* Limit */
7691 cupsd_subscription_t
*sub
; /* Subscription */
7692 cups_array_t
*ra
; /* Requested attributes array */
7693 ipp_attribute_t
*attr
; /* Attribute */
7694 cups_ptype_t dtype
; /* Destination type (printer/class) */
7695 char scheme
[HTTP_MAX_URI
],
7696 /* Scheme portion of URI */
7697 username
[HTTP_MAX_URI
],
7698 /* Username portion of URI */
7700 /* Host portion of URI */
7701 resource
[HTTP_MAX_URI
];
7702 /* Resource portion of URI */
7703 int port
; /* Port portion of URI */
7704 cupsd_job_t
*job
; /* Job pointer */
7705 cupsd_printer_t
*printer
; /* Printer */
7706 cupsd_policy_t
*policy
; /* Policy */
7707 cups_array_t
*exclude
; /* Private attributes array */
7710 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7711 "get_subscriptions(con=%p[%d], uri=%s)",
7712 con
, con
->number
, uri
->values
[0].string
.text
);
7715 * Is the destination valid?
7718 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7719 sizeof(scheme
), username
, sizeof(username
), host
,
7720 sizeof(host
), &port
, resource
, sizeof(resource
));
7722 if (!strcmp(resource
, "/") ||
7723 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6) ||
7724 (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10) ||
7725 (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9))
7730 else if (!strncmp(resource
, "/jobs/", 6) && resource
[6])
7733 job
= cupsdFindJob(atoi(resource
+ 6));
7737 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
7738 atoi(resource
+ 6));
7742 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7748 send_ipp_status(con
, IPP_NOT_FOUND
,
7749 _("The printer or class does not exist."));
7752 else if ((attr
= ippFindAttribute(con
->request
, "notify-job-id",
7753 IPP_TAG_INTEGER
)) != NULL
)
7755 job
= cupsdFindJob(attr
->values
[0].integer
);
7759 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
7760 attr
->values
[0].integer
);
7772 policy
= printer
->op_policy_ptr
;
7774 policy
= DefaultPolicyPtr
;
7776 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
7778 send_http_error(con
, status
, printer
);
7783 * Expire subscriptions as needed...
7786 cupsdExpireSubscriptions(NULL
, NULL
);
7789 * Copy the subscription attributes to the response using the
7790 * requested-attributes attribute that may be provided by the client.
7793 ra
= create_requested_array(con
->request
);
7795 if ((attr
= ippFindAttribute(con
->request
, "limit",
7796 IPP_TAG_INTEGER
)) != NULL
)
7797 limit
= attr
->values
[0].integer
;
7802 * See if we only want to see subscriptions for a specific user...
7805 if ((attr
= ippFindAttribute(con
->request
, "my-subscriptions",
7806 IPP_TAG_BOOLEAN
)) != NULL
&&
7807 attr
->values
[0].boolean
)
7808 strlcpy(username
, get_username(con
), sizeof(username
));
7812 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
), count
= 0;
7814 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
7815 if ((!printer
|| sub
->dest
== printer
) && (!job
|| sub
->job
== job
) &&
7816 (!username
[0] || !_cups_strcasecmp(username
, sub
->owner
)))
7818 ippAddSeparator(con
->response
);
7820 exclude
= cupsdGetPrivateAttrs(sub
->dest
? sub
->dest
->op_policy_ptr
:
7821 policy
, con
, sub
->dest
,
7824 copy_subscription_attrs(con
, sub
, ra
, exclude
);
7827 if (limit
&& count
>= limit
)
7831 cupsArrayDelete(ra
);
7834 con
->response
->request
.status
.status_code
= IPP_OK
;
7836 send_ipp_status(con
, IPP_NOT_FOUND
, _("No subscriptions found."));
7841 * 'get_username()' - Get the username associated with a request.
7844 static const char * /* O - Username */
7845 get_username(cupsd_client_t
*con
) /* I - Connection */
7847 ipp_attribute_t
*attr
; /* Attribute */
7850 if (con
->username
[0])
7851 return (con
->username
);
7852 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7853 IPP_TAG_NAME
)) != NULL
)
7854 return (attr
->values
[0].string
.text
);
7856 return ("anonymous");
7861 * 'hold_job()' - Hold a print job.
7865 hold_job(cupsd_client_t
*con
, /* I - Client connection */
7866 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
7868 ipp_attribute_t
*attr
; /* Current job-hold-until */
7869 const char *when
; /* New value */
7870 int jobid
; /* Job ID */
7871 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
7872 username
[HTTP_MAX_URI
], /* Username portion of URI */
7873 host
[HTTP_MAX_URI
], /* Host portion of URI */
7874 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7875 int port
; /* Port portion of URI */
7876 cupsd_job_t
*job
; /* Job information */
7879 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_job(%p[%d], %s)", con
, con
->number
,
7880 uri
->values
[0].string
.text
);
7883 * See if we have a job URI or a printer URI...
7886 if (!strcmp(uri
->name
, "printer-uri"))
7889 * Got a printer URI; see if we also have a job-id attribute...
7892 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7893 IPP_TAG_INTEGER
)) == NULL
)
7895 send_ipp_status(con
, IPP_BAD_REQUEST
,
7896 _("Got a printer-uri attribute but no job-id."));
7900 jobid
= attr
->values
[0].integer
;
7905 * Got a job URI; parse it to get the job ID...
7908 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7909 sizeof(scheme
), username
, sizeof(username
), host
,
7910 sizeof(host
), &port
, resource
, sizeof(resource
));
7912 if (strncmp(resource
, "/jobs/", 6))
7918 send_ipp_status(con
, IPP_BAD_REQUEST
,
7919 _("Bad job-uri \"%s\"."),
7920 uri
->values
[0].string
.text
);
7924 jobid
= atoi(resource
+ 6);
7928 * See if the job exists...
7931 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7934 * Nope - return a "not found" error...
7937 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
7942 * See if the job is owned by the requesting user...
7945 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7947 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
7948 cupsdFindDest(job
->dest
));
7953 * See if the job is in a state that allows holding...
7956 if (job
->state_value
> IPP_JOB_STOPPED
)
7959 * Return a "not-possible" error...
7962 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
7963 _("Job #%d is finished and cannot be altered."),
7969 * Hold the job and return...
7972 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
7973 IPP_TAG_KEYWORD
)) == NULL
)
7974 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
7978 when
= attr
->values
[0].string
.text
;
7980 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
7981 "Job job-hold-until value changed by user.");
7984 when
= "indefinite";
7986 cupsdSetJobHoldUntil(job
, when
, 1);
7987 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
, "Job held by \"%s\".",
7990 con
->response
->request
.status
.status_code
= IPP_OK
;
7995 * 'hold_new_jobs()' - Hold pending/new jobs on a printer or class.
7999 hold_new_jobs(cupsd_client_t
*con
, /* I - Connection */
8000 ipp_attribute_t
*uri
) /* I - Printer URI */
8002 http_status_t status
; /* Policy status */
8003 cups_ptype_t dtype
; /* Destination type (printer/class) */
8004 cupsd_printer_t
*printer
; /* Printer data */
8007 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_new_jobs(%p[%d], %s)", con
,
8008 con
->number
, uri
->values
[0].string
.text
);
8011 * Is the destination valid?
8014 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8020 send_ipp_status(con
, IPP_NOT_FOUND
,
8021 _("The printer or class does not exist."));
8029 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8031 send_http_error(con
, status
, printer
);
8036 * Hold pending/new jobs sent to the printer...
8039 printer
->holding_new_jobs
= 1;
8041 cupsdSetPrinterReasons(printer
, "+hold-new-jobs");
8043 if (dtype
& CUPS_PRINTER_CLASS
)
8044 cupsdLogMessage(CUPSD_LOG_INFO
,
8045 "Class \"%s\" now holding pending/new jobs (\"%s\").",
8046 printer
->name
, get_username(con
));
8048 cupsdLogMessage(CUPSD_LOG_INFO
,
8049 "Printer \"%s\" now holding pending/new jobs (\"%s\").",
8050 printer
->name
, get_username(con
));
8053 * Everything was ok, so return OK status...
8056 con
->response
->request
.status
.status_code
= IPP_OK
;
8061 * 'move_job()' - Move a job to a new destination.
8065 move_job(cupsd_client_t
*con
, /* I - Client connection */
8066 ipp_attribute_t
*uri
) /* I - Job URI */
8068 http_status_t status
; /* Policy status */
8069 ipp_attribute_t
*attr
; /* Current attribute */
8070 int jobid
; /* Job ID */
8071 cupsd_job_t
*job
; /* Current job */
8072 const char *src
; /* Source printer/class */
8073 cups_ptype_t stype
, /* Source type (printer or class) */
8074 dtype
; /* Destination type (printer/class) */
8075 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
8076 username
[HTTP_MAX_URI
], /* Username portion of URI */
8077 host
[HTTP_MAX_URI
], /* Host portion of URI */
8078 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8079 int port
; /* Port portion of URI */
8080 cupsd_printer_t
*sprinter
, /* Source printer */
8081 *dprinter
; /* Destination printer */
8084 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "move_job(%p[%d], %s)", con
, con
->number
,
8085 uri
->values
[0].string
.text
);
8088 * Get the new printer or class...
8091 if ((attr
= ippFindAttribute(con
->request
, "job-printer-uri",
8092 IPP_TAG_URI
)) == NULL
)
8095 * Need job-printer-uri...
8098 send_ipp_status(con
, IPP_BAD_REQUEST
,
8099 _("job-printer-uri attribute missing."));
8103 if (!cupsdValidateDest(attr
->values
[0].string
.text
, &dtype
, &dprinter
))
8109 send_ipp_status(con
, IPP_NOT_FOUND
,
8110 _("The printer or class does not exist."));
8115 * See if we have a job URI or a printer URI...
8118 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8119 sizeof(scheme
), username
, sizeof(username
), host
,
8120 sizeof(host
), &port
, resource
, sizeof(resource
));
8122 if (!strcmp(uri
->name
, "printer-uri"))
8125 * Got a printer URI; see if we also have a job-id attribute...
8128 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8129 IPP_TAG_INTEGER
)) == NULL
)
8135 if ((src
= cupsdValidateDest(uri
->values
[0].string
.text
, &stype
,
8136 &sprinter
)) == NULL
)
8142 send_ipp_status(con
, IPP_NOT_FOUND
,
8143 _("The printer or class does not exist."));
8152 * Otherwise, just move a single job...
8155 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
8158 * Nope - return a "not found" error...
8161 send_ipp_status(con
, IPP_NOT_FOUND
,
8162 _("Job #%d does not exist."), attr
->values
[0].integer
);
8168 * Job found, initialize source pointers...
8179 * Got a job URI; parse it to get the job ID...
8182 if (strncmp(resource
, "/jobs/", 6))
8188 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
8189 uri
->values
[0].string
.text
);
8194 * See if the job exists...
8197 jobid
= atoi(resource
+ 6);
8199 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8202 * Nope - return a "not found" error...
8205 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
8211 * Job found, initialize source pointers...
8220 * Check the policy of the destination printer...
8223 if ((status
= cupsdCheckPolicy(dprinter
->op_policy_ptr
, con
,
8224 job
? job
->username
: NULL
)) != HTTP_OK
)
8226 send_http_error(con
, status
, dprinter
);
8231 * Now move the job or jobs...
8237 * See if the job has been completed...
8240 if (job
->state_value
> IPP_JOB_STOPPED
)
8243 * Return a "not-possible" error...
8246 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8247 _("Job #%d is finished and cannot be altered."),
8253 * See if the job is owned by the requesting user...
8256 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8258 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8259 cupsdFindDest(job
->dest
));
8264 * Move the job to a different printer or class...
8267 cupsdMoveJob(job
, dprinter
);
8272 * Got the source printer, now look through the jobs...
8275 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
8277 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
8280 * See if the job is pointing at the source printer or has not been
8284 if (_cups_strcasecmp(job
->dest
, src
) ||
8285 job
->state_value
> IPP_JOB_STOPPED
)
8289 * See if the job can be moved by the requesting user...
8292 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8296 * Move the job to a different printer or class...
8299 cupsdMoveJob(job
, dprinter
);
8304 * Start jobs if possible...
8310 * Return with "everything is OK" status...
8313 con
->response
->request
.status
.status_code
= IPP_OK
;
8318 * 'ppd_parse_line()' - Parse a PPD default line.
8321 static int /* O - 0 on success, -1 on failure */
8322 ppd_parse_line(const char *line
, /* I - Line */
8323 char *option
, /* O - Option name */
8324 int olen
, /* I - Size of option name */
8325 char *choice
, /* O - Choice name */
8326 int clen
) /* I - Size of choice name */
8329 * Verify this is a default option line...
8332 if (strncmp(line
, "*Default", 8))
8336 * Read the option name...
8339 for (line
+= 8, olen
--;
8340 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
8351 * Skip everything else up to the colon (:)...
8354 while (*line
&& *line
!= ':')
8363 * Now grab the option choice, skipping leading whitespace...
8366 while (isspace(*line
& 255))
8370 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
8381 * Return with no errors...
8389 * 'print_job()' - Print a file to a printer or class.
8393 print_job(cupsd_client_t
*con
, /* I - Client connection */
8394 ipp_attribute_t
*uri
) /* I - Printer URI */
8396 ipp_attribute_t
*attr
; /* Current attribute */
8397 ipp_attribute_t
*doc_name
; /* document-name attribute */
8398 ipp_attribute_t
*format
; /* Document-format attribute */
8399 const char *default_format
; /* document-format-default value */
8400 cupsd_job_t
*job
; /* New job */
8401 char filename
[1024]; /* Job filename */
8402 mime_type_t
*filetype
; /* Type of file */
8403 char super
[MIME_MAX_SUPER
], /* Supertype of file */
8404 type
[MIME_MAX_TYPE
], /* Subtype of file */
8405 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
8406 /* Textual name of mime type */
8407 cupsd_printer_t
*printer
; /* Printer data */
8408 struct stat fileinfo
; /* File information */
8409 int kbytes
; /* Size of file */
8410 int compression
; /* Document compression */
8413 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "print_job(%p[%d], %s)", con
, con
->number
,
8414 uri
->values
[0].string
.text
);
8417 * Validate print file attributes, for now just document-format and
8418 * compression (CUPS only supports "none" and "gzip")...
8421 compression
= CUPS_FILE_NONE
;
8423 if ((attr
= ippFindAttribute(con
->request
, "compression",
8424 IPP_TAG_KEYWORD
)) != NULL
)
8426 if (strcmp(attr
->values
[0].string
.text
, "none")
8428 && strcmp(attr
->values
[0].string
.text
, "gzip")
8429 #endif /* HAVE_LIBZ */
8432 send_ipp_status(con
, IPP_ATTRIBUTES
,
8433 _("Unsupported compression \"%s\"."),
8434 attr
->values
[0].string
.text
);
8435 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
8436 "compression", NULL
, attr
->values
[0].string
.text
);
8441 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
8442 compression
= CUPS_FILE_GZIP
;
8443 #endif /* HAVE_LIBZ */
8447 * Do we have a file to print?
8452 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file in print request."));
8457 * Is the destination valid?
8460 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
8466 send_ipp_status(con
, IPP_NOT_FOUND
,
8467 _("The printer or class does not exist."));
8472 * Is it a format we support?
8475 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
8477 ippSetName(con
->request
, &doc_name
, "document-name-supplied");
8479 if ((format
= ippFindAttribute(con
->request
, "document-format",
8480 IPP_TAG_MIMETYPE
)) != NULL
)
8483 * Grab format from client...
8486 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%255[^;]", super
,
8489 send_ipp_status(con
, IPP_BAD_REQUEST
,
8490 _("Bad document-format \"%s\"."),
8491 format
->values
[0].string
.text
);
8495 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format-supplied", NULL
, ippGetString(format
, 0, NULL
));
8497 else if ((default_format
= cupsGetOption("document-format",
8498 printer
->num_options
,
8499 printer
->options
)) != NULL
)
8502 * Use default document format...
8505 if (sscanf(default_format
, "%15[^/]/%255[^;]", super
, type
) != 2)
8507 send_ipp_status(con
, IPP_BAD_REQUEST
,
8508 _("Bad document-format \"%s\"."),
8519 strlcpy(super
, "application", sizeof(super
));
8520 strlcpy(type
, "octet-stream", sizeof(type
));
8523 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
8526 * Auto-type the file...
8529 cupsdLogMessage(CUPSD_LOG_DEBUG
, "[Job ???] Auto-typing file...");
8532 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
8533 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
8537 filetype
= mimeType(MimeDatabase
, super
, type
);
8539 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job ???] Request file type is %s/%s.",
8540 filetype
->super
, filetype
->type
);
8542 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
, filetype
->type
);
8543 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format-detected", NULL
, mimetype
);
8546 filetype
= mimeType(MimeDatabase
, super
, type
);
8550 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
8553 * Replace the document-format attribute value with the auto-typed or
8557 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
8561 ippSetString(con
->request
, &format
, 0, mimetype
);
8563 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
8564 "document-format", NULL
, mimetype
);
8568 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
8569 _("Unsupported document-format \"%s\"."),
8570 format
? format
->values
[0].string
.text
:
8571 "application/octet-stream");
8572 cupsdLogMessage(CUPSD_LOG_INFO
,
8573 "Hint: Do you have the raw file printing rules enabled?");
8576 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
8577 "document-format", NULL
, format
->values
[0].string
.text
);
8583 * Read any embedded job ticket info from PS files...
8586 if (!_cups_strcasecmp(filetype
->super
, "application") &&
8587 (!_cups_strcasecmp(filetype
->type
, "postscript") ||
8588 !_cups_strcasecmp(filetype
->type
, "pdf")))
8589 read_job_ticket(con
);
8592 * Create the job object...
8595 if ((job
= add_job(con
, printer
, filetype
)) == NULL
)
8599 * Update quota data...
8602 if (stat(con
->filename
, &fileinfo
))
8605 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
8607 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
8609 job
->koctets
+= kbytes
;
8611 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets", IPP_TAG_INTEGER
)) != NULL
)
8612 attr
->values
[0].integer
+= kbytes
;
8615 * Add the job file...
8618 if (add_file(con
, job
, filetype
, compression
))
8621 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
, job
->num_files
);
8622 if (rename(con
->filename
, filename
))
8624 cupsdLogJob(job
, CUPSD_LOG_ERROR
, "Unable to rename job document file \"%s\": %s", filename
, strerror(errno
));
8626 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to rename job document file."));
8630 cupsdClearString(&con
->filename
);
8633 * See if we need to add the ending sheet...
8636 if (cupsdTimeoutJob(job
))
8640 * Log and save the job...
8643 cupsdLogJob(job
, CUPSD_LOG_INFO
,
8644 "File of type %s/%s queued by \"%s\".",
8645 filetype
->super
, filetype
->type
, job
->username
);
8646 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "hold_until=%d", (int)job
->hold_until
);
8647 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
8648 job
->dest
, job
->username
);
8651 * Start the job if possible...
8659 * 'read_job_ticket()' - Read a job ticket embedded in a print file.
8661 * This function only gets called when printing a single PDF or PostScript
8662 * file using the Print-Job operation. It doesn't work for Create-Job +
8663 * Send-File, since the job attributes need to be set at job creation
8664 * time for banners to work. The embedded job ticket stuff is here
8665 * primarily to allow the Windows printer driver for CUPS to pass in JCL
8666 * options and IPP attributes which otherwise would be lost.
8668 * The format of a job ticket is simple:
8670 * %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
8672 * %cupsJobTicket: attr1=value1
8673 * %cupsJobTicket: attr2=value2
8675 * %cupsJobTicket: attrN=valueN
8677 * Job ticket lines must appear immediately after the first line that
8678 * specifies PostScript (%!PS-Adobe-3.0) or PDF (%PDF) format, and CUPS
8679 * stops looking for job ticket info when it finds a line that does not begin
8680 * with "%cupsJobTicket:".
8682 * The maximum length of a job ticket line, including the prefix, is
8683 * 255 characters to conform with the Adobe DSC.
8685 * Read-only attributes are rejected with a notice to the error log in
8686 * case a malicious user tries anything. Since the job ticket is read
8687 * prior to attribute validation in print_job(), job ticket attributes
8688 * will go through the same validation as IPP attributes...
8692 read_job_ticket(cupsd_client_t
*con
) /* I - Client connection */
8694 cups_file_t
*fp
; /* File to read from */
8695 char line
[256]; /* Line data */
8696 int num_options
; /* Number of options */
8697 cups_option_t
*options
; /* Options */
8698 ipp_t
*ticket
; /* New attributes */
8699 ipp_attribute_t
*attr
, /* Current attribute */
8700 *attr2
, /* Job attribute */
8701 *prev2
; /* Previous job attribute */
8705 * First open the print file...
8708 if ((fp
= cupsFileOpen(con
->filename
, "rb")) == NULL
)
8710 cupsdLogMessage(CUPSD_LOG_ERROR
,
8711 "Unable to open print file for job ticket - %s",
8717 * Skip the first line...
8720 if (cupsFileGets(fp
, line
, sizeof(line
)) == NULL
)
8722 cupsdLogMessage(CUPSD_LOG_ERROR
,
8723 "Unable to read from print file for job ticket - %s",
8729 if (strncmp(line
, "%!PS-Adobe-", 11) && strncmp(line
, "%PDF-", 5))
8732 * Not a DSC-compliant file, so no job ticket info will be available...
8740 * Read job ticket info from the file...
8746 while (cupsFileGets(fp
, line
, sizeof(line
)))
8749 * Stop at the first non-ticket line...
8752 if (strncmp(line
, "%cupsJobTicket:", 15))
8756 * Add the options to the option array...
8759 num_options
= cupsParseOptions(line
+ 15, num_options
, &options
);
8763 * Done with the file; see if we have any options...
8768 if (num_options
== 0)
8772 * OK, convert the options to an attribute list, and apply them to
8777 cupsEncodeOptions(ticket
, num_options
, options
);
8780 * See what the user wants to change.
8783 for (attr
= ticket
->attrs
; attr
; attr
= attr
->next
)
8785 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
8788 if (!strncmp(attr
->name
, "date-time-at-", 13) ||
8789 !strcmp(attr
->name
, "job-impressions-completed") ||
8790 !strcmp(attr
->name
, "job-media-sheets-completed") ||
8791 !strncmp(attr
->name
, "job-k-octets", 12) ||
8792 !strcmp(attr
->name
, "job-id") ||
8793 !strcmp(attr
->name
, "job-originating-host-name") ||
8794 !strcmp(attr
->name
, "job-originating-user-name") ||
8795 !strcmp(attr
->name
, "job-pages-completed") ||
8796 !strcmp(attr
->name
, "job-printer-uri") ||
8797 !strncmp(attr
->name
, "job-state", 9) ||
8798 !strcmp(attr
->name
, "job-uri") ||
8799 !strncmp(attr
->name
, "time-at-", 8))
8800 continue; /* Read-only attrs */
8802 if ((attr2
= ippFindAttribute(con
->request
, attr
->name
,
8803 IPP_TAG_ZERO
)) != NULL
)
8806 * Some other value; first free the old value...
8809 if (con
->request
->attrs
== attr2
)
8811 con
->request
->attrs
= attr2
->next
;
8816 for (prev2
= con
->request
->attrs
; prev2
; prev2
= prev2
->next
)
8817 if (prev2
->next
== attr2
)
8819 prev2
->next
= attr2
->next
;
8824 if (con
->request
->last
== attr2
)
8825 con
->request
->last
= prev2
;
8827 ippDeleteAttribute(NULL
, attr2
);
8831 * Add new option by copying it...
8834 ippCopyAttribute(con
->request
, attr
, 0);
8838 * Then free the attribute list and option array...
8842 cupsFreeOptions(num_options
, options
);
8847 * 'reject_jobs()' - Reject print jobs to a printer.
8851 reject_jobs(cupsd_client_t
*con
, /* I - Client connection */
8852 ipp_attribute_t
*uri
) /* I - Printer or class URI */
8854 http_status_t status
; /* Policy status */
8855 cups_ptype_t dtype
; /* Destination type (printer/class) */
8856 cupsd_printer_t
*printer
; /* Printer data */
8857 ipp_attribute_t
*attr
; /* printer-state-message text */
8860 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "reject_jobs(%p[%d], %s)", con
,
8861 con
->number
, uri
->values
[0].string
.text
);
8864 * Is the destination valid?
8867 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8873 send_ipp_status(con
, IPP_NOT_FOUND
,
8874 _("The printer or class does not exist."));
8882 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8884 send_http_error(con
, status
, printer
);
8889 * Reject jobs sent to the printer...
8892 printer
->accepting
= 0;
8894 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
8895 IPP_TAG_TEXT
)) == NULL
)
8896 strlcpy(printer
->state_message
, "Rejecting Jobs",
8897 sizeof(printer
->state_message
));
8899 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
8900 sizeof(printer
->state_message
));
8902 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
8903 "No longer accepting jobs.");
8905 if (dtype
& CUPS_PRINTER_CLASS
)
8907 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
8909 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" rejecting jobs (\"%s\").",
8910 printer
->name
, get_username(con
));
8914 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
8916 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" rejecting jobs (\"%s\").",
8917 printer
->name
, get_username(con
));
8921 * Everything was ok, so return OK status...
8924 con
->response
->request
.status
.status_code
= IPP_OK
;
8929 * 'release_held_new_jobs()' - Release pending/new jobs on a printer or class.
8933 release_held_new_jobs(
8934 cupsd_client_t
*con
, /* I - Connection */
8935 ipp_attribute_t
*uri
) /* I - Printer URI */
8937 http_status_t status
; /* Policy status */
8938 cups_ptype_t dtype
; /* Destination type (printer/class) */
8939 cupsd_printer_t
*printer
; /* Printer data */
8942 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_held_new_jobs(%p[%d], %s)", con
,
8943 con
->number
, uri
->values
[0].string
.text
);
8946 * Is the destination valid?
8949 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8955 send_ipp_status(con
, IPP_NOT_FOUND
,
8956 _("The printer or class does not exist."));
8964 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8966 send_http_error(con
, status
, printer
);
8971 * Hold pending/new jobs sent to the printer...
8974 printer
->holding_new_jobs
= 0;
8976 cupsdSetPrinterReasons(printer
, "-hold-new-jobs");
8978 if (dtype
& CUPS_PRINTER_CLASS
)
8979 cupsdLogMessage(CUPSD_LOG_INFO
,
8980 "Class \"%s\" now printing pending/new jobs (\"%s\").",
8981 printer
->name
, get_username(con
));
8983 cupsdLogMessage(CUPSD_LOG_INFO
,
8984 "Printer \"%s\" now printing pending/new jobs (\"%s\").",
8985 printer
->name
, get_username(con
));
8990 * Everything was ok, so return OK status...
8993 con
->response
->request
.status
.status_code
= IPP_OK
;
8998 * 'release_job()' - Release a held print job.
9002 release_job(cupsd_client_t
*con
, /* I - Client connection */
9003 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9005 ipp_attribute_t
*attr
; /* Current attribute */
9006 int jobid
; /* Job ID */
9007 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9008 username
[HTTP_MAX_URI
], /* Username portion of URI */
9009 host
[HTTP_MAX_URI
], /* Host portion of URI */
9010 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9011 int port
; /* Port portion of URI */
9012 cupsd_job_t
*job
; /* Job information */
9015 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_job(%p[%d], %s)", con
,
9016 con
->number
, uri
->values
[0].string
.text
);
9019 * See if we have a job URI or a printer URI...
9022 if (!strcmp(uri
->name
, "printer-uri"))
9025 * Got a printer URI; see if we also have a job-id attribute...
9028 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9029 IPP_TAG_INTEGER
)) == NULL
)
9031 send_ipp_status(con
, IPP_BAD_REQUEST
,
9032 _("Got a printer-uri attribute but no job-id."));
9036 jobid
= attr
->values
[0].integer
;
9041 * Got a job URI; parse it to get the job ID...
9044 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9045 sizeof(scheme
), username
, sizeof(username
), host
,
9046 sizeof(host
), &port
, resource
, sizeof(resource
));
9048 if (strncmp(resource
, "/jobs/", 6))
9054 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9055 uri
->values
[0].string
.text
);
9059 jobid
= atoi(resource
+ 6);
9063 * See if the job exists...
9066 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9069 * Nope - return a "not found" error...
9072 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9077 * See if job is "held"...
9080 if (job
->state_value
!= IPP_JOB_HELD
)
9083 * Nope - return a "not possible" error...
9086 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not held."), jobid
);
9091 * See if the job is owned by the requesting user...
9094 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9096 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9097 cupsdFindDest(job
->dest
));
9102 * Reset the job-hold-until value to "no-hold"...
9105 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9106 IPP_TAG_KEYWORD
)) == NULL
)
9107 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9111 ippSetValueTag(job
->attrs
, &attr
, IPP_TAG_KEYWORD
);
9112 ippSetString(job
->attrs
, &attr
, 0, "no-hold");
9114 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
9115 "Job job-hold-until value changed by user.");
9116 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
9120 * Release the job and return...
9123 cupsdReleaseJob(job
);
9125 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
9126 "Job released by user.");
9128 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Released by \"%s\".", username
);
9130 con
->response
->request
.status
.status_code
= IPP_OK
;
9137 * 'renew_subscription()' - Renew an existing subscription...
9142 cupsd_client_t
*con
, /* I - Client connection */
9143 int sub_id
) /* I - Subscription ID */
9145 http_status_t status
; /* Policy status */
9146 cupsd_subscription_t
*sub
; /* Subscription */
9147 ipp_attribute_t
*lease
; /* notify-lease-duration */
9150 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
9151 "renew_subscription(con=%p[%d], sub_id=%d)",
9152 con
, con
->number
, sub_id
);
9155 * Is the subscription ID valid?
9158 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
9161 * Bad subscription ID...
9164 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
9172 * Job subscriptions cannot be renewed...
9175 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9176 _("Job subscriptions cannot be renewed."));
9184 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
9186 con
, sub
->owner
)) != HTTP_OK
)
9188 send_http_error(con
, status
, sub
->dest
);
9193 * Renew the subscription...
9196 lease
= ippFindAttribute(con
->request
, "notify-lease-duration",
9199 sub
->lease
= lease
? lease
->values
[0].integer
: DefaultLeaseDuration
;
9201 if (MaxLeaseDuration
&& (sub
->lease
== 0 || sub
->lease
> MaxLeaseDuration
))
9203 cupsdLogMessage(CUPSD_LOG_INFO
,
9204 "renew_subscription: Limiting notify-lease-duration to "
9207 sub
->lease
= MaxLeaseDuration
;
9210 sub
->expire
= sub
->lease
? time(NULL
) + sub
->lease
: 0;
9212 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
9214 con
->response
->request
.status
.status_code
= IPP_OK
;
9216 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
9217 "notify-lease-duration", sub
->lease
);
9222 * 'restart_job()' - Restart an old print job.
9226 restart_job(cupsd_client_t
*con
, /* I - Client connection */
9227 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9229 ipp_attribute_t
*attr
; /* Current attribute */
9230 int jobid
; /* Job ID */
9231 cupsd_job_t
*job
; /* Job information */
9232 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9233 username
[HTTP_MAX_URI
], /* Username portion of URI */
9234 host
[HTTP_MAX_URI
], /* Host portion of URI */
9235 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9236 int port
; /* Port portion of URI */
9239 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "restart_job(%p[%d], %s)", con
,
9240 con
->number
, uri
->values
[0].string
.text
);
9243 * See if we have a job URI or a printer URI...
9246 if (!strcmp(uri
->name
, "printer-uri"))
9249 * Got a printer URI; see if we also have a job-id attribute...
9252 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9253 IPP_TAG_INTEGER
)) == NULL
)
9255 send_ipp_status(con
, IPP_BAD_REQUEST
,
9256 _("Got a printer-uri attribute but no job-id."));
9260 jobid
= attr
->values
[0].integer
;
9265 * Got a job URI; parse it to get the job ID...
9268 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9269 sizeof(scheme
), username
, sizeof(username
), host
,
9270 sizeof(host
), &port
, resource
, sizeof(resource
));
9272 if (strncmp(resource
, "/jobs/", 6))
9278 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9279 uri
->values
[0].string
.text
);
9283 jobid
= atoi(resource
+ 6);
9287 * See if the job exists...
9290 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9293 * Nope - return a "not found" error...
9296 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9301 * See if job is in any of the "completed" states...
9304 if (job
->state_value
<= IPP_JOB_PROCESSING
)
9307 * Nope - return a "not possible" error...
9310 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not complete."),
9316 * See if we have retained the job files...
9321 if (!job
->attrs
|| job
->num_files
== 0)
9324 * Nope - return a "not possible" error...
9327 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9328 _("Job #%d cannot be restarted - no files."), jobid
);
9333 * See if the job is owned by the requesting user...
9336 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9338 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9339 cupsdFindDest(job
->dest
));
9344 * See if the job-hold-until attribute is specified...
9347 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
9348 IPP_TAG_KEYWORD
)) == NULL
)
9349 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
9351 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
9354 * Return the job to a held state...
9357 cupsdLogJob(job
, CUPSD_LOG_DEBUG
,
9358 "Restarted by \"%s\" with job-hold-until=%s.",
9359 username
, attr
->values
[0].string
.text
);
9360 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
9362 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
,
9363 NULL
, job
, "Job restarted by user with job-hold-until=%s",
9364 attr
->values
[0].string
.text
);
9369 * Restart the job...
9372 cupsdRestartJob(job
);
9376 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Restarted by \"%s\".", username
);
9378 con
->response
->request
.status
.status_code
= IPP_OK
;
9383 * 'save_auth_info()' - Save authentication information for a job.
9388 cupsd_client_t
*con
, /* I - Client connection */
9389 cupsd_job_t
*job
, /* I - Job */
9390 ipp_attribute_t
*auth_info
) /* I - auth-info attribute, if any */
9392 int i
; /* Looping var */
9393 char filename
[1024]; /* Job authentication filename */
9394 cups_file_t
*fp
; /* Job authentication file */
9395 char line
[65536]; /* Line for file */
9396 cupsd_printer_t
*dest
; /* Destination printer/class */
9400 * This function saves the in-memory authentication information for
9401 * a job so that it can be used to authenticate with a remote host.
9402 * The information is stored in a file that is readable only by the
9403 * root user. The fields are Base-64 encoded, each on a separate line,
9404 * followed by random number (up to 1024) of newlines to limit the
9405 * amount of information that is exposed.
9407 * Because of the potential for exposing of authentication information,
9408 * this functionality is only enabled when running cupsd as root.
9410 * This caching only works for the Basic and BasicDigest authentication
9411 * types. Digest authentication cannot be cached this way, and in
9412 * the future Kerberos authentication may make all of this obsolete.
9414 * Authentication information is saved whenever an authenticated
9415 * Print-Job, Create-Job, or CUPS-Authenticate-Job operation is
9418 * This information is deleted after a job is completed or canceled,
9419 * so reprints may require subsequent re-authentication.
9425 if ((dest
= cupsdFindDest(job
->dest
)) == NULL
)
9429 * Create the authentication file and change permissions...
9432 snprintf(filename
, sizeof(filename
), "%s/a%05d", RequestRoot
, job
->id
);
9433 if ((fp
= cupsFileOpen(filename
, "w")) == NULL
)
9435 cupsdLogMessage(CUPSD_LOG_ERROR
,
9436 "Unable to save authentication info to \"%s\" - %s",
9437 filename
, strerror(errno
));
9441 fchown(cupsFileNumber(fp
), 0, 0);
9442 fchmod(cupsFileNumber(fp
), 0400);
9444 cupsFilePuts(fp
, "CUPSD-AUTH-V3\n");
9447 i
< (int)(sizeof(job
->auth_env
) / sizeof(job
->auth_env
[0]));
9449 cupsdClearString(job
->auth_env
+ i
);
9451 if (auth_info
&& auth_info
->num_values
== dest
->num_auth_info_required
)
9454 * Write 1 to 3 auth values...
9458 i
< auth_info
->num_values
&&
9459 i
< (int)(sizeof(job
->auth_env
) / sizeof(job
->auth_env
[0]));
9462 if (strcmp(dest
->auth_info_required
[i
], "negotiate"))
9464 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[i
].string
.text
, (int)strlen(auth_info
->values
[i
].string
.text
));
9465 cupsFilePutConf(fp
, dest
->auth_info_required
[i
], line
);
9468 cupsFilePutConf(fp
, dest
->auth_info_required
[i
],
9469 auth_info
->values
[i
].string
.text
);
9471 if (!strcmp(dest
->auth_info_required
[i
], "username"))
9472 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_USERNAME=%s",
9473 auth_info
->values
[i
].string
.text
);
9474 else if (!strcmp(dest
->auth_info_required
[i
], "domain"))
9475 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_DOMAIN=%s",
9476 auth_info
->values
[i
].string
.text
);
9477 else if (!strcmp(dest
->auth_info_required
[i
], "password"))
9478 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_PASSWORD=%s",
9479 auth_info
->values
[i
].string
.text
);
9480 else if (!strcmp(dest
->auth_info_required
[i
], "negotiate"))
9481 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_NEGOTIATE=%s",
9482 auth_info
->values
[i
].string
.text
);
9487 else if (auth_info
&& auth_info
->num_values
== 2 &&
9488 dest
->num_auth_info_required
== 1 &&
9489 !strcmp(dest
->auth_info_required
[0], "negotiate"))
9492 * Allow fallback to username+password for Kerberized queues...
9495 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[0].string
.text
, (int)strlen(auth_info
->values
[0].string
.text
));
9496 cupsFilePutConf(fp
, "username", line
);
9498 cupsdSetStringf(job
->auth_env
+ 0, "AUTH_USERNAME=%s",
9499 auth_info
->values
[0].string
.text
);
9501 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[1].string
.text
, (int)strlen(auth_info
->values
[1].string
.text
));
9502 cupsFilePutConf(fp
, "password", line
);
9504 cupsdSetStringf(job
->auth_env
+ 1, "AUTH_PASSWORD=%s",
9505 auth_info
->values
[1].string
.text
);
9507 else if (con
->username
[0])
9510 * Write the authenticated username...
9513 httpEncode64_2(line
, sizeof(line
), con
->username
, (int)strlen(con
->username
));
9514 cupsFilePutConf(fp
, "username", line
);
9516 cupsdSetStringf(job
->auth_env
+ 0, "AUTH_USERNAME=%s", con
->username
);
9519 * Write the authenticated password...
9522 httpEncode64_2(line
, sizeof(line
), con
->password
, (int)strlen(con
->password
));
9523 cupsFilePutConf(fp
, "password", line
);
9525 cupsdSetStringf(job
->auth_env
+ 1, "AUTH_PASSWORD=%s", con
->password
);
9529 if (con
->gss_uid
> 0)
9531 cupsFilePrintf(fp
, "uid %d\n", (int)con
->gss_uid
);
9532 cupsdSetStringf(&job
->auth_uid
, "AUTH_UID=%d", (int)con
->gss_uid
);
9534 #endif /* HAVE_GSSAPI */
9537 * Write a random number of newlines to the end of the file...
9540 for (i
= (CUPS_RAND() % 1024); i
>= 0; i
--)
9541 cupsFilePutChar(fp
, '\n');
9544 * Close the file and return...
9552 * 'send_document()' - Send a file to a printer or class.
9556 send_document(cupsd_client_t
*con
, /* I - Client connection */
9557 ipp_attribute_t
*uri
) /* I - Printer URI */
9559 ipp_attribute_t
*attr
; /* Current attribute */
9560 ipp_attribute_t
*format
; /* Request's document-format attribute */
9561 ipp_attribute_t
*jformat
; /* Job's document-format attribute */
9562 const char *default_format
;/* document-format-default value */
9563 int jobid
; /* Job ID number */
9564 cupsd_job_t
*job
; /* Current job */
9565 char job_uri
[HTTP_MAX_URI
],
9567 scheme
[HTTP_MAX_URI
],
9568 /* Method portion of URI */
9569 username
[HTTP_MAX_URI
],
9570 /* Username portion of URI */
9572 /* Host portion of URI */
9573 resource
[HTTP_MAX_URI
];
9574 /* Resource portion of URI */
9575 int port
; /* Port portion of URI */
9576 mime_type_t
*filetype
; /* Type of file */
9577 char super
[MIME_MAX_SUPER
],
9578 /* Supertype of file */
9579 type
[MIME_MAX_TYPE
],
9580 /* Subtype of file */
9581 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
9582 /* Textual name of mime type */
9583 char filename
[1024]; /* Job filename */
9584 cupsd_printer_t
*printer
; /* Current printer */
9585 struct stat fileinfo
; /* File information */
9586 int kbytes
; /* Size of file */
9587 int compression
; /* Type of compression */
9588 int start_job
; /* Start the job? */
9591 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "send_document(%p[%d], %s)", con
,
9592 con
->number
, uri
->values
[0].string
.text
);
9595 * See if we have a job URI or a printer URI...
9598 if (!strcmp(uri
->name
, "printer-uri"))
9601 * Got a printer URI; see if we also have a job-id attribute...
9604 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9605 IPP_TAG_INTEGER
)) == NULL
)
9607 send_ipp_status(con
, IPP_BAD_REQUEST
,
9608 _("Got a printer-uri attribute but no job-id."));
9612 jobid
= attr
->values
[0].integer
;
9617 * Got a job URI; parse it to get the job ID...
9620 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9621 sizeof(scheme
), username
, sizeof(username
), host
,
9622 sizeof(host
), &port
, resource
, sizeof(resource
));
9624 if (strncmp(resource
, "/jobs/", 6))
9630 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9631 uri
->values
[0].string
.text
);
9635 jobid
= atoi(resource
+ 6);
9639 * See if the job exists...
9642 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9645 * Nope - return a "not found" error...
9648 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9652 printer
= cupsdFindDest(job
->dest
);
9655 * See if the job is owned by the requesting user...
9658 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9660 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9661 cupsdFindDest(job
->dest
));
9666 * OK, see if the client is sending the document compressed - CUPS
9667 * only supports "none" and "gzip".
9670 compression
= CUPS_FILE_NONE
;
9672 if ((attr
= ippFindAttribute(con
->request
, "compression",
9673 IPP_TAG_KEYWORD
)) != NULL
)
9675 if (strcmp(attr
->values
[0].string
.text
, "none")
9677 && strcmp(attr
->values
[0].string
.text
, "gzip")
9678 #endif /* HAVE_LIBZ */
9681 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Unsupported compression \"%s\"."),
9682 attr
->values
[0].string
.text
);
9683 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
9684 "compression", NULL
, attr
->values
[0].string
.text
);
9689 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
9690 compression
= CUPS_FILE_GZIP
;
9691 #endif /* HAVE_LIBZ */
9695 * Do we have a file to print?
9698 if ((attr
= ippFindAttribute(con
->request
, "last-document",
9699 IPP_TAG_BOOLEAN
)) == NULL
)
9701 send_ipp_status(con
, IPP_BAD_REQUEST
,
9702 _("Missing last-document attribute in request."));
9709 * Check for an empty request with "last-document" set to true, which is
9710 * used to close an "open" job by RFC 2911, section 3.3.2.
9713 if (job
->num_files
> 0 && attr
->values
[0].boolean
)
9716 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file in print request."));
9721 * Is it a format we support?
9726 if ((format
= ippFindAttribute(con
->request
, "document-format",
9727 IPP_TAG_MIMETYPE
)) != NULL
)
9730 * Grab format from client...
9733 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%255[^;]",
9736 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"."),
9737 format
->values
[0].string
.text
);
9741 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format-supplied", NULL
, ippGetString(format
, 0, NULL
));
9743 else if ((default_format
= cupsGetOption("document-format",
9744 printer
->num_options
,
9745 printer
->options
)) != NULL
)
9748 * Use default document format...
9751 if (sscanf(default_format
, "%15[^/]/%255[^;]", super
, type
) != 2)
9753 send_ipp_status(con
, IPP_BAD_REQUEST
,
9754 _("Bad document-format-default \"%s\"."), default_format
);
9761 * No document format attribute? Auto-type it!
9764 strlcpy(super
, "application", sizeof(super
));
9765 strlcpy(type
, "octet-stream", sizeof(type
));
9768 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
9771 * Auto-type the file...
9774 ipp_attribute_t
*doc_name
; /* document-name attribute */
9777 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Auto-typing file...");
9779 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
9780 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
9781 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
9785 filetype
= mimeType(MimeDatabase
, super
, type
);
9788 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Request file type is %s/%s.",
9789 filetype
->super
, filetype
->type
);
9791 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
, filetype
->type
);
9792 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format-detected", NULL
, mimetype
);
9795 filetype
= mimeType(MimeDatabase
, super
, type
);
9800 * Replace the document-format attribute value with the auto-typed or
9804 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9807 if ((jformat
= ippFindAttribute(job
->attrs
, "document-format",
9808 IPP_TAG_MIMETYPE
)) != NULL
)
9809 ippSetString(job
->attrs
, &jformat
, 0, mimetype
);
9811 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
9812 "document-format", NULL
, mimetype
);
9816 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9817 _("Unsupported document-format \"%s/%s\"."), super
, type
);
9818 cupsdLogMessage(CUPSD_LOG_INFO
,
9819 "Hint: Do you have the raw file printing rules enabled?");
9822 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9823 "document-format", NULL
, format
->values
[0].string
.text
);
9828 if (printer
->filetypes
&& !cupsArrayFind(printer
->filetypes
, filetype
))
9830 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9833 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9834 _("Unsupported document-format \"%s\"."), mimetype
);
9836 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9837 "document-format", NULL
, mimetype
);
9843 * Add the file to the job...
9846 if (add_file(con
, job
, filetype
, compression
))
9849 if ((attr
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
)) != NULL
)
9850 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name-supplied", NULL
, ippGetString(attr
, 0, NULL
));
9852 if (stat(con
->filename
, &fileinfo
))
9855 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
9857 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
9859 job
->koctets
+= kbytes
;
9861 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets", IPP_TAG_INTEGER
)) != NULL
)
9862 attr
->values
[0].integer
+= kbytes
;
9864 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
, job
->num_files
);
9865 if (rename(con
->filename
, filename
))
9867 cupsdLogJob(job
, CUPSD_LOG_ERROR
, "Unable to rename job document file \"%s\": %s", filename
, strerror(errno
));
9869 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to rename job document file."));
9873 cupsdClearString(&con
->filename
);
9875 cupsdLogJob(job
, CUPSD_LOG_INFO
, "File of type %s/%s queued by \"%s\".",
9876 filetype
->super
, filetype
->type
, job
->username
);
9879 * Start the job if this is the last document...
9884 if ((attr
= ippFindAttribute(con
->request
, "last-document",
9885 IPP_TAG_BOOLEAN
)) != NULL
&&
9886 attr
->values
[0].boolean
)
9889 * See if we need to add the ending sheet...
9892 if (cupsdTimeoutJob(job
))
9895 if (job
->state_value
== IPP_JOB_STOPPED
)
9897 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9898 job
->state_value
= IPP_JOB_PENDING
;
9900 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
9902 else if (job
->state_value
== IPP_JOB_HELD
)
9904 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9905 IPP_TAG_KEYWORD
)) == NULL
)
9906 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9908 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9910 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9911 job
->state_value
= IPP_JOB_PENDING
;
9913 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
9916 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-hold-until-specified");
9920 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
9926 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9927 IPP_TAG_KEYWORD
)) == NULL
)
9928 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9930 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9932 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
9933 job
->state_value
= IPP_JOB_HELD
;
9934 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
9936 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-incoming");
9939 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
9946 * Fill in the response info...
9949 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
9950 con
->clientname
, con
->clientport
, "/jobs/%d", jobid
);
9951 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
9954 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", jobid
);
9956 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
9958 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons",
9959 NULL
, job
->reasons
->values
[0].string
.text
);
9961 con
->response
->request
.status
.status_code
= IPP_OK
;
9964 * Start the job if necessary...
9973 * 'send_http_error()' - Send a HTTP error back to the IPP client.
9978 cupsd_client_t
*con
, /* I - Client connection */
9979 http_status_t status
, /* I - HTTP status code */
9980 cupsd_printer_t
*printer
) /* I - Printer, if any */
9982 ipp_attribute_t
*uri
; /* Request URI, if any */
9985 if ((uri
= ippFindAttribute(con
->request
, "printer-uri",
9986 IPP_TAG_URI
)) == NULL
)
9987 uri
= ippFindAttribute(con
->request
, "job-uri", IPP_TAG_URI
);
9989 cupsdLogMessage(status
== HTTP_FORBIDDEN
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
9990 "[Client %d] Returning HTTP %s for %s (%s) from %s",
9991 con
->number
, httpStatus(status
),
9993 ippOpString(con
->request
->request
.op
.operation_id
) :
9995 uri
? uri
->values
[0].string
.text
: "no URI",
9996 con
->http
->hostname
);
10000 int auth_type
; /* Type of authentication required */
10003 auth_type
= CUPSD_AUTH_NONE
;
10005 if (status
== HTTP_UNAUTHORIZED
&&
10006 printer
->num_auth_info_required
> 0 &&
10007 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
10009 (con
->request
->request
.op
.operation_id
== IPP_PRINT_JOB
||
10010 con
->request
->request
.op
.operation_id
== IPP_CREATE_JOB
||
10011 con
->request
->request
.op
.operation_id
== CUPS_AUTHENTICATE_JOB
))
10014 * Creating and authenticating jobs requires Kerberos...
10017 auth_type
= CUPSD_AUTH_NEGOTIATE
;
10022 * Use policy/location-defined authentication requirements...
10025 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
10026 cupsd_location_t
*auth
; /* Pointer to authentication element */
10029 if (printer
->type
& CUPS_PRINTER_CLASS
)
10030 snprintf(resource
, sizeof(resource
), "/classes/%s", printer
->name
);
10032 snprintf(resource
, sizeof(resource
), "/printers/%s", printer
->name
);
10034 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
10035 auth
->type
== CUPSD_AUTH_NONE
)
10036 auth
= cupsdFindPolicyOp(printer
->op_policy_ptr
,
10038 con
->request
->request
.op
.operation_id
:
10043 if (auth
->type
== CUPSD_AUTH_DEFAULT
)
10044 auth_type
= cupsdDefaultAuthType();
10046 auth_type
= auth
->type
;
10050 cupsdSendError(con
, status
, auth_type
);
10053 cupsdSendError(con
, status
, CUPSD_AUTH_NONE
);
10055 ippDelete(con
->response
);
10056 con
->response
= NULL
;
10063 * 'send_ipp_status()' - Send a status back to the IPP client.
10067 send_ipp_status(cupsd_client_t
*con
, /* I - Client connection */
10068 ipp_status_t status
, /* I - IPP status code */
10069 const char *message
,/* I - Status message */
10070 ...) /* I - Additional args as needed */
10072 va_list ap
; /* Pointer to additional args */
10073 char formatted
[1024]; /* Formatted errror message */
10076 va_start(ap
, message
);
10077 vsnprintf(formatted
, sizeof(formatted
),
10078 _cupsLangString(con
->language
, message
), ap
);
10081 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s: %s",
10082 ippOpString(con
->request
->request
.op
.operation_id
),
10083 ippErrorString(status
), formatted
);
10085 con
->response
->request
.status
.status_code
= status
;
10087 if (ippFindAttribute(con
->response
, "attributes-charset",
10088 IPP_TAG_ZERO
) == NULL
)
10089 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
10090 "attributes-charset", NULL
, "utf-8");
10092 if (ippFindAttribute(con
->response
, "attributes-natural-language",
10093 IPP_TAG_ZERO
) == NULL
)
10094 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
10095 "attributes-natural-language", NULL
, DefaultLanguage
);
10097 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
10098 "status-message", NULL
, formatted
);
10103 * 'set_default()' - Set the default destination...
10107 set_default(cupsd_client_t
*con
, /* I - Client connection */
10108 ipp_attribute_t
*uri
) /* I - Printer URI */
10110 http_status_t status
; /* Policy status */
10111 cups_ptype_t dtype
; /* Destination type (printer/class) */
10112 cupsd_printer_t
*printer
, /* Printer */
10113 *oldprinter
; /* Old default printer */
10116 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_default(%p[%d], %s)", con
,
10117 con
->number
, uri
->values
[0].string
.text
);
10120 * Is the destination valid?
10123 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10129 send_ipp_status(con
, IPP_NOT_FOUND
,
10130 _("The printer or class does not exist."));
10138 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
10140 send_http_error(con
, status
, NULL
);
10145 * Set it as the default...
10148 oldprinter
= DefaultPrinter
;
10149 DefaultPrinter
= printer
;
10152 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, oldprinter
, NULL
,
10153 "%s is no longer the default printer.", oldprinter
->name
);
10155 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
10156 "%s is now the default printer.", printer
->name
);
10158 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
| CUPSD_DIRTY_CLASSES
|
10159 CUPSD_DIRTY_PRINTCAP
);
10161 cupsdLogMessage(CUPSD_LOG_INFO
,
10162 "Default destination set to \"%s\" by \"%s\".",
10163 printer
->name
, get_username(con
));
10166 * Everything was ok, so return OK status...
10169 con
->response
->request
.status
.status_code
= IPP_OK
;
10174 * 'set_job_attrs()' - Set job attributes.
10178 set_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
10179 ipp_attribute_t
*uri
) /* I - Job URI */
10181 ipp_attribute_t
*attr
, /* Current attribute */
10182 *attr2
; /* Job attribute */
10183 int jobid
; /* Job ID */
10184 cupsd_job_t
*job
; /* Current job */
10185 char scheme
[HTTP_MAX_URI
],
10186 /* Method portion of URI */
10187 username
[HTTP_MAX_URI
],
10188 /* Username portion of URI */
10189 host
[HTTP_MAX_URI
],
10190 /* Host portion of URI */
10191 resource
[HTTP_MAX_URI
];
10192 /* Resource portion of URI */
10193 int port
; /* Port portion of URI */
10194 int event
; /* Events? */
10195 int check_jobs
; /* Check jobs? */
10198 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_job_attrs(%p[%d], %s)", con
,
10199 con
->number
, uri
->values
[0].string
.text
);
10202 * Start with "everything is OK" status...
10205 con
->response
->request
.status
.status_code
= IPP_OK
;
10208 * See if we have a job URI or a printer URI...
10211 if (!strcmp(uri
->name
, "printer-uri"))
10214 * Got a printer URI; see if we also have a job-id attribute...
10217 if ((attr
= ippFindAttribute(con
->request
, "job-id",
10218 IPP_TAG_INTEGER
)) == NULL
)
10220 send_ipp_status(con
, IPP_BAD_REQUEST
,
10221 _("Got a printer-uri attribute but no job-id."));
10225 jobid
= attr
->values
[0].integer
;
10230 * Got a job URI; parse it to get the job ID...
10233 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
10234 sizeof(scheme
), username
, sizeof(username
), host
,
10235 sizeof(host
), &port
, resource
, sizeof(resource
));
10237 if (strncmp(resource
, "/jobs/", 6))
10243 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
10244 uri
->values
[0].string
.text
);
10248 jobid
= atoi(resource
+ 6);
10252 * See if the job exists...
10255 if ((job
= cupsdFindJob(jobid
)) == NULL
)
10258 * Nope - return a "not found" error...
10261 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
10266 * See if the job has been completed...
10269 if (job
->state_value
> IPP_JOB_STOPPED
)
10272 * Return a "not-possible" error...
10275 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10276 _("Job #%d is finished and cannot be altered."), jobid
);
10281 * See if the job is owned by the requesting user...
10284 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10286 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
10287 cupsdFindDest(job
->dest
));
10292 * See what the user wants to change.
10300 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10302 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
10305 if (!strcmp(attr
->name
, "attributes-charset") ||
10306 !strcmp(attr
->name
, "attributes-natural-language") ||
10307 !strncmp(attr
->name
, "date-time-at-", 13) ||
10308 !strncmp(attr
->name
, "document-compression", 20) ||
10309 !strncmp(attr
->name
, "document-format", 15) ||
10310 !strcmp(attr
->name
, "job-detailed-status-messages") ||
10311 !strcmp(attr
->name
, "job-document-access-errors") ||
10312 !strcmp(attr
->name
, "job-id") ||
10313 !strcmp(attr
->name
, "job-impressions-completed") ||
10314 !strcmp(attr
->name
, "job-k-octets-completed") ||
10315 !strcmp(attr
->name
, "job-media-sheets-completed") ||
10316 !strcmp(attr
->name
, "job-originating-host-name") ||
10317 !strcmp(attr
->name
, "job-originating-user-name") ||
10318 !strcmp(attr
->name
, "job-pages-completed") ||
10319 !strcmp(attr
->name
, "job-printer-up-time") ||
10320 !strcmp(attr
->name
, "job-printer-uri") ||
10321 !strcmp(attr
->name
, "job-sheets") ||
10322 !strcmp(attr
->name
, "job-state-message") ||
10323 !strcmp(attr
->name
, "job-state-reasons") ||
10324 !strcmp(attr
->name
, "job-uri") ||
10325 !strcmp(attr
->name
, "number-of-documents") ||
10326 !strcmp(attr
->name
, "number-of-intervening-jobs") ||
10327 !strcmp(attr
->name
, "output-device-assigned") ||
10328 !strncmp(attr
->name
, "time-at-", 8))
10334 send_ipp_status(con
, IPP_ATTRIBUTES_NOT_SETTABLE
,
10335 _("%s cannot be changed."), attr
->name
);
10337 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
10338 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
10342 if (!strcmp(attr
->name
, "job-priority"))
10345 * Change the job priority...
10348 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10350 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-priority value."));
10352 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
10353 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
10355 else if (job
->state_value
>= IPP_JOB_PROCESSING
)
10357 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10358 _("Job is completed and cannot be changed."));
10361 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10363 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-priority to %d",
10364 attr
->values
[0].integer
);
10365 cupsdSetJobPriority(job
, attr
->values
[0].integer
);
10368 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
|
10369 CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
;
10372 else if (!strcmp(attr
->name
, "job-state"))
10375 * Change the job state...
10378 if (attr
->value_tag
!= IPP_TAG_ENUM
)
10380 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-state value."));
10382 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
10383 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
10387 switch (attr
->values
[0].integer
)
10389 case IPP_JOB_PENDING
:
10390 case IPP_JOB_HELD
:
10391 if (job
->state_value
> IPP_JOB_HELD
)
10393 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10394 _("Job state cannot be changed."));
10397 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10399 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10400 attr
->values
[0].integer
);
10401 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
, CUPSD_JOB_DEFAULT
, "Job state changed by \"%s\"", username
);
10406 case IPP_JOB_PROCESSING
:
10407 case IPP_JOB_STOPPED
:
10408 if (job
->state_value
!= attr
->values
[0].integer
)
10410 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10411 _("Job state cannot be changed."));
10416 case IPP_JOB_CANCELED
:
10417 case IPP_JOB_ABORTED
:
10418 case IPP_JOB_COMPLETED
:
10419 if (job
->state_value
> IPP_JOB_PROCESSING
)
10421 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10422 _("Job state cannot be changed."));
10425 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10427 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10428 attr
->values
[0].integer
);
10429 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
,
10431 "Job state changed by \"%s\"", username
);
10438 else if (con
->response
->request
.status
.status_code
!= IPP_OK
)
10440 else if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10441 IPP_TAG_ZERO
)) != NULL
)
10444 * Some other value; first free the old value...
10447 if (job
->attrs
->prev
)
10448 job
->attrs
->prev
->next
= attr2
->next
;
10450 job
->attrs
->attrs
= attr2
->next
;
10452 if (job
->attrs
->last
== attr2
)
10453 job
->attrs
->last
= job
->attrs
->prev
;
10455 ippDeleteAttribute(NULL
, attr2
);
10458 * Then copy the attribute...
10461 ippCopyAttribute(job
->attrs
, attr
, 0);
10464 * See if the job-name or job-hold-until is being changed.
10467 if (!strcmp(attr
->name
, "job-hold-until"))
10469 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-hold-until to %s",
10470 attr
->values
[0].string
.text
);
10471 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
10473 if (!strcmp(attr
->values
[0].string
.text
, "no-hold"))
10475 cupsdReleaseJob(job
);
10479 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
,
10480 "Job held by \"%s\".", username
);
10482 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
;
10485 else if (attr
->value_tag
== IPP_TAG_DELETEATTR
)
10488 * Delete the attribute...
10491 if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10492 IPP_TAG_ZERO
)) != NULL
)
10494 if (job
->attrs
->prev
)
10495 job
->attrs
->prev
->next
= attr2
->next
;
10497 job
->attrs
->attrs
= attr2
->next
;
10499 if (attr2
== job
->attrs
->last
)
10500 job
->attrs
->last
= job
->attrs
->prev
;
10502 ippDeleteAttribute(NULL
, attr2
);
10504 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10510 * Add new option by copying it...
10513 ippCopyAttribute(job
->attrs
, attr
, 0);
10515 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10524 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10527 * Send events as needed...
10530 if (event
& CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
)
10531 cupsdAddEvent(CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
,
10532 cupsdFindDest(job
->dest
), job
,
10533 "Job priority changed by user.");
10535 if (event
& CUPSD_EVENT_JOB_STATE
)
10536 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
10537 job
->state_value
== IPP_JOB_HELD
?
10538 "Job held by user." : "Job restarted by user.");
10540 if (event
& CUPSD_EVENT_JOB_CONFIG_CHANGED
)
10541 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
10542 "Job options changed by user.");
10545 * Start jobs if possible...
10554 * 'set_printer_attrs()' - Set printer attributes.
10558 set_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
10559 ipp_attribute_t
*uri
) /* I - Printer */
10561 http_status_t status
; /* Policy status */
10562 cups_ptype_t dtype
; /* Destination type (printer/class) */
10563 cupsd_printer_t
*printer
; /* Printer/class */
10564 ipp_attribute_t
*attr
; /* Printer attribute */
10565 int changed
= 0; /* Was anything changed? */
10568 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_attrs(%p[%d], %s)", con
,
10569 con
->number
, uri
->values
[0].string
.text
);
10572 * Is the destination valid?
10575 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10581 send_ipp_status(con
, IPP_NOT_FOUND
,
10582 _("The printer or class does not exist."));
10590 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10592 send_http_error(con
, status
, printer
);
10597 * Return a list of attributes that can be set via Set-Printer-Attributes.
10600 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
10601 IPP_TAG_TEXT
)) != NULL
)
10603 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
10607 if ((attr
= ippFindAttribute(con
->request
, "printer-geo-location", IPP_TAG_URI
)) != NULL
&& !strncmp(attr
->values
[0].string
.text
, "geo:", 4))
10609 cupsdSetString(&printer
->geo_location
, attr
->values
[0].string
.text
);
10613 if ((attr
= ippFindAttribute(con
->request
, "printer-organization", IPP_TAG_TEXT
)) != NULL
)
10615 cupsdSetString(&printer
->organization
, attr
->values
[0].string
.text
);
10619 if ((attr
= ippFindAttribute(con
->request
, "printer-organizational-unit", IPP_TAG_TEXT
)) != NULL
)
10621 cupsdSetString(&printer
->organizational_unit
, attr
->values
[0].string
.text
);
10625 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
10626 IPP_TAG_TEXT
)) != NULL
)
10628 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
10633 * Update the printer attributes and return...
10638 printer
->config_time
= time(NULL
);
10640 cupsdSetPrinterAttrs(printer
);
10641 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
10643 cupsdAddEvent(CUPSD_EVENT_PRINTER_CONFIG
, printer
, NULL
,
10644 "Printer \"%s\" description or location changed by \"%s\".",
10645 printer
->name
, get_username(con
));
10647 cupsdLogMessage(CUPSD_LOG_INFO
,
10648 "Printer \"%s\" description or location changed by \"%s\".",
10649 printer
->name
, get_username(con
));
10652 con
->response
->request
.status
.status_code
= IPP_OK
;
10657 * 'set_printer_defaults()' - Set printer default options from a request.
10660 static int /* O - 1 on success, 0 on failure */
10661 set_printer_defaults(
10662 cupsd_client_t
*con
, /* I - Client connection */
10663 cupsd_printer_t
*printer
) /* I - Printer */
10665 int i
; /* Looping var */
10666 ipp_attribute_t
*attr
; /* Current attribute */
10667 size_t namelen
; /* Length of attribute name */
10668 char name
[256], /* New attribute name */
10669 value
[256]; /* String version of integer attrs */
10672 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10675 * Skip non-printer attributes...
10678 if (attr
->group_tag
!= IPP_TAG_PRINTER
|| !attr
->name
)
10681 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_defaults: %s", attr
->name
);
10683 if (!strcmp(attr
->name
, "job-sheets-default"))
10686 * Only allow keywords and names...
10689 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10693 * Only allow job-sheets-default to be set when running without a
10694 * system high classification level...
10697 if (Classification
)
10700 cupsdSetString(&printer
->job_sheets
[0], attr
->values
[0].string
.text
);
10702 if (attr
->num_values
> 1)
10703 cupsdSetString(&printer
->job_sheets
[1], attr
->values
[1].string
.text
);
10705 cupsdSetString(&printer
->job_sheets
[1], "none");
10707 else if (!strcmp(attr
->name
, "requesting-user-name-allowed"))
10709 cupsdFreeStrings(&(printer
->users
));
10711 printer
->deny_users
= 0;
10713 if (attr
->value_tag
== IPP_TAG_NAME
&&
10714 (attr
->num_values
> 1 ||
10715 strcmp(attr
->values
[0].string
.text
, "all")))
10717 for (i
= 0; i
< attr
->num_values
; i
++)
10718 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
10721 else if (!strcmp(attr
->name
, "requesting-user-name-denied"))
10723 cupsdFreeStrings(&(printer
->users
));
10725 printer
->deny_users
= 1;
10727 if (attr
->value_tag
== IPP_TAG_NAME
&&
10728 (attr
->num_values
> 1 ||
10729 strcmp(attr
->values
[0].string
.text
, "none")))
10731 for (i
= 0; i
< attr
->num_values
; i
++)
10732 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
10735 else if (!strcmp(attr
->name
, "job-quota-period"))
10737 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10740 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-quota-period to %d...",
10741 attr
->values
[0].integer
);
10742 cupsdFreeQuotas(printer
);
10744 printer
->quota_period
= attr
->values
[0].integer
;
10746 else if (!strcmp(attr
->name
, "job-k-limit"))
10748 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10751 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-k-limit to %d...",
10752 attr
->values
[0].integer
);
10753 cupsdFreeQuotas(printer
);
10755 printer
->k_limit
= attr
->values
[0].integer
;
10757 else if (!strcmp(attr
->name
, "job-page-limit"))
10759 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10762 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-page-limit to %d...",
10763 attr
->values
[0].integer
);
10764 cupsdFreeQuotas(printer
);
10766 printer
->page_limit
= attr
->values
[0].integer
;
10768 else if (!strcmp(attr
->name
, "printer-op-policy"))
10770 cupsd_policy_t
*p
; /* Policy */
10773 if (attr
->value_tag
!= IPP_TAG_NAME
)
10776 if ((p
= cupsdFindPolicy(attr
->values
[0].string
.text
)) != NULL
)
10778 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10779 "Setting printer-op-policy to \"%s\"...",
10780 attr
->values
[0].string
.text
);
10781 cupsdSetString(&printer
->op_policy
, attr
->values
[0].string
.text
);
10782 printer
->op_policy_ptr
= p
;
10786 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10787 _("Unknown printer-op-policy \"%s\"."),
10788 attr
->values
[0].string
.text
);
10792 else if (!strcmp(attr
->name
, "printer-error-policy"))
10794 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10797 if (strcmp(attr
->values
[0].string
.text
, "retry-current-job") &&
10798 ((printer
->type
& CUPS_PRINTER_CLASS
) ||
10799 (strcmp(attr
->values
[0].string
.text
, "abort-job") &&
10800 strcmp(attr
->values
[0].string
.text
, "retry-job") &&
10801 strcmp(attr
->values
[0].string
.text
, "stop-printer"))))
10803 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10804 _("Unknown printer-error-policy \"%s\"."),
10805 attr
->values
[0].string
.text
);
10809 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10810 "Setting printer-error-policy to \"%s\"...",
10811 attr
->values
[0].string
.text
);
10812 cupsdSetString(&printer
->error_policy
, attr
->values
[0].string
.text
);
10816 * Skip any other non-default attributes...
10819 namelen
= strlen(attr
->name
);
10820 if (namelen
< 9 || strcmp(attr
->name
+ namelen
- 8, "-default") ||
10821 namelen
> (sizeof(name
) - 1) || attr
->num_values
!= 1)
10825 * OK, anything else must be a user-defined default...
10828 strlcpy(name
, attr
->name
, sizeof(name
));
10829 name
[namelen
- 8] = '\0'; /* Strip "-default" */
10831 switch (attr
->value_tag
)
10833 case IPP_TAG_DELETEATTR
:
10834 printer
->num_options
= cupsRemoveOption(name
,
10835 printer
->num_options
,
10836 &(printer
->options
));
10837 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10838 "Deleting %s", attr
->name
);
10841 case IPP_TAG_NAME
:
10842 case IPP_TAG_TEXT
:
10843 case IPP_TAG_KEYWORD
:
10845 printer
->num_options
= cupsAddOption(name
,
10846 attr
->values
[0].string
.text
,
10847 printer
->num_options
,
10848 &(printer
->options
));
10849 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10850 "Setting %s to \"%s\"...", attr
->name
,
10851 attr
->values
[0].string
.text
);
10854 case IPP_TAG_BOOLEAN
:
10855 printer
->num_options
= cupsAddOption(name
,
10856 attr
->values
[0].boolean
?
10858 printer
->num_options
,
10859 &(printer
->options
));
10860 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10861 "Setting %s to %s...", attr
->name
,
10862 attr
->values
[0].boolean
? "true" : "false");
10865 case IPP_TAG_INTEGER
:
10866 case IPP_TAG_ENUM
:
10867 sprintf(value
, "%d", attr
->values
[0].integer
);
10868 printer
->num_options
= cupsAddOption(name
, value
,
10869 printer
->num_options
,
10870 &(printer
->options
));
10871 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10872 "Setting %s to %s...", attr
->name
, value
);
10875 case IPP_TAG_RANGE
:
10876 sprintf(value
, "%d-%d", attr
->values
[0].range
.lower
,
10877 attr
->values
[0].range
.upper
);
10878 printer
->num_options
= cupsAddOption(name
, value
,
10879 printer
->num_options
,
10880 &(printer
->options
));
10881 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10882 "Setting %s to %s...", attr
->name
, value
);
10885 case IPP_TAG_RESOLUTION
:
10886 sprintf(value
, "%dx%d%s", attr
->values
[0].resolution
.xres
,
10887 attr
->values
[0].resolution
.yres
,
10888 attr
->values
[0].resolution
.units
== IPP_RES_PER_INCH
?
10890 printer
->num_options
= cupsAddOption(name
, value
,
10891 printer
->num_options
,
10892 &(printer
->options
));
10893 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10894 "Setting %s to %s...", attr
->name
, value
);
10898 /* Do nothing for other values */
10908 * 'start_printer()' - Start a printer.
10912 start_printer(cupsd_client_t
*con
, /* I - Client connection */
10913 ipp_attribute_t
*uri
) /* I - Printer URI */
10915 int i
; /* Temporary variable */
10916 http_status_t status
; /* Policy status */
10917 cups_ptype_t dtype
; /* Destination type (printer/class) */
10918 cupsd_printer_t
*printer
; /* Printer data */
10921 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_printer(%p[%d], %s)", con
,
10922 con
->number
, uri
->values
[0].string
.text
);
10925 * Is the destination valid?
10928 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10934 send_ipp_status(con
, IPP_NOT_FOUND
,
10935 _("The printer or class does not exist."));
10943 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10945 send_http_error(con
, status
, printer
);
10950 * Start the printer...
10953 printer
->state_message
[0] = '\0';
10955 cupsdStartPrinter(printer
, 1);
10957 if (dtype
& CUPS_PRINTER_CLASS
)
10958 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" started by \"%s\".",
10959 printer
->name
, get_username(con
));
10961 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" started by \"%s\".",
10962 printer
->name
, get_username(con
));
10970 if ((i
= check_quotas(con
, printer
)) < 0)
10972 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
10977 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
10982 * Everything was ok, so return OK status...
10985 con
->response
->request
.status
.status_code
= IPP_OK
;
10990 * 'stop_printer()' - Stop a printer.
10994 stop_printer(cupsd_client_t
*con
, /* I - Client connection */
10995 ipp_attribute_t
*uri
) /* I - Printer URI */
10997 http_status_t status
; /* Policy status */
10998 cups_ptype_t dtype
; /* Destination type (printer/class) */
10999 cupsd_printer_t
*printer
; /* Printer data */
11000 ipp_attribute_t
*attr
; /* printer-state-message attribute */
11003 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "stop_printer(%p[%d], %s)", con
,
11004 con
->number
, uri
->values
[0].string
.text
);
11007 * Is the destination valid?
11010 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11016 send_ipp_status(con
, IPP_NOT_FOUND
,
11017 _("The printer or class does not exist."));
11025 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11027 send_http_error(con
, status
, printer
);
11032 * Stop the printer...
11035 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
11036 IPP_TAG_TEXT
)) == NULL
)
11037 strlcpy(printer
->state_message
, "Paused", sizeof(printer
->state_message
));
11040 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
11041 sizeof(printer
->state_message
));
11044 cupsdStopPrinter(printer
, 1);
11046 if (dtype
& CUPS_PRINTER_CLASS
)
11047 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" stopped by \"%s\".",
11048 printer
->name
, get_username(con
));
11050 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" stopped by \"%s\".",
11051 printer
->name
, get_username(con
));
11054 * Everything was ok, so return OK status...
11057 con
->response
->request
.status
.status_code
= IPP_OK
;
11062 * 'url_encode_attr()' - URL-encode a string attribute.
11066 url_encode_attr(ipp_attribute_t
*attr
, /* I - Attribute */
11067 char *buffer
,/* I - String buffer */
11068 size_t bufsize
)/* I - Size of buffer */
11070 int i
; /* Looping var */
11071 char *bufptr
, /* Pointer into buffer */
11072 *bufend
; /* End of buffer */
11075 strlcpy(buffer
, attr
->name
, bufsize
);
11076 bufptr
= buffer
+ strlen(buffer
);
11077 bufend
= buffer
+ bufsize
- 1;
11079 for (i
= 0; i
< attr
->num_values
; i
++)
11081 if (bufptr
>= bufend
)
11089 if (bufptr
>= bufend
)
11094 bufptr
= url_encode_string(attr
->values
[i
].string
.text
, bufptr
, (size_t)(bufend
- bufptr
+ 1));
11096 if (bufptr
>= bufend
)
11107 * 'url_encode_string()' - URL-encode a string.
11110 static char * /* O - End of string */
11111 url_encode_string(const char *s
, /* I - String */
11112 char *buffer
, /* I - String buffer */
11113 size_t bufsize
) /* I - Size of buffer */
11115 char *bufptr
, /* Pointer into buffer */
11116 *bufend
; /* End of buffer */
11117 static const char *hex
= "0123456789ABCDEF";
11122 bufend
= buffer
+ bufsize
- 1;
11124 while (*s
&& bufptr
< bufend
)
11126 if (*s
== ' ' || *s
== '%' || *s
== '+')
11128 if (bufptr
>= (bufend
- 2))
11132 *bufptr
++ = hex
[(*s
>> 4) & 15];
11133 *bufptr
++ = hex
[*s
& 15];
11137 else if (*s
== '\'' || *s
== '\\')
11139 if (bufptr
>= (bufend
- 1))
11156 * 'user_allowed()' - See if a user is allowed to print to a queue.
11159 static int /* O - 0 if not allowed, 1 if allowed */
11160 user_allowed(cupsd_printer_t
*p
, /* I - Printer or class */
11161 const char *username
) /* I - Username */
11163 struct passwd
*pw
; /* User password data */
11164 char baseuser
[256], /* Base username */
11165 *baseptr
, /* Pointer to "@" in base username */
11166 *name
; /* Current user name */
11169 if (cupsArrayCount(p
->users
) == 0)
11172 if (!strcmp(username
, "root"))
11175 if (strchr(username
, '@'))
11178 * Strip @REALM for username check...
11181 strlcpy(baseuser
, username
, sizeof(baseuser
));
11183 if ((baseptr
= strchr(baseuser
, '@')) != NULL
)
11186 username
= baseuser
;
11189 pw
= getpwnam(username
);
11192 for (name
= (char *)cupsArrayFirst(p
->users
);
11194 name
= (char *)cupsArrayNext(p
->users
))
11196 if (name
[0] == '@')
11199 * Check group membership...
11202 if (cupsdCheckGroup(username
, pw
, name
+ 1))
11205 else if (name
[0] == '#')
11211 if (cupsdCheckGroup(username
, pw
, name
))
11214 else if (!_cups_strcasecmp(username
, name
))
11218 return ((name
!= NULL
) != p
->deny_users
);
11223 * 'validate_job()' - Validate printer options and destination.
11227 validate_job(cupsd_client_t
*con
, /* I - Client connection */
11228 ipp_attribute_t
*uri
) /* I - Printer URI */
11230 http_status_t status
; /* Policy status */
11231 ipp_attribute_t
*attr
; /* Current attribute */
11233 ipp_attribute_t
*auth_info
; /* auth-info attribute */
11234 #endif /* HAVE_SSL */
11235 ipp_attribute_t
*format
, /* Document-format attribute */
11236 *name
; /* Job-name attribute */
11237 cups_ptype_t dtype
; /* Destination type (printer/class) */
11238 char super
[MIME_MAX_SUPER
],
11239 /* Supertype of file */
11240 type
[MIME_MAX_TYPE
];
11241 /* Subtype of file */
11242 cupsd_printer_t
*printer
; /* Printer */
11245 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_job(%p[%d], %s)", con
,
11246 con
->number
, uri
->values
[0].string
.text
);
11249 * OK, see if the client is sending the document compressed - CUPS
11250 * doesn't support compression yet...
11253 if ((attr
= ippFindAttribute(con
->request
, "compression",
11254 IPP_TAG_KEYWORD
)) != NULL
)
11256 if (strcmp(attr
->values
[0].string
.text
, "none")
11258 && strcmp(attr
->values
[0].string
.text
, "gzip")
11259 #endif /* HAVE_LIBZ */
11262 send_ipp_status(con
, IPP_ATTRIBUTES
,
11263 _("Unsupported 'compression' value \"%s\"."),
11264 attr
->values
[0].string
.text
);
11265 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
11266 "compression", NULL
, attr
->values
[0].string
.text
);
11272 * Is it a format we support?
11275 if ((format
= ippFindAttribute(con
->request
, "document-format",
11276 IPP_TAG_MIMETYPE
)) != NULL
)
11278 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%255[^;]",
11281 send_ipp_status(con
, IPP_BAD_REQUEST
,
11282 _("Bad 'document-format' value \"%s\"."),
11283 format
->values
[0].string
.text
);
11287 if ((strcmp(super
, "application") || strcmp(type
, "octet-stream")) &&
11288 !mimeType(MimeDatabase
, super
, type
))
11290 cupsdLogMessage(CUPSD_LOG_INFO
,
11291 "Hint: Do you have the raw file printing rules enabled?");
11292 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
11293 _("Unsupported 'document-format' value \"%s\"."),
11294 format
->values
[0].string
.text
);
11295 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
11296 "document-format", NULL
, format
->values
[0].string
.text
);
11302 * Is the job-name valid?
11305 if ((name
= ippFindAttribute(con
->request
, "job-name", IPP_TAG_ZERO
)) != NULL
)
11307 int bad_name
= 0; /* Is the job-name value bad? */
11309 if ((name
->value_tag
!= IPP_TAG_NAME
&& name
->value_tag
!= IPP_TAG_NAMELANG
) ||
11310 name
->num_values
!= 1)
11317 * Validate that job-name conforms to RFC 5198 (Network Unicode) and
11318 * IPP Everywhere requirements for "name" values...
11321 const unsigned char *nameptr
; /* Pointer into "job-name" attribute */
11323 for (nameptr
= (unsigned char *)name
->values
[0].string
.text
;
11327 if (*nameptr
< ' ' && *nameptr
!= '\t')
11329 else if (*nameptr
== 0x7f)
11331 else if ((*nameptr
& 0xe0) == 0xc0)
11333 if ((nameptr
[1] & 0xc0) != 0x80)
11338 else if ((*nameptr
& 0xf0) == 0xe0)
11340 if ((nameptr
[1] & 0xc0) != 0x80 ||
11341 (nameptr
[2] & 0xc0) != 0x80)
11346 else if ((*nameptr
& 0xf8) == 0xf0)
11348 if ((nameptr
[1] & 0xc0) != 0x80 ||
11349 (nameptr
[2] & 0xc0) != 0x80 ||
11350 (nameptr
[3] & 0xc0) != 0x80)
11355 else if (*nameptr
& 0x80)
11365 if (StrictConformance
)
11367 send_ipp_status(con
, IPP_ATTRIBUTES
,
11368 _("Unsupported 'job-name' value."));
11369 ippCopyAttribute(con
->response
, name
, 0);
11374 cupsdLogMessage(CUPSD_LOG_WARN
,
11375 "Unsupported 'job-name' value, deleting from request.");
11376 ippDeleteAttribute(con
->request
, name
);
11382 * Is the destination valid?
11385 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11391 send_ipp_status(con
, IPP_NOT_FOUND
,
11392 _("The printer or class does not exist."));
11401 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
11402 #endif /* HAVE_SSL */
11404 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11406 send_http_error(con
, status
, printer
);
11409 else if (printer
->num_auth_info_required
== 1 &&
11410 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
11413 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
11417 else if (auth_info
&& !con
->http
->tls
&&
11418 !httpAddrLocalhost(con
->http
->hostaddr
))
11421 * Require encryption of auth-info over non-local connections...
11424 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
11427 #endif /* HAVE_SSL */
11430 * Everything was ok, so return OK status...
11433 con
->response
->request
.status
.status_code
= IPP_OK
;
11438 * 'validate_name()' - Make sure the printer name only contains valid chars.
11441 static int /* O - 0 if name is no good, 1 if good */
11442 validate_name(const char *name
) /* I - Name to check */
11444 const char *ptr
; /* Pointer into name */
11448 * Scan the whole name...
11451 for (ptr
= name
; *ptr
; ptr
++)
11452 if ((*ptr
> 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
11456 * All the characters are good; validate the length, too...
11459 return ((ptr
- name
) < 128);
11464 * 'validate_user()' - Validate the user for the request.
11467 static int /* O - 1 if permitted, 0 otherwise */
11468 validate_user(cupsd_job_t
*job
, /* I - Job */
11469 cupsd_client_t
*con
, /* I - Client connection */
11470 const char *owner
, /* I - Owner of job/resource */
11471 char *username
, /* O - Authenticated username */
11472 size_t userlen
) /* I - Length of username */
11474 cupsd_printer_t
*printer
; /* Printer for job */
11477 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
);
11480 * Validate input...
11483 if (!con
|| !owner
|| !username
|| userlen
<= 0)
11487 * Get the best authenticated username that is available.
11490 strlcpy(username
, get_username(con
), userlen
);
11493 * Check the username against the owner...
11496 printer
= cupsdFindDest(job
->dest
);
11498 return (cupsdCheckPolicy(printer
? printer
->op_policy_ptr
: DefaultPolicyPtr
,
11499 con
, owner
) == HTTP_OK
);