2 * IPP routines for the CUPS scheduler.
4 * Copyright 2007-2016 by Apple Inc.
5 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
7 * This file contains Kerberos support code, copyright 2006 by
10 * These coded instructions, statements, and computer programs are the
11 * property of Apple Inc. and are protected by Federal copyright
12 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
13 * which should have been included with this file. If this file is
14 * file is 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 void set_printer_defaults(cupsd_client_t
*con
,
128 cupsd_printer_t
*printer
);
129 static void start_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
130 static void stop_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
131 static void url_encode_attr(ipp_attribute_t
*attr
, char *buffer
, size_t bufsize
);
132 static char *url_encode_string(const char *s
, char *buffer
, size_t bufsize
);
133 static int user_allowed(cupsd_printer_t
*p
, const char *username
);
134 static void validate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
135 static int validate_name(const char *name
);
136 static int validate_user(cupsd_job_t
*job
, cupsd_client_t
*con
, const char *owner
, char *username
, size_t userlen
);
140 * 'cupsdProcessIPPRequest()' - Process an incoming IPP request.
143 int /* O - 1 on success, 0 on failure */
144 cupsdProcessIPPRequest(
145 cupsd_client_t
*con
) /* I - Client connection */
147 ipp_tag_t group
; /* Current group tag */
148 ipp_attribute_t
*attr
; /* Current attribute */
149 ipp_attribute_t
*charset
; /* Character set attribute */
150 ipp_attribute_t
*language
; /* Language attribute */
151 ipp_attribute_t
*uri
= NULL
; /* Printer or job URI attribute */
152 ipp_attribute_t
*username
; /* requesting-user-name attr */
153 int sub_id
; /* Subscription ID */
156 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
157 "cupsdProcessIPPRequest(%p[%d]): operation_id = %04x",
158 con
, con
->number
, con
->request
->request
.op
.operation_id
);
161 * First build an empty response message for this request...
164 con
->response
= ippNew();
166 con
->response
->request
.status
.version
[0] =
167 con
->request
->request
.op
.version
[0];
168 con
->response
->request
.status
.version
[1] =
169 con
->request
->request
.op
.version
[1];
170 con
->response
->request
.status
.request_id
=
171 con
->request
->request
.op
.request_id
;
174 * Then validate the request header and required attributes...
177 if (con
->request
->request
.any
.version
[0] != 1 &&
178 con
->request
->request
.any
.version
[0] != 2)
181 * Return an error, since we only support IPP 1.x and 2.x.
184 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
185 "%04X %s Bad request version number %d.%d",
186 IPP_VERSION_NOT_SUPPORTED
, con
->http
->hostname
,
187 con
->request
->request
.any
.version
[0],
188 con
->request
->request
.any
.version
[1]);
190 send_ipp_status(con
, IPP_VERSION_NOT_SUPPORTED
,
191 _("Bad request version number %d.%d."),
192 con
->request
->request
.any
.version
[0],
193 con
->request
->request
.any
.version
[1]);
195 else if (con
->request
->request
.any
.request_id
< 1)
198 * Return an error, since request IDs must be between 1 and 2^31-1
201 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
202 "%04X %s Bad request ID %d",
203 IPP_BAD_REQUEST
, con
->http
->hostname
,
204 con
->request
->request
.any
.request_id
);
206 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad request ID %d."),
207 con
->request
->request
.any
.request_id
);
209 else if (!con
->request
->attrs
)
211 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
212 "%04X %s No attributes in request",
213 IPP_BAD_REQUEST
, con
->http
->hostname
);
215 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No attributes in request."));
220 * Make sure that the attributes are provided in the correct order and
221 * don't repeat groups...
224 for (attr
= con
->request
->attrs
, group
= attr
->group_tag
;
227 if (attr
->group_tag
< group
&& attr
->group_tag
!= IPP_TAG_ZERO
)
230 * Out of order; return an error...
233 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
234 "%04X %s Attribute groups are out of order",
235 IPP_BAD_REQUEST
, con
->http
->hostname
);
237 send_ipp_status(con
, IPP_BAD_REQUEST
,
238 _("Attribute groups are out of order (%x < %x)."),
239 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
&&
257 !strcmp(attr
->name
, "attributes-charset") &&
258 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_CHARSET
)
266 if (attr
&& attr
->name
&&
267 !strcmp(attr
->name
, "attributes-natural-language") &&
268 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_LANGUAGE
)
273 * Reset language for this request if different from Accept-Language.
276 if (!con
->language
||
277 strcmp(attr
->values
[0].string
.text
, con
->language
->language
))
279 cupsLangFree(con
->language
);
280 con
->language
= cupsLangGet(attr
->values
[0].string
.text
);
286 if ((attr
= ippFindAttribute(con
->request
, "printer-uri",
287 IPP_TAG_URI
)) != NULL
)
289 else if ((attr
= ippFindAttribute(con
->request
, "job-uri",
290 IPP_TAG_URI
)) != NULL
)
292 else if (con
->request
->request
.op
.operation_id
== CUPS_GET_PPD
)
293 uri
= ippFindAttribute(con
->request
, "ppd-name", IPP_TAG_NAME
);
298 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
299 "attributes-charset", NULL
,
300 charset
->values
[0].string
.text
);
302 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
303 "attributes-charset", NULL
, "utf-8");
306 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
307 "attributes-natural-language", NULL
,
308 language
->values
[0].string
.text
);
310 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
311 "attributes-natural-language", NULL
, DefaultLanguage
);
314 _cups_strcasecmp(charset
->values
[0].string
.text
, "us-ascii") &&
315 _cups_strcasecmp(charset
->values
[0].string
.text
, "utf-8"))
318 * Bad character set...
321 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unsupported character set \"%s\"",
322 charset
->values
[0].string
.text
);
323 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
324 "%04X %s Unsupported attributes-charset value \"%s\"",
325 IPP_CHARSET
, con
->http
->hostname
,
326 charset
->values
[0].string
.text
);
327 send_ipp_status(con
, IPP_BAD_REQUEST
,
328 _("Unsupported character set \"%s\"."),
329 charset
->values
[0].string
.text
);
331 else if (!charset
|| !language
||
333 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEFAULT
&&
334 con
->request
->request
.op
.operation_id
!= CUPS_GET_PRINTERS
&&
335 con
->request
->request
.op
.operation_id
!= CUPS_GET_CLASSES
&&
336 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEVICES
&&
337 con
->request
->request
.op
.operation_id
!= CUPS_GET_PPDS
))
340 * Return an error, since attributes-charset,
341 * attributes-natural-language, and printer-uri/job-uri are required
342 * for all operations.
347 cupsdLogMessage(CUPSD_LOG_ERROR
,
348 "Missing attributes-charset attribute");
350 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
351 "%04X %s Missing attributes-charset attribute",
352 IPP_BAD_REQUEST
, con
->http
->hostname
);
357 cupsdLogMessage(CUPSD_LOG_ERROR
,
358 "Missing attributes-natural-language attribute");
360 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
361 "%04X %s Missing attributes-natural-language attribute",
362 IPP_BAD_REQUEST
, con
->http
->hostname
);
367 cupsdLogMessage(CUPSD_LOG_ERROR
,
368 "Missing printer-uri, job-uri, or ppd-name "
371 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
372 "%04X %s Missing printer-uri, job-uri, or ppd-name "
373 "attribute", IPP_BAD_REQUEST
, con
->http
->hostname
);
376 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Request attributes follow...");
378 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
379 cupsdLogMessage(CUPSD_LOG_DEBUG
,
380 "attr \"%s\": group_tag = %x, value_tag = %x",
381 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
384 cupsdLogMessage(CUPSD_LOG_DEBUG
, "End of attributes...");
386 send_ipp_status(con
, IPP_BAD_REQUEST
,
387 _("Missing required attributes."));
392 * OK, all the checks pass so far; make sure requesting-user-name is
393 * not "root" from a remote host...
396 if ((username
= ippFindAttribute(con
->request
, "requesting-user-name",
397 IPP_TAG_NAME
)) != NULL
)
400 * Check for root user...
403 if (!strcmp(username
->values
[0].string
.text
, "root") &&
404 _cups_strcasecmp(con
->http
->hostname
, "localhost") &&
405 strcmp(con
->username
, "root"))
408 * Remote unauthenticated user masquerading as local root...
411 ippSetString(con
->request
, &username
, 0, RemoteRoot
);
415 if ((attr
= ippFindAttribute(con
->request
, "notify-subscription-id",
416 IPP_TAG_INTEGER
)) != NULL
)
417 sub_id
= attr
->values
[0].integer
;
422 * Then try processing the operation...
426 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s",
427 ippOpString(con
->request
->request
.op
.operation_id
),
428 uri
->values
[0].string
.text
);
430 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s",
431 ippOpString(con
->request
->request
.op
.operation_id
));
433 switch (con
->request
->request
.op
.operation_id
)
435 case IPP_OP_PRINT_JOB
:
439 case IPP_OP_VALIDATE_JOB
:
440 validate_job(con
, uri
);
443 case IPP_OP_CREATE_JOB
:
444 create_job(con
, uri
);
447 case IPP_OP_SEND_DOCUMENT
:
448 send_document(con
, uri
);
451 case IPP_OP_CANCEL_JOB
:
452 cancel_job(con
, uri
);
455 case IPP_OP_GET_JOB_ATTRIBUTES
:
456 get_job_attrs(con
, uri
);
459 case IPP_OP_GET_JOBS
:
463 case IPP_OP_GET_PRINTER_ATTRIBUTES
:
464 get_printer_attrs(con
, uri
);
467 case IPP_OP_GET_PRINTER_SUPPORTED_VALUES
:
468 get_printer_supported(con
, uri
);
471 case IPP_OP_HOLD_JOB
:
475 case IPP_OP_RELEASE_JOB
:
476 release_job(con
, uri
);
479 case IPP_OP_RESTART_JOB
:
480 restart_job(con
, uri
);
483 case IPP_OP_PAUSE_PRINTER
:
484 stop_printer(con
, uri
);
487 case IPP_OP_RESUME_PRINTER
:
488 start_printer(con
, uri
);
491 case IPP_OP_PURGE_JOBS
:
492 case IPP_OP_CANCEL_JOBS
:
493 case IPP_OP_CANCEL_MY_JOBS
:
494 cancel_all_jobs(con
, uri
);
497 case IPP_OP_SET_JOB_ATTRIBUTES
:
498 set_job_attrs(con
, uri
);
501 case IPP_OP_SET_PRINTER_ATTRIBUTES
:
502 set_printer_attrs(con
, uri
);
505 case IPP_OP_HOLD_NEW_JOBS
:
506 hold_new_jobs(con
, uri
);
509 case IPP_OP_RELEASE_HELD_NEW_JOBS
:
510 release_held_new_jobs(con
, uri
);
513 case IPP_OP_CLOSE_JOB
:
517 case IPP_OP_CUPS_GET_DEFAULT
:
521 case IPP_OP_CUPS_GET_PRINTERS
:
522 get_printers(con
, 0);
525 case IPP_OP_CUPS_GET_CLASSES
:
526 get_printers(con
, CUPS_PRINTER_CLASS
);
529 case IPP_OP_CUPS_ADD_MODIFY_PRINTER
:
530 add_printer(con
, uri
);
533 case IPP_OP_CUPS_DELETE_PRINTER
:
534 delete_printer(con
, uri
);
537 case IPP_OP_CUPS_ADD_MODIFY_CLASS
:
541 case IPP_OP_CUPS_DELETE_CLASS
:
542 delete_printer(con
, uri
);
545 case IPP_OP_CUPS_ACCEPT_JOBS
:
546 case IPP_OP_ENABLE_PRINTER
:
547 accept_jobs(con
, uri
);
550 case IPP_OP_CUPS_REJECT_JOBS
:
551 case IPP_OP_DISABLE_PRINTER
:
552 reject_jobs(con
, uri
);
555 case IPP_OP_CUPS_SET_DEFAULT
:
556 set_default(con
, uri
);
559 case IPP_OP_CUPS_GET_DEVICES
:
563 case IPP_OP_CUPS_GET_DOCUMENT
:
564 get_document(con
, uri
);
567 case IPP_OP_CUPS_GET_PPD
:
571 case IPP_OP_CUPS_GET_PPDS
:
575 case IPP_OP_CUPS_MOVE_JOB
:
579 case IPP_OP_CUPS_AUTHENTICATE_JOB
:
580 authenticate_job(con
, uri
);
583 case IPP_OP_CREATE_PRINTER_SUBSCRIPTIONS
:
584 case IPP_OP_CREATE_JOB_SUBSCRIPTIONS
:
585 create_subscriptions(con
, uri
);
588 case IPP_OP_GET_SUBSCRIPTION_ATTRIBUTES
:
589 get_subscription_attrs(con
, sub_id
);
592 case IPP_OP_GET_SUBSCRIPTIONS
:
593 get_subscriptions(con
, uri
);
596 case IPP_OP_RENEW_SUBSCRIPTION
:
597 renew_subscription(con
, sub_id
);
600 case IPP_OP_CANCEL_SUBSCRIPTION
:
601 cancel_subscription(con
, sub_id
);
604 case IPP_OP_GET_NOTIFICATIONS
:
605 get_notifications(con
);
608 case IPP_OP_CUPS_CREATE_LOCAL_PRINTER
:
609 create_local_printer(con
);
613 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
614 "%04X %s Operation %04X (%s) not supported",
615 IPP_OPERATION_NOT_SUPPORTED
, con
->http
->hostname
,
616 con
->request
->request
.op
.operation_id
,
617 ippOpString(con
->request
->request
.op
.operation_id
));
619 send_ipp_status(con
, IPP_OPERATION_NOT_SUPPORTED
,
620 _("%s not supported."),
622 con
->request
->request
.op
.operation_id
));
632 * Sending data from the scheduler...
635 cupsdLogMessage(con
->response
->request
.status
.status_code
636 >= IPP_BAD_REQUEST
&&
637 con
->response
->request
.status
.status_code
638 != IPP_NOT_FOUND
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
639 "[Client %d] Returning IPP %s for %s (%s) from %s",
641 ippErrorString(con
->response
->request
.status
.status_code
),
642 ippOpString(con
->request
->request
.op
.operation_id
),
643 uri
? uri
->values
[0].string
.text
: "no URI",
644 con
->http
->hostname
);
646 httpClearFields(con
->http
);
648 #ifdef CUPSD_USE_CHUNKING
650 * Because older versions of CUPS (1.1.17 and older) and some IPP
651 * clients do not implement chunking properly, we cannot use
652 * chunking by default. This may become the default in future
653 * CUPS releases, or we might add a configuration directive for
657 if (con
->http
->version
== HTTP_1_1
)
659 cupsdLogMessage(CUPSD_LOG_DEBUG
,
660 "[Client %d] Transfer-Encoding: chunked",
663 cupsdSetLength(con
->http
, 0);
666 #endif /* CUPSD_USE_CHUNKING */
668 size_t length
; /* Length of response */
671 length
= ippLength(con
->response
);
673 if (con
->file
>= 0 && !con
->pipe_pid
)
675 struct stat fileinfo
; /* File information */
677 if (!fstat(con
->file
, &fileinfo
))
678 length
+= (size_t)fileinfo
.st_size
;
681 cupsdLogMessage(CUPSD_LOG_DEBUG
,
682 "[Client %d] Content-Length: " CUPS_LLFMT
,
683 con
->number
, CUPS_LLCAST length
);
684 httpSetLength(con
->http
, length
);
687 if (cupsdSendHeader(con
, HTTP_OK
, "application/ipp", CUPSD_AUTH_NONE
))
690 * Tell the caller the response header was sent successfully...
693 cupsdAddSelect(httpGetFd(con
->http
), (cupsd_selfunc_t
)cupsdReadClient
,
694 (cupsd_selfunc_t
)cupsdWriteClient
, con
);
701 * Tell the caller the response header could not be sent...
710 * Sending data from a subprocess like cups-deviced; tell the caller
711 * everything is A-OK so far...
720 * 'cupsdTimeoutJob()' - Timeout a job waiting on job files.
723 int /* O - 0 on success, -1 on error */
724 cupsdTimeoutJob(cupsd_job_t
*job
) /* I - Job to timeout */
726 cupsd_printer_t
*printer
; /* Destination printer or class */
727 ipp_attribute_t
*attr
; /* job-sheets attribute */
728 int kbytes
; /* Kilobytes in banner */
731 job
->pending_timeout
= 0;
734 * See if we need to add the ending sheet...
737 if (!cupsdLoadJob(job
))
740 printer
= cupsdFindDest(job
->dest
);
741 attr
= ippFindAttribute(job
->attrs
, "job-sheets", IPP_TAG_NAME
);
743 if (printer
&& !(printer
->type
& CUPS_PRINTER_REMOTE
) &&
744 attr
&& attr
->num_values
> 1)
750 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding end banner page \"%s\".",
751 attr
->values
[1].string
.text
);
753 if ((kbytes
= copy_banner(NULL
, job
, attr
->values
[1].string
.text
)) < 0)
756 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
764 * 'accept_jobs()' - Accept print jobs to a printer.
768 accept_jobs(cupsd_client_t
*con
, /* I - Client connection */
769 ipp_attribute_t
*uri
) /* I - Printer or class URI */
771 http_status_t status
; /* Policy status */
772 cups_ptype_t dtype
; /* Destination type (printer/class) */
773 cupsd_printer_t
*printer
; /* Printer data */
776 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "accept_jobs(%p[%d], %s)", con
,
777 con
->number
, uri
->values
[0].string
.text
);
780 * Is the destination valid?
783 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
789 send_ipp_status(con
, IPP_NOT_FOUND
,
790 _("The printer or class does not exist."));
798 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
800 send_http_error(con
, status
, printer
);
805 * Accept jobs sent to the printer...
808 printer
->accepting
= 1;
809 printer
->state_message
[0] = '\0';
811 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
812 "Now accepting jobs.");
814 if (dtype
& CUPS_PRINTER_CLASS
)
816 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
818 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" now accepting jobs (\"%s\").",
819 printer
->name
, get_username(con
));
823 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
825 cupsdLogMessage(CUPSD_LOG_INFO
,
826 "Printer \"%s\" now accepting jobs (\"%s\").",
827 printer
->name
, get_username(con
));
831 * Everything was ok, so return OK status...
834 con
->response
->request
.status
.status_code
= IPP_OK
;
839 * 'add_class()' - Add a class to the system.
843 add_class(cupsd_client_t
*con
, /* I - Client connection */
844 ipp_attribute_t
*uri
) /* I - URI of class */
846 http_status_t status
; /* Policy status */
847 int i
; /* Looping var */
848 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
849 username
[HTTP_MAX_URI
], /* Username portion of URI */
850 host
[HTTP_MAX_URI
], /* Host portion of URI */
851 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
852 int port
; /* Port portion of URI */
853 cupsd_printer_t
*pclass
, /* Class */
854 *member
; /* Member printer/class */
855 cups_ptype_t dtype
; /* Destination type */
856 ipp_attribute_t
*attr
; /* Printer attribute */
857 int modify
; /* Non-zero if we just modified */
858 int need_restart_job
; /* Need to restart job? */
861 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_class(%p[%d], %s)", con
,
862 con
->number
, uri
->values
[0].string
.text
);
865 * Do we have a valid URI?
868 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
869 sizeof(scheme
), username
, sizeof(username
), host
,
870 sizeof(host
), &port
, resource
, sizeof(resource
));
873 if (strncmp(resource
, "/classes/", 9) || strlen(resource
) == 9)
876 * No, return an error...
879 send_ipp_status(con
, IPP_BAD_REQUEST
,
880 _("The printer-uri must be of the form "
881 "\"ipp://HOSTNAME/classes/CLASSNAME\"."));
886 * Do we have a valid printer name?
889 if (!validate_name(resource
+ 9))
892 * No, return an error...
895 send_ipp_status(con
, IPP_BAD_REQUEST
,
896 _("The printer-uri \"%s\" contains invalid characters."),
897 uri
->values
[0].string
.text
);
902 * See if the class already exists; if not, create a new class...
905 if ((pclass
= cupsdFindClass(resource
+ 9)) == NULL
)
908 * Class doesn't exist; see if we have a printer of the same name...
911 if ((pclass
= cupsdFindPrinter(resource
+ 9)) != NULL
)
914 * Yes, return an error...
917 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
918 _("A printer named \"%s\" already exists."),
924 * No, check the default policy and then add the class...
927 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
929 send_http_error(con
, status
, NULL
);
933 pclass
= cupsdAddClass(resource
+ 9);
936 else if ((status
= cupsdCheckPolicy(pclass
->op_policy_ptr
, con
,
939 send_http_error(con
, status
, pclass
);
946 * Look for attributes and copy them over as needed...
949 need_restart_job
= 0;
951 if ((attr
= ippFindAttribute(con
->request
, "printer-location", IPP_TAG_TEXT
)) != NULL
)
952 cupsdSetString(&pclass
->location
, attr
->values
[0].string
.text
);
954 if ((attr
= ippFindAttribute(con
->request
, "printer-geo-location", IPP_TAG_URI
)) != NULL
&& !strncmp(attr
->values
[0].string
.text
, "geo:", 4))
955 cupsdSetString(&pclass
->geo_location
, attr
->values
[0].string
.text
);
957 if ((attr
= ippFindAttribute(con
->request
, "printer-organization", IPP_TAG_TEXT
)) != NULL
)
958 cupsdSetString(&pclass
->organization
, attr
->values
[0].string
.text
);
960 if ((attr
= ippFindAttribute(con
->request
, "printer-organizational-unit", IPP_TAG_TEXT
)) != NULL
)
961 cupsdSetString(&pclass
->organizational_unit
, attr
->values
[0].string
.text
);
963 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
964 IPP_TAG_TEXT
)) != NULL
)
965 cupsdSetString(&pclass
->info
, attr
->values
[0].string
.text
);
967 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
968 IPP_TAG_BOOLEAN
)) != NULL
&&
969 attr
->values
[0].boolean
!= pclass
->accepting
)
971 cupsdLogMessage(CUPSD_LOG_INFO
,
972 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
973 pclass
->name
, attr
->values
[0].boolean
, pclass
->accepting
);
975 pclass
->accepting
= attr
->values
[0].boolean
;
977 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s accepting jobs.",
978 pclass
->accepting
? "Now" : "No longer");
981 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared", IPP_TAG_BOOLEAN
)) != NULL
)
983 if (pclass
->type
& CUPS_PRINTER_REMOTE
)
986 * Cannot re-share remote printers.
989 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Cannot change printer-is-shared for remote queues."));
993 if (pclass
->shared
&& !ippGetBoolean(attr
, 0))
994 cupsdDeregisterPrinter(pclass
, 1);
996 cupsdLogMessage(CUPSD_LOG_INFO
,
997 "Setting %s printer-is-shared to %d (was %d.)",
998 pclass
->name
, attr
->values
[0].boolean
, pclass
->shared
);
1000 pclass
->shared
= ippGetBoolean(attr
, 0);
1003 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
1004 IPP_TAG_ENUM
)) != NULL
)
1006 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
1007 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
1009 send_ipp_status(con
, IPP_BAD_REQUEST
,
1010 _("Attempt to set %s printer-state to bad value %d."),
1011 pclass
->name
, attr
->values
[0].integer
);
1015 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
1016 pclass
->name
, attr
->values
[0].integer
, pclass
->state
);
1018 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
1019 cupsdStopPrinter(pclass
, 0);
1022 cupsdSetPrinterState(pclass
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
1023 need_restart_job
= 1;
1026 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
1027 IPP_TAG_TEXT
)) != NULL
)
1029 strlcpy(pclass
->state_message
, attr
->values
[0].string
.text
,
1030 sizeof(pclass
->state_message
));
1032 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s",
1033 pclass
->state_message
);
1035 if ((attr
= ippFindAttribute(con
->request
, "member-uris",
1036 IPP_TAG_URI
)) != NULL
)
1039 * Clear the printer array as needed...
1042 need_restart_job
= 1;
1044 if (pclass
->num_printers
> 0)
1046 free(pclass
->printers
);
1047 pclass
->num_printers
= 0;
1051 * Add each printer or class that is listed...
1054 for (i
= 0; i
< attr
->num_values
; i
++)
1057 * Search for the printer or class URI...
1060 if (!cupsdValidateDest(attr
->values
[i
].string
.text
, &dtype
, &member
))
1066 send_ipp_status(con
, IPP_NOT_FOUND
,
1067 _("The printer or class does not exist."));
1070 else if (dtype
& CUPS_PRINTER_CLASS
)
1072 send_ipp_status(con
, IPP_BAD_REQUEST
,
1073 _("Nested classes are not allowed."));
1078 * Add it to the class...
1081 cupsdAddPrinterToClass(pclass
, member
);
1085 set_printer_defaults(con
, pclass
);
1087 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
1088 IPP_TAG_KEYWORD
)) != NULL
)
1089 cupsdSetAuthInfoRequired(pclass
, NULL
, attr
);
1091 pclass
->config_time
= time(NULL
);
1094 * Update the printer class attributes and return...
1097 cupsdSetPrinterAttrs(pclass
);
1098 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
1100 if (need_restart_job
&& pclass
->job
)
1103 * Reset the current job to a "pending" status...
1106 cupsdSetJobState(pclass
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
1107 "Job restarted because the class was modified.");
1110 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1114 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
1115 pclass
, NULL
, "Class \"%s\" modified by \"%s\".",
1116 pclass
->name
, get_username(con
));
1118 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" modified by \"%s\".",
1119 pclass
->name
, get_username(con
));
1123 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
1124 pclass
, NULL
, "New class \"%s\" added by \"%s\".",
1125 pclass
->name
, get_username(con
));
1127 cupsdLogMessage(CUPSD_LOG_INFO
, "New class \"%s\" added by \"%s\".",
1128 pclass
->name
, get_username(con
));
1131 con
->response
->request
.status
.status_code
= IPP_OK
;
1136 * 'add_file()' - Add a file to a job.
1139 static int /* O - 0 on success, -1 on error */
1140 add_file(cupsd_client_t
*con
, /* I - Connection to client */
1141 cupsd_job_t
*job
, /* I - Job to add to */
1142 mime_type_t
*filetype
, /* I - Type of file */
1143 int compression
) /* I - Compression */
1145 mime_type_t
**filetypes
; /* New filetypes array... */
1146 int *compressions
; /* New compressions array... */
1149 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1150 "add_file(con=%p[%d], job=%d, filetype=%s/%s, "
1151 "compression=%d)", con
, con
? con
->number
: -1, job
->id
,
1152 filetype
->super
, filetype
->type
, compression
);
1155 * Add the file to the job...
1158 if (job
->num_files
== 0)
1160 compressions
= (int *)malloc(sizeof(int));
1161 filetypes
= (mime_type_t
**)malloc(sizeof(mime_type_t
*));
1165 compressions
= (int *)realloc(job
->compressions
,
1166 (size_t)(job
->num_files
+ 1) * sizeof(int));
1167 filetypes
= (mime_type_t
**)realloc(job
->filetypes
,
1168 (size_t)(job
->num_files
+ 1) *
1169 sizeof(mime_type_t
*));
1173 job
->compressions
= compressions
;
1176 job
->filetypes
= filetypes
;
1178 if (!compressions
|| !filetypes
)
1180 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1181 "Job aborted because the scheduler ran out of memory.");
1184 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1185 _("Unable to allocate memory for file types."));
1190 job
->compressions
[job
->num_files
] = compression
;
1191 job
->filetypes
[job
->num_files
] = filetype
;
1196 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1203 * 'add_job()' - Add a job to a print queue.
1206 static cupsd_job_t
* /* O - Job object */
1207 add_job(cupsd_client_t
*con
, /* I - Client connection */
1208 cupsd_printer_t
*printer
, /* I - Destination printer */
1209 mime_type_t
*filetype
) /* I - First print file type, if any */
1211 http_status_t status
; /* Policy status */
1212 ipp_attribute_t
*attr
, /* Current attribute */
1213 *auth_info
; /* auth-info attribute */
1214 const char *mandatory
; /* Current mandatory job attribute */
1215 const char *val
; /* Default option value */
1216 int priority
; /* Job priority */
1217 cupsd_job_t
*job
; /* Current job */
1218 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
1219 int kbytes
; /* Size of print file */
1220 int i
; /* Looping var */
1221 int lowerpagerange
; /* Page range bound */
1222 int exact
; /* Did we have an exact match? */
1223 ipp_attribute_t
*media_col
, /* media-col attribute */
1224 *media_margin
; /* media-*-margin attribute */
1225 ipp_t
*unsup_col
; /* media-col in unsupported response */
1226 static const char * const readonly
[] =/* List of read-only attributes */
1228 "date-time-at-completed",
1229 "date-time-at-creation",
1230 "date-time-at-processing",
1231 "job-detailed-status-messages",
1232 "job-document-access-errors",
1234 "job-impressions-completed",
1235 "job-k-octets-completed",
1236 "job-media-sheets-completed",
1237 "job-pages-completed",
1238 "job-printer-up-time",
1241 "job-state-message",
1242 "job-state-reasons",
1244 "number-of-documents",
1245 "number-of-intervening-jobs",
1246 "output-device-assigned",
1247 "time-at-completed",
1249 "time-at-processing"
1253 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job(%p[%d], %p(%s), %p(%s/%s))",
1254 con
, con
->number
, printer
, printer
->name
,
1255 filetype
, filetype
? filetype
->super
: "none",
1256 filetype
? filetype
->type
: "none");
1259 * Check remote printing to non-shared printer...
1262 if (!printer
->shared
&&
1263 _cups_strcasecmp(con
->http
->hostname
, "localhost") &&
1264 _cups_strcasecmp(con
->http
->hostname
, ServerName
))
1266 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
1267 _("The printer or class is not shared."));
1275 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
1277 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
1279 send_http_error(con
, status
, printer
);
1282 else if (printer
->num_auth_info_required
== 1 &&
1283 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
1286 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
1290 else if (auth_info
&& !con
->http
->tls
&&
1291 !httpAddrLocalhost(con
->http
->hostaddr
))
1294 * Require encryption of auth-info over non-local connections...
1297 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
1300 #endif /* HAVE_SSL */
1303 * See if the printer is accepting jobs...
1306 if (!printer
->accepting
)
1308 send_ipp_status(con
, IPP_NOT_ACCEPTING
,
1309 _("Destination \"%s\" is not accepting jobs."),
1315 * Validate job template attributes; for now just document-format,
1316 * copies, job-sheets, number-up, page-ranges, mandatory attributes, and
1320 for (i
= 0; i
< (int)(sizeof(readonly
) / sizeof(readonly
[0])); i
++)
1322 if ((attr
= ippFindAttribute(con
->request
, readonly
[i
], IPP_TAG_ZERO
)) != NULL
)
1324 ippDeleteAttribute(con
->request
, attr
);
1326 if (StrictConformance
)
1328 send_ipp_status(con
, IPP_BAD_REQUEST
, _("The '%s' Job Status attribute cannot be supplied in a job creation request."), readonly
[i
]);
1332 cupsdLogMessage(CUPSD_LOG_INFO
, "Unexpected '%s' Job Status attribute in a job creation request.", readonly
[i
]);
1338 for (mandatory
= (char *)cupsArrayFirst(printer
->pc
->mandatory
);
1340 mandatory
= (char *)cupsArrayNext(printer
->pc
->mandatory
))
1342 if (!ippFindAttribute(con
->request
, mandatory
, IPP_TAG_ZERO
))
1345 * Missing a required attribute...
1348 send_ipp_status(con
, IPP_CONFLICT
,
1349 _("The \"%s\" attribute is required for print jobs."),
1356 if (filetype
&& printer
->filetypes
&&
1357 !cupsArrayFind(printer
->filetypes
, filetype
))
1359 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
1360 /* MIME media type string */
1363 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
1366 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
1367 _("Unsupported format \"%s\"."), mimetype
);
1369 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
1370 "document-format", NULL
, mimetype
);
1375 if ((attr
= ippFindAttribute(con
->request
, "copies",
1376 IPP_TAG_INTEGER
)) != NULL
)
1378 if (attr
->values
[0].integer
< 1 || attr
->values
[0].integer
> MaxCopies
)
1380 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad copies value %d."),
1381 attr
->values
[0].integer
);
1382 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1383 "copies", attr
->values
[0].integer
);
1388 if ((attr
= ippFindAttribute(con
->request
, "job-sheets",
1389 IPP_TAG_ZERO
)) != NULL
)
1391 if (attr
->value_tag
!= IPP_TAG_KEYWORD
&&
1392 attr
->value_tag
!= IPP_TAG_NAME
)
1394 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value type."));
1398 if (attr
->num_values
> 2)
1400 send_ipp_status(con
, IPP_BAD_REQUEST
,
1401 _("Too many job-sheets values (%d > 2)."),
1406 for (i
= 0; i
< attr
->num_values
; i
++)
1407 if (strcmp(attr
->values
[i
].string
.text
, "none") &&
1408 !cupsdFindBanner(attr
->values
[i
].string
.text
))
1410 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value \"%s\"."),
1411 attr
->values
[i
].string
.text
);
1416 if ((attr
= ippFindAttribute(con
->request
, "number-up",
1417 IPP_TAG_INTEGER
)) != NULL
)
1419 if (attr
->values
[0].integer
!= 1 &&
1420 attr
->values
[0].integer
!= 2 &&
1421 attr
->values
[0].integer
!= 4 &&
1422 attr
->values
[0].integer
!= 6 &&
1423 attr
->values
[0].integer
!= 9 &&
1424 attr
->values
[0].integer
!= 16)
1426 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad number-up value %d."),
1427 attr
->values
[0].integer
);
1428 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1429 "number-up", attr
->values
[0].integer
);
1434 if ((attr
= ippFindAttribute(con
->request
, "page-ranges",
1435 IPP_TAG_RANGE
)) != NULL
)
1437 for (i
= 0, lowerpagerange
= 1; i
< attr
->num_values
; i
++)
1439 if (attr
->values
[i
].range
.lower
< lowerpagerange
||
1440 attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
1442 send_ipp_status(con
, IPP_BAD_REQUEST
,
1443 _("Bad page-ranges values %d-%d."),
1444 attr
->values
[i
].range
.lower
,
1445 attr
->values
[i
].range
.upper
);
1449 lowerpagerange
= attr
->values
[i
].range
.upper
+ 1;
1454 * Do media selection as needed...
1457 if (!ippFindAttribute(con
->request
, "PageRegion", IPP_TAG_ZERO
) &&
1458 !ippFindAttribute(con
->request
, "PageSize", IPP_TAG_ZERO
) &&
1459 _ppdCacheGetPageSize(printer
->pc
, con
->request
, NULL
, &exact
))
1462 (media_col
= ippFindAttribute(con
->request
, "media-col",
1463 IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
1465 send_ipp_status(con
, IPP_OK_SUBST
, _("Unsupported margins."));
1467 unsup_col
= ippNew();
1468 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1469 "media-bottom-margin",
1470 IPP_TAG_INTEGER
)) != NULL
)
1471 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1472 "media-bottom-margin", media_margin
->values
[0].integer
);
1474 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1475 "media-left-margin",
1476 IPP_TAG_INTEGER
)) != NULL
)
1477 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1478 "media-left-margin", media_margin
->values
[0].integer
);
1480 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1481 "media-right-margin",
1482 IPP_TAG_INTEGER
)) != NULL
)
1483 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1484 "media-right-margin", media_margin
->values
[0].integer
);
1486 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1488 IPP_TAG_INTEGER
)) != NULL
)
1489 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1490 "media-top-margin", media_margin
->values
[0].integer
);
1492 ippAddCollection(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, "media-col",
1494 ippDelete(unsup_col
);
1499 * Make sure we aren't over our limit...
1502 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1505 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1507 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Too many active jobs."));
1511 if ((i
= check_quotas(con
, printer
)) < 0)
1513 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
1518 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
1523 * Create the job and set things up...
1526 if ((attr
= ippFindAttribute(con
->request
, "job-priority",
1527 IPP_TAG_INTEGER
)) != NULL
)
1528 priority
= attr
->values
[0].integer
;
1531 if ((val
= cupsGetOption("job-priority", printer
->num_options
,
1532 printer
->options
)) != NULL
)
1533 priority
= atoi(val
);
1537 ippAddInteger(con
->request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-priority",
1541 if ((attr
= ippFindAttribute(con
->request
, "job-name", IPP_TAG_ZERO
)) == NULL
)
1542 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
, "Untitled");
1543 else if ((attr
->value_tag
!= IPP_TAG_NAME
&&
1544 attr
->value_tag
!= IPP_TAG_NAMELANG
) ||
1545 attr
->num_values
!= 1)
1547 send_ipp_status(con
, IPP_ATTRIBUTES
,
1548 _("Bad job-name value: Wrong type or count."));
1549 if ((attr
= ippCopyAttribute(con
->response
, attr
, 0)) != NULL
)
1550 attr
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
1553 else if (!ippValidateAttribute(attr
))
1555 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad job-name value: %s"),
1556 cupsLastErrorString());
1557 if ((attr
= ippCopyAttribute(con
->response
, attr
, 0)) != NULL
)
1558 attr
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
1562 if ((job
= cupsdAddJob(priority
, printer
->name
)) == NULL
)
1564 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1565 _("Unable to add job for destination \"%s\"."),
1570 job
->dtype
= printer
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
1571 job
->attrs
= con
->request
;
1573 con
->request
= ippNewRequest(job
->attrs
->request
.op
.operation_id
);
1575 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1578 apply_printer_defaults(printer
, job
);
1580 attr
= ippFindAttribute(job
->attrs
, "requesting-user-name", IPP_TAG_NAME
);
1582 if (con
->username
[0])
1584 cupsdSetString(&job
->username
, con
->username
);
1587 ippSetString(job
->attrs
, &attr
, 0, con
->username
);
1591 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1592 "add_job: requesting-user-name=\"%s\"",
1593 attr
->values
[0].string
.text
);
1595 cupsdSetString(&job
->username
, attr
->values
[0].string
.text
);
1598 cupsdSetString(&job
->username
, "anonymous");
1601 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1602 "job-originating-user-name", NULL
, job
->username
);
1605 ippSetGroupTag(job
->attrs
, &attr
, IPP_TAG_JOB
);
1606 ippSetName(job
->attrs
, &attr
, "job-originating-user-name");
1609 if (con
->username
[0] || auth_info
)
1611 save_auth_info(con
, job
, auth_info
);
1614 * Remove the auth-info attribute from the attribute data...
1618 ippDeleteAttribute(job
->attrs
, auth_info
);
1621 if ((attr
= ippFindAttribute(con
->request
, "job-name", IPP_TAG_NAME
)) != NULL
)
1622 cupsdSetString(&(job
->name
), attr
->values
[0].string
.text
);
1624 if ((attr
= ippFindAttribute(job
->attrs
, "job-originating-host-name",
1625 IPP_TAG_ZERO
)) != NULL
)
1628 * Request contains a job-originating-host-name attribute; validate it...
1631 if (attr
->value_tag
!= IPP_TAG_NAME
||
1632 attr
->num_values
!= 1 ||
1633 strcmp(con
->http
->hostname
, "localhost"))
1636 * Can't override the value if we aren't connected via localhost.
1637 * Also, we can only have 1 value and it must be a name value.
1640 ippDeleteAttribute(job
->attrs
, attr
);
1641 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-originating-host-name", NULL
, con
->http
->hostname
);
1644 ippSetGroupTag(job
->attrs
, &attr
, IPP_TAG_JOB
);
1649 * No job-originating-host-name attribute, so use the hostname from
1653 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1654 "job-originating-host-name", NULL
, con
->http
->hostname
);
1657 ippAddOutOfBand(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NOVALUE
, "date-time-at-completed");
1658 ippAddDate(job
->attrs
, IPP_TAG_JOB
, "date-time-at-creation", ippTimeToDate(time(NULL
)));
1659 ippAddOutOfBand(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NOVALUE
, "date-time-at-processing");
1660 ippAddOutOfBand(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NOVALUE
, "time-at-completed");
1661 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation", time(NULL
));
1662 ippAddOutOfBand(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NOVALUE
, "time-at-processing");
1665 * Add remaining job attributes...
1668 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1669 job
->state
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_ENUM
,
1670 "job-state", IPP_JOB_STOPPED
);
1671 job
->state_value
= (ipp_jstate_t
)job
->state
->values
[0].integer
;
1672 job
->reasons
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1673 "job-state-reasons", NULL
, "job-incoming");
1674 job
->impressions
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-impressions-completed", 0);
1675 job
->sheets
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1676 "job-media-sheets-completed", 0);
1677 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-printer-uri", NULL
,
1680 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets", IPP_TAG_INTEGER
)) != NULL
)
1681 attr
->values
[0].integer
= 0;
1683 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-k-octets", 0);
1685 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
1686 IPP_TAG_KEYWORD
)) == NULL
)
1687 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
1690 if ((val
= cupsGetOption("job-hold-until", printer
->num_options
,
1691 printer
->options
)) == NULL
)
1694 attr
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1695 "job-hold-until", NULL
, val
);
1697 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
1700 * Hold job until specified time...
1703 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
1705 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1706 job
->state_value
= IPP_JOB_HELD
;
1708 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-hold-until-specified");
1710 else if (job
->attrs
->request
.op
.operation_id
== IPP_CREATE_JOB
)
1712 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
1713 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1714 job
->state_value
= IPP_JOB_HELD
;
1718 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1719 job
->state_value
= IPP_JOB_PENDING
;
1721 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
1724 if (!(printer
->type
& CUPS_PRINTER_REMOTE
) || Classification
)
1727 * Add job sheets options...
1730 if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1731 IPP_TAG_ZERO
)) == NULL
)
1733 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1734 "Adding default job-sheets values \"%s,%s\"...",
1735 printer
->job_sheets
[0], printer
->job_sheets
[1]);
1737 attr
= ippAddStrings(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-sheets",
1739 ippSetString(job
->attrs
, &attr
, 0, printer
->job_sheets
[0]);
1740 ippSetString(job
->attrs
, &attr
, 1, printer
->job_sheets
[1]);
1743 job
->job_sheets
= attr
;
1746 * Enforce classification level if set...
1751 cupsdLogMessage(CUPSD_LOG_INFO
,
1752 "Classification=\"%s\", ClassifyOverride=%d",
1753 Classification
? Classification
: "(null)",
1756 if (ClassifyOverride
)
1758 if (!strcmp(attr
->values
[0].string
.text
, "none") &&
1759 (attr
->num_values
== 1 ||
1760 !strcmp(attr
->values
[1].string
.text
, "none")))
1763 * Force the leading banner to have the classification on it...
1766 ippSetString(job
->attrs
, &attr
, 0, Classification
);
1768 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1769 "job-sheets=\"%s,none\", "
1770 "job-originating-user-name=\"%s\"",
1771 Classification
, job
->username
);
1773 else if (attr
->num_values
== 2 &&
1774 strcmp(attr
->values
[0].string
.text
,
1775 attr
->values
[1].string
.text
) &&
1776 strcmp(attr
->values
[0].string
.text
, "none") &&
1777 strcmp(attr
->values
[1].string
.text
, "none"))
1780 * Can't put two different security markings on the same document!
1783 ippSetString(job
->attrs
, &attr
, 1, attr
->values
[0].string
.text
);
1785 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1786 "job-sheets=\"%s,%s\", "
1787 "job-originating-user-name=\"%s\"",
1788 attr
->values
[0].string
.text
,
1789 attr
->values
[1].string
.text
, job
->username
);
1791 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1792 strcmp(attr
->values
[0].string
.text
, "none") &&
1793 (attr
->num_values
== 1 ||
1794 (strcmp(attr
->values
[1].string
.text
, Classification
) &&
1795 strcmp(attr
->values
[1].string
.text
, "none"))))
1797 if (attr
->num_values
== 1)
1798 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1799 "CLASSIFICATION OVERRIDDEN "
1800 "job-sheets=\"%s\", "
1801 "job-originating-user-name=\"%s\"",
1802 attr
->values
[0].string
.text
, job
->username
);
1804 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1805 "CLASSIFICATION OVERRIDDEN "
1806 "job-sheets=\"%s,%s\",fffff "
1807 "job-originating-user-name=\"%s\"",
1808 attr
->values
[0].string
.text
,
1809 attr
->values
[1].string
.text
, job
->username
);
1812 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1813 (attr
->num_values
== 1 ||
1814 strcmp(attr
->values
[1].string
.text
, Classification
)))
1817 * Force the banner to have the classification on it...
1820 if (attr
->num_values
> 1 &&
1821 !strcmp(attr
->values
[0].string
.text
, attr
->values
[1].string
.text
))
1823 ippSetString(job
->attrs
, &attr
, 0, Classification
);
1824 ippSetString(job
->attrs
, &attr
, 1, Classification
);
1828 if (attr
->num_values
== 1 ||
1829 strcmp(attr
->values
[0].string
.text
, "none"))
1830 ippSetString(job
->attrs
, &attr
, 0, Classification
);
1832 if (attr
->num_values
> 1 &&
1833 strcmp(attr
->values
[1].string
.text
, "none"))
1834 ippSetString(job
->attrs
, &attr
, 1, Classification
);
1837 if (attr
->num_values
> 1)
1838 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1839 "CLASSIFICATION FORCED "
1840 "job-sheets=\"%s,%s\", "
1841 "job-originating-user-name=\"%s\"",
1842 attr
->values
[0].string
.text
,
1843 attr
->values
[1].string
.text
, job
->username
);
1845 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1846 "CLASSIFICATION FORCED "
1847 "job-sheets=\"%s\", "
1848 "job-originating-user-name=\"%s\"",
1849 Classification
, job
->username
);
1854 * See if we need to add the starting sheet...
1857 if (!(printer
->type
& CUPS_PRINTER_REMOTE
))
1859 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding start banner page \"%s\".",
1860 attr
->values
[0].string
.text
);
1862 if ((kbytes
= copy_banner(con
, job
, attr
->values
[0].string
.text
)) < 0)
1864 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1865 "Aborting job because the start banner could not be "
1870 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
1873 else if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1874 IPP_TAG_ZERO
)) != NULL
)
1875 job
->job_sheets
= attr
;
1878 * Fill in the response info...
1881 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
1882 con
->clientname
, con
->clientport
, "/jobs/%d", job
->id
);
1883 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
1886 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1888 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
1890 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_TEXT
, "job-state-message", NULL
, "");
1891 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons",
1892 NULL
, job
->reasons
->values
[0].string
.text
);
1894 con
->response
->request
.status
.status_code
= IPP_OK
;
1897 * Add any job subscriptions...
1900 add_job_subscriptions(con
, job
);
1903 * Set all but the first two attributes to the job attributes group...
1906 for (attr
= job
->attrs
->attrs
->next
->next
; attr
; attr
= attr
->next
)
1907 attr
->group_tag
= IPP_TAG_JOB
;
1910 * Fire the "job created" event...
1913 cupsdAddEvent(CUPSD_EVENT_JOB_CREATED
, printer
, job
, "Job created.");
1916 * Return the new job...
1924 * 'add_job_subscriptions()' - Add any subscriptions for a job.
1928 add_job_subscriptions(
1929 cupsd_client_t
*con
, /* I - Client connection */
1930 cupsd_job_t
*job
) /* I - Newly created job */
1932 int i
; /* Looping var */
1933 ipp_attribute_t
*prev
, /* Previous attribute */
1934 *next
, /* Next attribute */
1935 *attr
; /* Current attribute */
1936 cupsd_subscription_t
*sub
; /* Subscription object */
1937 const char *recipient
, /* notify-recipient-uri */
1938 *pullmethod
; /* notify-pull-method */
1939 ipp_attribute_t
*user_data
; /* notify-user-data */
1940 int interval
; /* notify-time-interval */
1941 unsigned mask
; /* notify-events */
1945 * Find the first subscription group attribute; return if we have
1949 for (attr
= job
->attrs
->attrs
; attr
; attr
= attr
->next
)
1950 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
1957 * Process the subscription attributes in the request...
1966 mask
= CUPSD_EVENT_NONE
;
1968 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
1970 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
1971 attr
->value_tag
== IPP_TAG_URI
)
1974 * Validate the recipient scheme against the ServerBin/notifier
1978 char notifier
[1024], /* Notifier filename */
1979 scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
1980 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
1981 host
[HTTP_MAX_URI
], /* Host portion of URI */
1982 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
1983 int port
; /* Port portion of URI */
1986 recipient
= attr
->values
[0].string
.text
;
1988 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
1989 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
1990 host
, sizeof(host
), &port
,
1991 resource
, sizeof(resource
)) < HTTP_URI_OK
)
1993 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
1994 _("Bad notify-recipient-uri \"%s\"."), recipient
);
1995 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
1996 "notify-status-code", IPP_URI_SCHEME
);
2000 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
2002 if (access(notifier
, X_OK
))
2004 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2005 _("notify-recipient-uri URI \"%s\" uses unknown "
2006 "scheme."), recipient
);
2007 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2008 "notify-status-code", IPP_URI_SCHEME
);
2012 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
2014 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2015 _("notify-recipient-uri URI \"%s\" is already used."),
2017 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2018 "notify-status-code", IPP_ATTRIBUTES
);
2022 else if (!strcmp(attr
->name
, "notify-pull-method") &&
2023 attr
->value_tag
== IPP_TAG_KEYWORD
)
2025 pullmethod
= attr
->values
[0].string
.text
;
2027 if (strcmp(pullmethod
, "ippget"))
2029 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2030 _("Bad notify-pull-method \"%s\"."), pullmethod
);
2031 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2032 "notify-status-code", IPP_ATTRIBUTES
);
2036 else if (!strcmp(attr
->name
, "notify-charset") &&
2037 attr
->value_tag
== IPP_TAG_CHARSET
&&
2038 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
2039 strcmp(attr
->values
[0].string
.text
, "utf-8"))
2041 send_ipp_status(con
, IPP_CHARSET
,
2042 _("Character set \"%s\" not supported."),
2043 attr
->values
[0].string
.text
);
2046 else if (!strcmp(attr
->name
, "notify-natural-language") &&
2047 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
2048 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
2050 send_ipp_status(con
, IPP_CHARSET
,
2051 _("Language \"%s\" not supported."),
2052 attr
->values
[0].string
.text
);
2055 else if (!strcmp(attr
->name
, "notify-user-data") &&
2056 attr
->value_tag
== IPP_TAG_STRING
)
2058 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
2060 send_ipp_status(con
, IPP_REQUEST_VALUE
,
2061 _("The notify-user-data value is too large "
2062 "(%d > 63 octets)."),
2063 attr
->values
[0].unknown
.length
);
2069 else if (!strcmp(attr
->name
, "notify-events") &&
2070 attr
->value_tag
== IPP_TAG_KEYWORD
)
2072 for (i
= 0; i
< attr
->num_values
; i
++)
2073 mask
|= cupsdEventValue(attr
->values
[i
].string
.text
);
2075 else if (!strcmp(attr
->name
, "notify-lease-duration"))
2077 send_ipp_status(con
, IPP_BAD_REQUEST
,
2078 _("The notify-lease-duration attribute cannot be "
2079 "used with job subscriptions."));
2082 else if (!strcmp(attr
->name
, "notify-time-interval") &&
2083 attr
->value_tag
== IPP_TAG_INTEGER
)
2084 interval
= attr
->values
[0].integer
;
2089 if (!recipient
&& !pullmethod
)
2092 if (mask
== CUPSD_EVENT_NONE
)
2093 mask
= CUPSD_EVENT_JOB_COMPLETED
;
2095 if ((sub
= cupsdAddSubscription(mask
, cupsdFindDest(job
->dest
), job
,
2096 recipient
, 0)) != NULL
)
2098 sub
->interval
= interval
;
2100 cupsdSetString(&sub
->owner
, job
->username
);
2104 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
2105 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
2106 (size_t)sub
->user_data_len
);
2109 ippAddSeparator(con
->response
);
2110 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
2111 "notify-subscription-id", sub
->id
);
2113 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
2121 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
2124 * Remove all of the subscription attributes from the job request...
2126 * TODO: Optimize this since subscription groups have to come at the
2127 * end of the request...
2130 for (attr
= job
->attrs
->attrs
, prev
= NULL
; attr
; attr
= next
)
2134 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
||
2135 attr
->group_tag
== IPP_TAG_ZERO
)
2138 * Free and remove this attribute...
2141 ippDeleteAttribute(NULL
, attr
);
2146 job
->attrs
->attrs
= next
;
2152 job
->attrs
->last
= prev
;
2153 job
->attrs
->current
= prev
;
2158 * 'add_job_uuid()' - Add job-uuid attribute to a job.
2160 * See RFC 4122 for the definition of UUIDs and the format.
2164 add_job_uuid(cupsd_job_t
*job
) /* I - Job */
2166 char uuid
[64]; /* job-uuid string */
2170 * Add a job-uuid attribute if none exists...
2173 if (!ippFindAttribute(job
->attrs
, "job-uuid", IPP_TAG_URI
))
2174 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uuid", NULL
,
2175 httpAssembleUUID(ServerName
, RemotePort
, job
->dest
, job
->id
,
2176 uuid
, sizeof(uuid
)));
2181 * 'add_printer()' - Add a printer to the system.
2185 add_printer(cupsd_client_t
*con
, /* I - Client connection */
2186 ipp_attribute_t
*uri
) /* I - URI of printer */
2188 http_status_t status
; /* Policy status */
2189 int i
; /* Looping var */
2190 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
2191 username
[HTTP_MAX_URI
], /* Username portion of URI */
2192 host
[HTTP_MAX_URI
], /* Host portion of URI */
2193 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2194 int port
; /* Port portion of URI */
2195 cupsd_printer_t
*printer
; /* Printer/class */
2196 ipp_attribute_t
*attr
; /* Printer attribute */
2197 cups_file_t
*fp
; /* Script/PPD file */
2198 char line
[1024]; /* Line from file... */
2199 char srcfile
[1024], /* Source Script/PPD file */
2200 dstfile
[1024]; /* Destination Script/PPD file */
2201 int modify
; /* Non-zero if we are modifying */
2202 int changed_driver
, /* Changed the PPD? */
2203 need_restart_job
, /* Need to restart job? */
2204 set_device_uri
, /* Did we set the device URI? */
2205 set_port_monitor
; /* Did we set the port monitor? */
2208 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer(%p[%d], %s)", con
,
2209 con
->number
, uri
->values
[0].string
.text
);
2212 * Do we have a valid URI?
2215 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
2216 sizeof(scheme
), username
, sizeof(username
), host
,
2217 sizeof(host
), &port
, resource
, sizeof(resource
));
2219 if (strncmp(resource
, "/printers/", 10) || strlen(resource
) == 10)
2222 * No, return an error...
2225 send_ipp_status(con
, IPP_BAD_REQUEST
,
2226 _("The printer-uri must be of the form "
2227 "\"ipp://HOSTNAME/printers/PRINTERNAME\"."));
2232 * Do we have a valid printer name?
2235 if (!validate_name(resource
+ 10))
2238 * No, return an error...
2241 send_ipp_status(con
, IPP_BAD_REQUEST
,
2242 _("The printer-uri \"%s\" contains invalid characters."),
2243 uri
->values
[0].string
.text
);
2248 * See if the printer already exists; if not, create a new printer...
2251 if ((printer
= cupsdFindPrinter(resource
+ 10)) == NULL
)
2254 * Printer doesn't exist; see if we have a class of the same name...
2257 if ((printer
= cupsdFindClass(resource
+ 10)) != NULL
)
2260 * Yes, return an error...
2263 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2264 _("A class named \"%s\" already exists."),
2270 * No, check the default policy then add the printer...
2273 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2275 send_http_error(con
, status
, NULL
);
2279 printer
= cupsdAddPrinter(resource
+ 10);
2282 else if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
2285 send_http_error(con
, status
, printer
);
2292 * Look for attributes and copy them over as needed...
2296 need_restart_job
= 0;
2298 if ((attr
= ippFindAttribute(con
->request
, "printer-is-temporary", IPP_TAG_BOOLEAN
)) != NULL
)
2299 printer
->temporary
= ippGetBoolean(attr
, 0);
2301 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
2302 IPP_TAG_TEXT
)) != NULL
)
2303 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
2305 if ((attr
= ippFindAttribute(con
->request
, "printer-geo-location", IPP_TAG_URI
)) != NULL
&& !strncmp(attr
->values
[0].string
.text
, "geo:", 4))
2306 cupsdSetString(&printer
->geo_location
, attr
->values
[0].string
.text
);
2308 if ((attr
= ippFindAttribute(con
->request
, "printer-organization", IPP_TAG_TEXT
)) != NULL
)
2309 cupsdSetString(&printer
->organization
, attr
->values
[0].string
.text
);
2311 if ((attr
= ippFindAttribute(con
->request
, "printer-organizational-unit", IPP_TAG_TEXT
)) != NULL
)
2312 cupsdSetString(&printer
->organizational_unit
, attr
->values
[0].string
.text
);
2314 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
2315 IPP_TAG_TEXT
)) != NULL
)
2316 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
2320 if ((attr
= ippFindAttribute(con
->request
, "device-uri",
2321 IPP_TAG_URI
)) != NULL
)
2324 * Do we have a valid device URI?
2327 http_uri_status_t uri_status
; /* URI separation status */
2328 char old_device_uri
[1024];
2329 /* Old device URI */
2330 static const char * const uri_status_strings
[] =
2333 "Bad arguments to function.",
2334 "Bad resource path.",
2336 "Bad hostname/address.",
2337 "Bad username/password.",
2341 "Missing URI scheme.",
2342 "Unknown URI scheme",
2343 "Missing resource path."
2347 need_restart_job
= 1;
2349 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
,
2350 attr
->values
[0].string
.text
,
2351 scheme
, sizeof(scheme
),
2352 username
, sizeof(username
),
2353 host
, sizeof(host
), &port
,
2354 resource
, sizeof(resource
));
2356 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2357 "%s device-uri: %s", printer
->name
,
2358 uri_status_strings
[uri_status
- HTTP_URI_STATUS_OVERFLOW
]);
2360 if (uri_status
< HTTP_URI_OK
)
2362 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri \"%s\"."),
2363 attr
->values
[0].string
.text
);
2367 if (!strcmp(scheme
, "file"))
2370 * See if the administrator has enabled file devices...
2373 if (!FileDevice
&& strcmp(resource
, "/dev/null"))
2376 * File devices are disabled and the URL is not file:/dev/null...
2379 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2380 _("File device URIs have been disabled. "
2381 "To enable, see the FileDevice directive in "
2382 "\"%s/cups-files.conf\"."),
2390 * See if the backend exists and is executable...
2393 snprintf(srcfile
, sizeof(srcfile
), "%s/backend/%s", ServerBin
, scheme
);
2394 if (access(srcfile
, X_OK
))
2397 * Could not find device in list!
2400 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2401 _("Bad device-uri scheme \"%s\"."), scheme
);
2406 if (printer
->sanitized_device_uri
)
2407 strlcpy(old_device_uri
, printer
->sanitized_device_uri
,
2408 sizeof(old_device_uri
));
2410 old_device_uri
[0] = '\0';
2412 cupsdSetDeviceURI(printer
, attr
->values
[0].string
.text
);
2414 cupsdLogMessage(CUPSD_LOG_INFO
,
2415 "Setting %s device-uri to \"%s\" (was \"%s\".)",
2416 printer
->name
, printer
->sanitized_device_uri
,
2422 set_port_monitor
= 0;
2424 if ((attr
= ippFindAttribute(con
->request
, "port-monitor",
2425 IPP_TAG_NAME
)) != NULL
)
2427 ipp_attribute_t
*supported
; /* port-monitor-supported attribute */
2430 need_restart_job
= 1;
2432 supported
= ippFindAttribute(printer
->ppd_attrs
, "port-monitor-supported",
2436 for (i
= 0; i
< supported
->num_values
; i
++)
2437 if (!strcmp(supported
->values
[i
].string
.text
,
2438 attr
->values
[0].string
.text
))
2442 if (!supported
|| i
>= supported
->num_values
)
2444 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad port-monitor \"%s\"."),
2445 attr
->values
[0].string
.text
);
2449 cupsdLogMessage(CUPSD_LOG_INFO
,
2450 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2451 printer
->name
, attr
->values
[0].string
.text
,
2452 printer
->port_monitor
? printer
->port_monitor
: "none");
2454 if (strcmp(attr
->values
[0].string
.text
, "none"))
2455 cupsdSetString(&printer
->port_monitor
, attr
->values
[0].string
.text
);
2457 cupsdClearString(&printer
->port_monitor
);
2459 set_port_monitor
= 1;
2462 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
2463 IPP_TAG_BOOLEAN
)) != NULL
&&
2464 attr
->values
[0].boolean
!= printer
->accepting
)
2466 cupsdLogMessage(CUPSD_LOG_INFO
,
2467 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
2468 printer
->name
, attr
->values
[0].boolean
, printer
->accepting
);
2470 printer
->accepting
= attr
->values
[0].boolean
;
2472 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2473 "%s accepting jobs.",
2474 printer
->accepting
? "Now" : "No longer");
2477 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared", IPP_TAG_BOOLEAN
)) != NULL
)
2479 if (ippGetBoolean(attr
, 0) &&
2480 printer
->num_auth_info_required
== 1 &&
2481 !strcmp(printer
->auth_info_required
[0], "negotiate"))
2483 send_ipp_status(con
, IPP_BAD_REQUEST
,
2484 _("Cannot share a remote Kerberized printer."));
2488 if (printer
->type
& CUPS_PRINTER_REMOTE
)
2491 * Cannot re-share remote printers.
2494 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Cannot change printer-is-shared for remote queues."));
2498 if (printer
->shared
&& !ippGetBoolean(attr
, 0))
2499 cupsdDeregisterPrinter(printer
, 1);
2501 cupsdLogMessage(CUPSD_LOG_INFO
,
2502 "Setting %s printer-is-shared to %d (was %d.)",
2503 printer
->name
, attr
->values
[0].boolean
, printer
->shared
);
2505 printer
->shared
= ippGetBoolean(attr
, 0);
2506 if (printer
->shared
&& printer
->temporary
)
2507 printer
->temporary
= 0;
2510 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
2511 IPP_TAG_ENUM
)) != NULL
)
2513 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
2514 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
2516 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad printer-state value %d."),
2517 attr
->values
[0].integer
);
2521 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
2522 printer
->name
, attr
->values
[0].integer
, printer
->state
);
2524 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
2525 cupsdStopPrinter(printer
, 0);
2528 need_restart_job
= 1;
2529 cupsdSetPrinterState(printer
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
2533 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
2534 IPP_TAG_TEXT
)) != NULL
)
2536 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
2537 sizeof(printer
->state_message
));
2539 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
, "%s",
2540 printer
->state_message
);
2543 if ((attr
= ippFindAttribute(con
->request
, "printer-state-reasons",
2544 IPP_TAG_KEYWORD
)) != NULL
)
2546 if (attr
->num_values
>
2547 (int)(sizeof(printer
->reasons
) / sizeof(printer
->reasons
[0])))
2549 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2550 _("Too many printer-state-reasons values (%d > %d)."),
2552 (int)(sizeof(printer
->reasons
) /
2553 sizeof(printer
->reasons
[0])));
2557 for (i
= 0; i
< printer
->num_reasons
; i
++)
2558 _cupsStrFree(printer
->reasons
[i
]);
2560 printer
->num_reasons
= 0;
2561 for (i
= 0; i
< attr
->num_values
; i
++)
2563 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
2566 printer
->reasons
[printer
->num_reasons
] =
2567 _cupsStrRetain(attr
->values
[i
].string
.text
);
2568 printer
->num_reasons
++;
2570 if (!strcmp(attr
->values
[i
].string
.text
, "paused") &&
2571 printer
->state
!= IPP_PRINTER_STOPPED
)
2573 cupsdLogMessage(CUPSD_LOG_INFO
,
2574 "Setting %s printer-state to %d (was %d.)",
2575 printer
->name
, IPP_PRINTER_STOPPED
, printer
->state
);
2576 cupsdStopPrinter(printer
, 0);
2580 if (PrintcapFormat
== PRINTCAP_PLIST
)
2581 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2583 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2584 "Printer \"%s\" state changed.", printer
->name
);
2587 set_printer_defaults(con
, printer
);
2589 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
2590 IPP_TAG_KEYWORD
)) != NULL
)
2591 cupsdSetAuthInfoRequired(printer
, NULL
, attr
);
2594 * See if we have all required attributes...
2597 if (!printer
->device_uri
)
2598 cupsdSetString(&printer
->device_uri
, "file:///dev/null");
2601 * See if we have a PPD file attached to the request...
2606 need_restart_job
= 1;
2609 strlcpy(srcfile
, con
->filename
, sizeof(srcfile
));
2611 if ((fp
= cupsFileOpen(srcfile
, "rb")))
2614 * Yes; get the first line from it...
2618 cupsFileGets(fp
, line
, sizeof(line
));
2622 * Then see what kind of file it is...
2625 if (strncmp(line
, "*PPD-Adobe", 10))
2627 send_ipp_status(con
, IPP_STATUS_ERROR_DOCUMENT_FORMAT_NOT_SUPPORTED
, _("Bad PPD file."));
2631 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2635 * The new file is a PPD file, so move the file over to the ppd
2639 if (copy_file(srcfile
, dstfile
, ConfigFilePerm
))
2641 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file - %s"), strerror(errno
));
2645 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Copied PPD file successfully");
2648 else if ((attr
= ippFindAttribute(con
->request
, "ppd-name", IPP_TAG_NAME
)) != NULL
)
2650 const char *ppd_name
= ippGetString(attr
, 0, NULL
);
2651 /* ppd-name value */
2653 need_restart_job
= 1;
2656 if (!strcmp(ppd_name
, "raw"))
2659 * Raw driver, remove any existing PPD file.
2662 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
, printer
->name
);
2665 else if (strstr(ppd_name
, "../"))
2667 send_ipp_status(con
, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES
, _("Invalid ppd-name value."));
2676 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
, printer
->name
);
2678 if (copy_model(con
, ppd_name
, dstfile
))
2680 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file."));
2684 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Copied PPD file successfully");
2691 * If we changed the PPD, then remove the printer's cache file and clear the
2692 * printer-state-reasons...
2695 char cache_name
[1024]; /* Cache filename for printer attrs */
2697 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.data", CacheDir
,
2701 cupsdSetPrinterReasons(printer
, "none");
2704 * (Re)register color profiles...
2707 cupsdRegisterColor(printer
);
2711 * If we set the device URI but not the port monitor, check which port
2712 * monitor to use by default...
2715 if (set_device_uri
&& !set_port_monitor
)
2717 ppd_file_t
*ppd
; /* PPD file */
2718 ppd_attr_t
*ppdattr
; /* cupsPortMonitor attribute */
2721 httpSeparateURI(HTTP_URI_CODING_ALL
, printer
->device_uri
, scheme
,
2722 sizeof(scheme
), username
, sizeof(username
), host
,
2723 sizeof(host
), &port
, resource
, sizeof(resource
));
2725 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
,
2727 if ((ppd
= _ppdOpenFile(srcfile
, _PPD_LOCALIZATION_NONE
)) != NULL
)
2729 for (ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2731 ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
2732 if (!strcmp(scheme
, ppdattr
->spec
))
2734 cupsdLogMessage(CUPSD_LOG_INFO
,
2735 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2736 printer
->name
, ppdattr
->value
,
2737 printer
->port_monitor
? printer
->port_monitor
2740 if (strcmp(ppdattr
->value
, "none"))
2741 cupsdSetString(&printer
->port_monitor
, ppdattr
->value
);
2743 cupsdClearString(&printer
->port_monitor
);
2752 printer
->config_time
= time(NULL
);
2755 * Update the printer attributes and return...
2758 cupsdSetPrinterAttrs(printer
);
2759 if (!printer
->temporary
)
2760 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2762 if (need_restart_job
&& printer
->job
)
2765 * Restart the current job...
2768 cupsdSetJobState(printer
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
2769 "Job restarted because the printer was modified.");
2772 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2776 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
2777 printer
, NULL
, "Printer \"%s\" modified by \"%s\".",
2778 printer
->name
, get_username(con
));
2780 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" modified by \"%s\".",
2781 printer
->name
, get_username(con
));
2785 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
2786 printer
, NULL
, "New printer \"%s\" added by \"%s\".",
2787 printer
->name
, get_username(con
));
2789 cupsdLogMessage(CUPSD_LOG_INFO
, "New printer \"%s\" added by \"%s\".",
2790 printer
->name
, get_username(con
));
2793 con
->response
->request
.status
.status_code
= IPP_OK
;
2798 * 'add_printer_state_reasons()' - Add the "printer-state-reasons" attribute
2799 * based upon the printer state...
2803 add_printer_state_reasons(
2804 cupsd_client_t
*con
, /* I - Client connection */
2805 cupsd_printer_t
*p
) /* I - Printer info */
2807 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2808 "add_printer_state_reasons(%p[%d], %p[%s])",
2809 con
, con
->number
, p
, p
->name
);
2811 if (p
->num_reasons
== 0)
2812 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2813 "printer-state-reasons", NULL
, "none");
2815 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2816 "printer-state-reasons", p
->num_reasons
, NULL
,
2817 (const char * const *)p
->reasons
);
2822 * 'add_queued_job_count()' - Add the "queued-job-count" attribute for
2823 * the specified printer or class.
2827 add_queued_job_count(
2828 cupsd_client_t
*con
, /* I - Client connection */
2829 cupsd_printer_t
*p
) /* I - Printer or class */
2831 int count
; /* Number of jobs on destination */
2834 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_queued_job_count(%p[%d], %p[%s])",
2835 con
, con
->number
, p
, p
->name
);
2837 count
= cupsdGetPrinterJobCount(p
->name
);
2839 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2840 "queued-job-count", count
);
2845 * 'apply_printer_defaults()' - Apply printer default options to a job.
2849 apply_printer_defaults(
2850 cupsd_printer_t
*printer
, /* I - Printer */
2851 cupsd_job_t
*job
) /* I - Job */
2853 int i
, /* Looping var */
2854 num_options
; /* Number of default options */
2855 cups_option_t
*options
, /* Default options */
2856 *option
; /* Current option */
2860 * Collect all of the default options and add the missing ones to the
2864 for (i
= printer
->num_options
, num_options
= 0, options
= NULL
,
2865 option
= printer
->options
;
2868 if (!ippFindAttribute(job
->attrs
, option
->name
, IPP_TAG_ZERO
))
2870 num_options
= cupsAddOption(option
->name
, option
->value
, num_options
,
2875 * Encode these options as attributes in the job object...
2878 cupsEncodeOptions2(job
->attrs
, num_options
, options
, IPP_TAG_JOB
);
2879 cupsFreeOptions(num_options
, options
);
2884 * 'authenticate_job()' - Set job authentication info.
2888 authenticate_job(cupsd_client_t
*con
, /* I - Client connection */
2889 ipp_attribute_t
*uri
) /* I - Job URI */
2891 ipp_attribute_t
*attr
, /* job-id attribute */
2892 *auth_info
; /* auth-info attribute */
2893 int jobid
; /* Job ID */
2894 cupsd_job_t
*job
; /* Current job */
2895 char scheme
[HTTP_MAX_URI
],
2896 /* Method portion of URI */
2897 username
[HTTP_MAX_URI
],
2898 /* Username portion of URI */
2900 /* Host portion of URI */
2901 resource
[HTTP_MAX_URI
];
2902 /* Resource portion of URI */
2903 int port
; /* Port portion of URI */
2906 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "authenticate_job(%p[%d], %s)",
2907 con
, con
->number
, uri
->values
[0].string
.text
);
2910 * Start with "everything is OK" status...
2913 con
->response
->request
.status
.status_code
= IPP_OK
;
2916 * See if we have a job URI or a printer URI...
2919 if (!strcmp(uri
->name
, "printer-uri"))
2922 * Got a printer URI; see if we also have a job-id attribute...
2925 if ((attr
= ippFindAttribute(con
->request
, "job-id",
2926 IPP_TAG_INTEGER
)) == NULL
)
2928 send_ipp_status(con
, IPP_BAD_REQUEST
,
2929 _("Got a printer-uri attribute but no job-id."));
2933 jobid
= attr
->values
[0].integer
;
2938 * Got a job URI; parse it to get the job ID...
2941 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
2942 sizeof(scheme
), username
, sizeof(username
), host
,
2943 sizeof(host
), &port
, resource
, sizeof(resource
));
2945 if (strncmp(resource
, "/jobs/", 6))
2951 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
2952 uri
->values
[0].string
.text
);
2956 jobid
= atoi(resource
+ 6);
2960 * See if the job exists...
2963 if ((job
= cupsdFindJob(jobid
)) == NULL
)
2966 * Nope - return a "not found" error...
2969 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
2974 * See if the job has been completed...
2977 if (job
->state_value
!= IPP_JOB_HELD
)
2980 * Return a "not-possible" error...
2983 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2984 _("Job #%d is not held for authentication."),
2990 * See if we have already authenticated...
2993 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
2995 if (!con
->username
[0] && !auth_info
)
2997 cupsd_printer_t
*printer
; /* Job destination */
3000 * No auth data. If we need to authenticate via Kerberos, send a
3001 * HTTP auth challenge, otherwise just return an IPP error...
3004 printer
= cupsdFindDest(job
->dest
);
3006 if (printer
&& printer
->num_auth_info_required
> 0 &&
3007 !strcmp(printer
->auth_info_required
[0], "negotiate"))
3008 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
3010 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
3011 _("No authentication information provided."));
3016 * See if the job is owned by the requesting user...
3019 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3021 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3022 cupsdFindDest(job
->dest
));
3027 * Save the authentication information for this job...
3030 save_auth_info(con
, job
, auth_info
);
3033 * Reset the job-hold-until value to "no-hold"...
3036 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
3037 IPP_TAG_KEYWORD
)) == NULL
)
3038 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
3042 ippSetValueTag(job
->attrs
, &attr
, IPP_TAG_KEYWORD
);
3043 ippSetString(job
->attrs
, &attr
, 0, "no-hold");
3047 * Release the job and return...
3050 cupsdReleaseJob(job
);
3052 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, NULL
, job
, "Job authenticated by user");
3054 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Authenticated by \"%s\".", con
->username
);
3061 * 'cancel_all_jobs()' - Cancel all or selected print jobs.
3065 cancel_all_jobs(cupsd_client_t
*con
, /* I - Client connection */
3066 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3068 int i
; /* Looping var */
3069 http_status_t status
; /* Policy status */
3070 cups_ptype_t dtype
; /* Destination type */
3071 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3072 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
3073 hostname
[HTTP_MAX_URI
], /* Host portion of URI */
3074 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3075 int port
; /* Port portion of URI */
3076 ipp_attribute_t
*attr
; /* Attribute in request */
3077 const char *username
= NULL
; /* Username */
3078 cupsd_jobaction_t purge
= CUPSD_JOB_DEFAULT
;
3080 cupsd_printer_t
*printer
; /* Printer */
3081 ipp_attribute_t
*job_ids
; /* job-ids attribute */
3082 cupsd_job_t
*job
; /* Job */
3085 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_all_jobs(%p[%d], %s)", con
,
3086 con
->number
, uri
->values
[0].string
.text
);
3089 * Get the jobs to cancel/purge...
3092 switch (con
->request
->request
.op
.operation_id
)
3094 case IPP_PURGE_JOBS
:
3096 * Get the username (if any) for the jobs we want to cancel (only if
3097 * "my-jobs" is specified...
3100 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
3101 IPP_TAG_BOOLEAN
)) != NULL
&&
3102 attr
->values
[0].boolean
)
3104 if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3105 IPP_TAG_NAME
)) != NULL
)
3106 username
= attr
->values
[0].string
.text
;
3109 send_ipp_status(con
, IPP_BAD_REQUEST
,
3110 _("Missing requesting-user-name attribute."));
3116 * Look for the "purge-jobs" attribute...
3119 if ((attr
= ippFindAttribute(con
->request
, "purge-jobs",
3120 IPP_TAG_BOOLEAN
)) != NULL
)
3121 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
3123 purge
= CUPSD_JOB_PURGE
;
3126 case IPP_CANCEL_MY_JOBS
:
3127 if (con
->username
[0])
3128 username
= con
->username
;
3129 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3130 IPP_TAG_NAME
)) != NULL
)
3131 username
= attr
->values
[0].string
.text
;
3134 send_ipp_status(con
, IPP_BAD_REQUEST
,
3135 _("Missing requesting-user-name attribute."));
3143 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
3146 * See if we have a printer URI...
3149 if (strcmp(uri
->name
, "printer-uri"))
3151 send_ipp_status(con
, IPP_BAD_REQUEST
,
3152 _("The printer-uri attribute is required."));
3157 * And if the destination is valid...
3160 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3166 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
,
3167 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
3168 hostname
, sizeof(hostname
), &port
,
3169 resource
, sizeof(resource
));
3171 if ((!strncmp(resource
, "/printers/", 10) && resource
[10]) ||
3172 (!strncmp(resource
, "/classes/", 9) && resource
[9]))
3174 send_ipp_status(con
, IPP_NOT_FOUND
,
3175 _("The printer or class does not exist."));
3183 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
3185 send_http_error(con
, status
, NULL
);
3191 for (i
= 0; i
< job_ids
->num_values
; i
++)
3193 if ((job
= cupsdFindJob(job_ids
->values
[i
].integer
)) == NULL
)
3196 if (con
->request
->request
.op
.operation_id
== IPP_CANCEL_MY_JOBS
&&
3197 _cups_strcasecmp(job
->username
, username
))
3201 if (i
< job_ids
->num_values
)
3203 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3204 job_ids
->values
[i
].integer
);
3208 for (i
= 0; i
< job_ids
->num_values
; i
++)
3210 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
3212 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3213 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
3214 "Job canceled by user.");
3217 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
3218 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3224 * Cancel all jobs on all printers...
3227 cupsdCancelJobs(NULL
, username
, purge
);
3229 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs were %s by \"%s\".",
3230 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3240 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
3243 send_http_error(con
, status
, printer
);
3249 for (i
= 0; i
< job_ids
->num_values
; i
++)
3251 if ((job
= cupsdFindJob(job_ids
->values
[i
].integer
)) == NULL
||
3252 _cups_strcasecmp(job
->dest
, printer
->name
))
3255 if (con
->request
->request
.op
.operation_id
== IPP_CANCEL_MY_JOBS
&&
3256 _cups_strcasecmp(job
->username
, username
))
3260 if (i
< job_ids
->num_values
)
3262 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3263 job_ids
->values
[i
].integer
);
3267 for (i
= 0; i
< job_ids
->num_values
; i
++)
3269 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
3271 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3272 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
3273 "Job canceled by user.");
3276 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
3277 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3283 * Cancel all of the jobs on the named printer...
3286 cupsdCancelJobs(printer
->name
, username
, purge
);
3288 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs on \"%s\" were %s by \"%s\".",
3290 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3295 con
->response
->request
.status
.status_code
= IPP_OK
;
3302 * 'cancel_job()' - Cancel a print job.
3306 cancel_job(cupsd_client_t
*con
, /* I - Client connection */
3307 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3309 ipp_attribute_t
*attr
; /* Current attribute */
3310 int jobid
; /* Job ID */
3311 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3312 username
[HTTP_MAX_URI
], /* Username portion of URI */
3313 host
[HTTP_MAX_URI
], /* Host portion of URI */
3314 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3315 int port
; /* Port portion of URI */
3316 cupsd_job_t
*job
; /* Job information */
3317 cups_ptype_t dtype
; /* Destination type (printer/class) */
3318 cupsd_printer_t
*printer
; /* Printer data */
3319 cupsd_jobaction_t purge
; /* Purge the job? */
3322 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_job(%p[%d], %s)", con
,
3323 con
->number
, uri
->values
[0].string
.text
);
3326 * See if we have a job URI or a printer URI...
3329 if (!strcmp(uri
->name
, "printer-uri"))
3332 * Got a printer URI; see if we also have a job-id attribute...
3335 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3336 IPP_TAG_INTEGER
)) == NULL
)
3338 send_ipp_status(con
, IPP_BAD_REQUEST
,
3339 _("Got a printer-uri attribute but no job-id."));
3343 if ((jobid
= attr
->values
[0].integer
) == 0)
3346 * Find the current job on the specified printer...
3349 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3355 send_ipp_status(con
, IPP_NOT_FOUND
,
3356 _("The printer or class does not exist."));
3361 * See if there are any pending jobs...
3364 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3366 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3367 if (job
->state_value
<= IPP_JOB_PROCESSING
&&
3368 !_cups_strcasecmp(job
->dest
, printer
->name
))
3376 * No, try stopped jobs...
3379 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3381 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3382 if (job
->state_value
== IPP_JOB_STOPPED
&&
3383 !_cups_strcasecmp(job
->dest
, printer
->name
))
3390 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("No active jobs on %s."),
3400 * Got a job URI; parse it to get the job ID...
3403 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
3404 sizeof(scheme
), username
, sizeof(username
), host
,
3405 sizeof(host
), &port
, resource
, sizeof(resource
));
3407 if (strncmp(resource
, "/jobs/", 6))
3413 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
3414 uri
->values
[0].string
.text
);
3418 jobid
= atoi(resource
+ 6);
3422 * Look for the "purge-job" attribute...
3425 if ((attr
= ippFindAttribute(con
->request
, "purge-job",
3426 IPP_TAG_BOOLEAN
)) != NULL
)
3427 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
3429 purge
= CUPSD_JOB_DEFAULT
;
3432 * See if the job exists...
3435 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3438 * Nope - return a "not found" error...
3441 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
3446 * See if the job is owned by the requesting user...
3449 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3451 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3452 cupsdFindDest(job
->dest
));
3457 * See if the job is already completed, canceled, or aborted; if so,
3458 * we can't cancel...
3461 if (job
->state_value
>= IPP_JOB_CANCELED
&& purge
!= CUPSD_JOB_PURGE
)
3463 switch (job
->state_value
)
3465 case IPP_JOB_CANCELED
:
3466 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3467 _("Job #%d is already canceled - can\'t cancel."),
3471 case IPP_JOB_ABORTED
:
3472 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3473 _("Job #%d is already aborted - can\'t cancel."),
3478 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3479 _("Job #%d is already completed - can\'t cancel."),
3488 * Cancel the job and return...
3491 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3492 purge
== CUPSD_JOB_PURGE
? "Job purged by \"%s\"" :
3493 "Job canceled by \"%s\"",
3497 if (purge
== CUPSD_JOB_PURGE
)
3498 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Purged by \"%s\".", jobid
,
3501 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Canceled by \"%s\".", jobid
,
3504 con
->response
->request
.status
.status_code
= IPP_OK
;
3509 * 'cancel_subscription()' - Cancel a subscription.
3513 cancel_subscription(
3514 cupsd_client_t
*con
, /* I - Client connection */
3515 int sub_id
) /* I - Subscription ID */
3517 http_status_t status
; /* Policy status */
3518 cupsd_subscription_t
*sub
; /* Subscription */
3521 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3522 "cancel_subscription(con=%p[%d], sub_id=%d)",
3523 con
, con
->number
, sub_id
);
3526 * Is the subscription ID valid?
3529 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
3532 * Bad subscription ID...
3535 send_ipp_status(con
, IPP_NOT_FOUND
,
3536 _("Subscription #%d does not exist."), sub_id
);
3544 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
3546 con
, sub
->owner
)) != HTTP_OK
)
3548 send_http_error(con
, status
, sub
->dest
);
3553 * Cancel the subscription...
3556 cupsdDeleteSubscription(sub
, 1);
3558 con
->response
->request
.status
.status_code
= IPP_OK
;
3563 * 'check_rss_recipient()' - Check that we do not have a duplicate RSS feed URI.
3566 static int /* O - 1 if OK, 0 if not */
3567 check_rss_recipient(
3568 const char *recipient
) /* I - Recipient URI */
3570 cupsd_subscription_t
*sub
; /* Current subscription */
3573 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
);
3575 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
3579 * Compare the URIs up to the first ?...
3582 const char *r1
, *r2
;
3584 for (r1
= recipient
, r2
= sub
->recipient
;
3585 *r1
== *r2
&& *r1
&& *r1
!= '?' && *r2
&& *r2
!= '?';
3597 * 'check_quotas()' - Check quotas for a printer and user.
3600 static int /* O - 1 if OK, 0 if forbidden,
3601 -1 if limit reached */
3602 check_quotas(cupsd_client_t
*con
, /* I - Client connection */
3603 cupsd_printer_t
*p
) /* I - Printer or class */
3605 char username
[33], /* Username */
3606 *name
; /* Current user name */
3607 cupsd_quota_t
*q
; /* Quota data */
3608 #ifdef HAVE_MBR_UID_TO_UUID
3610 * Use Apple membership APIs which require that all names represent
3611 * valid user account or group records accessible by the server.
3614 uuid_t usr_uuid
; /* UUID for job requesting user */
3615 uuid_t usr2_uuid
; /* UUID for ACL user name entry */
3616 uuid_t grp_uuid
; /* UUID for ACL group name entry */
3617 int mbr_err
; /* Error from membership function */
3618 int is_member
; /* Is this user a member? */
3621 * Use standard POSIX APIs for checking users and groups...
3624 struct passwd
*pw
; /* User password data */
3625 #endif /* HAVE_MBR_UID_TO_UUID */
3628 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "check_quotas(%p[%d], %p[%s])",
3629 con
, con
->number
, p
, p
->name
);
3632 * Figure out who is printing...
3635 strlcpy(username
, get_username(con
), sizeof(username
));
3637 if ((name
= strchr(username
, '@')) != NULL
)
3638 *name
= '\0'; /* Strip @REALM */
3641 * Check global active job limits for printers and users...
3644 if (MaxJobsPerPrinter
)
3647 * Check if there are too many pending jobs on this printer...
3650 if (cupsdGetPrinterJobCount(p
->name
) >= MaxJobsPerPrinter
)
3652 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for printer \"%s\"...",
3661 * Check if there are too many pending jobs for this user...
3664 if (cupsdGetUserJobCount(username
) >= MaxJobsPerUser
)
3666 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for user \"%s\"...",
3673 * Check against users...
3676 if (cupsArrayCount(p
->users
) == 0 && p
->k_limit
== 0 && p
->page_limit
== 0)
3679 if (cupsArrayCount(p
->users
))
3681 #ifdef HAVE_MBR_UID_TO_UUID
3683 * Get UUID for job requesting user...
3686 if (mbr_user_name_to_uuid((char *)username
, usr_uuid
))
3692 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3693 "check_quotas: UUID lookup failed for user \"%s\"",
3695 cupsdLogMessage(CUPSD_LOG_INFO
,
3696 "Denying user \"%s\" access to printer \"%s\" "
3697 "(unknown user)...",
3703 * Get UID and GID of requesting user...
3706 pw
= getpwnam(username
);
3708 #endif /* HAVE_MBR_UID_TO_UUID */
3710 for (name
= (char *)cupsArrayFirst(p
->users
);
3712 name
= (char *)cupsArrayNext(p
->users
))
3716 * Check group membership...
3719 #ifdef HAVE_MBR_UID_TO_UUID
3722 if (uuid_parse(name
+ 2, grp_uuid
))
3723 uuid_clear(grp_uuid
);
3725 else if ((mbr_err
= mbr_group_name_to_uuid(name
+ 1, grp_uuid
)) != 0)
3728 * Invalid ACL entries are ignored for matching; just record a
3729 * warning in the log...
3732 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3733 "check_quotas: UUID lookup failed for ACL entry "
3734 "\"%s\" (err=%d)", name
, mbr_err
);
3735 cupsdLogMessage(CUPSD_LOG_WARN
,
3736 "Access control entry \"%s\" not a valid group name; "
3737 "entry ignored", name
);
3740 if ((mbr_err
= mbr_check_membership(usr_uuid
, grp_uuid
,
3744 * At this point, there should be no errors, but check anyways...
3747 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3748 "check_quotas: group \"%s\" membership check "
3749 "failed (err=%d)", name
+ 1, mbr_err
);
3754 * Stop if we found a match...
3761 if (cupsdCheckGroup(username
, pw
, name
+ 1))
3763 #endif /* HAVE_MBR_UID_TO_UUID */
3765 #ifdef HAVE_MBR_UID_TO_UUID
3770 if (uuid_parse(name
+ 1, usr2_uuid
))
3771 uuid_clear(usr2_uuid
);
3773 else if ((mbr_err
= mbr_user_name_to_uuid(name
, usr2_uuid
)) != 0)
3776 * Invalid ACL entries are ignored for matching; just record a
3777 * warning in the log...
3780 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3781 "check_quotas: UUID lookup failed for ACL entry "
3782 "\"%s\" (err=%d)", name
, mbr_err
);
3783 cupsdLogMessage(CUPSD_LOG_WARN
,
3784 "Access control entry \"%s\" not a valid user name; "
3785 "entry ignored", name
);
3788 if (!uuid_compare(usr_uuid
, usr2_uuid
))
3792 else if (!_cups_strcasecmp(username
, name
))
3794 #endif /* HAVE_MBR_UID_TO_UUID */
3796 if ((name
!= NULL
) == p
->deny_users
)
3798 cupsdLogMessage(CUPSD_LOG_INFO
,
3799 "Denying user \"%s\" access to printer \"%s\"...",
3809 if (p
->k_limit
|| p
->page_limit
)
3811 if ((q
= cupsdUpdateQuota(p
, username
, 0, 0)) == NULL
)
3813 cupsdLogMessage(CUPSD_LOG_ERROR
,
3814 "Unable to allocate quota data for user \"%s\"",
3819 if ((q
->k_count
>= p
->k_limit
&& p
->k_limit
) ||
3820 (q
->page_count
>= p
->page_limit
&& p
->page_limit
))
3822 cupsdLogMessage(CUPSD_LOG_INFO
, "User \"%s\" is over the quota limit...",
3829 * If we have gotten this far, we're done!
3837 * 'close_job()' - Close a multi-file job.
3841 close_job(cupsd_client_t
*con
, /* I - Client connection */
3842 ipp_attribute_t
*uri
) /* I - Printer URI */
3844 cupsd_job_t
*job
; /* Job */
3845 ipp_attribute_t
*attr
; /* Attribute */
3846 char job_uri
[HTTP_MAX_URI
],
3848 username
[256]; /* User name */
3851 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "close_job(%p[%d], %s)", con
,
3852 con
->number
, uri
->values
[0].string
.text
);
3855 * See if we have a job URI or a printer URI...
3858 if (strcmp(uri
->name
, "printer-uri"))
3861 * job-uri is not supported by Close-Job!
3864 send_ipp_status(con
, IPP_BAD_REQUEST
,
3865 _("Close-Job doesn't support the job-uri attribute."));
3870 * Got a printer URI; see if we also have a job-id attribute...
3873 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3874 IPP_TAG_INTEGER
)) == NULL
)
3876 send_ipp_status(con
, IPP_BAD_REQUEST
,
3877 _("Got a printer-uri attribute but no job-id."));
3881 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
3884 * Nope - return a "not found" error...
3887 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3888 attr
->values
[0].integer
);
3893 * See if the job is owned by the requesting user...
3896 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3898 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3899 cupsdFindDest(job
->dest
));
3904 * Add any ending sheet...
3907 if (cupsdTimeoutJob(job
))
3910 if (job
->state_value
== IPP_JOB_STOPPED
)
3912 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
3913 job
->state_value
= IPP_JOB_PENDING
;
3915 else if (job
->state_value
== IPP_JOB_HELD
)
3917 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
3918 IPP_TAG_KEYWORD
)) == NULL
)
3919 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
3921 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
3923 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
3924 job
->state_value
= IPP_JOB_PENDING
;
3929 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
3932 * Fill in the response info...
3935 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
3936 con
->clientname
, con
->clientport
, "/jobs/%d", job
->id
);
3937 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
3940 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
3942 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
3945 con
->response
->request
.status
.status_code
= IPP_OK
;
3948 * Start the job if necessary...
3956 * 'copy_attrs()' - Copy attributes from one request to another.
3960 copy_attrs(ipp_t
*to
, /* I - Destination request */
3961 ipp_t
*from
, /* I - Source request */
3962 cups_array_t
*ra
, /* I - Requested attributes */
3963 ipp_tag_t group
, /* I - Group to copy */
3964 int quickcopy
, /* I - Do a quick copy? */
3965 cups_array_t
*exclude
) /* I - Attributes to exclude? */
3967 ipp_attribute_t
*fromattr
; /* Source attribute */
3970 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3971 "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)",
3972 to
, from
, ra
, group
, quickcopy
);
3977 for (fromattr
= from
->attrs
; fromattr
; fromattr
= fromattr
->next
)
3980 * Filter attributes as needed...
3983 if ((group
!= IPP_TAG_ZERO
&& fromattr
->group_tag
!= group
&&
3984 fromattr
->group_tag
!= IPP_TAG_ZERO
) || !fromattr
->name
)
3987 if (!strcmp(fromattr
->name
, "document-password") ||
3988 !strcmp(fromattr
->name
, "job-authorization-uri") ||
3989 !strcmp(fromattr
->name
, "job-password") ||
3990 !strcmp(fromattr
->name
, "job-password-encryption") ||
3991 !strcmp(fromattr
->name
, "job-printer-uri"))
3995 (cupsArrayFind(exclude
, fromattr
->name
) ||
3996 cupsArrayFind(exclude
, "all")))
3999 * We need to exclude this attribute for security reasons; we require the
4000 * job-id attribute regardless of the security settings for IPP
4003 * The job-printer-uri attribute is handled by copy_job_attrs().
4005 * Subscription attribute security is handled by copy_subscription_attrs().
4008 if (strcmp(fromattr
->name
, "job-id"))
4012 if (!ra
|| cupsArrayFind(ra
, fromattr
->name
))
4015 * Don't send collection attributes by default to IPP/1.x clients
4016 * since many do not support collections. Also don't send
4017 * media-col-database unless specifically requested by the client.
4020 if (fromattr
->value_tag
== IPP_TAG_BEGIN_COLLECTION
&&
4022 (to
->request
.status
.version
[0] == 1 ||
4023 !strcmp(fromattr
->name
, "media-col-database")))
4026 ippCopyAttribute(to
, fromattr
, quickcopy
);
4033 * 'copy_banner()' - Copy a banner file to the requests directory for the
4037 static int /* O - Size of banner file in kbytes */
4038 copy_banner(cupsd_client_t
*con
, /* I - Client connection */
4039 cupsd_job_t
*job
, /* I - Job information */
4040 const char *name
) /* I - Name of banner */
4042 int i
; /* Looping var */
4043 int kbytes
; /* Size of banner file in kbytes */
4044 char filename
[1024]; /* Job filename */
4045 cupsd_banner_t
*banner
; /* Pointer to banner */
4046 cups_file_t
*in
; /* Input file */
4047 cups_file_t
*out
; /* Output file */
4048 int ch
; /* Character from file */
4049 char attrname
[255], /* Name of attribute */
4050 *s
; /* Pointer into name */
4051 ipp_attribute_t
*attr
; /* Attribute */
4054 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4055 "copy_banner(con=%p[%d], job=%p[%d], name=\"%s\")",
4056 con
, con
? con
->number
: -1, job
, job
->id
,
4057 name
? name
: "(null)");
4060 * Find the banner; return if not found or "none"...
4063 if (!name
|| !strcmp(name
, "none") ||
4064 (banner
= cupsdFindBanner(name
)) == NULL
)
4068 * Open the banner and job files...
4071 if (add_file(con
, job
, banner
->filetype
, 0))
4074 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
4076 if ((out
= cupsFileOpen(filename
, "w")) == NULL
)
4078 cupsdLogMessage(CUPSD_LOG_ERROR
,
4079 "Unable to create banner job file %s - %s",
4080 filename
, strerror(errno
));
4085 fchmod(cupsFileNumber(out
), 0640);
4086 fchown(cupsFileNumber(out
), RunUser
, Group
);
4089 * Try the localized banner file under the subdirectory...
4092 strlcpy(attrname
, job
->attrs
->attrs
->next
->values
[0].string
.text
,
4094 if (strlen(attrname
) > 2 && attrname
[2] == '-')
4097 * Convert ll-cc to ll_CC...
4101 attrname
[3] = (char)toupper(attrname
[3] & 255);
4102 attrname
[4] = (char)toupper(attrname
[4] & 255);
4105 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4108 if (access(filename
, 0) && strlen(attrname
) > 2)
4111 * Wasn't able to find "ll_CC" locale file; try the non-national
4112 * localization banner directory.
4117 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4121 if (access(filename
, 0))
4124 * Use the non-localized banner file.
4127 snprintf(filename
, sizeof(filename
), "%s/banners/%s", DataDir
, name
);
4130 if ((in
= cupsFileOpen(filename
, "r")) == NULL
)
4134 cupsdLogMessage(CUPSD_LOG_ERROR
,
4135 "Unable to open banner template file %s - %s",
4136 filename
, strerror(errno
));
4142 * Parse the file to the end...
4145 while ((ch
= cupsFileGetChar(in
)) != EOF
)
4149 * Get an attribute name...
4152 for (s
= attrname
; (ch
= cupsFileGetChar(in
)) != EOF
;)
4153 if (!isalpha(ch
& 255) && ch
!= '-' && ch
!= '?')
4155 else if (s
< (attrname
+ sizeof(attrname
) - 1))
4165 * Ignore { followed by stuff that is not an attribute name...
4168 cupsFilePrintf(out
, "{%s%c", attrname
, ch
);
4173 * See if it is defined...
4176 if (attrname
[0] == '?')
4181 if (!strcmp(s
, "printer-name"))
4183 cupsFilePuts(out
, job
->dest
);
4186 else if ((attr
= ippFindAttribute(job
->attrs
, s
, IPP_TAG_ZERO
)) == NULL
)
4189 * See if we have a leading question mark...
4192 if (attrname
[0] != '?')
4195 * Nope, write to file as-is; probably a PostScript procedure...
4198 cupsFilePrintf(out
, "{%s}", attrname
);
4205 * Output value(s)...
4208 for (i
= 0; i
< attr
->num_values
; i
++)
4211 cupsFilePutChar(out
, ',');
4213 switch (attr
->value_tag
)
4215 case IPP_TAG_INTEGER
:
4217 if (!strncmp(s
, "time-at-", 8))
4219 struct timeval tv
; /* Time value */
4221 tv
.tv_sec
= attr
->values
[i
].integer
;
4224 cupsFilePuts(out
, cupsdGetDateTime(&tv
, CUPSD_TIME_STANDARD
));
4227 cupsFilePrintf(out
, "%d", attr
->values
[i
].integer
);
4230 case IPP_TAG_BOOLEAN
:
4231 cupsFilePrintf(out
, "%d", attr
->values
[i
].boolean
);
4234 case IPP_TAG_NOVALUE
:
4235 cupsFilePuts(out
, "novalue");
4238 case IPP_TAG_RANGE
:
4239 cupsFilePrintf(out
, "%d-%d", attr
->values
[i
].range
.lower
,
4240 attr
->values
[i
].range
.upper
);
4243 case IPP_TAG_RESOLUTION
:
4244 cupsFilePrintf(out
, "%dx%d%s", attr
->values
[i
].resolution
.xres
,
4245 attr
->values
[i
].resolution
.yres
,
4246 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
4251 case IPP_TAG_STRING
:
4254 case IPP_TAG_KEYWORD
:
4255 case IPP_TAG_CHARSET
:
4256 case IPP_TAG_LANGUAGE
:
4257 if (!_cups_strcasecmp(banner
->filetype
->type
, "postscript"))
4260 * Need to quote strings for PS banners...
4265 for (p
= attr
->values
[i
].string
.text
; *p
; p
++)
4267 if (*p
== '(' || *p
== ')' || *p
== '\\')
4269 cupsFilePutChar(out
, '\\');
4270 cupsFilePutChar(out
, *p
);
4272 else if (*p
< 32 || *p
> 126)
4273 cupsFilePrintf(out
, "\\%03o", *p
& 255);
4275 cupsFilePutChar(out
, *p
);
4279 cupsFilePuts(out
, attr
->values
[i
].string
.text
);
4283 break; /* anti-compiler-warning-code */
4287 else if (ch
== '\\') /* Quoted char */
4289 ch
= cupsFileGetChar(in
);
4291 if (ch
!= '{') /* Only do special handling for \{ */
4292 cupsFilePutChar(out
, '\\');
4294 cupsFilePutChar(out
, ch
);
4297 cupsFilePutChar(out
, ch
);
4301 kbytes
= (cupsFileTell(out
) + 1023) / 1024;
4303 job
->koctets
+= kbytes
;
4305 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets", IPP_TAG_INTEGER
)) != NULL
)
4306 attr
->values
[0].integer
+= kbytes
;
4315 * 'copy_file()' - Copy a PPD file...
4318 static int /* O - 0 = success, -1 = error */
4319 copy_file(const char *from
, /* I - Source file */
4320 const char *to
, /* I - Destination file */
4321 mode_t mode
) /* I - Permissions */
4323 cups_file_t
*src
, /* Source file */
4324 *dst
; /* Destination file */
4325 int bytes
; /* Bytes to read/write */
4326 char buffer
[2048]; /* Copy buffer */
4329 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_file(\"%s\", \"%s\")", from
, to
);
4332 * Open the source and destination file for a copy...
4335 if ((src
= cupsFileOpen(from
, "rb")) == NULL
)
4338 if ((dst
= cupsdCreateConfFile(to
, mode
)) == NULL
)
4345 * Copy the source file to the destination...
4348 while ((bytes
= cupsFileRead(src
, buffer
, sizeof(buffer
))) > 0)
4349 if (cupsFileWrite(dst
, buffer
, (size_t)bytes
) < bytes
)
4357 * Close both files and return...
4362 return (cupsdCloseCreatedConfFile(dst
, to
));
4367 * 'copy_model()' - Copy a PPD model file, substituting default values
4371 static int /* O - 0 = success, -1 = error */
4372 copy_model(cupsd_client_t
*con
, /* I - Client connection */
4373 const char *from
, /* I - Source file */
4374 const char *to
) /* I - Destination file */
4376 fd_set input
; /* select() input set */
4377 struct timeval timeout
; /* select() timeout */
4378 int maxfd
; /* Max file descriptor for select() */
4379 char tempfile
[1024]; /* Temporary PPD file */
4380 int tempfd
; /* Temporary PPD file descriptor */
4381 int temppid
; /* Process ID of cups-driverd */
4382 int temppipe
[2]; /* Temporary pipes */
4383 char *argv
[4], /* Command-line arguments */
4384 *envp
[MAX_ENV
]; /* Environment */
4385 cups_file_t
*src
, /* Source file */
4386 *dst
; /* Destination file */
4387 ppd_file_t
*ppd
; /* PPD file */
4388 int bytes
, /* Bytes from pipe */
4389 total
; /* Total bytes from pipe */
4390 char buffer
[2048]; /* Copy buffer */
4391 int i
; /* Looping var */
4392 char option
[PPD_MAX_NAME
], /* Option name */
4393 choice
[PPD_MAX_NAME
]; /* Choice name */
4394 ppd_size_t
*size
; /* Default size */
4395 int num_defaults
; /* Number of default options */
4396 cups_option_t
*defaults
; /* Default options */
4397 char cups_protocol
[PPD_MAX_LINE
];
4398 /* cupsProtocol attribute */
4401 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_model(con=%p, from=\"%s\", to=\"%s\")", con
, from
, to
);
4404 * Run cups-driverd to get the PPD file...
4407 argv
[0] = "cups-driverd";
4409 argv
[2] = (char *)from
;
4412 cupsdLoadEnv(envp
, (int)(sizeof(envp
) / sizeof(envp
[0])));
4414 snprintf(buffer
, sizeof(buffer
), "%s/daemon/cups-driverd", ServerBin
);
4415 snprintf(tempfile
, sizeof(tempfile
), "%s/%d.ppd", TempDir
, con
->number
);
4416 tempfd
= open(tempfile
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
4417 if (tempfd
< 0 || cupsdOpenPipe(temppipe
))
4420 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4421 "copy_model: Running \"cups-driverd cat %s\"...", from
);
4423 if (!cupsdStartProcess(buffer
, argv
, envp
, -1, temppipe
[1], CGIPipes
[1],
4424 -1, -1, 0, DefaultProfile
, NULL
, &temppid
))
4435 * Wait up to 30 seconds for the PPD file to be copied...
4440 if (temppipe
[0] > CGIPipes
[0])
4441 maxfd
= temppipe
[0] + 1;
4443 maxfd
= CGIPipes
[0] + 1;
4448 * See if we have data ready...
4452 FD_SET(temppipe
[0], &input
);
4453 FD_SET(CGIPipes
[0], &input
);
4455 timeout
.tv_sec
= 30;
4456 timeout
.tv_usec
= 0;
4458 if ((i
= select(maxfd
, &input
, NULL
, NULL
, &timeout
)) < 0)
4468 * We have timed out...
4474 if (FD_ISSET(temppipe
[0], &input
))
4477 * Read the PPD file from the pipe, and write it to the PPD file.
4480 if ((bytes
= read(temppipe
[0], buffer
, sizeof(buffer
))) > 0)
4482 if (write(tempfd
, buffer
, (size_t)bytes
) < bytes
)
4491 if (FD_ISSET(CGIPipes
[0], &input
))
4501 * No data from cups-deviced...
4504 cupsdLogMessage(CUPSD_LOG_ERROR
, "copy_model: empty PPD file");
4510 * Open the source file for a copy...
4513 if ((src
= cupsFileOpen(tempfile
, "rb")) == NULL
)
4520 * Read the source file and see what page sizes are supported...
4523 if ((ppd
= _ppdOpen(src
, _PPD_LOCALIZATION_NONE
)) == NULL
)
4531 * Open the destination (if possible) and set the default options...
4536 cups_protocol
[0] = '\0';
4538 if ((dst
= cupsFileOpen(to
, "rb")) != NULL
)
4541 * Read all of the default lines from the old PPD...
4544 while (cupsFileGets(dst
, buffer
, sizeof(buffer
)))
4545 if (!strncmp(buffer
, "*Default", 8))
4548 * Add the default option...
4551 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
4552 choice
, sizeof(choice
)))
4554 ppd_option_t
*ppdo
; /* PPD option */
4558 * Only add the default if the default hasn't already been
4559 * set and the choice exists in the new PPD...
4562 if (!cupsGetOption(option
, num_defaults
, defaults
) &&
4563 (ppdo
= ppdFindOption(ppd
, option
)) != NULL
&&
4564 ppdFindChoice(ppdo
, choice
))
4565 num_defaults
= cupsAddOption(option
, choice
, num_defaults
,
4569 else if (!strncmp(buffer
, "*cupsProtocol:", 14))
4570 strlcpy(cups_protocol
, buffer
, sizeof(cups_protocol
));
4574 else if ((size
= ppdPageSize(ppd
, DefaultPaperSize
)) != NULL
)
4577 * Add the default media sizes...
4580 num_defaults
= cupsAddOption("PageSize", size
->name
,
4581 num_defaults
, &defaults
);
4582 num_defaults
= cupsAddOption("PageRegion", size
->name
,
4583 num_defaults
, &defaults
);
4584 num_defaults
= cupsAddOption("PaperDimension", size
->name
,
4585 num_defaults
, &defaults
);
4586 num_defaults
= cupsAddOption("ImageableArea", size
->name
,
4587 num_defaults
, &defaults
);
4593 * Open the destination file for a copy...
4596 if ((dst
= cupsdCreateConfFile(to
, ConfigFilePerm
)) == NULL
)
4598 cupsFreeOptions(num_defaults
, defaults
);
4605 * Copy the source file to the destination...
4608 cupsFileRewind(src
);
4610 while (cupsFileGets(src
, buffer
, sizeof(buffer
)))
4612 if (!strncmp(buffer
, "*Default", 8))
4615 * Check for an previous default option choice...
4618 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
4619 choice
, sizeof(choice
)))
4621 const char *val
; /* Default option value */
4624 if ((val
= cupsGetOption(option
, num_defaults
, defaults
)) != NULL
)
4627 * Substitute the previous choice...
4630 snprintf(buffer
, sizeof(buffer
), "*Default%s: %s", option
, val
);
4635 cupsFilePrintf(dst
, "%s\n", buffer
);
4638 if (cups_protocol
[0])
4639 cupsFilePrintf(dst
, "%s\n", cups_protocol
);
4641 cupsFreeOptions(num_defaults
, defaults
);
4644 * Close both files and return...
4651 return (cupsdCloseCreatedConfFile(dst
, to
));
4656 * 'copy_job_attrs()' - Copy job attributes.
4660 copy_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
4661 cupsd_job_t
*job
, /* I - Job */
4662 cups_array_t
*ra
, /* I - Requested attributes array */
4663 cups_array_t
*exclude
) /* I - Private attributes array */
4665 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
4669 * Send the requested attributes for each job...
4672 if (!cupsArrayFind(exclude
, "all"))
4674 if ((!exclude
|| !cupsArrayFind(exclude
, "number-of-documents")) &&
4675 (!ra
|| cupsArrayFind(ra
, "number-of-documents")))
4676 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4677 "number-of-documents", job
->num_files
);
4679 if ((!exclude
|| !cupsArrayFind(exclude
, "job-media-progress")) &&
4680 (!ra
|| cupsArrayFind(ra
, "job-media-progress")))
4681 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4682 "job-media-progress", job
->progress
);
4684 if ((!exclude
|| !cupsArrayFind(exclude
, "job-more-info")) &&
4685 (!ra
|| cupsArrayFind(ra
, "job-more-info")))
4687 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "http",
4688 NULL
, con
->clientname
, con
->clientport
, "/jobs/%d",
4690 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4691 "job-more-info", NULL
, job_uri
);
4694 if (job
->state_value
> IPP_JOB_PROCESSING
&&
4695 (!exclude
|| !cupsArrayFind(exclude
, "job-preserved")) &&
4696 (!ra
|| cupsArrayFind(ra
, "job-preserved")))
4697 ippAddBoolean(con
->response
, IPP_TAG_JOB
, "job-preserved",
4698 job
->num_files
> 0);
4700 if ((!exclude
|| !cupsArrayFind(exclude
, "job-printer-up-time")) &&
4701 (!ra
|| cupsArrayFind(ra
, "job-printer-up-time")))
4702 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4703 "job-printer-up-time", time(NULL
));
4706 if (!ra
|| cupsArrayFind(ra
, "job-printer-uri"))
4708 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
4709 con
->clientname
, con
->clientport
,
4710 (job
->dtype
& CUPS_PRINTER_CLASS
) ? "/classes/%s" :
4713 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4714 "job-printer-uri", NULL
, job_uri
);
4717 if (!ra
|| cupsArrayFind(ra
, "job-uri"))
4719 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
4720 con
->clientname
, con
->clientport
, "/jobs/%d",
4722 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4723 "job-uri", NULL
, job_uri
);
4728 copy_attrs(con
->response
, job
->attrs
, ra
, IPP_TAG_JOB
, 0, exclude
);
4733 * Generate attributes from the job structure...
4736 if (job
->completed_time
&& (!ra
|| cupsArrayFind(ra
, "date-time-at-completed")))
4737 ippAddDate(con
->response
, IPP_TAG_JOB
, "date-time-at-completed", ippTimeToDate(job
->completed_time
));
4739 if (job
->creation_time
&& (!ra
|| cupsArrayFind(ra
, "date-time-at-creation")))
4740 ippAddDate(con
->response
, IPP_TAG_JOB
, "date-time-at-creation", ippTimeToDate(job
->creation_time
));
4742 if (!ra
|| cupsArrayFind(ra
, "job-id"))
4743 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
4745 if (!ra
|| cupsArrayFind(ra
, "job-k-octets"))
4746 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-k-octets", job
->koctets
);
4748 if (job
->name
&& (!ra
|| cupsArrayFind(ra
, "job-name")))
4749 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_CONST_TAG(IPP_TAG_NAME
), "job-name", NULL
, job
->name
);
4751 if (job
->username
&& (!ra
|| cupsArrayFind(ra
, "job-originating-user-name")))
4752 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_CONST_TAG(IPP_TAG_NAME
), "job-originating-user-name", NULL
, job
->username
);
4754 if (!ra
|| cupsArrayFind(ra
, "job-state"))
4755 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state", (int)job
->state_value
);
4757 if (!ra
|| cupsArrayFind(ra
, "job-state-reasons"))
4759 switch (job
->state_value
)
4761 default : /* Should never get here for processing, pending, held, or stopped jobs since they don't get unloaded... */
4763 case IPP_JSTATE_ABORTED
:
4764 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons", NULL
, "job-aborted-by-system");
4766 case IPP_JSTATE_CANCELED
:
4767 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons", NULL
, "job-canceled-by-user");
4769 case IPP_JSTATE_COMPLETED
:
4770 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons", NULL
, "job-completed-successfully");
4775 if (job
->completed_time
&& (!ra
|| cupsArrayFind(ra
, "time-at-completed")))
4776 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-completed", (int)job
->completed_time
);
4778 if (job
->creation_time
&& (!ra
|| cupsArrayFind(ra
, "time-at-creation")))
4779 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation", (int)job
->creation_time
);
4785 * 'copy_printer_attrs()' - Copy printer attributes.
4790 cupsd_client_t
*con
, /* I - Client connection */
4791 cupsd_printer_t
*printer
, /* I - Printer */
4792 cups_array_t
*ra
) /* I - Requested attributes array */
4794 char printer_uri
[HTTP_MAX_URI
];
4796 char printer_icons
[HTTP_MAX_URI
];
4798 time_t curtime
; /* Current time */
4799 int i
; /* Looping var */
4803 * Copy the printer attributes to the response using requested-attributes
4804 * and document-format attributes that may be provided by the client.
4807 curtime
= time(NULL
);
4809 if (!ra
|| cupsArrayFind(ra
, "marker-change-time"))
4810 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4811 "marker-change-time", printer
->marker_time
);
4813 if (printer
->num_printers
> 0 &&
4814 (!ra
|| cupsArrayFind(ra
, "member-uris")))
4816 ipp_attribute_t
*member_uris
; /* member-uris attribute */
4817 cupsd_printer_t
*p2
; /* Printer in class */
4818 ipp_attribute_t
*p2_uri
; /* printer-uri-supported for class printer */
4821 if ((member_uris
= ippAddStrings(con
->response
, IPP_TAG_PRINTER
,
4822 IPP_TAG_URI
, "member-uris",
4823 printer
->num_printers
, NULL
,
4826 for (i
= 0; i
< printer
->num_printers
; i
++)
4828 p2
= printer
->printers
[i
];
4830 if ((p2_uri
= ippFindAttribute(p2
->attrs
, "printer-uri-supported",
4831 IPP_TAG_URI
)) != NULL
)
4832 member_uris
->values
[i
].string
.text
=
4833 _cupsStrRetain(p2_uri
->values
[0].string
.text
);
4836 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
,
4837 sizeof(printer_uri
), "ipp", NULL
, con
->clientname
,
4839 (p2
->type
& CUPS_PRINTER_CLASS
) ?
4840 "/classes/%s" : "/printers/%s", p2
->name
);
4841 member_uris
->values
[i
].string
.text
= _cupsStrAlloc(printer_uri
);
4847 if (printer
->alert
&& (!ra
|| cupsArrayFind(ra
, "printer-alert")))
4848 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_STRING
,
4849 "printer-alert", NULL
, printer
->alert
);
4851 if (printer
->alert_description
&&
4852 (!ra
|| cupsArrayFind(ra
, "printer-alert-description")))
4853 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4854 "printer-alert-description", NULL
,
4855 printer
->alert_description
);
4857 if (!ra
|| cupsArrayFind(ra
, "printer-config-change-date-time"))
4858 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-config-change-date-time", ippTimeToDate(printer
->config_time
));
4860 if (!ra
|| cupsArrayFind(ra
, "printer-config-change-time"))
4861 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4862 "printer-config-change-time", printer
->config_time
);
4864 if (!ra
|| cupsArrayFind(ra
, "printer-current-time"))
4865 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-current-time",
4866 ippTimeToDate(curtime
));
4868 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
4869 if (!ra
|| cupsArrayFind(ra
, "printer-dns-sd-name"))
4871 if (printer
->reg_name
)
4872 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4873 "printer-dns-sd-name", NULL
, printer
->reg_name
);
4875 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
4876 "printer-dns-sd-name", 0);
4878 #endif /* HAVE_DNSSD || HAVE_AVAHI */
4880 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy"))
4881 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4882 "printer-error-policy", NULL
, printer
->error_policy
);
4884 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy-supported"))
4886 static const char * const errors
[] =/* printer-error-policy-supported values */
4889 "retry-current-job",
4894 if (printer
->type
& CUPS_PRINTER_CLASS
)
4895 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
4896 "printer-error-policy-supported", NULL
, "retry-current-job");
4898 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
4899 "printer-error-policy-supported",
4900 sizeof(errors
) / sizeof(errors
[0]), NULL
, errors
);
4903 if (!ra
|| cupsArrayFind(ra
, "printer-icons"))
4905 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_icons
, sizeof(printer_icons
),
4906 "http", NULL
, con
->clientname
, con
->clientport
,
4907 "/icons/%s.png", printer
->name
);
4908 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-icons",
4909 NULL
, printer_icons
);
4910 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-icons=\"%s\"", printer_icons
);
4913 if (!ra
|| cupsArrayFind(ra
, "printer-is-accepting-jobs"))
4914 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs", (char)printer
->accepting
);
4916 if (!ra
|| cupsArrayFind(ra
, "printer-is-shared"))
4917 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-shared", (char)printer
->shared
);
4919 if (!ra
|| cupsArrayFind(ra
, "printer-is-temporary"))
4920 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-temporary", (char)printer
->temporary
);
4922 if (!ra
|| cupsArrayFind(ra
, "printer-more-info"))
4924 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
4925 "http", NULL
, con
->clientname
, con
->clientport
,
4926 (printer
->type
& CUPS_PRINTER_CLASS
) ?
4927 "/classes/%s" : "/printers/%s", printer
->name
);
4928 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
4929 "printer-more-info", NULL
, printer_uri
);
4932 if (!ra
|| cupsArrayFind(ra
, "printer-op-policy"))
4933 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4934 "printer-op-policy", NULL
, printer
->op_policy
);
4936 if (!ra
|| cupsArrayFind(ra
, "printer-state"))
4937 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
4940 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-date-time"))
4941 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-state-change-date-time", ippTimeToDate(printer
->state_time
));
4943 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-time"))
4944 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4945 "printer-state-change-time", printer
->state_time
);
4947 if (!ra
|| cupsArrayFind(ra
, "printer-state-message"))
4948 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4949 "printer-state-message", NULL
, printer
->state_message
);
4951 if (!ra
|| cupsArrayFind(ra
, "printer-state-reasons"))
4952 add_printer_state_reasons(con
, printer
);
4954 if (!ra
|| cupsArrayFind(ra
, "printer-type"))
4956 cups_ptype_t type
; /* printer-type value */
4959 * Add the CUPS-specific printer-type attribute...
4962 type
= printer
->type
;
4964 if (printer
== DefaultPrinter
)
4965 type
|= CUPS_PRINTER_DEFAULT
;
4967 if (!printer
->accepting
)
4968 type
|= CUPS_PRINTER_REJECTING
;
4970 if (!printer
->shared
)
4971 type
|= CUPS_PRINTER_NOT_SHARED
;
4973 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-type", (int)type
);
4976 if (!ra
|| cupsArrayFind(ra
, "printer-up-time"))
4977 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4978 "printer-up-time", curtime
);
4980 if (!ra
|| cupsArrayFind(ra
, "printer-uri-supported"))
4982 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
4983 "ipp", NULL
, con
->clientname
, con
->clientport
,
4984 (printer
->type
& CUPS_PRINTER_CLASS
) ?
4985 "/classes/%s" : "/printers/%s", printer
->name
);
4986 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
4987 "printer-uri-supported", NULL
, printer_uri
);
4988 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-uri-supported=\"%s\"",
4992 if (!ra
|| cupsArrayFind(ra
, "queued-job-count"))
4993 add_queued_job_count(con
, printer
);
4995 copy_attrs(con
->response
, printer
->attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
4996 if (printer
->ppd_attrs
)
4997 copy_attrs(con
->response
, printer
->ppd_attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
4998 copy_attrs(con
->response
, CommonData
, ra
, IPP_TAG_ZERO
, IPP_TAG_COPY
, NULL
);
5003 * 'copy_subscription_attrs()' - Copy subscription attributes.
5007 copy_subscription_attrs(
5008 cupsd_client_t
*con
, /* I - Client connection */
5009 cupsd_subscription_t
*sub
, /* I - Subscription */
5010 cups_array_t
*ra
, /* I - Requested attributes array */
5011 cups_array_t
*exclude
) /* I - Private attributes array */
5013 ipp_attribute_t
*attr
; /* Current attribute */
5014 char printer_uri
[HTTP_MAX_URI
];
5016 int count
; /* Number of events */
5017 unsigned mask
; /* Current event mask */
5018 const char *name
; /* Current event name */
5021 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5022 "copy_subscription_attrs(con=%p, sub=%p, ra=%p, exclude=%p)",
5023 con
, sub
, ra
, exclude
);
5026 * Copy the subscription attributes to the response using the
5027 * requested-attributes attribute that may be provided by the client.
5030 if (!exclude
|| !cupsArrayFind(exclude
, "all"))
5032 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-events")) &&
5033 (!ra
|| cupsArrayFind(ra
, "notify-events")))
5035 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_subscription_attrs: notify-events");
5037 if ((name
= cupsdEventName((cupsd_eventmask_t
)sub
->mask
)) != NULL
)
5040 * Simple event list...
5043 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
,
5044 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5045 "notify-events", NULL
, name
);
5050 * Complex event list...
5053 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5054 if (sub
->mask
& mask
)
5057 attr
= ippAddStrings(con
->response
, IPP_TAG_SUBSCRIPTION
,
5058 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5059 "notify-events", count
, NULL
, NULL
);
5061 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5062 if (sub
->mask
& mask
)
5064 attr
->values
[count
].string
.text
=
5065 (char *)cupsdEventName((cupsd_eventmask_t
)mask
);
5072 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-lease-duration")) &&
5073 (!sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-lease-duration"))))
5074 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5075 "notify-lease-duration", sub
->lease
);
5077 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-recipient-uri")) &&
5078 (sub
->recipient
&& (!ra
|| cupsArrayFind(ra
, "notify-recipient-uri"))))
5079 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5080 "notify-recipient-uri", NULL
, sub
->recipient
);
5081 else if ((!exclude
|| !cupsArrayFind(exclude
, "notify-pull-method")) &&
5082 (!ra
|| cupsArrayFind(ra
, "notify-pull-method")))
5083 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_KEYWORD
,
5084 "notify-pull-method", NULL
, "ippget");
5086 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-subscriber-user-name")) &&
5087 (!ra
|| cupsArrayFind(ra
, "notify-subscriber-user-name")))
5088 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_NAME
,
5089 "notify-subscriber-user-name", NULL
, sub
->owner
);
5091 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-time-interval")) &&
5092 (!ra
|| cupsArrayFind(ra
, "notify-time-interval")))
5093 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5094 "notify-time-interval", sub
->interval
);
5096 if (sub
->user_data_len
> 0 &&
5097 (!exclude
|| !cupsArrayFind(exclude
, "notify-user-data")) &&
5098 (!ra
|| cupsArrayFind(ra
, "notify-user-data")))
5099 ippAddOctetString(con
->response
, IPP_TAG_SUBSCRIPTION
, "notify-user-data",
5100 sub
->user_data
, sub
->user_data_len
);
5103 if (sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-job-id")))
5104 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5105 "notify-job-id", sub
->job
->id
);
5107 if (sub
->dest
&& (!ra
|| cupsArrayFind(ra
, "notify-printer-uri")))
5109 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5110 "ipp", NULL
, con
->clientname
, con
->clientport
,
5111 "/printers/%s", sub
->dest
->name
);
5112 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5113 "notify-printer-uri", NULL
, printer_uri
);
5116 if (!ra
|| cupsArrayFind(ra
, "notify-subscription-id"))
5117 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5118 "notify-subscription-id", sub
->id
);
5123 * 'create_job()' - Print a file to a printer or class.
5127 create_job(cupsd_client_t
*con
, /* I - Client connection */
5128 ipp_attribute_t
*uri
) /* I - Printer URI */
5130 int i
; /* Looping var */
5131 cupsd_printer_t
*printer
; /* Printer */
5132 cupsd_job_t
*job
; /* New job */
5133 static const char * const forbidden_attrs
[] =
5134 { /* List of forbidden attributes */
5138 "document-natural-language"
5142 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "create_job(%p[%d], %s)", con
,
5143 con
->number
, uri
->values
[0].string
.text
);
5146 * Is the destination valid?
5149 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
5155 send_ipp_status(con
, IPP_NOT_FOUND
,
5156 _("The printer or class does not exist."));
5161 * Check for invalid Create-Job attributes and log a warning or error depending
5162 * on whether cupsd is running in "strict conformance" mode...
5166 i
< (int)(sizeof(forbidden_attrs
) / sizeof(forbidden_attrs
[0]));
5168 if (ippFindAttribute(con
->request
, forbidden_attrs
[i
], IPP_TAG_ZERO
))
5170 if (StrictConformance
)
5172 send_ipp_status(con
, IPP_BAD_REQUEST
,
5173 _("The '%s' operation attribute cannot be supplied in a "
5174 "Create-Job request."), forbidden_attrs
[i
]);
5178 cupsdLogMessage(CUPSD_LOG_WARN
,
5179 "Unexpected '%s' operation attribute in a Create-Job "
5180 "request.", forbidden_attrs
[i
]);
5184 * Create the job object...
5187 if ((job
= add_job(con
, printer
, NULL
)) == NULL
)
5190 job
->pending_timeout
= 1;
5193 * Save and log the job...
5196 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
5197 job
->dest
, job
->username
);
5202 * 'create_local_bg_thread()' - Background thread for creating a local print queue.
5205 static void * /* O - Exit status */
5206 create_local_bg_thread(
5207 cupsd_printer_t
*printer
) /* I - Printer */
5209 cups_file_t
*from
, /* Source file */
5210 *to
; /* Destination file */
5211 char fromppd
[1024], /* Source PPD */
5212 toppd
[1024], /* Destination PPD */
5213 scheme
[32], /* URI scheme */
5214 userpass
[256], /* User:pass */
5215 host
[256], /* Hostname */
5216 resource
[1024], /* Resource path */
5217 line
[1024]; /* Line from PPD */
5218 int port
; /* Port number */
5219 http_encryption_t encryption
; /* Type of encryption to use */
5220 http_t
*http
; /* Connection to printer */
5221 ipp_t
*request
, /* Request to printer */
5222 *response
; /* Response from printer */
5223 ipp_attribute_t
*attr
; /* Attribute in response */
5227 * Try connecting to the printer...
5230 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s: Generating PPD file from \"%s\"...", printer
->name
, printer
->device_uri
);
5232 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
)
5234 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: Bad device URI \"%s\".", printer
->name
, printer
->device_uri
);
5238 if (!strcmp(scheme
, "ipps") || port
== 443)
5239 encryption
= HTTP_ENCRYPTION_ALWAYS
;
5241 encryption
= HTTP_ENCRYPTION_IF_REQUESTED
;
5243 if ((http
= httpConnect2(host
, port
, NULL
, AF_UNSPEC
, encryption
, 1, 30000, NULL
)) == NULL
)
5245 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: Unable to connect to %s:%d: %s", printer
->name
, host
, port
, cupsLastErrorString());
5250 * Query the printer for its capabilities...
5253 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s: Connected to %s:%d, sending Get-Printer-Attributes request...", printer
->name
, host
, port
);
5255 request
= ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES
);
5256 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
, printer
->device_uri
);
5257 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
, "requested-attributes", NULL
, "all");
5259 response
= cupsDoRequest(http
, request
, resource
);
5261 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s: Get-Printer-Attributes returned %s", printer
->name
, ippErrorString(cupsLastError()));
5263 // TODO: Grab printer icon file...
5267 * Write the PPD for the queue...
5270 if (_ppdCreateFromIPP(fromppd
, sizeof(fromppd
), response
))
5272 if ((!printer
->info
|| !*(printer
->info
)) && (attr
= ippFindAttribute(response
, "printer-info", IPP_TAG_TEXT
)) != NULL
)
5273 cupsdSetString(&printer
->info
, ippGetString(attr
, 0, NULL
));
5275 if ((!printer
->location
|| !*(printer
->location
)) && (attr
= ippFindAttribute(response
, "printer-location", IPP_TAG_TEXT
)) != NULL
)
5276 cupsdSetString(&printer
->location
, ippGetString(attr
, 0, NULL
));
5278 if ((!printer
->geo_location
|| !*(printer
->geo_location
)) && (attr
= ippFindAttribute(response
, "printer-geo-location", IPP_TAG_URI
)) != NULL
)
5279 cupsdSetString(&printer
->geo_location
, ippGetString(attr
, 0, NULL
));
5281 if ((from
= cupsFileOpen(fromppd
, "r")) == NULL
)
5283 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: Unable to read generated PPD: %s", printer
->name
, strerror(errno
));
5287 snprintf(toppd
, sizeof(toppd
), "%s/ppd/%s.ppd", ServerRoot
, printer
->name
);
5288 if ((to
= cupsdCreateConfFile(toppd
, ConfigFilePerm
)) == NULL
)
5290 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: Unable to create PPD for printer: %s", printer
->name
, strerror(errno
));
5291 cupsFileClose(from
);
5295 while (cupsFileGets(from
, line
, sizeof(line
)))
5296 cupsFilePrintf(to
, "%s\n", line
);
5298 cupsFileClose(from
);
5299 if (!cupsdCloseCreatedConfFile(to
, toppd
))
5301 printer
->config_time
= time(NULL
);
5302 printer
->state
= IPP_PSTATE_IDLE
;
5303 printer
->accepting
= 1;
5305 cupsdSetPrinterAttrs(printer
);
5307 cupsdAddEvent(CUPSD_EVENT_PRINTER_CONFIG
, printer
, NULL
, "Printer \"%s\" is now available.", printer
->name
);
5308 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" is now available.", printer
->name
);
5312 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: PPD creation failed.", printer
->name
);
5319 * 'create_local_printer()' - Create a local (temporary) print queue.
5323 create_local_printer(
5324 cupsd_client_t
*con
) /* I - Client connection */
5326 ipp_attribute_t
*device_uri
, /* device-uri attribute */
5327 *printer_geo_location
, /* printer-geo-location attribute */
5328 *printer_info
, /* printer-info attribute */
5329 *printer_location
, /* printer-location attribute */
5330 *printer_name
; /* printer-name attribute */
5331 cupsd_printer_t
*printer
; /* New printer */
5332 http_status_t status
; /* Policy status */
5333 char name
[128], /* Sanitized printer name */
5334 *nameptr
, /* Pointer into name */
5335 uri
[1024]; /* printer-uri-supported value */
5336 const char *ptr
; /* Pointer into attribute value */
5340 * Require local access to create a local printer...
5343 if (!httpAddrLocalhost(httpGetAddress(con
->http
)))
5345 send_ipp_status(con
, IPP_STATUS_ERROR_FORBIDDEN
, _("Only local users can create a local printer."));
5350 * Check any other policy limits...
5353 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5355 send_http_error(con
, status
, NULL
);
5360 * Grab needed attributes...
5363 if ((printer_name
= ippFindAttribute(con
->request
, "printer-name", IPP_TAG_ZERO
)) == NULL
|| ippGetGroupTag(printer_name
) != IPP_TAG_PRINTER
|| ippGetValueTag(printer_name
) != IPP_TAG_NAME
)
5366 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Missing required attribute \"%s\"."), "printer-name");
5367 else if (ippGetGroupTag(printer_name
) != IPP_TAG_PRINTER
)
5368 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Attribute \"%s\" is in the wrong group."), "printer-name");
5370 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Attribute \"%s\" is the wrong value type."), "printer-name");
5375 for (nameptr
= name
, ptr
= ippGetString(printer_name
, 0, NULL
); *ptr
&& nameptr
< (name
+ sizeof(name
) - 1); ptr
++)
5378 * Sanitize the printer name...
5381 if (_cups_isalnum(*ptr
))
5383 else if (nameptr
== name
|| nameptr
[-1] != '_')
5389 if ((device_uri
= ippFindAttribute(con
->request
, "device-uri", IPP_TAG_ZERO
)) == NULL
|| ippGetGroupTag(device_uri
) != IPP_TAG_PRINTER
|| ippGetValueTag(device_uri
) != IPP_TAG_URI
)
5392 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Missing required attribute \"%s\"."), "device-uri");
5393 else if (ippGetGroupTag(device_uri
) != IPP_TAG_PRINTER
)
5394 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Attribute \"%s\" is in the wrong group."), "device-uri");
5396 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Attribute \"%s\" is the wrong value type."), "device-uri");
5401 printer_geo_location
= ippFindAttribute(con
->request
, "printer-geo-location", IPP_TAG_URI
);
5402 printer_info
= ippFindAttribute(con
->request
, "printer-info", IPP_TAG_TEXT
);
5403 printer_location
= ippFindAttribute(con
->request
, "printer-location", IPP_TAG_TEXT
);
5406 * See if the printer already exists...
5409 if ((printer
= cupsdFindDest(name
)) != NULL
)
5411 send_ipp_status(con
, IPP_STATUS_ERROR_NOT_POSSIBLE
, _("Printer \"%s\" already exists."), name
);
5412 goto add_printer_attributes
;
5416 * Create the printer...
5419 if ((printer
= cupsdAddPrinter(name
)) == NULL
)
5421 send_ipp_status(con
, IPP_STATUS_ERROR_INTERNAL
, _("Unable to create printer."));
5425 cupsdSetDeviceURI(printer
, ippGetString(device_uri
, 0, NULL
));
5427 if (printer_geo_location
)
5428 cupsdSetString(&printer
->geo_location
, ippGetString(printer_geo_location
, 0, NULL
));
5430 cupsdSetString(&printer
->info
, ippGetString(printer_info
, 0, NULL
));
5431 if (printer_location
)
5432 cupsdSetString(&printer
->location
, ippGetString(printer_location
, 0, NULL
));
5434 cupsdSetPrinterAttrs(printer
);
5437 * Run a background thread to create the PPD...
5440 _cupsThreadCreate((_cups_thread_func_t
)create_local_bg_thread
, printer
);
5443 * Return printer attributes...
5446 send_ipp_status(con
, IPP_STATUS_OK
, _("Local printer created."));
5448 add_printer_attributes
:
5450 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs", (char)printer
->accepting
);
5451 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state", printer
->state
);
5452 add_printer_state_reasons(con
, printer
);
5454 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), httpIsEncrypted(con
->http
) ? "ipps" : "ipp", NULL
, con
->clientname
, con
->clientport
, "/printers/%s", printer
->name
);
5455 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-uri-supported", NULL
, uri
);
5460 * 'create_requested_array()' - Create an array for the requested-attributes.
5463 static cups_array_t
* /* O - Array of attributes or NULL */
5464 create_requested_array(ipp_t
*request
) /* I - IPP request */
5466 cups_array_t
*ra
; /* Requested attributes array */
5470 * Create the array for standard attributes...
5473 ra
= ippCreateRequestedArray(request
);
5476 * Add CUPS defaults as needed...
5479 if (cupsArrayFind(ra
, "printer-defaults"))
5482 * Include user-set defaults...
5485 char *name
; /* Option name */
5487 cupsArrayRemove(ra
, "printer-defaults");
5489 for (name
= (char *)cupsArrayFirst(CommonDefaults
);
5491 name
= (char *)cupsArrayNext(CommonDefaults
))
5492 if (!cupsArrayFind(ra
, name
))
5493 cupsArrayAdd(ra
, name
);
5501 * 'create_subscriptions()' - Create one or more notification subscriptions.
5505 create_subscriptions(
5506 cupsd_client_t
*con
, /* I - Client connection */
5507 ipp_attribute_t
*uri
) /* I - Printer URI */
5509 http_status_t status
; /* Policy status */
5510 int i
; /* Looping var */
5511 ipp_attribute_t
*attr
; /* Current attribute */
5512 cups_ptype_t dtype
; /* Destination type (printer/class) */
5513 char scheme
[HTTP_MAX_URI
],
5514 /* Scheme portion of URI */
5515 userpass
[HTTP_MAX_URI
],
5516 /* Username portion of URI */
5518 /* Host portion of URI */
5519 resource
[HTTP_MAX_URI
];
5520 /* Resource portion of URI */
5521 int port
; /* Port portion of URI */
5522 cupsd_printer_t
*printer
; /* Printer/class */
5523 cupsd_job_t
*job
; /* Job */
5524 int jobid
; /* Job ID */
5525 cupsd_subscription_t
*sub
; /* Subscription object */
5526 const char *username
, /* requesting-user-name or
5527 authenticated username */
5528 *recipient
, /* notify-recipient-uri */
5529 *pullmethod
; /* notify-pull-method */
5530 ipp_attribute_t
*user_data
; /* notify-user-data */
5531 int interval
, /* notify-time-interval */
5532 lease
; /* notify-lease-duration */
5533 unsigned mask
; /* notify-events */
5534 ipp_attribute_t
*notify_events
,/* notify-events(-default) */
5535 *notify_lease
; /* notify-lease-duration(-default) */
5539 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
5541 if (attr
->group_tag
!= IPP_TAG_ZERO
)
5542 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "g%04x v%04x %s", attr
->group_tag
,
5543 attr
->value_tag
, attr
->name
);
5545 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "----SEP----");
5550 * Is the destination valid?
5553 cupsdLogMessage(CUPSD_LOG_DEBUG
, "create_subscriptions(con=%p(%d), uri=\"%s\")", con
, con
->number
, uri
->values
[0].string
.text
);
5555 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
5556 sizeof(scheme
), userpass
, sizeof(userpass
), host
,
5557 sizeof(host
), &port
, resource
, sizeof(resource
));
5559 if (!strcmp(resource
, "/"))
5561 dtype
= (cups_ptype_t
)0;
5564 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
5566 dtype
= (cups_ptype_t
)0;
5569 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
5571 dtype
= CUPS_PRINTER_CLASS
;
5574 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
5580 send_ipp_status(con
, IPP_NOT_FOUND
,
5581 _("The printer or class does not exist."));
5591 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
5594 send_http_error(con
, status
, printer
);
5598 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5600 send_http_error(con
, status
, NULL
);
5605 * Get the user that is requesting the subscription...
5608 username
= get_username(con
);
5611 * Find the first subscription group attribute; return if we have
5615 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
5616 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
5621 send_ipp_status(con
, IPP_BAD_REQUEST
,
5622 _("No subscription attributes in request."));
5627 * Process the subscription attributes in the request...
5630 con
->response
->request
.status
.status_code
= IPP_BAD_REQUEST
;
5638 lease
= DefaultLeaseDuration
;
5640 mask
= CUPSD_EVENT_NONE
;
5644 notify_events
= ippFindAttribute(printer
->attrs
, "notify-events-default",
5646 notify_lease
= ippFindAttribute(printer
->attrs
,
5647 "notify-lease-duration-default",
5651 lease
= notify_lease
->values
[0].integer
;
5655 notify_events
= NULL
;
5656 notify_lease
= NULL
;
5659 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
5661 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
5662 attr
->value_tag
== IPP_TAG_URI
)
5665 * Validate the recipient scheme against the ServerBin/notifier
5669 char notifier
[1024]; /* Notifier filename */
5672 recipient
= attr
->values
[0].string
.text
;
5674 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
5675 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
5676 host
, sizeof(host
), &port
,
5677 resource
, sizeof(resource
)) < HTTP_URI_OK
)
5679 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5680 _("Bad notify-recipient-uri \"%s\"."), recipient
);
5681 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5682 "notify-status-code", IPP_URI_SCHEME
);
5686 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
5688 if (access(notifier
, X_OK
))
5690 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5691 _("notify-recipient-uri URI \"%s\" uses unknown "
5692 "scheme."), recipient
);
5693 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5694 "notify-status-code", IPP_URI_SCHEME
);
5698 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
5700 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5701 _("notify-recipient-uri URI \"%s\" is already used."),
5703 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5704 "notify-status-code", IPP_ATTRIBUTES
);
5708 else if (!strcmp(attr
->name
, "notify-pull-method") &&
5709 attr
->value_tag
== IPP_TAG_KEYWORD
)
5711 pullmethod
= attr
->values
[0].string
.text
;
5713 if (strcmp(pullmethod
, "ippget"))
5715 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5716 _("Bad notify-pull-method \"%s\"."), pullmethod
);
5717 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5718 "notify-status-code", IPP_ATTRIBUTES
);
5722 else if (!strcmp(attr
->name
, "notify-charset") &&
5723 attr
->value_tag
== IPP_TAG_CHARSET
&&
5724 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
5725 strcmp(attr
->values
[0].string
.text
, "utf-8"))
5727 send_ipp_status(con
, IPP_CHARSET
,
5728 _("Character set \"%s\" not supported."),
5729 attr
->values
[0].string
.text
);
5732 else if (!strcmp(attr
->name
, "notify-natural-language") &&
5733 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
5734 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
5736 send_ipp_status(con
, IPP_CHARSET
,
5737 _("Language \"%s\" not supported."),
5738 attr
->values
[0].string
.text
);
5741 else if (!strcmp(attr
->name
, "notify-user-data") &&
5742 attr
->value_tag
== IPP_TAG_STRING
)
5744 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
5746 send_ipp_status(con
, IPP_REQUEST_VALUE
,
5747 _("The notify-user-data value is too large "
5748 "(%d > 63 octets)."),
5749 attr
->values
[0].unknown
.length
);
5755 else if (!strcmp(attr
->name
, "notify-events") &&
5756 attr
->value_tag
== IPP_TAG_KEYWORD
)
5757 notify_events
= attr
;
5758 else if (!strcmp(attr
->name
, "notify-lease-duration") &&
5759 attr
->value_tag
== IPP_TAG_INTEGER
)
5760 lease
= attr
->values
[0].integer
;
5761 else if (!strcmp(attr
->name
, "notify-time-interval") &&
5762 attr
->value_tag
== IPP_TAG_INTEGER
)
5763 interval
= attr
->values
[0].integer
;
5764 else if (!strcmp(attr
->name
, "notify-job-id") &&
5765 attr
->value_tag
== IPP_TAG_INTEGER
)
5766 jobid
= attr
->values
[0].integer
;
5773 for (i
= 0; i
< notify_events
->num_values
; i
++)
5774 mask
|= cupsdEventValue(notify_events
->values
[i
].string
.text
);
5778 cupsdLogMessage(CUPSD_LOG_DEBUG
, "recipient=\"%s\"", recipient
);
5780 cupsdLogMessage(CUPSD_LOG_DEBUG
, "pullmethod=\"%s\"", pullmethod
);
5781 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-lease-duration=%d", lease
);
5782 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-time-interval=%d", interval
);
5784 if (!recipient
&& !pullmethod
)
5787 if (mask
== CUPSD_EVENT_NONE
)
5790 mask
= CUPSD_EVENT_JOB_COMPLETED
;
5792 mask
= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
5795 send_ipp_status(con
, IPP_BAD_REQUEST
,
5796 _("notify-events not specified."));
5801 if (MaxLeaseDuration
&& (lease
== 0 || lease
> MaxLeaseDuration
))
5803 cupsdLogMessage(CUPSD_LOG_INFO
,
5804 "create_subscriptions: Limiting notify-lease-duration to "
5807 lease
= MaxLeaseDuration
;
5812 if ((job
= cupsdFindJob(jobid
)) == NULL
)
5814 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
5822 if ((sub
= cupsdAddSubscription(mask
, printer
, job
, recipient
, 0)) == NULL
)
5824 send_ipp_status(con
, IPP_TOO_MANY_SUBSCRIPTIONS
,
5825 _("There are too many subscriptions."));
5830 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription #%d for job %d.",
5833 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5834 "Added subscription #%d for printer \"%s\".",
5835 sub
->id
, printer
->name
);
5837 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription #%d for server.",
5840 sub
->interval
= interval
;
5842 sub
->expire
= lease
? time(NULL
) + lease
: 0;
5844 cupsdSetString(&sub
->owner
, username
);
5848 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
5849 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
5850 (size_t)sub
->user_data_len
);
5853 ippAddSeparator(con
->response
);
5854 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5855 "notify-subscription-id", sub
->id
);
5857 con
->response
->request
.status
.status_code
= IPP_OK
;
5863 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
5868 * 'delete_printer()' - Remove a printer or class from the system.
5872 delete_printer(cupsd_client_t
*con
, /* I - Client connection */
5873 ipp_attribute_t
*uri
) /* I - URI of printer or class */
5875 http_status_t status
; /* Policy status */
5876 cups_ptype_t dtype
; /* Destination type (printer/class) */
5877 cupsd_printer_t
*printer
; /* Printer/class */
5878 char filename
[1024]; /* Script/PPD filename */
5879 int temporary
; /* Temporary queue? */
5882 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "delete_printer(%p[%d], %s)", con
,
5883 con
->number
, uri
->values
[0].string
.text
);
5886 * Do we have a valid URI?
5889 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
5895 send_ipp_status(con
, IPP_NOT_FOUND
,
5896 _("The printer or class does not exist."));
5904 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5906 send_http_error(con
, status
, NULL
);
5911 * Remove old jobs...
5914 cupsdCancelJobs(printer
->name
, NULL
, 1);
5917 * Remove old subscriptions and send a "deleted printer" event...
5920 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED
, printer
, NULL
,
5921 "%s \"%s\" deleted by \"%s\".",
5922 (dtype
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
5923 printer
->name
, get_username(con
));
5925 cupsdExpireSubscriptions(printer
, NULL
);
5928 * Remove any old PPD or script files...
5931 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
5934 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd.O", ServerRoot
,
5938 snprintf(filename
, sizeof(filename
), "%s/%s.png", CacheDir
, printer
->name
);
5941 snprintf(filename
, sizeof(filename
), "%s/%s.data", CacheDir
, printer
->name
);
5945 * Unregister color profiles...
5948 cupsdUnregisterColor(printer
);
5950 temporary
= printer
->temporary
;
5952 if (dtype
& CUPS_PRINTER_CLASS
)
5954 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" deleted by \"%s\".",
5955 printer
->name
, get_username(con
));
5957 cupsdDeletePrinter(printer
, 0);
5959 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
5963 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" deleted by \"%s\".",
5964 printer
->name
, get_username(con
));
5966 if (cupsdDeletePrinter(printer
, 0) && !temporary
)
5967 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
5970 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
5974 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
5977 * Return with no errors...
5980 con
->response
->request
.status
.status_code
= IPP_OK
;
5985 * 'get_default()' - Get the default destination.
5989 get_default(cupsd_client_t
*con
) /* I - Client connection */
5991 http_status_t status
; /* Policy status */
5992 cups_array_t
*ra
; /* Requested attributes array */
5995 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_default(%p[%d])", con
, con
->number
);
6001 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6003 send_http_error(con
, status
, NULL
);
6009 ra
= create_requested_array(con
->request
);
6011 copy_printer_attrs(con
, DefaultPrinter
, ra
);
6013 cupsArrayDelete(ra
);
6015 con
->response
->request
.status
.status_code
= IPP_OK
;
6018 send_ipp_status(con
, IPP_NOT_FOUND
, _("No default printer."));
6023 * 'get_devices()' - Get the list of available devices on the local system.
6027 get_devices(cupsd_client_t
*con
) /* I - Client connection */
6029 http_status_t status
; /* Policy status */
6030 ipp_attribute_t
*limit
, /* limit attribute */
6031 *timeout
, /* timeout attribute */
6032 *requested
, /* requested-attributes attribute */
6033 *exclude
, /* exclude-schemes attribute */
6034 *include
; /* include-schemes attribute */
6035 char command
[1024], /* cups-deviced command */
6036 options
[2048], /* Options to pass to command */
6038 /* String for requested attributes */
6040 /* String for excluded schemes */
6042 /* String for included schemes */
6045 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_devices(%p[%d])", con
, con
->number
);
6051 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6053 send_http_error(con
, status
, NULL
);
6058 * Run cups-deviced command with the given options...
6061 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
6062 timeout
= ippFindAttribute(con
->request
, "timeout", IPP_TAG_INTEGER
);
6063 requested
= ippFindAttribute(con
->request
, "requested-attributes",
6065 exclude
= ippFindAttribute(con
->request
, "exclude-schemes", IPP_TAG_NAME
);
6066 include
= ippFindAttribute(con
->request
, "include-schemes", IPP_TAG_NAME
);
6069 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
6071 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
6074 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
6076 exclude_str
[0] = '\0';
6079 url_encode_attr(include
, include_str
, sizeof(include_str
));
6081 include_str
[0] = '\0';
6083 snprintf(command
, sizeof(command
), "%s/daemon/cups-deviced", ServerBin
);
6084 snprintf(options
, sizeof(options
),
6085 "%d+%d+%d+%d+%s%s%s%s%s",
6086 con
->request
->request
.op
.request_id
,
6087 limit
? limit
->values
[0].integer
: 0,
6088 timeout
? timeout
->values
[0].integer
: 15,
6091 exclude_str
[0] ? "%20" : "", exclude_str
,
6092 include_str
[0] ? "%20" : "", include_str
);
6094 if (cupsdSendCommand(con
, command
, options
, 1))
6097 * Command started successfully, don't send an IPP response here...
6100 ippDelete(con
->response
);
6101 con
->response
= NULL
;
6106 * Command failed, return "internal error" so the user knows something
6110 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
6111 _("cups-deviced failed to execute."));
6117 * 'get_document()' - Get a copy of a job file.
6121 get_document(cupsd_client_t
*con
, /* I - Client connection */
6122 ipp_attribute_t
*uri
) /* I - Job URI */
6124 http_status_t status
; /* Policy status */
6125 ipp_attribute_t
*attr
; /* Current attribute */
6126 int jobid
; /* Job ID */
6127 int docnum
; /* Document number */
6128 cupsd_job_t
*job
; /* Current job */
6129 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
6130 username
[HTTP_MAX_URI
], /* Username portion of URI */
6131 host
[HTTP_MAX_URI
], /* Host portion of URI */
6132 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6133 int port
; /* Port portion of URI */
6134 char filename
[1024], /* Filename for document */
6135 format
[1024]; /* Format for document */
6138 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_document(%p[%d], %s)", con
,
6139 con
->number
, uri
->values
[0].string
.text
);
6142 * See if we have a job URI or a printer URI...
6145 if (!strcmp(uri
->name
, "printer-uri"))
6148 * Got a printer URI; see if we also have a job-id attribute...
6151 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6152 IPP_TAG_INTEGER
)) == NULL
)
6154 send_ipp_status(con
, IPP_BAD_REQUEST
,
6155 _("Got a printer-uri attribute but no job-id."));
6159 jobid
= attr
->values
[0].integer
;
6164 * Got a job URI; parse it to get the job ID...
6167 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6168 sizeof(scheme
), username
, sizeof(username
), host
,
6169 sizeof(host
), &port
, resource
, sizeof(resource
));
6171 if (strncmp(resource
, "/jobs/", 6))
6177 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
6178 uri
->values
[0].string
.text
);
6182 jobid
= atoi(resource
+ 6);
6186 * See if the job exists...
6189 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6192 * Nope - return a "not found" error...
6195 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
6203 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
,
6204 job
->username
)) != HTTP_OK
)
6206 send_http_error(con
, status
, NULL
);
6211 * Get the document number...
6214 if ((attr
= ippFindAttribute(con
->request
, "document-number",
6215 IPP_TAG_INTEGER
)) == NULL
)
6217 send_ipp_status(con
, IPP_BAD_REQUEST
,
6218 _("Missing document-number attribute."));
6222 if ((docnum
= attr
->values
[0].integer
) < 1 || docnum
> job
->num_files
||
6223 attr
->num_values
> 1)
6225 send_ipp_status(con
, IPP_NOT_FOUND
,
6226 _("Document #%d does not exist in job #%d."), docnum
,
6231 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, jobid
,
6233 if ((con
->file
= open(filename
, O_RDONLY
)) == -1)
6235 cupsdLogMessage(CUPSD_LOG_ERROR
,
6236 "Unable to open document %d in job %d - %s", docnum
, jobid
,
6238 send_ipp_status(con
, IPP_NOT_FOUND
,
6239 _("Unable to open document #%d in job #%d."), docnum
,
6244 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
6248 snprintf(format
, sizeof(format
), "%s/%s", job
->filetypes
[docnum
- 1]->super
,
6249 job
->filetypes
[docnum
- 1]->type
);
6251 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format",
6253 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "document-number",
6255 if ((attr
= ippFindAttribute(job
->attrs
, "document-name",
6256 IPP_TAG_NAME
)) != NULL
)
6257 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name",
6258 NULL
, attr
->values
[0].string
.text
);
6263 * 'get_job_attrs()' - Get job attributes.
6267 get_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
6268 ipp_attribute_t
*uri
) /* I - Job URI */
6270 http_status_t status
; /* Policy status */
6271 ipp_attribute_t
*attr
; /* Current attribute */
6272 int jobid
; /* Job ID */
6273 cupsd_job_t
*job
; /* Current job */
6274 cupsd_printer_t
*printer
; /* Current printer */
6275 cupsd_policy_t
*policy
; /* Current security policy */
6276 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6277 username
[HTTP_MAX_URI
], /* Username portion of URI */
6278 host
[HTTP_MAX_URI
], /* Host portion of URI */
6279 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6280 int port
; /* Port portion of URI */
6281 cups_array_t
*ra
, /* Requested attributes array */
6282 *exclude
; /* Private attributes array */
6285 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_job_attrs(%p[%d], %s)", con
,
6286 con
->number
, uri
->values
[0].string
.text
);
6289 * See if we have a job URI or a printer URI...
6292 if (!strcmp(uri
->name
, "printer-uri"))
6295 * Got a printer URI; see if we also have a job-id attribute...
6298 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6299 IPP_TAG_INTEGER
)) == NULL
)
6301 send_ipp_status(con
, IPP_BAD_REQUEST
,
6302 _("Got a printer-uri attribute but no job-id."));
6306 jobid
= attr
->values
[0].integer
;
6311 * Got a job URI; parse it to get the job ID...
6314 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6315 sizeof(scheme
), username
, sizeof(username
), host
,
6316 sizeof(host
), &port
, resource
, sizeof(resource
));
6318 if (strncmp(resource
, "/jobs/", 6))
6324 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
6325 uri
->values
[0].string
.text
);
6329 jobid
= atoi(resource
+ 6);
6333 * See if the job exists...
6336 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6339 * Nope - return a "not found" error...
6342 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
6350 if ((printer
= job
->printer
) == NULL
)
6351 printer
= cupsdFindDest(job
->dest
);
6354 policy
= printer
->op_policy_ptr
;
6356 policy
= DefaultPolicyPtr
;
6358 if ((status
= cupsdCheckPolicy(policy
, con
, job
->username
)) != HTTP_OK
)
6360 send_http_error(con
, status
, NULL
);
6364 exclude
= cupsdGetPrivateAttrs(policy
, con
, printer
, job
->username
);
6367 * Copy attributes...
6372 ra
= create_requested_array(con
->request
);
6373 copy_job_attrs(con
, job
, ra
, exclude
);
6374 cupsArrayDelete(ra
);
6376 con
->response
->request
.status
.status_code
= IPP_OK
;
6381 * 'get_jobs()' - Get a list of jobs for the specified printer.
6385 get_jobs(cupsd_client_t
*con
, /* I - Client connection */
6386 ipp_attribute_t
*uri
) /* I - Printer URI */
6388 http_status_t status
; /* Policy status */
6389 ipp_attribute_t
*attr
; /* Current attribute */
6390 const char *dest
; /* Destination */
6391 cups_ptype_t dtype
; /* Destination type (printer/class) */
6392 cups_ptype_t dmask
; /* Destination type mask */
6393 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6394 username
[HTTP_MAX_URI
], /* Username portion of URI */
6395 host
[HTTP_MAX_URI
], /* Host portion of URI */
6396 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6397 int port
; /* Port portion of URI */
6398 int job_comparison
; /* Job comparison */
6399 ipp_jstate_t job_state
; /* job-state value */
6400 int first_job_id
= 1, /* First job ID */
6401 first_index
= 1, /* First index */
6402 current_index
= 0; /* Current index */
6403 int limit
= 0; /* Maximum number of jobs to return */
6404 int count
; /* Number of jobs that match */
6405 int need_load_job
= 0; /* Do we need to load the job? */
6406 const char *job_attr
; /* Job attribute requested */
6407 ipp_attribute_t
*job_ids
; /* job-ids attribute */
6408 cupsd_job_t
*job
; /* Current job pointer */
6409 cupsd_printer_t
*printer
; /* Printer */
6410 cups_array_t
*list
; /* Which job list... */
6411 int delete_list
= 0; /* Delete the list afterwards? */
6412 cups_array_t
*ra
, /* Requested attributes array */
6413 *exclude
; /* Private attributes array */
6414 cupsd_policy_t
*policy
; /* Current policy */
6417 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs(%p[%d], %s)", con
, con
->number
,
6418 uri
->values
[0].string
.text
);
6421 * Is the destination valid?
6424 if (strcmp(uri
->name
, "printer-uri"))
6426 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No printer-uri in request."));
6430 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6431 sizeof(scheme
), username
, sizeof(username
), host
,
6432 sizeof(host
), &port
, resource
, sizeof(resource
));
6434 if (!strcmp(resource
, "/") || !strcmp(resource
, "/jobs"))
6437 dtype
= (cups_ptype_t
)0;
6438 dmask
= (cups_ptype_t
)0;
6441 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6444 dtype
= (cups_ptype_t
)0;
6445 dmask
= CUPS_PRINTER_CLASS
;
6448 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6451 dtype
= CUPS_PRINTER_CLASS
;
6452 dmask
= CUPS_PRINTER_CLASS
;
6455 else if ((dest
= cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
,
6462 send_ipp_status(con
, IPP_NOT_FOUND
,
6463 _("The printer or class does not exist."));
6468 dtype
&= CUPS_PRINTER_CLASS
;
6469 dmask
= CUPS_PRINTER_CLASS
;
6477 policy
= printer
->op_policy_ptr
;
6479 policy
= DefaultPolicyPtr
;
6481 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
6483 send_http_error(con
, status
, NULL
);
6487 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
6490 * See if the "which-jobs" attribute have been specified...
6493 if ((attr
= ippFindAttribute(con
->request
, "which-jobs",
6494 IPP_TAG_KEYWORD
)) != NULL
&& job_ids
)
6496 send_ipp_status(con
, IPP_CONFLICT
,
6497 _("The %s attribute cannot be provided with job-ids."),
6501 else if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "not-completed"))
6503 job_comparison
= -1;
6504 job_state
= IPP_JOB_STOPPED
;
6507 else if (!strcmp(attr
->values
[0].string
.text
, "completed"))
6510 job_state
= IPP_JOB_CANCELED
;
6511 list
= cupsdGetCompletedJobs(printer
);
6514 else if (!strcmp(attr
->values
[0].string
.text
, "aborted"))
6517 job_state
= IPP_JOB_ABORTED
;
6518 list
= cupsdGetCompletedJobs(printer
);
6521 else if (!strcmp(attr
->values
[0].string
.text
, "all"))
6524 job_state
= IPP_JOB_PENDING
;
6527 else if (!strcmp(attr
->values
[0].string
.text
, "canceled"))
6530 job_state
= IPP_JOB_CANCELED
;
6531 list
= cupsdGetCompletedJobs(printer
);
6534 else if (!strcmp(attr
->values
[0].string
.text
, "pending"))
6537 job_state
= IPP_JOB_PENDING
;
6540 else if (!strcmp(attr
->values
[0].string
.text
, "pending-held"))
6543 job_state
= IPP_JOB_HELD
;
6546 else if (!strcmp(attr
->values
[0].string
.text
, "processing"))
6549 job_state
= IPP_JOB_PROCESSING
;
6550 list
= PrintingJobs
;
6552 else if (!strcmp(attr
->values
[0].string
.text
, "processing-stopped"))
6555 job_state
= IPP_JOB_STOPPED
;
6560 send_ipp_status(con
, IPP_ATTRIBUTES
,
6561 _("The which-jobs value \"%s\" is not supported."),
6562 attr
->values
[0].string
.text
);
6563 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
6564 "which-jobs", NULL
, attr
->values
[0].string
.text
);
6569 * See if they want to limit the number of jobs reported...
6572 if ((attr
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
)) != NULL
)
6576 send_ipp_status(con
, IPP_CONFLICT
,
6577 _("The %s attribute cannot be provided with job-ids."),
6582 limit
= attr
->values
[0].integer
;
6585 if ((attr
= ippFindAttribute(con
->request
, "first-index", IPP_TAG_INTEGER
)) != NULL
)
6589 send_ipp_status(con
, IPP_CONFLICT
,
6590 _("The %s attribute cannot be provided with job-ids."),
6595 first_index
= attr
->values
[0].integer
;
6597 else if ((attr
= ippFindAttribute(con
->request
, "first-job-id", IPP_TAG_INTEGER
)) != NULL
)
6601 send_ipp_status(con
, IPP_CONFLICT
,
6602 _("The %s attribute cannot be provided with job-ids."),
6607 first_job_id
= attr
->values
[0].integer
;
6611 * See if we only want to see jobs for a specific user...
6614 if ((attr
= ippFindAttribute(con
->request
, "my-jobs", IPP_TAG_BOOLEAN
)) != NULL
&& job_ids
)
6616 send_ipp_status(con
, IPP_CONFLICT
,
6617 _("The %s attribute cannot be provided with job-ids."),
6621 else if (attr
&& attr
->values
[0].boolean
)
6622 strlcpy(username
, get_username(con
), sizeof(username
));
6626 ra
= create_requested_array(con
->request
);
6627 for (job_attr
= (char *)cupsArrayFirst(ra
); job_attr
; job_attr
= (char *)cupsArrayNext(ra
))
6628 if (strcmp(job_attr
, "job-id") &&
6629 strcmp(job_attr
, "job-k-octets") &&
6630 strcmp(job_attr
, "job-media-progress") &&
6631 strcmp(job_attr
, "job-more-info") &&
6632 strcmp(job_attr
, "job-name") &&
6633 strcmp(job_attr
, "job-originating-user-name") &&
6634 strcmp(job_attr
, "job-preserved") &&
6635 strcmp(job_attr
, "job-printer-up-time") &&
6636 strcmp(job_attr
, "job-printer-uri") &&
6637 strcmp(job_attr
, "job-state") &&
6638 strcmp(job_attr
, "job-state-reasons") &&
6639 strcmp(job_attr
, "job-uri") &&
6640 strcmp(job_attr
, "time-at-completed") &&
6641 strcmp(job_attr
, "time-at-creation") &&
6642 strcmp(job_attr
, "number-of-documents"))
6648 if (need_load_job
&& (limit
== 0 || limit
> 500) && (list
== Jobs
|| delete_list
))
6651 * Limit expensive Get-Jobs for job history to 500 jobs...
6654 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
, "limit", 500);
6657 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
, "limit", limit
);
6661 cupsdLogClient(con
, CUPSD_LOG_INFO
, "Limiting Get-Jobs response to %d jobs.", limit
);
6665 * OK, build a list of jobs for this printer...
6670 int i
; /* Looping var */
6672 for (i
= 0; i
< job_ids
->num_values
; i
++)
6674 if (!cupsdFindJob(job_ids
->values
[i
].integer
))
6678 if (i
< job_ids
->num_values
)
6680 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
6681 job_ids
->values
[i
].integer
);
6685 for (i
= 0; i
< job_ids
->num_values
; i
++)
6687 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
6689 if (need_load_job
&& !job
->attrs
)
6695 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d", job
->id
);
6701 ippAddSeparator(con
->response
);
6703 exclude
= cupsdGetPrivateAttrs(job
->printer
?
6704 job
->printer
->op_policy_ptr
:
6705 policy
, con
, job
->printer
,
6708 copy_job_attrs(con
, job
, ra
, exclude
);
6713 for (count
= 0, job
= (cupsd_job_t
*)cupsArrayFirst(list
);
6714 (limit
<= 0 || count
< limit
) && job
;
6715 job
= (cupsd_job_t
*)cupsArrayNext(list
))
6718 * Filter out jobs that don't match...
6721 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
6722 "get_jobs: job->id=%d, dest=\"%s\", username=\"%s\", "
6723 "state_value=%d, attrs=%p", job
->id
, job
->dest
,
6724 job
->username
, job
->state_value
, job
->attrs
);
6726 if (!job
->dest
|| !job
->username
)
6729 if (!job
->dest
|| !job
->username
)
6732 if ((dest
&& strcmp(job
->dest
, dest
)) &&
6733 (!job
->printer
|| !dest
|| strcmp(job
->printer
->name
, dest
)))
6735 if ((job
->dtype
& dmask
) != dtype
&&
6736 (!job
->printer
|| (job
->printer
->type
& dmask
) != dtype
))
6739 if ((job_comparison
< 0 && job
->state_value
> job_state
) ||
6740 (job_comparison
== 0 && job
->state_value
!= job_state
) ||
6741 (job_comparison
> 0 && job
->state_value
< job_state
))
6744 if (job
->id
< first_job_id
)
6748 if (current_index
< first_index
)
6751 if (need_load_job
&& !job
->attrs
)
6757 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d", job
->id
);
6762 if (username
[0] && _cups_strcasecmp(username
, job
->username
))
6766 ippAddSeparator(con
->response
);
6770 exclude
= cupsdGetPrivateAttrs(job
->printer
?
6771 job
->printer
->op_policy_ptr
:
6772 policy
, con
, job
->printer
,
6775 copy_job_attrs(con
, job
, ra
, exclude
);
6778 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: count=%d", count
);
6781 cupsArrayDelete(ra
);
6784 cupsArrayDelete(list
);
6786 con
->response
->request
.status
.status_code
= IPP_OK
;
6791 * 'get_notifications()' - Get events for a subscription.
6795 get_notifications(cupsd_client_t
*con
) /* I - Client connection */
6797 int i
, j
; /* Looping vars */
6798 http_status_t status
; /* Policy status */
6799 cupsd_subscription_t
*sub
; /* Subscription */
6800 ipp_attribute_t
*ids
, /* notify-subscription-ids */
6801 *sequences
; /* notify-sequence-numbers */
6802 int min_seq
; /* Minimum sequence number */
6803 int interval
; /* Poll interval */
6806 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_notifications(con=%p[%d])",
6810 * Get subscription attributes...
6813 ids
= ippFindAttribute(con
->request
, "notify-subscription-ids",
6815 sequences
= ippFindAttribute(con
->request
, "notify-sequence-numbers",
6820 send_ipp_status(con
, IPP_BAD_REQUEST
,
6821 _("Missing notify-subscription-ids attribute."));
6826 * Are the subscription IDs valid?
6829 for (i
= 0, interval
= 60; i
< ids
->num_values
; i
++)
6831 if ((sub
= cupsdFindSubscription(ids
->values
[i
].integer
)) == NULL
)
6834 * Bad subscription ID...
6837 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
6838 ids
->values
[i
].integer
);
6846 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
6848 con
, sub
->owner
)) != HTTP_OK
)
6850 send_http_error(con
, status
, sub
->dest
);
6855 * Check the subscription type and update the interval accordingly.
6858 if (sub
->job
&& sub
->job
->state_value
== IPP_JOB_PROCESSING
&&
6861 else if (sub
->job
&& sub
->job
->state_value
>= IPP_JOB_STOPPED
)
6863 else if (sub
->dest
&& sub
->dest
->state
== IPP_PRINTER_PROCESSING
&&
6869 * Tell the client to poll again in N seconds...
6873 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
6874 "notify-get-interval", interval
);
6876 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
6877 "printer-up-time", time(NULL
));
6880 * Copy the subscription event attributes to the response.
6883 con
->response
->request
.status
.status_code
=
6884 interval
? IPP_OK
: IPP_OK_EVENTS_COMPLETE
;
6886 for (i
= 0; i
< ids
->num_values
; i
++)
6889 * Get the subscription and sequence number...
6892 sub
= cupsdFindSubscription(ids
->values
[i
].integer
);
6894 if (sequences
&& i
< sequences
->num_values
)
6895 min_seq
= sequences
->values
[i
].integer
;
6900 * If we don't have any new events, nothing to do here...
6903 if (min_seq
> (sub
->first_event_id
+ cupsArrayCount(sub
->events
)))
6907 * Otherwise copy all of the new events...
6910 if (sub
->first_event_id
> min_seq
)
6913 j
= min_seq
- sub
->first_event_id
;
6915 for (; j
< cupsArrayCount(sub
->events
); j
++)
6917 ippAddSeparator(con
->response
);
6919 copy_attrs(con
->response
,
6920 ((cupsd_event_t
*)cupsArrayIndex(sub
->events
, j
))->attrs
, NULL
,
6921 IPP_TAG_EVENT_NOTIFICATION
, 0, NULL
);
6928 * 'get_ppd()' - Get a named PPD from the local system.
6932 get_ppd(cupsd_client_t
*con
, /* I - Client connection */
6933 ipp_attribute_t
*uri
) /* I - Printer URI or PPD name */
6935 http_status_t status
; /* Policy status */
6936 cupsd_printer_t
*dest
; /* Destination */
6937 cups_ptype_t dtype
; /* Destination type */
6940 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppd(%p[%d], %p[%s=%s])", con
,
6941 con
->number
, uri
, uri
->name
, uri
->values
[0].string
.text
);
6943 if (!strcmp(ippGetName(uri
), "ppd-name"))
6946 * Return a PPD file from cups-driverd...
6949 const char *ppd_name
= ippGetString(uri
, 0, NULL
);
6950 /* ppd-name value */
6951 char command
[1024], /* cups-driverd command */
6952 options
[1024], /* Options to pass to command */
6953 oppd_name
[1024]; /* Escaped ppd-name */
6959 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6961 send_http_error(con
, status
, NULL
);
6966 * Check ppd-name value...
6969 if (strstr(ppd_name
, "../"))
6971 send_ipp_status(con
, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES
, _("Invalid ppd-name value."));
6976 * Run cups-driverd command with the given options...
6979 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
6980 url_encode_string(ppd_name
, oppd_name
, sizeof(oppd_name
));
6981 snprintf(options
, sizeof(options
), "get+%d+%s", ippGetRequestId(con
->request
), oppd_name
);
6983 if (cupsdSendCommand(con
, command
, options
, 0))
6986 * Command started successfully, don't send an IPP response here...
6989 ippDelete(con
->response
);
6990 con
->response
= NULL
;
6995 * Command failed, return "internal error" so the user knows something
6999 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("cups-driverd failed to execute."));
7002 else if (!strcmp(ippGetName(uri
), "printer-uri") && cupsdValidateDest(ippGetString(uri
, 0, NULL
), &dtype
, &dest
))
7004 int i
; /* Looping var */
7005 char filename
[1024]; /* PPD filename */
7011 if ((status
= cupsdCheckPolicy(dest
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7013 send_http_error(con
, status
, dest
);
7018 * See if we need the PPD for a class or remote printer...
7021 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
, dest
->name
);
7023 if ((dtype
& CUPS_PRINTER_REMOTE
) && access(filename
, 0))
7025 send_ipp_status(con
, IPP_STATUS_CUPS_SEE_OTHER
, _("See remote printer."));
7026 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
, dest
->uri
);
7029 else if (dtype
& CUPS_PRINTER_CLASS
)
7031 for (i
= 0; i
< dest
->num_printers
; i
++)
7032 if (!(dest
->printers
[i
]->type
& CUPS_PRINTER_CLASS
))
7034 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
, dest
->printers
[i
]->name
);
7036 if (!access(filename
, 0))
7040 if (i
< dest
->num_printers
)
7041 dest
= dest
->printers
[i
];
7044 send_ipp_status(con
, IPP_STATUS_CUPS_SEE_OTHER
, _("See remote printer."));
7045 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
, dest
->printers
[0]->uri
);
7051 * Found the printer with the PPD file, now see if there is one...
7054 if ((con
->file
= open(filename
, O_RDONLY
)) < 0)
7056 send_ipp_status(con
, IPP_STATUS_ERROR_NOT_FOUND
, _("The PPD file \"%s\" could not be opened: %s"), ippGetString(uri
, 0, NULL
), strerror(errno
));
7060 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
7064 ippSetStatusCode(con
->response
, IPP_STATUS_OK
);
7067 send_ipp_status(con
, IPP_STATUS_ERROR_NOT_FOUND
, _("The PPD file \"%s\" could not be found."), ippGetString(uri
, 0, NULL
));
7072 * 'get_ppds()' - Get the list of PPD files on the local system.
7076 get_ppds(cupsd_client_t
*con
) /* I - Client connection */
7078 http_status_t status
; /* Policy status */
7079 ipp_attribute_t
*limit
, /* Limit attribute */
7080 *device
, /* ppd-device-id attribute */
7081 *language
, /* ppd-natural-language attribute */
7082 *make
, /* ppd-make attribute */
7083 *model
, /* ppd-make-and-model attribute */
7084 *model_number
, /* ppd-model-number attribute */
7085 *product
, /* ppd-product attribute */
7086 *psversion
, /* ppd-psverion attribute */
7087 *type
, /* ppd-type attribute */
7088 *requested
, /* requested-attributes attribute */
7089 *exclude
, /* exclude-schemes attribute */
7090 *include
; /* include-schemes attribute */
7091 char command
[1024], /* cups-driverd command */
7092 options
[4096], /* Options to pass to command */
7093 device_str
[256],/* Escaped ppd-device-id string */
7095 /* Escaped ppd-natural-language */
7096 make_str
[256], /* Escaped ppd-make string */
7097 model_str
[256], /* Escaped ppd-make-and-model string */
7098 model_number_str
[256],
7099 /* ppd-model-number string */
7101 /* Escaped ppd-product string */
7103 /* Escaped ppd-psversion string */
7104 type_str
[256], /* Escaped ppd-type string */
7106 /* String for requested attributes */
7108 /* String for excluded schemes */
7110 /* String for included schemes */
7113 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppds(%p[%d])", con
, con
->number
);
7119 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7121 send_http_error(con
, status
, NULL
);
7126 * Run cups-driverd command with the given options...
7129 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
7130 device
= ippFindAttribute(con
->request
, "ppd-device-id", IPP_TAG_TEXT
);
7131 language
= ippFindAttribute(con
->request
, "ppd-natural-language",
7133 make
= ippFindAttribute(con
->request
, "ppd-make", IPP_TAG_TEXT
);
7134 model
= ippFindAttribute(con
->request
, "ppd-make-and-model",
7136 model_number
= ippFindAttribute(con
->request
, "ppd-model-number",
7138 product
= ippFindAttribute(con
->request
, "ppd-product", IPP_TAG_TEXT
);
7139 psversion
= ippFindAttribute(con
->request
, "ppd-psversion", IPP_TAG_TEXT
);
7140 type
= ippFindAttribute(con
->request
, "ppd-type", IPP_TAG_KEYWORD
);
7141 requested
= ippFindAttribute(con
->request
, "requested-attributes",
7143 exclude
= ippFindAttribute(con
->request
, "exclude-schemes",
7145 include
= ippFindAttribute(con
->request
, "include-schemes",
7149 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
7151 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
7154 url_encode_attr(device
, device_str
, sizeof(device_str
));
7156 device_str
[0] = '\0';
7159 url_encode_attr(language
, language_str
, sizeof(language_str
));
7161 language_str
[0] = '\0';
7164 url_encode_attr(make
, make_str
, sizeof(make_str
));
7169 url_encode_attr(model
, model_str
, sizeof(model_str
));
7171 model_str
[0] = '\0';
7174 snprintf(model_number_str
, sizeof(model_number_str
), "ppd-model-number=%d",
7175 model_number
->values
[0].integer
);
7177 model_number_str
[0] = '\0';
7180 url_encode_attr(product
, product_str
, sizeof(product_str
));
7182 product_str
[0] = '\0';
7185 url_encode_attr(psversion
, psversion_str
, sizeof(psversion_str
));
7187 psversion_str
[0] = '\0';
7190 url_encode_attr(type
, type_str
, sizeof(type_str
));
7195 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
7197 exclude_str
[0] = '\0';
7200 url_encode_attr(include
, include_str
, sizeof(include_str
));
7202 include_str
[0] = '\0';
7204 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7205 snprintf(options
, sizeof(options
),
7206 "list+%d+%d+%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
7207 con
->request
->request
.op
.request_id
,
7208 limit
? limit
->values
[0].integer
: 0,
7210 device
? "%20" : "", device_str
,
7211 language
? "%20" : "", language_str
,
7212 make
? "%20" : "", make_str
,
7213 model
? "%20" : "", model_str
,
7214 model_number
? "%20" : "", model_number_str
,
7215 product
? "%20" : "", product_str
,
7216 psversion
? "%20" : "", psversion_str
,
7217 type
? "%20" : "", type_str
,
7218 exclude_str
[0] ? "%20" : "", exclude_str
,
7219 include_str
[0] ? "%20" : "", include_str
);
7221 if (cupsdSendCommand(con
, command
, options
, 0))
7224 * Command started successfully, don't send an IPP response here...
7227 ippDelete(con
->response
);
7228 con
->response
= NULL
;
7233 * Command failed, return "internal error" so the user knows something
7237 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7238 _("cups-driverd failed to execute."));
7244 * 'get_printer_attrs()' - Get printer attributes.
7248 get_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
7249 ipp_attribute_t
*uri
) /* I - Printer URI */
7251 http_status_t status
; /* Policy status */
7252 cups_ptype_t dtype
; /* Destination type (printer/class) */
7253 cupsd_printer_t
*printer
; /* Printer/class */
7254 cups_array_t
*ra
; /* Requested attributes array */
7257 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_attrs(%p[%d], %s)", con
,
7258 con
->number
, uri
->values
[0].string
.text
);
7261 * Is the destination valid?
7264 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7270 send_ipp_status(con
, IPP_NOT_FOUND
,
7271 _("The printer or class does not exist."));
7279 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7281 send_http_error(con
, status
, printer
);
7286 * Send the attributes...
7289 ra
= create_requested_array(con
->request
);
7291 copy_printer_attrs(con
, printer
, ra
);
7293 cupsArrayDelete(ra
);
7295 con
->response
->request
.status
.status_code
= IPP_OK
;
7300 * 'get_printer_supported()' - Get printer supported values.
7304 get_printer_supported(
7305 cupsd_client_t
*con
, /* I - Client connection */
7306 ipp_attribute_t
*uri
) /* I - Printer URI */
7308 http_status_t status
; /* Policy status */
7309 cups_ptype_t dtype
; /* Destination type (printer/class) */
7310 cupsd_printer_t
*printer
; /* Printer/class */
7313 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_supported(%p[%d], %s)", con
,
7314 con
->number
, uri
->values
[0].string
.text
);
7317 * Is the destination valid?
7320 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7326 send_ipp_status(con
, IPP_NOT_FOUND
,
7327 _("The printer or class does not exist."));
7335 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7337 send_http_error(con
, status
, printer
);
7342 * Return a list of attributes that can be set via Set-Printer-Attributes.
7345 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7346 "printer-geo-location", 0);
7347 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7349 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7350 "printer-location", 0);
7351 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7352 "printer-organization", 0);
7353 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7354 "printer-organizational-unit", 0);
7356 con
->response
->request
.status
.status_code
= IPP_OK
;
7361 * 'get_printers()' - Get a list of printers or classes.
7365 get_printers(cupsd_client_t
*con
, /* I - Client connection */
7366 int type
) /* I - 0 or CUPS_PRINTER_CLASS */
7368 http_status_t status
; /* Policy status */
7369 ipp_attribute_t
*attr
; /* Current attribute */
7370 int limit
; /* Max number of printers to return */
7371 int count
; /* Number of printers that match */
7372 cupsd_printer_t
*printer
; /* Current printer pointer */
7373 cups_ptype_t printer_type
, /* printer-type attribute */
7374 printer_mask
; /* printer-type-mask attribute */
7375 char *location
; /* Location string */
7376 const char *username
; /* Current user */
7377 char *first_printer_name
; /* first-printer-name attribute */
7378 cups_array_t
*ra
; /* Requested attributes array */
7379 int local
; /* Local connection? */
7382 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printers(%p[%d], %x)", con
,
7389 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7391 send_http_error(con
, status
, NULL
);
7396 * Check for printers...
7399 if (!Printers
|| !cupsArrayCount(Printers
))
7401 send_ipp_status(con
, IPP_NOT_FOUND
, _("No destinations added."));
7406 * See if they want to limit the number of printers reported...
7409 if ((attr
= ippFindAttribute(con
->request
, "limit",
7410 IPP_TAG_INTEGER
)) != NULL
)
7411 limit
= attr
->values
[0].integer
;
7415 if ((attr
= ippFindAttribute(con
->request
, "first-printer-name",
7416 IPP_TAG_NAME
)) != NULL
)
7417 first_printer_name
= attr
->values
[0].string
.text
;
7419 first_printer_name
= NULL
;
7422 * Support filtering...
7425 if ((attr
= ippFindAttribute(con
->request
, "printer-type",
7426 IPP_TAG_ENUM
)) != NULL
)
7427 printer_type
= (cups_ptype_t
)attr
->values
[0].integer
;
7429 printer_type
= (cups_ptype_t
)0;
7431 if ((attr
= ippFindAttribute(con
->request
, "printer-type-mask",
7432 IPP_TAG_ENUM
)) != NULL
)
7433 printer_mask
= (cups_ptype_t
)attr
->values
[0].integer
;
7435 printer_mask
= (cups_ptype_t
)0;
7437 local
= httpAddrLocalhost(&(con
->clientaddr
));
7439 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
7440 IPP_TAG_TEXT
)) != NULL
)
7441 location
= attr
->values
[0].string
.text
;
7445 if (con
->username
[0])
7446 username
= con
->username
;
7447 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7448 IPP_TAG_NAME
)) != NULL
)
7449 username
= attr
->values
[0].string
.text
;
7453 ra
= create_requested_array(con
->request
);
7456 * OK, build a list of printers for this printer...
7459 if (first_printer_name
)
7461 if ((printer
= cupsdFindDest(first_printer_name
)) == NULL
)
7462 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7465 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7468 count
< limit
&& printer
;
7469 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
7471 if (!local
&& !printer
->shared
)
7474 if ((!type
|| (printer
->type
& CUPS_PRINTER_CLASS
) == type
) &&
7475 (printer
->type
& printer_mask
) == printer_type
&&
7477 (printer
->location
&& !_cups_strcasecmp(printer
->location
, location
))))
7480 * If a username is specified, see if it is allowed or denied
7484 if (cupsArrayCount(printer
->users
) && username
&&
7485 !user_allowed(printer
, username
))
7489 * Add the group separator as needed...
7493 ippAddSeparator(con
->response
);
7498 * Send the attributes...
7501 copy_printer_attrs(con
, printer
, ra
);
7505 cupsArrayDelete(ra
);
7507 con
->response
->request
.status
.status_code
= IPP_OK
;
7512 * 'get_subscription_attrs()' - Get subscription attributes.
7516 get_subscription_attrs(
7517 cupsd_client_t
*con
, /* I - Client connection */
7518 int sub_id
) /* I - Subscription ID */
7520 http_status_t status
; /* Policy status */
7521 cupsd_subscription_t
*sub
; /* Subscription */
7522 cupsd_policy_t
*policy
; /* Current security policy */
7523 cups_array_t
*ra
, /* Requested attributes array */
7524 *exclude
; /* Private attributes array */
7527 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7528 "get_subscription_attrs(con=%p[%d], sub_id=%d)",
7529 con
, con
->number
, sub_id
);
7532 * Expire subscriptions as needed...
7535 cupsdExpireSubscriptions(NULL
, NULL
);
7538 * Is the subscription ID valid?
7541 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
7544 * Bad subscription ID...
7547 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
7557 policy
= sub
->dest
->op_policy_ptr
;
7559 policy
= DefaultPolicyPtr
;
7561 if ((status
= cupsdCheckPolicy(policy
, con
, sub
->owner
)) != HTTP_OK
)
7563 send_http_error(con
, status
, sub
->dest
);
7567 exclude
= cupsdGetPrivateAttrs(policy
, con
, sub
->dest
, sub
->owner
);
7570 * Copy the subscription attributes to the response using the
7571 * requested-attributes attribute that may be provided by the client.
7574 ra
= create_requested_array(con
->request
);
7576 copy_subscription_attrs(con
, sub
, ra
, exclude
);
7578 cupsArrayDelete(ra
);
7580 con
->response
->request
.status
.status_code
= IPP_OK
;
7585 * 'get_subscriptions()' - Get subscriptions.
7589 get_subscriptions(cupsd_client_t
*con
, /* I - Client connection */
7590 ipp_attribute_t
*uri
) /* I - Printer/job URI */
7592 http_status_t status
; /* Policy status */
7593 int count
; /* Number of subscriptions */
7594 int limit
; /* Limit */
7595 cupsd_subscription_t
*sub
; /* Subscription */
7596 cups_array_t
*ra
; /* Requested attributes array */
7597 ipp_attribute_t
*attr
; /* Attribute */
7598 cups_ptype_t dtype
; /* Destination type (printer/class) */
7599 char scheme
[HTTP_MAX_URI
],
7600 /* Scheme portion of URI */
7601 username
[HTTP_MAX_URI
],
7602 /* Username portion of URI */
7604 /* Host portion of URI */
7605 resource
[HTTP_MAX_URI
];
7606 /* Resource portion of URI */
7607 int port
; /* Port portion of URI */
7608 cupsd_job_t
*job
; /* Job pointer */
7609 cupsd_printer_t
*printer
; /* Printer */
7610 cupsd_policy_t
*policy
; /* Policy */
7611 cups_array_t
*exclude
; /* Private attributes array */
7614 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7615 "get_subscriptions(con=%p[%d], uri=%s)",
7616 con
, con
->number
, uri
->values
[0].string
.text
);
7619 * Is the destination valid?
7622 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7623 sizeof(scheme
), username
, sizeof(username
), host
,
7624 sizeof(host
), &port
, resource
, sizeof(resource
));
7626 if (!strcmp(resource
, "/") ||
7627 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6) ||
7628 (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10) ||
7629 (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9))
7634 else if (!strncmp(resource
, "/jobs/", 6) && resource
[6])
7637 job
= cupsdFindJob(atoi(resource
+ 6));
7641 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
7642 atoi(resource
+ 6));
7646 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7652 send_ipp_status(con
, IPP_NOT_FOUND
,
7653 _("The printer or class does not exist."));
7656 else if ((attr
= ippFindAttribute(con
->request
, "notify-job-id",
7657 IPP_TAG_INTEGER
)) != NULL
)
7659 job
= cupsdFindJob(attr
->values
[0].integer
);
7663 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
7664 attr
->values
[0].integer
);
7676 policy
= printer
->op_policy_ptr
;
7678 policy
= DefaultPolicyPtr
;
7680 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
7682 send_http_error(con
, status
, printer
);
7687 * Expire subscriptions as needed...
7690 cupsdExpireSubscriptions(NULL
, NULL
);
7693 * Copy the subscription attributes to the response using the
7694 * requested-attributes attribute that may be provided by the client.
7697 ra
= create_requested_array(con
->request
);
7699 if ((attr
= ippFindAttribute(con
->request
, "limit",
7700 IPP_TAG_INTEGER
)) != NULL
)
7701 limit
= attr
->values
[0].integer
;
7706 * See if we only want to see subscriptions for a specific user...
7709 if ((attr
= ippFindAttribute(con
->request
, "my-subscriptions",
7710 IPP_TAG_BOOLEAN
)) != NULL
&&
7711 attr
->values
[0].boolean
)
7712 strlcpy(username
, get_username(con
), sizeof(username
));
7716 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
), count
= 0;
7718 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
7719 if ((!printer
|| sub
->dest
== printer
) && (!job
|| sub
->job
== job
) &&
7720 (!username
[0] || !_cups_strcasecmp(username
, sub
->owner
)))
7722 ippAddSeparator(con
->response
);
7724 exclude
= cupsdGetPrivateAttrs(sub
->dest
? sub
->dest
->op_policy_ptr
:
7725 policy
, con
, sub
->dest
,
7728 copy_subscription_attrs(con
, sub
, ra
, exclude
);
7731 if (limit
&& count
>= limit
)
7735 cupsArrayDelete(ra
);
7738 con
->response
->request
.status
.status_code
= IPP_OK
;
7740 send_ipp_status(con
, IPP_NOT_FOUND
, _("No subscriptions found."));
7745 * 'get_username()' - Get the username associated with a request.
7748 static const char * /* O - Username */
7749 get_username(cupsd_client_t
*con
) /* I - Connection */
7751 ipp_attribute_t
*attr
; /* Attribute */
7754 if (con
->username
[0])
7755 return (con
->username
);
7756 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7757 IPP_TAG_NAME
)) != NULL
)
7758 return (attr
->values
[0].string
.text
);
7760 return ("anonymous");
7765 * 'hold_job()' - Hold a print job.
7769 hold_job(cupsd_client_t
*con
, /* I - Client connection */
7770 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
7772 ipp_attribute_t
*attr
; /* Current job-hold-until */
7773 const char *when
; /* New value */
7774 int jobid
; /* Job ID */
7775 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
7776 username
[HTTP_MAX_URI
], /* Username portion of URI */
7777 host
[HTTP_MAX_URI
], /* Host portion of URI */
7778 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7779 int port
; /* Port portion of URI */
7780 cupsd_job_t
*job
; /* Job information */
7783 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_job(%p[%d], %s)", con
, con
->number
,
7784 uri
->values
[0].string
.text
);
7787 * See if we have a job URI or a printer URI...
7790 if (!strcmp(uri
->name
, "printer-uri"))
7793 * Got a printer URI; see if we also have a job-id attribute...
7796 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7797 IPP_TAG_INTEGER
)) == NULL
)
7799 send_ipp_status(con
, IPP_BAD_REQUEST
,
7800 _("Got a printer-uri attribute but no job-id."));
7804 jobid
= attr
->values
[0].integer
;
7809 * Got a job URI; parse it to get the job ID...
7812 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7813 sizeof(scheme
), username
, sizeof(username
), host
,
7814 sizeof(host
), &port
, resource
, sizeof(resource
));
7816 if (strncmp(resource
, "/jobs/", 6))
7822 send_ipp_status(con
, IPP_BAD_REQUEST
,
7823 _("Bad job-uri \"%s\"."),
7824 uri
->values
[0].string
.text
);
7828 jobid
= atoi(resource
+ 6);
7832 * See if the job exists...
7835 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7838 * Nope - return a "not found" error...
7841 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
7846 * See if the job is owned by the requesting user...
7849 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7851 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
7852 cupsdFindDest(job
->dest
));
7857 * See if the job is in a state that allows holding...
7860 if (job
->state_value
> IPP_JOB_STOPPED
)
7863 * Return a "not-possible" error...
7866 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
7867 _("Job #%d is finished and cannot be altered."),
7873 * Hold the job and return...
7876 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
7877 IPP_TAG_KEYWORD
)) == NULL
)
7878 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
7882 when
= attr
->values
[0].string
.text
;
7884 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
7885 "Job job-hold-until value changed by user.");
7888 when
= "indefinite";
7890 cupsdSetJobHoldUntil(job
, when
, 1);
7891 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
, "Job held by \"%s\".",
7894 con
->response
->request
.status
.status_code
= IPP_OK
;
7899 * 'hold_new_jobs()' - Hold pending/new jobs on a printer or class.
7903 hold_new_jobs(cupsd_client_t
*con
, /* I - Connection */
7904 ipp_attribute_t
*uri
) /* I - Printer URI */
7906 http_status_t status
; /* Policy status */
7907 cups_ptype_t dtype
; /* Destination type (printer/class) */
7908 cupsd_printer_t
*printer
; /* Printer data */
7911 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_new_jobs(%p[%d], %s)", con
,
7912 con
->number
, uri
->values
[0].string
.text
);
7915 * Is the destination valid?
7918 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7924 send_ipp_status(con
, IPP_NOT_FOUND
,
7925 _("The printer or class does not exist."));
7933 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7935 send_http_error(con
, status
, printer
);
7940 * Hold pending/new jobs sent to the printer...
7943 printer
->holding_new_jobs
= 1;
7945 cupsdSetPrinterReasons(printer
, "+hold-new-jobs");
7947 if (dtype
& CUPS_PRINTER_CLASS
)
7948 cupsdLogMessage(CUPSD_LOG_INFO
,
7949 "Class \"%s\" now holding pending/new jobs (\"%s\").",
7950 printer
->name
, get_username(con
));
7952 cupsdLogMessage(CUPSD_LOG_INFO
,
7953 "Printer \"%s\" now holding pending/new jobs (\"%s\").",
7954 printer
->name
, get_username(con
));
7957 * Everything was ok, so return OK status...
7960 con
->response
->request
.status
.status_code
= IPP_OK
;
7965 * 'move_job()' - Move a job to a new destination.
7969 move_job(cupsd_client_t
*con
, /* I - Client connection */
7970 ipp_attribute_t
*uri
) /* I - Job URI */
7972 http_status_t status
; /* Policy status */
7973 ipp_attribute_t
*attr
; /* Current attribute */
7974 int jobid
; /* Job ID */
7975 cupsd_job_t
*job
; /* Current job */
7976 const char *src
; /* Source printer/class */
7977 cups_ptype_t stype
, /* Source type (printer or class) */
7978 dtype
; /* Destination type (printer/class) */
7979 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
7980 username
[HTTP_MAX_URI
], /* Username portion of URI */
7981 host
[HTTP_MAX_URI
], /* Host portion of URI */
7982 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7983 int port
; /* Port portion of URI */
7984 cupsd_printer_t
*sprinter
, /* Source printer */
7985 *dprinter
; /* Destination printer */
7988 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "move_job(%p[%d], %s)", con
, con
->number
,
7989 uri
->values
[0].string
.text
);
7992 * Get the new printer or class...
7995 if ((attr
= ippFindAttribute(con
->request
, "job-printer-uri",
7996 IPP_TAG_URI
)) == NULL
)
7999 * Need job-printer-uri...
8002 send_ipp_status(con
, IPP_BAD_REQUEST
,
8003 _("job-printer-uri attribute missing."));
8007 if (!cupsdValidateDest(attr
->values
[0].string
.text
, &dtype
, &dprinter
))
8013 send_ipp_status(con
, IPP_NOT_FOUND
,
8014 _("The printer or class does not exist."));
8019 * See if we have a job URI or a printer URI...
8022 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8023 sizeof(scheme
), username
, sizeof(username
), host
,
8024 sizeof(host
), &port
, resource
, sizeof(resource
));
8026 if (!strcmp(uri
->name
, "printer-uri"))
8029 * Got a printer URI; see if we also have a job-id attribute...
8032 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8033 IPP_TAG_INTEGER
)) == NULL
)
8039 if ((src
= cupsdValidateDest(uri
->values
[0].string
.text
, &stype
,
8040 &sprinter
)) == NULL
)
8046 send_ipp_status(con
, IPP_NOT_FOUND
,
8047 _("The printer or class does not exist."));
8056 * Otherwise, just move a single job...
8059 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
8062 * Nope - return a "not found" error...
8065 send_ipp_status(con
, IPP_NOT_FOUND
,
8066 _("Job #%d does not exist."), attr
->values
[0].integer
);
8072 * Job found, initialize source pointers...
8083 * Got a job URI; parse it to get the job ID...
8086 if (strncmp(resource
, "/jobs/", 6))
8092 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
8093 uri
->values
[0].string
.text
);
8098 * See if the job exists...
8101 jobid
= atoi(resource
+ 6);
8103 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8106 * Nope - return a "not found" error...
8109 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
8115 * Job found, initialize source pointers...
8124 * Check the policy of the destination printer...
8127 if ((status
= cupsdCheckPolicy(dprinter
->op_policy_ptr
, con
,
8128 job
? job
->username
: NULL
)) != HTTP_OK
)
8130 send_http_error(con
, status
, dprinter
);
8135 * Now move the job or jobs...
8141 * See if the job has been completed...
8144 if (job
->state_value
> IPP_JOB_STOPPED
)
8147 * Return a "not-possible" error...
8150 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8151 _("Job #%d is finished and cannot be altered."),
8157 * See if the job is owned by the requesting user...
8160 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8162 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8163 cupsdFindDest(job
->dest
));
8168 * Move the job to a different printer or class...
8171 cupsdMoveJob(job
, dprinter
);
8176 * Got the source printer, now look through the jobs...
8179 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
8181 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
8184 * See if the job is pointing at the source printer or has not been
8188 if (_cups_strcasecmp(job
->dest
, src
) ||
8189 job
->state_value
> IPP_JOB_STOPPED
)
8193 * See if the job can be moved by the requesting user...
8196 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8200 * Move the job to a different printer or class...
8203 cupsdMoveJob(job
, dprinter
);
8208 * Start jobs if possible...
8214 * Return with "everything is OK" status...
8217 con
->response
->request
.status
.status_code
= IPP_OK
;
8222 * 'ppd_parse_line()' - Parse a PPD default line.
8225 static int /* O - 0 on success, -1 on failure */
8226 ppd_parse_line(const char *line
, /* I - Line */
8227 char *option
, /* O - Option name */
8228 int olen
, /* I - Size of option name */
8229 char *choice
, /* O - Choice name */
8230 int clen
) /* I - Size of choice name */
8233 * Verify this is a default option line...
8236 if (strncmp(line
, "*Default", 8))
8240 * Read the option name...
8243 for (line
+= 8, olen
--;
8244 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
8255 * Skip everything else up to the colon (:)...
8258 while (*line
&& *line
!= ':')
8267 * Now grab the option choice, skipping leading whitespace...
8270 while (isspace(*line
& 255))
8274 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
8285 * Return with no errors...
8293 * 'print_job()' - Print a file to a printer or class.
8297 print_job(cupsd_client_t
*con
, /* I - Client connection */
8298 ipp_attribute_t
*uri
) /* I - Printer URI */
8300 ipp_attribute_t
*attr
; /* Current attribute */
8301 ipp_attribute_t
*doc_name
; /* document-name attribute */
8302 ipp_attribute_t
*format
; /* Document-format attribute */
8303 const char *default_format
; /* document-format-default value */
8304 cupsd_job_t
*job
; /* New job */
8305 char filename
[1024]; /* Job filename */
8306 mime_type_t
*filetype
; /* Type of file */
8307 char super
[MIME_MAX_SUPER
], /* Supertype of file */
8308 type
[MIME_MAX_TYPE
], /* Subtype of file */
8309 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
8310 /* Textual name of mime type */
8311 cupsd_printer_t
*printer
; /* Printer data */
8312 struct stat fileinfo
; /* File information */
8313 int kbytes
; /* Size of file */
8314 int compression
; /* Document compression */
8317 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "print_job(%p[%d], %s)", con
, con
->number
,
8318 uri
->values
[0].string
.text
);
8321 * Validate print file attributes, for now just document-format and
8322 * compression (CUPS only supports "none" and "gzip")...
8325 compression
= CUPS_FILE_NONE
;
8327 if ((attr
= ippFindAttribute(con
->request
, "compression",
8328 IPP_TAG_KEYWORD
)) != NULL
)
8330 if (strcmp(attr
->values
[0].string
.text
, "none")
8332 && strcmp(attr
->values
[0].string
.text
, "gzip")
8333 #endif /* HAVE_LIBZ */
8336 send_ipp_status(con
, IPP_ATTRIBUTES
,
8337 _("Unsupported compression \"%s\"."),
8338 attr
->values
[0].string
.text
);
8339 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
8340 "compression", NULL
, attr
->values
[0].string
.text
);
8345 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
8346 compression
= CUPS_FILE_GZIP
;
8347 #endif /* HAVE_LIBZ */
8351 * Do we have a file to print?
8356 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file in print request."));
8361 * Is the destination valid?
8364 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
8370 send_ipp_status(con
, IPP_NOT_FOUND
,
8371 _("The printer or class does not exist."));
8376 * Is it a format we support?
8379 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
8381 ippSetName(con
->request
, &doc_name
, "document-name-supplied");
8383 if ((format
= ippFindAttribute(con
->request
, "document-format",
8384 IPP_TAG_MIMETYPE
)) != NULL
)
8387 * Grab format from client...
8390 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%255[^;]", super
,
8393 send_ipp_status(con
, IPP_BAD_REQUEST
,
8394 _("Bad document-format \"%s\"."),
8395 format
->values
[0].string
.text
);
8399 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format-supplied", NULL
, ippGetString(format
, 0, NULL
));
8401 else if ((default_format
= cupsGetOption("document-format",
8402 printer
->num_options
,
8403 printer
->options
)) != NULL
)
8406 * Use default document format...
8409 if (sscanf(default_format
, "%15[^/]/%255[^;]", super
, type
) != 2)
8411 send_ipp_status(con
, IPP_BAD_REQUEST
,
8412 _("Bad document-format \"%s\"."),
8423 strlcpy(super
, "application", sizeof(super
));
8424 strlcpy(type
, "octet-stream", sizeof(type
));
8427 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
8430 * Auto-type the file...
8433 cupsdLogMessage(CUPSD_LOG_DEBUG
, "[Job ???] Auto-typing file...");
8436 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
8437 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
8441 filetype
= mimeType(MimeDatabase
, super
, type
);
8443 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job ???] Request file type is %s/%s.",
8444 filetype
->super
, filetype
->type
);
8446 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
, filetype
->type
);
8447 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format-detected", NULL
, mimetype
);
8450 filetype
= mimeType(MimeDatabase
, super
, type
);
8454 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
8457 * Replace the document-format attribute value with the auto-typed or
8461 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
8465 ippSetString(con
->request
, &format
, 0, mimetype
);
8467 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
8468 "document-format", NULL
, mimetype
);
8472 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
8473 _("Unsupported document-format \"%s\"."),
8474 format
? format
->values
[0].string
.text
:
8475 "application/octet-stream");
8476 cupsdLogMessage(CUPSD_LOG_INFO
,
8477 "Hint: Do you have the raw file printing rules enabled?");
8480 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
8481 "document-format", NULL
, format
->values
[0].string
.text
);
8487 * Read any embedded job ticket info from PS files...
8490 if (!_cups_strcasecmp(filetype
->super
, "application") &&
8491 (!_cups_strcasecmp(filetype
->type
, "postscript") ||
8492 !_cups_strcasecmp(filetype
->type
, "pdf")))
8493 read_job_ticket(con
);
8496 * Create the job object...
8499 if ((job
= add_job(con
, printer
, filetype
)) == NULL
)
8503 * Update quota data...
8506 if (stat(con
->filename
, &fileinfo
))
8509 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
8511 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
8513 job
->koctets
+= kbytes
;
8515 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets", IPP_TAG_INTEGER
)) != NULL
)
8516 attr
->values
[0].integer
+= kbytes
;
8519 * Add the job file...
8522 if (add_file(con
, job
, filetype
, compression
))
8525 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
, job
->num_files
);
8526 if (rename(con
->filename
, filename
))
8528 cupsdLogJob(job
, CUPSD_LOG_ERROR
, "Unable to rename job document file \"%s\": %s", filename
, strerror(errno
));
8530 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to rename job document file."));
8534 cupsdClearString(&con
->filename
);
8537 * See if we need to add the ending sheet...
8540 if (cupsdTimeoutJob(job
))
8544 * Log and save the job...
8547 cupsdLogJob(job
, CUPSD_LOG_INFO
,
8548 "File of type %s/%s queued by \"%s\".",
8549 filetype
->super
, filetype
->type
, job
->username
);
8550 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "hold_until=%d", (int)job
->hold_until
);
8551 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
8552 job
->dest
, job
->username
);
8555 * Start the job if possible...
8563 * 'read_job_ticket()' - Read a job ticket embedded in a print file.
8565 * This function only gets called when printing a single PDF or PostScript
8566 * file using the Print-Job operation. It doesn't work for Create-Job +
8567 * Send-File, since the job attributes need to be set at job creation
8568 * time for banners to work. The embedded job ticket stuff is here
8569 * primarily to allow the Windows printer driver for CUPS to pass in JCL
8570 * options and IPP attributes which otherwise would be lost.
8572 * The format of a job ticket is simple:
8574 * %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
8576 * %cupsJobTicket: attr1=value1
8577 * %cupsJobTicket: attr2=value2
8579 * %cupsJobTicket: attrN=valueN
8581 * Job ticket lines must appear immediately after the first line that
8582 * specifies PostScript (%!PS-Adobe-3.0) or PDF (%PDF) format, and CUPS
8583 * stops looking for job ticket info when it finds a line that does not begin
8584 * with "%cupsJobTicket:".
8586 * The maximum length of a job ticket line, including the prefix, is
8587 * 255 characters to conform with the Adobe DSC.
8589 * Read-only attributes are rejected with a notice to the error log in
8590 * case a malicious user tries anything. Since the job ticket is read
8591 * prior to attribute validation in print_job(), job ticket attributes
8592 * will go through the same validation as IPP attributes...
8596 read_job_ticket(cupsd_client_t
*con
) /* I - Client connection */
8598 cups_file_t
*fp
; /* File to read from */
8599 char line
[256]; /* Line data */
8600 int num_options
; /* Number of options */
8601 cups_option_t
*options
; /* Options */
8602 ipp_t
*ticket
; /* New attributes */
8603 ipp_attribute_t
*attr
, /* Current attribute */
8604 *attr2
, /* Job attribute */
8605 *prev2
; /* Previous job attribute */
8609 * First open the print file...
8612 if ((fp
= cupsFileOpen(con
->filename
, "rb")) == NULL
)
8614 cupsdLogMessage(CUPSD_LOG_ERROR
,
8615 "Unable to open print file for job ticket - %s",
8621 * Skip the first line...
8624 if (cupsFileGets(fp
, line
, sizeof(line
)) == NULL
)
8626 cupsdLogMessage(CUPSD_LOG_ERROR
,
8627 "Unable to read from print file for job ticket - %s",
8633 if (strncmp(line
, "%!PS-Adobe-", 11) && strncmp(line
, "%PDF-", 5))
8636 * Not a DSC-compliant file, so no job ticket info will be available...
8644 * Read job ticket info from the file...
8650 while (cupsFileGets(fp
, line
, sizeof(line
)))
8653 * Stop at the first non-ticket line...
8656 if (strncmp(line
, "%cupsJobTicket:", 15))
8660 * Add the options to the option array...
8663 num_options
= cupsParseOptions(line
+ 15, num_options
, &options
);
8667 * Done with the file; see if we have any options...
8672 if (num_options
== 0)
8676 * OK, convert the options to an attribute list, and apply them to
8681 cupsEncodeOptions(ticket
, num_options
, options
);
8684 * See what the user wants to change.
8687 for (attr
= ticket
->attrs
; attr
; attr
= attr
->next
)
8689 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
8692 if (!strncmp(attr
->name
, "date-time-at-", 13) ||
8693 !strcmp(attr
->name
, "job-impressions-completed") ||
8694 !strcmp(attr
->name
, "job-media-sheets-completed") ||
8695 !strncmp(attr
->name
, "job-k-octets", 12) ||
8696 !strcmp(attr
->name
, "job-id") ||
8697 !strcmp(attr
->name
, "job-originating-host-name") ||
8698 !strcmp(attr
->name
, "job-originating-user-name") ||
8699 !strcmp(attr
->name
, "job-pages-completed") ||
8700 !strcmp(attr
->name
, "job-printer-uri") ||
8701 !strncmp(attr
->name
, "job-state", 9) ||
8702 !strcmp(attr
->name
, "job-uri") ||
8703 !strncmp(attr
->name
, "time-at-", 8))
8704 continue; /* Read-only attrs */
8706 if ((attr2
= ippFindAttribute(con
->request
, attr
->name
,
8707 IPP_TAG_ZERO
)) != NULL
)
8710 * Some other value; first free the old value...
8713 if (con
->request
->attrs
== attr2
)
8715 con
->request
->attrs
= attr2
->next
;
8720 for (prev2
= con
->request
->attrs
; prev2
; prev2
= prev2
->next
)
8721 if (prev2
->next
== attr2
)
8723 prev2
->next
= attr2
->next
;
8728 if (con
->request
->last
== attr2
)
8729 con
->request
->last
= prev2
;
8731 ippDeleteAttribute(NULL
, attr2
);
8735 * Add new option by copying it...
8738 ippCopyAttribute(con
->request
, attr
, 0);
8742 * Then free the attribute list and option array...
8746 cupsFreeOptions(num_options
, options
);
8751 * 'reject_jobs()' - Reject print jobs to a printer.
8755 reject_jobs(cupsd_client_t
*con
, /* I - Client connection */
8756 ipp_attribute_t
*uri
) /* I - Printer or class URI */
8758 http_status_t status
; /* Policy status */
8759 cups_ptype_t dtype
; /* Destination type (printer/class) */
8760 cupsd_printer_t
*printer
; /* Printer data */
8761 ipp_attribute_t
*attr
; /* printer-state-message text */
8764 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "reject_jobs(%p[%d], %s)", con
,
8765 con
->number
, uri
->values
[0].string
.text
);
8768 * Is the destination valid?
8771 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8777 send_ipp_status(con
, IPP_NOT_FOUND
,
8778 _("The printer or class does not exist."));
8786 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8788 send_http_error(con
, status
, printer
);
8793 * Reject jobs sent to the printer...
8796 printer
->accepting
= 0;
8798 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
8799 IPP_TAG_TEXT
)) == NULL
)
8800 strlcpy(printer
->state_message
, "Rejecting Jobs",
8801 sizeof(printer
->state_message
));
8803 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
8804 sizeof(printer
->state_message
));
8806 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
8807 "No longer accepting jobs.");
8809 if (dtype
& CUPS_PRINTER_CLASS
)
8811 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
8813 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" rejecting jobs (\"%s\").",
8814 printer
->name
, get_username(con
));
8818 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
8820 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" rejecting jobs (\"%s\").",
8821 printer
->name
, get_username(con
));
8825 * Everything was ok, so return OK status...
8828 con
->response
->request
.status
.status_code
= IPP_OK
;
8833 * 'release_held_new_jobs()' - Release pending/new jobs on a printer or class.
8837 release_held_new_jobs(
8838 cupsd_client_t
*con
, /* I - Connection */
8839 ipp_attribute_t
*uri
) /* I - Printer URI */
8841 http_status_t status
; /* Policy status */
8842 cups_ptype_t dtype
; /* Destination type (printer/class) */
8843 cupsd_printer_t
*printer
; /* Printer data */
8846 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_held_new_jobs(%p[%d], %s)", con
,
8847 con
->number
, uri
->values
[0].string
.text
);
8850 * Is the destination valid?
8853 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8859 send_ipp_status(con
, IPP_NOT_FOUND
,
8860 _("The printer or class does not exist."));
8868 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8870 send_http_error(con
, status
, printer
);
8875 * Hold pending/new jobs sent to the printer...
8878 printer
->holding_new_jobs
= 0;
8880 cupsdSetPrinterReasons(printer
, "-hold-new-jobs");
8882 if (dtype
& CUPS_PRINTER_CLASS
)
8883 cupsdLogMessage(CUPSD_LOG_INFO
,
8884 "Class \"%s\" now printing pending/new jobs (\"%s\").",
8885 printer
->name
, get_username(con
));
8887 cupsdLogMessage(CUPSD_LOG_INFO
,
8888 "Printer \"%s\" now printing pending/new jobs (\"%s\").",
8889 printer
->name
, get_username(con
));
8892 * Everything was ok, so return OK status...
8895 con
->response
->request
.status
.status_code
= IPP_OK
;
8900 * 'release_job()' - Release a held print job.
8904 release_job(cupsd_client_t
*con
, /* I - Client connection */
8905 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
8907 ipp_attribute_t
*attr
; /* Current attribute */
8908 int jobid
; /* Job ID */
8909 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
8910 username
[HTTP_MAX_URI
], /* Username portion of URI */
8911 host
[HTTP_MAX_URI
], /* Host portion of URI */
8912 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8913 int port
; /* Port portion of URI */
8914 cupsd_job_t
*job
; /* Job information */
8917 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_job(%p[%d], %s)", con
,
8918 con
->number
, uri
->values
[0].string
.text
);
8921 * See if we have a job URI or a printer URI...
8924 if (!strcmp(uri
->name
, "printer-uri"))
8927 * Got a printer URI; see if we also have a job-id attribute...
8930 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8931 IPP_TAG_INTEGER
)) == NULL
)
8933 send_ipp_status(con
, IPP_BAD_REQUEST
,
8934 _("Got a printer-uri attribute but no job-id."));
8938 jobid
= attr
->values
[0].integer
;
8943 * Got a job URI; parse it to get the job ID...
8946 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8947 sizeof(scheme
), username
, sizeof(username
), host
,
8948 sizeof(host
), &port
, resource
, sizeof(resource
));
8950 if (strncmp(resource
, "/jobs/", 6))
8956 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
8957 uri
->values
[0].string
.text
);
8961 jobid
= atoi(resource
+ 6);
8965 * See if the job exists...
8968 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8971 * Nope - return a "not found" error...
8974 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
8979 * See if job is "held"...
8982 if (job
->state_value
!= IPP_JOB_HELD
)
8985 * Nope - return a "not possible" error...
8988 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not held."), jobid
);
8993 * See if the job is owned by the requesting user...
8996 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8998 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8999 cupsdFindDest(job
->dest
));
9004 * Reset the job-hold-until value to "no-hold"...
9007 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9008 IPP_TAG_KEYWORD
)) == NULL
)
9009 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9013 ippSetValueTag(job
->attrs
, &attr
, IPP_TAG_KEYWORD
);
9014 ippSetString(job
->attrs
, &attr
, 0, "no-hold");
9016 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
9017 "Job job-hold-until value changed by user.");
9018 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
9022 * Release the job and return...
9025 cupsdReleaseJob(job
);
9027 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
9028 "Job released by user.");
9030 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Released by \"%s\".", username
);
9032 con
->response
->request
.status
.status_code
= IPP_OK
;
9039 * 'renew_subscription()' - Renew an existing subscription...
9044 cupsd_client_t
*con
, /* I - Client connection */
9045 int sub_id
) /* I - Subscription ID */
9047 http_status_t status
; /* Policy status */
9048 cupsd_subscription_t
*sub
; /* Subscription */
9049 ipp_attribute_t
*lease
; /* notify-lease-duration */
9052 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
9053 "renew_subscription(con=%p[%d], sub_id=%d)",
9054 con
, con
->number
, sub_id
);
9057 * Is the subscription ID valid?
9060 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
9063 * Bad subscription ID...
9066 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
9074 * Job subscriptions cannot be renewed...
9077 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9078 _("Job subscriptions cannot be renewed."));
9086 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
9088 con
, sub
->owner
)) != HTTP_OK
)
9090 send_http_error(con
, status
, sub
->dest
);
9095 * Renew the subscription...
9098 lease
= ippFindAttribute(con
->request
, "notify-lease-duration",
9101 sub
->lease
= lease
? lease
->values
[0].integer
: DefaultLeaseDuration
;
9103 if (MaxLeaseDuration
&& (sub
->lease
== 0 || sub
->lease
> MaxLeaseDuration
))
9105 cupsdLogMessage(CUPSD_LOG_INFO
,
9106 "renew_subscription: Limiting notify-lease-duration to "
9109 sub
->lease
= MaxLeaseDuration
;
9112 sub
->expire
= sub
->lease
? time(NULL
) + sub
->lease
: 0;
9114 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
9116 con
->response
->request
.status
.status_code
= IPP_OK
;
9118 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
9119 "notify-lease-duration", sub
->lease
);
9124 * 'restart_job()' - Restart an old print job.
9128 restart_job(cupsd_client_t
*con
, /* I - Client connection */
9129 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9131 ipp_attribute_t
*attr
; /* Current attribute */
9132 int jobid
; /* Job ID */
9133 cupsd_job_t
*job
; /* Job information */
9134 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9135 username
[HTTP_MAX_URI
], /* Username portion of URI */
9136 host
[HTTP_MAX_URI
], /* Host portion of URI */
9137 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9138 int port
; /* Port portion of URI */
9141 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "restart_job(%p[%d], %s)", con
,
9142 con
->number
, uri
->values
[0].string
.text
);
9145 * See if we have a job URI or a printer URI...
9148 if (!strcmp(uri
->name
, "printer-uri"))
9151 * Got a printer URI; see if we also have a job-id attribute...
9154 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9155 IPP_TAG_INTEGER
)) == NULL
)
9157 send_ipp_status(con
, IPP_BAD_REQUEST
,
9158 _("Got a printer-uri attribute but no job-id."));
9162 jobid
= attr
->values
[0].integer
;
9167 * Got a job URI; parse it to get the job ID...
9170 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9171 sizeof(scheme
), username
, sizeof(username
), host
,
9172 sizeof(host
), &port
, resource
, sizeof(resource
));
9174 if (strncmp(resource
, "/jobs/", 6))
9180 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9181 uri
->values
[0].string
.text
);
9185 jobid
= atoi(resource
+ 6);
9189 * See if the job exists...
9192 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9195 * Nope - return a "not found" error...
9198 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9203 * See if job is in any of the "completed" states...
9206 if (job
->state_value
<= IPP_JOB_PROCESSING
)
9209 * Nope - return a "not possible" error...
9212 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not complete."),
9218 * See if we have retained the job files...
9223 if (!job
->attrs
|| job
->num_files
== 0)
9226 * Nope - return a "not possible" error...
9229 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9230 _("Job #%d cannot be restarted - no files."), jobid
);
9235 * See if the job is owned by the requesting user...
9238 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9240 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9241 cupsdFindDest(job
->dest
));
9246 * See if the job-hold-until attribute is specified...
9249 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
9250 IPP_TAG_KEYWORD
)) == NULL
)
9251 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
9253 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
9256 * Return the job to a held state...
9259 cupsdLogJob(job
, CUPSD_LOG_DEBUG
,
9260 "Restarted by \"%s\" with job-hold-until=%s.",
9261 username
, attr
->values
[0].string
.text
);
9262 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
9264 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
,
9265 NULL
, job
, "Job restarted by user with job-hold-until=%s",
9266 attr
->values
[0].string
.text
);
9271 * Restart the job...
9274 cupsdRestartJob(job
);
9278 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Restarted by \"%s\".", username
);
9280 con
->response
->request
.status
.status_code
= IPP_OK
;
9285 * 'save_auth_info()' - Save authentication information for a job.
9290 cupsd_client_t
*con
, /* I - Client connection */
9291 cupsd_job_t
*job
, /* I - Job */
9292 ipp_attribute_t
*auth_info
) /* I - auth-info attribute, if any */
9294 int i
; /* Looping var */
9295 char filename
[1024]; /* Job authentication filename */
9296 cups_file_t
*fp
; /* Job authentication file */
9297 char line
[65536]; /* Line for file */
9298 cupsd_printer_t
*dest
; /* Destination printer/class */
9302 * This function saves the in-memory authentication information for
9303 * a job so that it can be used to authenticate with a remote host.
9304 * The information is stored in a file that is readable only by the
9305 * root user. The fields are Base-64 encoded, each on a separate line,
9306 * followed by random number (up to 1024) of newlines to limit the
9307 * amount of information that is exposed.
9309 * Because of the potential for exposing of authentication information,
9310 * this functionality is only enabled when running cupsd as root.
9312 * This caching only works for the Basic and BasicDigest authentication
9313 * types. Digest authentication cannot be cached this way, and in
9314 * the future Kerberos authentication may make all of this obsolete.
9316 * Authentication information is saved whenever an authenticated
9317 * Print-Job, Create-Job, or CUPS-Authenticate-Job operation is
9320 * This information is deleted after a job is completed or canceled,
9321 * so reprints may require subsequent re-authentication.
9327 if ((dest
= cupsdFindDest(job
->dest
)) == NULL
)
9331 * Create the authentication file and change permissions...
9334 snprintf(filename
, sizeof(filename
), "%s/a%05d", RequestRoot
, job
->id
);
9335 if ((fp
= cupsFileOpen(filename
, "w")) == NULL
)
9337 cupsdLogMessage(CUPSD_LOG_ERROR
,
9338 "Unable to save authentication info to \"%s\" - %s",
9339 filename
, strerror(errno
));
9343 fchown(cupsFileNumber(fp
), 0, 0);
9344 fchmod(cupsFileNumber(fp
), 0400);
9346 cupsFilePuts(fp
, "CUPSD-AUTH-V3\n");
9349 i
< (int)(sizeof(job
->auth_env
) / sizeof(job
->auth_env
[0]));
9351 cupsdClearString(job
->auth_env
+ i
);
9353 if (auth_info
&& auth_info
->num_values
== dest
->num_auth_info_required
)
9356 * Write 1 to 3 auth values...
9360 i
< auth_info
->num_values
&&
9361 i
< (int)(sizeof(job
->auth_env
) / sizeof(job
->auth_env
[0]));
9364 if (strcmp(dest
->auth_info_required
[i
], "negotiate"))
9366 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[i
].string
.text
, (int)strlen(auth_info
->values
[i
].string
.text
));
9367 cupsFilePutConf(fp
, dest
->auth_info_required
[i
], line
);
9370 cupsFilePutConf(fp
, dest
->auth_info_required
[i
],
9371 auth_info
->values
[i
].string
.text
);
9373 if (!strcmp(dest
->auth_info_required
[i
], "username"))
9374 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_USERNAME=%s",
9375 auth_info
->values
[i
].string
.text
);
9376 else if (!strcmp(dest
->auth_info_required
[i
], "domain"))
9377 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_DOMAIN=%s",
9378 auth_info
->values
[i
].string
.text
);
9379 else if (!strcmp(dest
->auth_info_required
[i
], "password"))
9380 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_PASSWORD=%s",
9381 auth_info
->values
[i
].string
.text
);
9382 else if (!strcmp(dest
->auth_info_required
[i
], "negotiate"))
9383 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_NEGOTIATE=%s",
9384 auth_info
->values
[i
].string
.text
);
9389 else if (auth_info
&& auth_info
->num_values
== 2 &&
9390 dest
->num_auth_info_required
== 1 &&
9391 !strcmp(dest
->auth_info_required
[0], "negotiate"))
9394 * Allow fallback to username+password for Kerberized queues...
9397 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[0].string
.text
, (int)strlen(auth_info
->values
[0].string
.text
));
9398 cupsFilePutConf(fp
, "username", line
);
9400 cupsdSetStringf(job
->auth_env
+ 0, "AUTH_USERNAME=%s",
9401 auth_info
->values
[0].string
.text
);
9403 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[1].string
.text
, (int)strlen(auth_info
->values
[1].string
.text
));
9404 cupsFilePutConf(fp
, "password", line
);
9406 cupsdSetStringf(job
->auth_env
+ 1, "AUTH_PASSWORD=%s",
9407 auth_info
->values
[1].string
.text
);
9409 else if (con
->username
[0])
9412 * Write the authenticated username...
9415 httpEncode64_2(line
, sizeof(line
), con
->username
, (int)strlen(con
->username
));
9416 cupsFilePutConf(fp
, "username", line
);
9418 cupsdSetStringf(job
->auth_env
+ 0, "AUTH_USERNAME=%s", con
->username
);
9421 * Write the authenticated password...
9424 httpEncode64_2(line
, sizeof(line
), con
->password
, (int)strlen(con
->password
));
9425 cupsFilePutConf(fp
, "password", line
);
9427 cupsdSetStringf(job
->auth_env
+ 1, "AUTH_PASSWORD=%s", con
->password
);
9431 if (con
->gss_uid
> 0)
9433 cupsFilePrintf(fp
, "uid %d\n", (int)con
->gss_uid
);
9434 cupsdSetStringf(&job
->auth_uid
, "AUTH_UID=%d", (int)con
->gss_uid
);
9436 #endif /* HAVE_GSSAPI */
9439 * Write a random number of newlines to the end of the file...
9442 for (i
= (CUPS_RAND() % 1024); i
>= 0; i
--)
9443 cupsFilePutChar(fp
, '\n');
9446 * Close the file and return...
9454 * 'send_document()' - Send a file to a printer or class.
9458 send_document(cupsd_client_t
*con
, /* I - Client connection */
9459 ipp_attribute_t
*uri
) /* I - Printer URI */
9461 ipp_attribute_t
*attr
; /* Current attribute */
9462 ipp_attribute_t
*format
; /* Request's document-format attribute */
9463 ipp_attribute_t
*jformat
; /* Job's document-format attribute */
9464 const char *default_format
;/* document-format-default value */
9465 int jobid
; /* Job ID number */
9466 cupsd_job_t
*job
; /* Current job */
9467 char job_uri
[HTTP_MAX_URI
],
9469 scheme
[HTTP_MAX_URI
],
9470 /* Method portion of URI */
9471 username
[HTTP_MAX_URI
],
9472 /* Username portion of URI */
9474 /* Host portion of URI */
9475 resource
[HTTP_MAX_URI
];
9476 /* Resource portion of URI */
9477 int port
; /* Port portion of URI */
9478 mime_type_t
*filetype
; /* Type of file */
9479 char super
[MIME_MAX_SUPER
],
9480 /* Supertype of file */
9481 type
[MIME_MAX_TYPE
],
9482 /* Subtype of file */
9483 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
9484 /* Textual name of mime type */
9485 char filename
[1024]; /* Job filename */
9486 cupsd_printer_t
*printer
; /* Current printer */
9487 struct stat fileinfo
; /* File information */
9488 int kbytes
; /* Size of file */
9489 int compression
; /* Type of compression */
9490 int start_job
; /* Start the job? */
9493 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "send_document(%p[%d], %s)", con
,
9494 con
->number
, uri
->values
[0].string
.text
);
9497 * See if we have a job URI or a printer URI...
9500 if (!strcmp(uri
->name
, "printer-uri"))
9503 * Got a printer URI; see if we also have a job-id attribute...
9506 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9507 IPP_TAG_INTEGER
)) == NULL
)
9509 send_ipp_status(con
, IPP_BAD_REQUEST
,
9510 _("Got a printer-uri attribute but no job-id."));
9514 jobid
= attr
->values
[0].integer
;
9519 * Got a job URI; parse it to get the job ID...
9522 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9523 sizeof(scheme
), username
, sizeof(username
), host
,
9524 sizeof(host
), &port
, resource
, sizeof(resource
));
9526 if (strncmp(resource
, "/jobs/", 6))
9532 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9533 uri
->values
[0].string
.text
);
9537 jobid
= atoi(resource
+ 6);
9541 * See if the job exists...
9544 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9547 * Nope - return a "not found" error...
9550 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9554 printer
= cupsdFindDest(job
->dest
);
9557 * See if the job is owned by the requesting user...
9560 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9562 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9563 cupsdFindDest(job
->dest
));
9568 * OK, see if the client is sending the document compressed - CUPS
9569 * only supports "none" and "gzip".
9572 compression
= CUPS_FILE_NONE
;
9574 if ((attr
= ippFindAttribute(con
->request
, "compression",
9575 IPP_TAG_KEYWORD
)) != NULL
)
9577 if (strcmp(attr
->values
[0].string
.text
, "none")
9579 && strcmp(attr
->values
[0].string
.text
, "gzip")
9580 #endif /* HAVE_LIBZ */
9583 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Unsupported compression \"%s\"."),
9584 attr
->values
[0].string
.text
);
9585 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
9586 "compression", NULL
, attr
->values
[0].string
.text
);
9591 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
9592 compression
= CUPS_FILE_GZIP
;
9593 #endif /* HAVE_LIBZ */
9597 * Do we have a file to print?
9600 if ((attr
= ippFindAttribute(con
->request
, "last-document",
9601 IPP_TAG_BOOLEAN
)) == NULL
)
9603 send_ipp_status(con
, IPP_BAD_REQUEST
,
9604 _("Missing last-document attribute in request."));
9611 * Check for an empty request with "last-document" set to true, which is
9612 * used to close an "open" job by RFC 2911, section 3.3.2.
9615 if (job
->num_files
> 0 && attr
->values
[0].boolean
)
9618 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file in print request."));
9623 * Is it a format we support?
9628 if ((format
= ippFindAttribute(con
->request
, "document-format",
9629 IPP_TAG_MIMETYPE
)) != NULL
)
9632 * Grab format from client...
9635 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%255[^;]",
9638 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"."),
9639 format
->values
[0].string
.text
);
9643 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format-supplied", NULL
, ippGetString(format
, 0, NULL
));
9645 else if ((default_format
= cupsGetOption("document-format",
9646 printer
->num_options
,
9647 printer
->options
)) != NULL
)
9650 * Use default document format...
9653 if (sscanf(default_format
, "%15[^/]/%255[^;]", super
, type
) != 2)
9655 send_ipp_status(con
, IPP_BAD_REQUEST
,
9656 _("Bad document-format-default \"%s\"."), default_format
);
9663 * No document format attribute? Auto-type it!
9666 strlcpy(super
, "application", sizeof(super
));
9667 strlcpy(type
, "octet-stream", sizeof(type
));
9670 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
9673 * Auto-type the file...
9676 ipp_attribute_t
*doc_name
; /* document-name attribute */
9679 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Auto-typing file...");
9681 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
9682 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
9683 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
9687 filetype
= mimeType(MimeDatabase
, super
, type
);
9690 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Request file type is %s/%s.",
9691 filetype
->super
, filetype
->type
);
9693 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
, filetype
->type
);
9694 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format-detected", NULL
, mimetype
);
9697 filetype
= mimeType(MimeDatabase
, super
, type
);
9702 * Replace the document-format attribute value with the auto-typed or
9706 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9709 if ((jformat
= ippFindAttribute(job
->attrs
, "document-format",
9710 IPP_TAG_MIMETYPE
)) != NULL
)
9711 ippSetString(job
->attrs
, &jformat
, 0, mimetype
);
9713 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
9714 "document-format", NULL
, mimetype
);
9718 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9719 _("Unsupported document-format \"%s/%s\"."), super
, type
);
9720 cupsdLogMessage(CUPSD_LOG_INFO
,
9721 "Hint: Do you have the raw file printing rules enabled?");
9724 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9725 "document-format", NULL
, format
->values
[0].string
.text
);
9730 if (printer
->filetypes
&& !cupsArrayFind(printer
->filetypes
, filetype
))
9732 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9735 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9736 _("Unsupported document-format \"%s\"."), mimetype
);
9738 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9739 "document-format", NULL
, mimetype
);
9745 * Add the file to the job...
9748 if (add_file(con
, job
, filetype
, compression
))
9751 if ((attr
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
)) != NULL
)
9752 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name-supplied", NULL
, ippGetString(attr
, 0, NULL
));
9754 if (stat(con
->filename
, &fileinfo
))
9757 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
9759 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
9761 job
->koctets
+= kbytes
;
9763 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets", IPP_TAG_INTEGER
)) != NULL
)
9764 attr
->values
[0].integer
+= kbytes
;
9766 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
, job
->num_files
);
9767 if (rename(con
->filename
, filename
))
9769 cupsdLogJob(job
, CUPSD_LOG_ERROR
, "Unable to rename job document file \"%s\": %s", filename
, strerror(errno
));
9771 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to rename job document file."));
9775 cupsdClearString(&con
->filename
);
9777 cupsdLogJob(job
, CUPSD_LOG_INFO
, "File of type %s/%s queued by \"%s\".",
9778 filetype
->super
, filetype
->type
, job
->username
);
9781 * Start the job if this is the last document...
9786 if ((attr
= ippFindAttribute(con
->request
, "last-document",
9787 IPP_TAG_BOOLEAN
)) != NULL
&&
9788 attr
->values
[0].boolean
)
9791 * See if we need to add the ending sheet...
9794 if (cupsdTimeoutJob(job
))
9797 if (job
->state_value
== IPP_JOB_STOPPED
)
9799 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9800 job
->state_value
= IPP_JOB_PENDING
;
9802 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
9804 else if (job
->state_value
== IPP_JOB_HELD
)
9806 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9807 IPP_TAG_KEYWORD
)) == NULL
)
9808 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9810 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9812 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9813 job
->state_value
= IPP_JOB_PENDING
;
9815 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
9818 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-hold-until-specified");
9822 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
9828 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9829 IPP_TAG_KEYWORD
)) == NULL
)
9830 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9832 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9834 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
9835 job
->state_value
= IPP_JOB_HELD
;
9836 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
9838 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-incoming");
9841 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
9848 * Fill in the response info...
9851 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
9852 con
->clientname
, con
->clientport
, "/jobs/%d", jobid
);
9853 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
9856 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", jobid
);
9858 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
9860 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons",
9861 NULL
, job
->reasons
->values
[0].string
.text
);
9863 con
->response
->request
.status
.status_code
= IPP_OK
;
9866 * Start the job if necessary...
9875 * 'send_http_error()' - Send a HTTP error back to the IPP client.
9880 cupsd_client_t
*con
, /* I - Client connection */
9881 http_status_t status
, /* I - HTTP status code */
9882 cupsd_printer_t
*printer
) /* I - Printer, if any */
9884 ipp_attribute_t
*uri
; /* Request URI, if any */
9887 if ((uri
= ippFindAttribute(con
->request
, "printer-uri",
9888 IPP_TAG_URI
)) == NULL
)
9889 uri
= ippFindAttribute(con
->request
, "job-uri", IPP_TAG_URI
);
9891 cupsdLogMessage(status
== HTTP_FORBIDDEN
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
9892 "[Client %d] Returning HTTP %s for %s (%s) from %s",
9893 con
->number
, httpStatus(status
),
9895 ippOpString(con
->request
->request
.op
.operation_id
) :
9897 uri
? uri
->values
[0].string
.text
: "no URI",
9898 con
->http
->hostname
);
9902 int auth_type
; /* Type of authentication required */
9905 auth_type
= CUPSD_AUTH_NONE
;
9907 if (status
== HTTP_UNAUTHORIZED
&&
9908 printer
->num_auth_info_required
> 0 &&
9909 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
9911 (con
->request
->request
.op
.operation_id
== IPP_PRINT_JOB
||
9912 con
->request
->request
.op
.operation_id
== IPP_CREATE_JOB
||
9913 con
->request
->request
.op
.operation_id
== CUPS_AUTHENTICATE_JOB
))
9916 * Creating and authenticating jobs requires Kerberos...
9919 auth_type
= CUPSD_AUTH_NEGOTIATE
;
9924 * Use policy/location-defined authentication requirements...
9927 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9928 cupsd_location_t
*auth
; /* Pointer to authentication element */
9931 if (printer
->type
& CUPS_PRINTER_CLASS
)
9932 snprintf(resource
, sizeof(resource
), "/classes/%s", printer
->name
);
9934 snprintf(resource
, sizeof(resource
), "/printers/%s", printer
->name
);
9936 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
9937 auth
->type
== CUPSD_AUTH_NONE
)
9938 auth
= cupsdFindPolicyOp(printer
->op_policy_ptr
,
9940 con
->request
->request
.op
.operation_id
:
9945 if (auth
->type
== CUPSD_AUTH_DEFAULT
)
9946 auth_type
= cupsdDefaultAuthType();
9948 auth_type
= auth
->type
;
9952 cupsdSendError(con
, status
, auth_type
);
9955 cupsdSendError(con
, status
, CUPSD_AUTH_NONE
);
9957 ippDelete(con
->response
);
9958 con
->response
= NULL
;
9965 * 'send_ipp_status()' - Send a status back to the IPP client.
9969 send_ipp_status(cupsd_client_t
*con
, /* I - Client connection */
9970 ipp_status_t status
, /* I - IPP status code */
9971 const char *message
,/* I - Status message */
9972 ...) /* I - Additional args as needed */
9974 va_list ap
; /* Pointer to additional args */
9975 char formatted
[1024]; /* Formatted errror message */
9978 va_start(ap
, message
);
9979 vsnprintf(formatted
, sizeof(formatted
),
9980 _cupsLangString(con
->language
, message
), ap
);
9983 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s: %s",
9984 ippOpString(con
->request
->request
.op
.operation_id
),
9985 ippErrorString(status
), formatted
);
9987 con
->response
->request
.status
.status_code
= status
;
9989 if (ippFindAttribute(con
->response
, "attributes-charset",
9990 IPP_TAG_ZERO
) == NULL
)
9991 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
9992 "attributes-charset", NULL
, "utf-8");
9994 if (ippFindAttribute(con
->response
, "attributes-natural-language",
9995 IPP_TAG_ZERO
) == NULL
)
9996 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
9997 "attributes-natural-language", NULL
, DefaultLanguage
);
9999 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
10000 "status-message", NULL
, formatted
);
10005 * 'set_default()' - Set the default destination...
10009 set_default(cupsd_client_t
*con
, /* I - Client connection */
10010 ipp_attribute_t
*uri
) /* I - Printer URI */
10012 http_status_t status
; /* Policy status */
10013 cups_ptype_t dtype
; /* Destination type (printer/class) */
10014 cupsd_printer_t
*printer
, /* Printer */
10015 *oldprinter
; /* Old default printer */
10018 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_default(%p[%d], %s)", con
,
10019 con
->number
, uri
->values
[0].string
.text
);
10022 * Is the destination valid?
10025 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10031 send_ipp_status(con
, IPP_NOT_FOUND
,
10032 _("The printer or class does not exist."));
10040 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
10042 send_http_error(con
, status
, NULL
);
10047 * Set it as the default...
10050 oldprinter
= DefaultPrinter
;
10051 DefaultPrinter
= printer
;
10054 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, oldprinter
, NULL
,
10055 "%s is no longer the default printer.", oldprinter
->name
);
10057 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
10058 "%s is now the default printer.", printer
->name
);
10060 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
| CUPSD_DIRTY_CLASSES
|
10061 CUPSD_DIRTY_PRINTCAP
);
10063 cupsdLogMessage(CUPSD_LOG_INFO
,
10064 "Default destination set to \"%s\" by \"%s\".",
10065 printer
->name
, get_username(con
));
10068 * Everything was ok, so return OK status...
10071 con
->response
->request
.status
.status_code
= IPP_OK
;
10076 * 'set_job_attrs()' - Set job attributes.
10080 set_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
10081 ipp_attribute_t
*uri
) /* I - Job URI */
10083 ipp_attribute_t
*attr
, /* Current attribute */
10084 *attr2
; /* Job attribute */
10085 int jobid
; /* Job ID */
10086 cupsd_job_t
*job
; /* Current job */
10087 char scheme
[HTTP_MAX_URI
],
10088 /* Method portion of URI */
10089 username
[HTTP_MAX_URI
],
10090 /* Username portion of URI */
10091 host
[HTTP_MAX_URI
],
10092 /* Host portion of URI */
10093 resource
[HTTP_MAX_URI
];
10094 /* Resource portion of URI */
10095 int port
; /* Port portion of URI */
10096 int event
; /* Events? */
10097 int check_jobs
; /* Check jobs? */
10100 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_job_attrs(%p[%d], %s)", con
,
10101 con
->number
, uri
->values
[0].string
.text
);
10104 * Start with "everything is OK" status...
10107 con
->response
->request
.status
.status_code
= IPP_OK
;
10110 * See if we have a job URI or a printer URI...
10113 if (!strcmp(uri
->name
, "printer-uri"))
10116 * Got a printer URI; see if we also have a job-id attribute...
10119 if ((attr
= ippFindAttribute(con
->request
, "job-id",
10120 IPP_TAG_INTEGER
)) == NULL
)
10122 send_ipp_status(con
, IPP_BAD_REQUEST
,
10123 _("Got a printer-uri attribute but no job-id."));
10127 jobid
= attr
->values
[0].integer
;
10132 * Got a job URI; parse it to get the job ID...
10135 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
10136 sizeof(scheme
), username
, sizeof(username
), host
,
10137 sizeof(host
), &port
, resource
, sizeof(resource
));
10139 if (strncmp(resource
, "/jobs/", 6))
10145 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
10146 uri
->values
[0].string
.text
);
10150 jobid
= atoi(resource
+ 6);
10154 * See if the job exists...
10157 if ((job
= cupsdFindJob(jobid
)) == NULL
)
10160 * Nope - return a "not found" error...
10163 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
10168 * See if the job has been completed...
10171 if (job
->state_value
> IPP_JOB_STOPPED
)
10174 * Return a "not-possible" error...
10177 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10178 _("Job #%d is finished and cannot be altered."), jobid
);
10183 * See if the job is owned by the requesting user...
10186 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10188 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
10189 cupsdFindDest(job
->dest
));
10194 * See what the user wants to change.
10202 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10204 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
10207 if (!strcmp(attr
->name
, "attributes-charset") ||
10208 !strcmp(attr
->name
, "attributes-natural-language") ||
10209 !strncmp(attr
->name
, "date-time-at-", 13) ||
10210 !strncmp(attr
->name
, "document-compression", 20) ||
10211 !strncmp(attr
->name
, "document-format", 15) ||
10212 !strcmp(attr
->name
, "job-detailed-status-messages") ||
10213 !strcmp(attr
->name
, "job-document-access-errors") ||
10214 !strcmp(attr
->name
, "job-id") ||
10215 !strcmp(attr
->name
, "job-impressions-completed") ||
10216 !strcmp(attr
->name
, "job-k-octets-completed") ||
10217 !strcmp(attr
->name
, "job-media-sheets-completed") ||
10218 !strcmp(attr
->name
, "job-originating-host-name") ||
10219 !strcmp(attr
->name
, "job-originating-user-name") ||
10220 !strcmp(attr
->name
, "job-pages-completed") ||
10221 !strcmp(attr
->name
, "job-printer-up-time") ||
10222 !strcmp(attr
->name
, "job-printer-uri") ||
10223 !strcmp(attr
->name
, "job-sheets") ||
10224 !strcmp(attr
->name
, "job-state-message") ||
10225 !strcmp(attr
->name
, "job-state-reasons") ||
10226 !strcmp(attr
->name
, "job-uri") ||
10227 !strcmp(attr
->name
, "number-of-documents") ||
10228 !strcmp(attr
->name
, "number-of-intervening-jobs") ||
10229 !strcmp(attr
->name
, "output-device-assigned") ||
10230 !strncmp(attr
->name
, "time-at-", 8))
10236 send_ipp_status(con
, IPP_ATTRIBUTES_NOT_SETTABLE
,
10237 _("%s cannot be changed."), attr
->name
);
10239 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
10240 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
10244 if (!strcmp(attr
->name
, "job-priority"))
10247 * Change the job priority...
10250 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10252 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-priority value."));
10254 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
10255 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
10257 else if (job
->state_value
>= IPP_JOB_PROCESSING
)
10259 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10260 _("Job is completed and cannot be changed."));
10263 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10265 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-priority to %d",
10266 attr
->values
[0].integer
);
10267 cupsdSetJobPriority(job
, attr
->values
[0].integer
);
10270 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
|
10271 CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
;
10274 else if (!strcmp(attr
->name
, "job-state"))
10277 * Change the job state...
10280 if (attr
->value_tag
!= IPP_TAG_ENUM
)
10282 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-state value."));
10284 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
10285 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
10289 switch (attr
->values
[0].integer
)
10291 case IPP_JOB_PENDING
:
10292 case IPP_JOB_HELD
:
10293 if (job
->state_value
> IPP_JOB_HELD
)
10295 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10296 _("Job state cannot be changed."));
10299 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10301 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10302 attr
->values
[0].integer
);
10303 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
, CUPSD_JOB_DEFAULT
, "Job state changed by \"%s\"", username
);
10308 case IPP_JOB_PROCESSING
:
10309 case IPP_JOB_STOPPED
:
10310 if (job
->state_value
!= attr
->values
[0].integer
)
10312 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10313 _("Job state cannot be changed."));
10318 case IPP_JOB_CANCELED
:
10319 case IPP_JOB_ABORTED
:
10320 case IPP_JOB_COMPLETED
:
10321 if (job
->state_value
> IPP_JOB_PROCESSING
)
10323 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10324 _("Job state cannot be changed."));
10327 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10329 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10330 attr
->values
[0].integer
);
10331 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
,
10333 "Job state changed by \"%s\"", username
);
10340 else if (con
->response
->request
.status
.status_code
!= IPP_OK
)
10342 else if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10343 IPP_TAG_ZERO
)) != NULL
)
10346 * Some other value; first free the old value...
10349 if (job
->attrs
->prev
)
10350 job
->attrs
->prev
->next
= attr2
->next
;
10352 job
->attrs
->attrs
= attr2
->next
;
10354 if (job
->attrs
->last
== attr2
)
10355 job
->attrs
->last
= job
->attrs
->prev
;
10357 ippDeleteAttribute(NULL
, attr2
);
10360 * Then copy the attribute...
10363 ippCopyAttribute(job
->attrs
, attr
, 0);
10366 * See if the job-name or job-hold-until is being changed.
10369 if (!strcmp(attr
->name
, "job-hold-until"))
10371 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-hold-until to %s",
10372 attr
->values
[0].string
.text
);
10373 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
10375 if (!strcmp(attr
->values
[0].string
.text
, "no-hold"))
10377 cupsdReleaseJob(job
);
10381 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
,
10382 "Job held by \"%s\".", username
);
10384 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
;
10387 else if (attr
->value_tag
== IPP_TAG_DELETEATTR
)
10390 * Delete the attribute...
10393 if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10394 IPP_TAG_ZERO
)) != NULL
)
10396 if (job
->attrs
->prev
)
10397 job
->attrs
->prev
->next
= attr2
->next
;
10399 job
->attrs
->attrs
= attr2
->next
;
10401 if (attr2
== job
->attrs
->last
)
10402 job
->attrs
->last
= job
->attrs
->prev
;
10404 ippDeleteAttribute(NULL
, attr2
);
10406 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10412 * Add new option by copying it...
10415 ippCopyAttribute(job
->attrs
, attr
, 0);
10417 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10426 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10429 * Send events as needed...
10432 if (event
& CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
)
10433 cupsdAddEvent(CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
,
10434 cupsdFindDest(job
->dest
), job
,
10435 "Job priority changed by user.");
10437 if (event
& CUPSD_EVENT_JOB_STATE
)
10438 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
10439 job
->state_value
== IPP_JOB_HELD
?
10440 "Job held by user." : "Job restarted by user.");
10442 if (event
& CUPSD_EVENT_JOB_CONFIG_CHANGED
)
10443 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
10444 "Job options changed by user.");
10447 * Start jobs if possible...
10456 * 'set_printer_attrs()' - Set printer attributes.
10460 set_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
10461 ipp_attribute_t
*uri
) /* I - Printer */
10463 http_status_t status
; /* Policy status */
10464 cups_ptype_t dtype
; /* Destination type (printer/class) */
10465 cupsd_printer_t
*printer
; /* Printer/class */
10466 ipp_attribute_t
*attr
; /* Printer attribute */
10467 int changed
= 0; /* Was anything changed? */
10470 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_attrs(%p[%d], %s)", con
,
10471 con
->number
, uri
->values
[0].string
.text
);
10474 * Is the destination valid?
10477 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10483 send_ipp_status(con
, IPP_NOT_FOUND
,
10484 _("The printer or class does not exist."));
10492 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10494 send_http_error(con
, status
, printer
);
10499 * Return a list of attributes that can be set via Set-Printer-Attributes.
10502 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
10503 IPP_TAG_TEXT
)) != NULL
)
10505 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
10509 if ((attr
= ippFindAttribute(con
->request
, "printer-geo-location", IPP_TAG_URI
)) != NULL
&& !strncmp(attr
->values
[0].string
.text
, "geo:", 4))
10511 cupsdSetString(&printer
->geo_location
, attr
->values
[0].string
.text
);
10515 if ((attr
= ippFindAttribute(con
->request
, "printer-organization", IPP_TAG_TEXT
)) != NULL
)
10517 cupsdSetString(&printer
->organization
, attr
->values
[0].string
.text
);
10521 if ((attr
= ippFindAttribute(con
->request
, "printer-organizational-unit", IPP_TAG_TEXT
)) != NULL
)
10523 cupsdSetString(&printer
->organizational_unit
, attr
->values
[0].string
.text
);
10527 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
10528 IPP_TAG_TEXT
)) != NULL
)
10530 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
10535 * Update the printer attributes and return...
10540 printer
->config_time
= time(NULL
);
10542 cupsdSetPrinterAttrs(printer
);
10543 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
10545 cupsdAddEvent(CUPSD_EVENT_PRINTER_CONFIG
, printer
, NULL
,
10546 "Printer \"%s\" description or location changed by \"%s\".",
10547 printer
->name
, get_username(con
));
10549 cupsdLogMessage(CUPSD_LOG_INFO
,
10550 "Printer \"%s\" description or location changed by \"%s\".",
10551 printer
->name
, get_username(con
));
10554 con
->response
->request
.status
.status_code
= IPP_OK
;
10559 * 'set_printer_defaults()' - Set printer default options from a request.
10563 set_printer_defaults(
10564 cupsd_client_t
*con
, /* I - Client connection */
10565 cupsd_printer_t
*printer
) /* I - Printer */
10567 int i
; /* Looping var */
10568 ipp_attribute_t
*attr
; /* Current attribute */
10569 size_t namelen
; /* Length of attribute name */
10570 char name
[256], /* New attribute name */
10571 value
[256]; /* String version of integer attrs */
10574 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10577 * Skip non-printer attributes...
10580 if (attr
->group_tag
!= IPP_TAG_PRINTER
|| !attr
->name
)
10583 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_defaults: %s", attr
->name
);
10585 if (!strcmp(attr
->name
, "job-sheets-default"))
10588 * Only allow keywords and names...
10591 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10595 * Only allow job-sheets-default to be set when running without a
10596 * system high classification level...
10599 if (Classification
)
10602 cupsdSetString(&printer
->job_sheets
[0], attr
->values
[0].string
.text
);
10604 if (attr
->num_values
> 1)
10605 cupsdSetString(&printer
->job_sheets
[1], attr
->values
[1].string
.text
);
10607 cupsdSetString(&printer
->job_sheets
[1], "none");
10609 else if (!strcmp(attr
->name
, "requesting-user-name-allowed"))
10611 cupsdFreeStrings(&(printer
->users
));
10613 printer
->deny_users
= 0;
10615 if (attr
->value_tag
== IPP_TAG_NAME
&&
10616 (attr
->num_values
> 1 ||
10617 strcmp(attr
->values
[0].string
.text
, "all")))
10619 for (i
= 0; i
< attr
->num_values
; i
++)
10620 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
10623 else if (!strcmp(attr
->name
, "requesting-user-name-denied"))
10625 cupsdFreeStrings(&(printer
->users
));
10627 printer
->deny_users
= 1;
10629 if (attr
->value_tag
== IPP_TAG_NAME
&&
10630 (attr
->num_values
> 1 ||
10631 strcmp(attr
->values
[0].string
.text
, "none")))
10633 for (i
= 0; i
< attr
->num_values
; i
++)
10634 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
10637 else if (!strcmp(attr
->name
, "job-quota-period"))
10639 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10642 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-quota-period to %d...",
10643 attr
->values
[0].integer
);
10644 cupsdFreeQuotas(printer
);
10646 printer
->quota_period
= attr
->values
[0].integer
;
10648 else if (!strcmp(attr
->name
, "job-k-limit"))
10650 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10653 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-k-limit to %d...",
10654 attr
->values
[0].integer
);
10655 cupsdFreeQuotas(printer
);
10657 printer
->k_limit
= attr
->values
[0].integer
;
10659 else if (!strcmp(attr
->name
, "job-page-limit"))
10661 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10664 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-page-limit to %d...",
10665 attr
->values
[0].integer
);
10666 cupsdFreeQuotas(printer
);
10668 printer
->page_limit
= attr
->values
[0].integer
;
10670 else if (!strcmp(attr
->name
, "printer-op-policy"))
10672 cupsd_policy_t
*p
; /* Policy */
10675 if (attr
->value_tag
!= IPP_TAG_NAME
)
10678 if ((p
= cupsdFindPolicy(attr
->values
[0].string
.text
)) != NULL
)
10680 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10681 "Setting printer-op-policy to \"%s\"...",
10682 attr
->values
[0].string
.text
);
10683 cupsdSetString(&printer
->op_policy
, attr
->values
[0].string
.text
);
10684 printer
->op_policy_ptr
= p
;
10688 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10689 _("Unknown printer-op-policy \"%s\"."),
10690 attr
->values
[0].string
.text
);
10694 else if (!strcmp(attr
->name
, "printer-error-policy"))
10696 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10699 if (strcmp(attr
->values
[0].string
.text
, "retry-current-job") &&
10700 ((printer
->type
& CUPS_PRINTER_CLASS
) ||
10701 (strcmp(attr
->values
[0].string
.text
, "abort-job") &&
10702 strcmp(attr
->values
[0].string
.text
, "retry-job") &&
10703 strcmp(attr
->values
[0].string
.text
, "stop-printer"))))
10705 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10706 _("Unknown printer-error-policy \"%s\"."),
10707 attr
->values
[0].string
.text
);
10711 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10712 "Setting printer-error-policy to \"%s\"...",
10713 attr
->values
[0].string
.text
);
10714 cupsdSetString(&printer
->error_policy
, attr
->values
[0].string
.text
);
10718 * Skip any other non-default attributes...
10721 namelen
= strlen(attr
->name
);
10722 if (namelen
< 9 || strcmp(attr
->name
+ namelen
- 8, "-default") ||
10723 namelen
> (sizeof(name
) - 1) || attr
->num_values
!= 1)
10727 * OK, anything else must be a user-defined default...
10730 strlcpy(name
, attr
->name
, sizeof(name
));
10731 name
[namelen
- 8] = '\0'; /* Strip "-default" */
10733 switch (attr
->value_tag
)
10735 case IPP_TAG_DELETEATTR
:
10736 printer
->num_options
= cupsRemoveOption(name
,
10737 printer
->num_options
,
10738 &(printer
->options
));
10739 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10740 "Deleting %s", attr
->name
);
10743 case IPP_TAG_NAME
:
10744 case IPP_TAG_TEXT
:
10745 case IPP_TAG_KEYWORD
:
10747 printer
->num_options
= cupsAddOption(name
,
10748 attr
->values
[0].string
.text
,
10749 printer
->num_options
,
10750 &(printer
->options
));
10751 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10752 "Setting %s to \"%s\"...", attr
->name
,
10753 attr
->values
[0].string
.text
);
10756 case IPP_TAG_BOOLEAN
:
10757 printer
->num_options
= cupsAddOption(name
,
10758 attr
->values
[0].boolean
?
10760 printer
->num_options
,
10761 &(printer
->options
));
10762 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10763 "Setting %s to %s...", attr
->name
,
10764 attr
->values
[0].boolean
? "true" : "false");
10767 case IPP_TAG_INTEGER
:
10768 case IPP_TAG_ENUM
:
10769 sprintf(value
, "%d", attr
->values
[0].integer
);
10770 printer
->num_options
= cupsAddOption(name
, value
,
10771 printer
->num_options
,
10772 &(printer
->options
));
10773 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10774 "Setting %s to %s...", attr
->name
, value
);
10777 case IPP_TAG_RANGE
:
10778 sprintf(value
, "%d-%d", attr
->values
[0].range
.lower
,
10779 attr
->values
[0].range
.upper
);
10780 printer
->num_options
= cupsAddOption(name
, value
,
10781 printer
->num_options
,
10782 &(printer
->options
));
10783 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10784 "Setting %s to %s...", attr
->name
, value
);
10787 case IPP_TAG_RESOLUTION
:
10788 sprintf(value
, "%dx%d%s", attr
->values
[0].resolution
.xres
,
10789 attr
->values
[0].resolution
.yres
,
10790 attr
->values
[0].resolution
.units
== IPP_RES_PER_INCH
?
10792 printer
->num_options
= cupsAddOption(name
, value
,
10793 printer
->num_options
,
10794 &(printer
->options
));
10795 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10796 "Setting %s to %s...", attr
->name
, value
);
10800 /* Do nothing for other values */
10808 * 'start_printer()' - Start a printer.
10812 start_printer(cupsd_client_t
*con
, /* I - Client connection */
10813 ipp_attribute_t
*uri
) /* I - Printer URI */
10815 int i
; /* Temporary variable */
10816 http_status_t status
; /* Policy status */
10817 cups_ptype_t dtype
; /* Destination type (printer/class) */
10818 cupsd_printer_t
*printer
; /* Printer data */
10821 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_printer(%p[%d], %s)", con
,
10822 con
->number
, uri
->values
[0].string
.text
);
10825 * Is the destination valid?
10828 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10834 send_ipp_status(con
, IPP_NOT_FOUND
,
10835 _("The printer or class does not exist."));
10843 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10845 send_http_error(con
, status
, printer
);
10850 * Start the printer...
10853 printer
->state_message
[0] = '\0';
10855 cupsdStartPrinter(printer
, 1);
10857 if (dtype
& CUPS_PRINTER_CLASS
)
10858 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" started by \"%s\".",
10859 printer
->name
, get_username(con
));
10861 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" started by \"%s\".",
10862 printer
->name
, get_username(con
));
10870 if ((i
= check_quotas(con
, printer
)) < 0)
10872 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
10877 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
10882 * Everything was ok, so return OK status...
10885 con
->response
->request
.status
.status_code
= IPP_OK
;
10890 * 'stop_printer()' - Stop a printer.
10894 stop_printer(cupsd_client_t
*con
, /* I - Client connection */
10895 ipp_attribute_t
*uri
) /* I - Printer URI */
10897 http_status_t status
; /* Policy status */
10898 cups_ptype_t dtype
; /* Destination type (printer/class) */
10899 cupsd_printer_t
*printer
; /* Printer data */
10900 ipp_attribute_t
*attr
; /* printer-state-message attribute */
10903 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "stop_printer(%p[%d], %s)", con
,
10904 con
->number
, uri
->values
[0].string
.text
);
10907 * Is the destination valid?
10910 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10916 send_ipp_status(con
, IPP_NOT_FOUND
,
10917 _("The printer or class does not exist."));
10925 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10927 send_http_error(con
, status
, printer
);
10932 * Stop the printer...
10935 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
10936 IPP_TAG_TEXT
)) == NULL
)
10937 strlcpy(printer
->state_message
, "Paused", sizeof(printer
->state_message
));
10940 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
10941 sizeof(printer
->state_message
));
10944 cupsdStopPrinter(printer
, 1);
10946 if (dtype
& CUPS_PRINTER_CLASS
)
10947 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" stopped by \"%s\".",
10948 printer
->name
, get_username(con
));
10950 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" stopped by \"%s\".",
10951 printer
->name
, get_username(con
));
10954 * Everything was ok, so return OK status...
10957 con
->response
->request
.status
.status_code
= IPP_OK
;
10962 * 'url_encode_attr()' - URL-encode a string attribute.
10966 url_encode_attr(ipp_attribute_t
*attr
, /* I - Attribute */
10967 char *buffer
,/* I - String buffer */
10968 size_t bufsize
)/* I - Size of buffer */
10970 int i
; /* Looping var */
10971 char *bufptr
, /* Pointer into buffer */
10972 *bufend
; /* End of buffer */
10975 strlcpy(buffer
, attr
->name
, bufsize
);
10976 bufptr
= buffer
+ strlen(buffer
);
10977 bufend
= buffer
+ bufsize
- 1;
10979 for (i
= 0; i
< attr
->num_values
; i
++)
10981 if (bufptr
>= bufend
)
10989 if (bufptr
>= bufend
)
10994 bufptr
= url_encode_string(attr
->values
[i
].string
.text
, bufptr
, (size_t)(bufend
- bufptr
+ 1));
10996 if (bufptr
>= bufend
)
11007 * 'url_encode_string()' - URL-encode a string.
11010 static char * /* O - End of string */
11011 url_encode_string(const char *s
, /* I - String */
11012 char *buffer
, /* I - String buffer */
11013 size_t bufsize
) /* I - Size of buffer */
11015 char *bufptr
, /* Pointer into buffer */
11016 *bufend
; /* End of buffer */
11017 static const char *hex
= "0123456789ABCDEF";
11022 bufend
= buffer
+ bufsize
- 1;
11024 while (*s
&& bufptr
< bufend
)
11026 if (*s
== ' ' || *s
== '%' || *s
== '+')
11028 if (bufptr
>= (bufend
- 2))
11032 *bufptr
++ = hex
[(*s
>> 4) & 15];
11033 *bufptr
++ = hex
[*s
& 15];
11037 else if (*s
== '\'' || *s
== '\\')
11039 if (bufptr
>= (bufend
- 1))
11056 * 'user_allowed()' - See if a user is allowed to print to a queue.
11059 static int /* O - 0 if not allowed, 1 if allowed */
11060 user_allowed(cupsd_printer_t
*p
, /* I - Printer or class */
11061 const char *username
) /* I - Username */
11063 struct passwd
*pw
; /* User password data */
11064 char baseuser
[256], /* Base username */
11065 *baseptr
, /* Pointer to "@" in base username */
11066 *name
; /* Current user name */
11069 if (cupsArrayCount(p
->users
) == 0)
11072 if (!strcmp(username
, "root"))
11075 if (strchr(username
, '@'))
11078 * Strip @REALM for username check...
11081 strlcpy(baseuser
, username
, sizeof(baseuser
));
11083 if ((baseptr
= strchr(baseuser
, '@')) != NULL
)
11086 username
= baseuser
;
11089 pw
= getpwnam(username
);
11092 for (name
= (char *)cupsArrayFirst(p
->users
);
11094 name
= (char *)cupsArrayNext(p
->users
))
11096 if (name
[0] == '@')
11099 * Check group membership...
11102 if (cupsdCheckGroup(username
, pw
, name
+ 1))
11105 else if (name
[0] == '#')
11111 if (cupsdCheckGroup(username
, pw
, name
))
11114 else if (!_cups_strcasecmp(username
, name
))
11118 return ((name
!= NULL
) != p
->deny_users
);
11123 * 'validate_job()' - Validate printer options and destination.
11127 validate_job(cupsd_client_t
*con
, /* I - Client connection */
11128 ipp_attribute_t
*uri
) /* I - Printer URI */
11130 http_status_t status
; /* Policy status */
11131 ipp_attribute_t
*attr
; /* Current attribute */
11133 ipp_attribute_t
*auth_info
; /* auth-info attribute */
11134 #endif /* HAVE_SSL */
11135 ipp_attribute_t
*format
, /* Document-format attribute */
11136 *name
; /* Job-name attribute */
11137 cups_ptype_t dtype
; /* Destination type (printer/class) */
11138 char super
[MIME_MAX_SUPER
],
11139 /* Supertype of file */
11140 type
[MIME_MAX_TYPE
];
11141 /* Subtype of file */
11142 cupsd_printer_t
*printer
; /* Printer */
11145 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_job(%p[%d], %s)", con
,
11146 con
->number
, uri
->values
[0].string
.text
);
11149 * OK, see if the client is sending the document compressed - CUPS
11150 * doesn't support compression yet...
11153 if ((attr
= ippFindAttribute(con
->request
, "compression",
11154 IPP_TAG_KEYWORD
)) != NULL
)
11156 if (strcmp(attr
->values
[0].string
.text
, "none")
11158 && strcmp(attr
->values
[0].string
.text
, "gzip")
11159 #endif /* HAVE_LIBZ */
11162 send_ipp_status(con
, IPP_ATTRIBUTES
,
11163 _("Unsupported 'compression' value \"%s\"."),
11164 attr
->values
[0].string
.text
);
11165 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
11166 "compression", NULL
, attr
->values
[0].string
.text
);
11172 * Is it a format we support?
11175 if ((format
= ippFindAttribute(con
->request
, "document-format",
11176 IPP_TAG_MIMETYPE
)) != NULL
)
11178 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%255[^;]",
11181 send_ipp_status(con
, IPP_BAD_REQUEST
,
11182 _("Bad 'document-format' value \"%s\"."),
11183 format
->values
[0].string
.text
);
11187 if ((strcmp(super
, "application") || strcmp(type
, "octet-stream")) &&
11188 !mimeType(MimeDatabase
, super
, type
))
11190 cupsdLogMessage(CUPSD_LOG_INFO
,
11191 "Hint: Do you have the raw file printing rules enabled?");
11192 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
11193 _("Unsupported 'document-format' value \"%s\"."),
11194 format
->values
[0].string
.text
);
11195 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
11196 "document-format", NULL
, format
->values
[0].string
.text
);
11202 * Is the job-name valid?
11205 if ((name
= ippFindAttribute(con
->request
, "job-name", IPP_TAG_ZERO
)) != NULL
)
11207 int bad_name
= 0; /* Is the job-name value bad? */
11209 if ((name
->value_tag
!= IPP_TAG_NAME
&& name
->value_tag
!= IPP_TAG_NAMELANG
) ||
11210 name
->num_values
!= 1)
11217 * Validate that job-name conforms to RFC 5198 (Network Unicode) and
11218 * IPP Everywhere requirements for "name" values...
11221 const unsigned char *nameptr
; /* Pointer into "job-name" attribute */
11223 for (nameptr
= (unsigned char *)name
->values
[0].string
.text
;
11227 if (*nameptr
< ' ' && *nameptr
!= '\t')
11229 else if (*nameptr
== 0x7f)
11231 else if ((*nameptr
& 0xe0) == 0xc0)
11233 if ((nameptr
[1] & 0xc0) != 0x80)
11238 else if ((*nameptr
& 0xf0) == 0xe0)
11240 if ((nameptr
[1] & 0xc0) != 0x80 ||
11241 (nameptr
[2] & 0xc0) != 0x80)
11246 else if ((*nameptr
& 0xf8) == 0xf0)
11248 if ((nameptr
[1] & 0xc0) != 0x80 ||
11249 (nameptr
[2] & 0xc0) != 0x80 ||
11250 (nameptr
[3] & 0xc0) != 0x80)
11255 else if (*nameptr
& 0x80)
11265 if (StrictConformance
)
11267 send_ipp_status(con
, IPP_ATTRIBUTES
,
11268 _("Unsupported 'job-name' value."));
11269 ippCopyAttribute(con
->response
, name
, 0);
11274 cupsdLogMessage(CUPSD_LOG_WARN
,
11275 "Unsupported 'job-name' value, deleting from request.");
11276 ippDeleteAttribute(con
->request
, name
);
11282 * Is the destination valid?
11285 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11291 send_ipp_status(con
, IPP_NOT_FOUND
,
11292 _("The printer or class does not exist."));
11301 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
11302 #endif /* HAVE_SSL */
11304 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11306 send_http_error(con
, status
, printer
);
11309 else if (printer
->num_auth_info_required
== 1 &&
11310 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
11313 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
11317 else if (auth_info
&& !con
->http
->tls
&&
11318 !httpAddrLocalhost(con
->http
->hostaddr
))
11321 * Require encryption of auth-info over non-local connections...
11324 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
11327 #endif /* HAVE_SSL */
11330 * Everything was ok, so return OK status...
11333 con
->response
->request
.status
.status_code
= IPP_OK
;
11338 * 'validate_name()' - Make sure the printer name only contains valid chars.
11341 static int /* O - 0 if name is no good, 1 if good */
11342 validate_name(const char *name
) /* I - Name to check */
11344 const char *ptr
; /* Pointer into name */
11348 * Scan the whole name...
11351 for (ptr
= name
; *ptr
; ptr
++)
11352 if ((*ptr
> 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
11356 * All the characters are good; validate the length, too...
11359 return ((ptr
- name
) < 128);
11364 * 'validate_user()' - Validate the user for the request.
11367 static int /* O - 1 if permitted, 0 otherwise */
11368 validate_user(cupsd_job_t
*job
, /* I - Job */
11369 cupsd_client_t
*con
, /* I - Client connection */
11370 const char *owner
, /* I - Owner of job/resource */
11371 char *username
, /* O - Authenticated username */
11372 size_t userlen
) /* I - Length of username */
11374 cupsd_printer_t
*printer
; /* Printer for job */
11377 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
);
11380 * Validate input...
11383 if (!con
|| !owner
|| !username
|| userlen
<= 0)
11387 * Get the best authenticated username that is available.
11390 strlcpy(username
, get_username(con
), userlen
);
11393 * Check the username against the owner...
11396 printer
= cupsdFindDest(job
->dest
);
11398 return (cupsdCheckPolicy(printer
? printer
->op_policy_ptr
: DefaultPolicyPtr
,
11399 con
, owner
) == HTTP_OK
);