4 * IPP routines for the CUPS scheduler.
6 * Copyright 2007-2014 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
9 * This file contains Kerberos support code, copyright 2006 by
12 * These coded instructions, statements, and computer programs are the
13 * property of Apple Inc. and are protected by Federal copyright
14 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
15 * which should have been included with this file. If this file is
16 * file is missing or damaged, see the license at "http://www.cups.org/".
20 * Include necessary headers...
24 #include <cups/ppd-private.h>
27 /*# include <ApplicationServices/ApplicationServices.h>
28 extern CFUUIDRef ColorSyncCreateUUIDFromUInt32(unsigned id);
29 # include <CoreFoundation/CoreFoundation.h>*/
30 # ifdef HAVE_MEMBERSHIP_H
31 # include <membership.h>
32 # endif /* HAVE_MEMBERSHIP_H */
33 # ifdef HAVE_MEMBERSHIPPRIV_H
34 # include <membershipPriv.h>
36 extern int mbr_user_name_to_uuid(const char* name
, uuid_t uu
);
37 extern int mbr_group_name_to_uuid(const char* name
, uuid_t uu
);
38 extern int mbr_check_membership_by_id(uuid_t user
, gid_t group
, int* ismember
);
39 # endif /* HAVE_MEMBERSHIPPRIV_H */
40 #endif /* __APPLE__ */
47 static void accept_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
48 static void add_class(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
49 static int add_file(cupsd_client_t
*con
, cupsd_job_t
*job
,
50 mime_type_t
*filetype
, int compression
);
51 static cupsd_job_t
*add_job(cupsd_client_t
*con
, cupsd_printer_t
*printer
,
52 mime_type_t
*filetype
);
53 static void add_job_subscriptions(cupsd_client_t
*con
, cupsd_job_t
*job
);
54 static void add_job_uuid(cupsd_job_t
*job
);
55 static void add_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
56 static void add_printer_state_reasons(cupsd_client_t
*con
,
58 static void add_queued_job_count(cupsd_client_t
*con
, cupsd_printer_t
*p
);
59 static void apply_printer_defaults(cupsd_printer_t
*printer
,
61 static void authenticate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
62 static void cancel_all_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
63 static void cancel_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
64 static void cancel_subscription(cupsd_client_t
*con
, int id
);
65 static int check_rss_recipient(const char *recipient
);
66 static int check_quotas(cupsd_client_t
*con
, cupsd_printer_t
*p
);
67 static void close_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
68 static void copy_attrs(ipp_t
*to
, ipp_t
*from
, cups_array_t
*ra
,
69 ipp_tag_t group
, int quickcopy
,
70 cups_array_t
*exclude
);
71 static int copy_banner(cupsd_client_t
*con
, cupsd_job_t
*job
,
73 static int copy_file(const char *from
, const char *to
);
74 static int copy_model(cupsd_client_t
*con
, const char *from
,
76 static void copy_job_attrs(cupsd_client_t
*con
,
78 cups_array_t
*ra
, cups_array_t
*exclude
);
79 static void copy_printer_attrs(cupsd_client_t
*con
,
80 cupsd_printer_t
*printer
,
82 static void copy_subscription_attrs(cupsd_client_t
*con
,
83 cupsd_subscription_t
*sub
,
85 cups_array_t
*exclude
);
86 static void create_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
87 static cups_array_t
*create_requested_array(ipp_t
*request
);
88 static void create_subscription(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
89 static void delete_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
90 static void get_default(cupsd_client_t
*con
);
91 static void get_devices(cupsd_client_t
*con
);
92 static void get_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
93 static void get_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
94 static void get_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
95 static void get_notifications(cupsd_client_t
*con
);
96 static void get_ppd(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
97 static void get_ppds(cupsd_client_t
*con
);
98 static void get_printers(cupsd_client_t
*con
, int type
);
99 static void get_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
100 static void get_printer_supported(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
101 static void get_subscription_attrs(cupsd_client_t
*con
, int sub_id
);
102 static void get_subscriptions(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
103 static const char *get_username(cupsd_client_t
*con
);
104 static void hold_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
105 static void hold_new_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
106 static void move_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
107 static int ppd_parse_line(const char *line
, char *option
, int olen
,
108 char *choice
, int clen
);
109 static void print_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
110 static void read_job_ticket(cupsd_client_t
*con
);
111 static void reject_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
112 static void release_held_new_jobs(cupsd_client_t
*con
,
113 ipp_attribute_t
*uri
);
114 static void release_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
115 static void renew_subscription(cupsd_client_t
*con
, int sub_id
);
116 static void restart_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
117 static void save_auth_info(cupsd_client_t
*con
, cupsd_job_t
*job
,
118 ipp_attribute_t
*auth_info
);
119 static void send_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
120 static void send_http_error(cupsd_client_t
*con
, http_status_t status
,
121 cupsd_printer_t
*printer
);
122 static void send_ipp_status(cupsd_client_t
*con
, ipp_status_t status
,
123 const char *message
, ...)
124 __attribute__((__format__(__printf__
, 3, 4)));
125 static void set_default(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
126 static void set_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
127 static void set_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
128 static void set_printer_defaults(cupsd_client_t
*con
,
129 cupsd_printer_t
*printer
);
130 static void start_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
131 static void stop_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
132 static void url_encode_attr(ipp_attribute_t
*attr
, char *buffer
,
134 static char *url_encode_string(const char *s
, char *buffer
, int bufsize
);
135 static int user_allowed(cupsd_printer_t
*p
, const char *username
);
136 static void validate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
137 static int validate_name(const char *name
);
138 static int validate_user(cupsd_job_t
*job
, cupsd_client_t
*con
,
139 const char *owner
, char *username
,
144 * 'cupsdProcessIPPRequest()' - Process an incoming IPP request.
147 int /* O - 1 on success, 0 on failure */
148 cupsdProcessIPPRequest(
149 cupsd_client_t
*con
) /* I - Client connection */
151 ipp_tag_t group
; /* Current group tag */
152 ipp_attribute_t
*attr
; /* Current attribute */
153 ipp_attribute_t
*charset
; /* Character set attribute */
154 ipp_attribute_t
*language
; /* Language attribute */
155 ipp_attribute_t
*uri
= NULL
; /* Printer or job URI attribute */
156 ipp_attribute_t
*username
; /* requesting-user-name attr */
157 int sub_id
; /* Subscription ID */
160 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
161 "cupsdProcessIPPRequest(%p[%d]): operation_id = %04x",
162 con
, con
->number
, con
->request
->request
.op
.operation_id
);
165 * First build an empty response message for this request...
168 con
->response
= ippNew();
170 con
->response
->request
.status
.version
[0] =
171 con
->request
->request
.op
.version
[0];
172 con
->response
->request
.status
.version
[1] =
173 con
->request
->request
.op
.version
[1];
174 con
->response
->request
.status
.request_id
=
175 con
->request
->request
.op
.request_id
;
178 * Then validate the request header and required attributes...
181 if (con
->request
->request
.any
.version
[0] != 1 &&
182 con
->request
->request
.any
.version
[0] != 2)
185 * Return an error, since we only support IPP 1.x and 2.x.
188 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
189 "%04X %s Bad request version number %d.%d",
190 IPP_VERSION_NOT_SUPPORTED
, con
->http
->hostname
,
191 con
->request
->request
.any
.version
[0],
192 con
->request
->request
.any
.version
[1]);
194 send_ipp_status(con
, IPP_VERSION_NOT_SUPPORTED
,
195 _("Bad request version number %d.%d."),
196 con
->request
->request
.any
.version
[0],
197 con
->request
->request
.any
.version
[1]);
199 else if (con
->request
->request
.any
.request_id
< 1)
202 * Return an error, since request IDs must be between 1 and 2^31-1
205 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
206 "%04X %s Bad request ID %d",
207 IPP_BAD_REQUEST
, con
->http
->hostname
,
208 con
->request
->request
.any
.request_id
);
210 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad request ID %d."),
211 con
->request
->request
.any
.request_id
);
213 else if (!con
->request
->attrs
)
215 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
216 "%04X %s No attributes in request",
217 IPP_BAD_REQUEST
, con
->http
->hostname
);
219 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No attributes in request."));
224 * Make sure that the attributes are provided in the correct order and
225 * don't repeat groups...
228 for (attr
= con
->request
->attrs
, group
= attr
->group_tag
;
231 if (attr
->group_tag
< group
&& attr
->group_tag
!= IPP_TAG_ZERO
)
234 * Out of order; return an error...
237 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
238 "%04X %s Attribute groups are out of order",
239 IPP_BAD_REQUEST
, con
->http
->hostname
);
241 send_ipp_status(con
, IPP_BAD_REQUEST
,
242 _("Attribute groups are out of order (%x < %x)."),
243 attr
->group_tag
, group
);
247 group
= attr
->group_tag
;
252 * Then make sure that the first three attributes are:
255 * attributes-natural-language
256 * printer-uri/job-uri
259 attr
= con
->request
->attrs
;
260 if (attr
&& attr
->name
&&
261 !strcmp(attr
->name
, "attributes-charset") &&
262 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_CHARSET
)
270 if (attr
&& attr
->name
&&
271 !strcmp(attr
->name
, "attributes-natural-language") &&
272 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_LANGUAGE
)
277 * Reset language for this request if different from Accept-Language.
280 if (!con
->language
||
281 strcmp(attr
->values
[0].string
.text
, con
->language
->language
))
283 cupsLangFree(con
->language
);
284 con
->language
= cupsLangGet(attr
->values
[0].string
.text
);
290 if ((attr
= ippFindAttribute(con
->request
, "printer-uri",
291 IPP_TAG_URI
)) != NULL
)
293 else if ((attr
= ippFindAttribute(con
->request
, "job-uri",
294 IPP_TAG_URI
)) != NULL
)
296 else if (con
->request
->request
.op
.operation_id
== CUPS_GET_PPD
)
297 uri
= ippFindAttribute(con
->request
, "ppd-name", IPP_TAG_NAME
);
302 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
303 "attributes-charset", NULL
,
304 charset
->values
[0].string
.text
);
306 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
307 "attributes-charset", NULL
, "utf-8");
310 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
311 "attributes-natural-language", NULL
,
312 language
->values
[0].string
.text
);
314 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
315 "attributes-natural-language", NULL
, DefaultLanguage
);
318 _cups_strcasecmp(charset
->values
[0].string
.text
, "us-ascii") &&
319 _cups_strcasecmp(charset
->values
[0].string
.text
, "utf-8"))
322 * Bad character set...
325 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unsupported character set \"%s\"",
326 charset
->values
[0].string
.text
);
327 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
328 "%04X %s Unsupported attributes-charset value \"%s\"",
329 IPP_CHARSET
, con
->http
->hostname
,
330 charset
->values
[0].string
.text
);
331 send_ipp_status(con
, IPP_BAD_REQUEST
,
332 _("Unsupported character set \"%s\"."),
333 charset
->values
[0].string
.text
);
335 else if (!charset
|| !language
||
337 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEFAULT
&&
338 con
->request
->request
.op
.operation_id
!= CUPS_GET_PRINTERS
&&
339 con
->request
->request
.op
.operation_id
!= CUPS_GET_CLASSES
&&
340 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEVICES
&&
341 con
->request
->request
.op
.operation_id
!= CUPS_GET_PPDS
))
344 * Return an error, since attributes-charset,
345 * attributes-natural-language, and printer-uri/job-uri are required
346 * for all operations.
351 cupsdLogMessage(CUPSD_LOG_ERROR
,
352 "Missing attributes-charset attribute");
354 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
355 "%04X %s Missing attributes-charset attribute",
356 IPP_BAD_REQUEST
, con
->http
->hostname
);
361 cupsdLogMessage(CUPSD_LOG_ERROR
,
362 "Missing attributes-natural-language attribute");
364 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
365 "%04X %s Missing attributes-natural-language attribute",
366 IPP_BAD_REQUEST
, con
->http
->hostname
);
371 cupsdLogMessage(CUPSD_LOG_ERROR
,
372 "Missing printer-uri, job-uri, or ppd-name "
375 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
376 "%04X %s Missing printer-uri, job-uri, or ppd-name "
377 "attribute", IPP_BAD_REQUEST
, con
->http
->hostname
);
380 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Request attributes follow...");
382 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
383 cupsdLogMessage(CUPSD_LOG_DEBUG
,
384 "attr \"%s\": group_tag = %x, value_tag = %x",
385 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
388 cupsdLogMessage(CUPSD_LOG_DEBUG
, "End of attributes...");
390 send_ipp_status(con
, IPP_BAD_REQUEST
,
391 _("Missing required attributes."));
396 * OK, all the checks pass so far; make sure requesting-user-name is
397 * not "root" from a remote host...
400 if ((username
= ippFindAttribute(con
->request
, "requesting-user-name",
401 IPP_TAG_NAME
)) != NULL
)
404 * Check for root user...
407 if (!strcmp(username
->values
[0].string
.text
, "root") &&
408 _cups_strcasecmp(con
->http
->hostname
, "localhost") &&
409 strcmp(con
->username
, "root"))
412 * Remote unauthenticated user masquerading as local root...
415 _cupsStrFree(username
->values
[0].string
.text
);
416 username
->values
[0].string
.text
= _cupsStrAlloc(RemoteRoot
);
420 if ((attr
= ippFindAttribute(con
->request
, "notify-subscription-id",
421 IPP_TAG_INTEGER
)) != NULL
)
422 sub_id
= attr
->values
[0].integer
;
427 * Then try processing the operation...
431 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s",
432 ippOpString(con
->request
->request
.op
.operation_id
),
433 uri
->values
[0].string
.text
);
435 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s",
436 ippOpString(con
->request
->request
.op
.operation_id
));
438 switch (con
->request
->request
.op
.operation_id
)
444 case IPP_VALIDATE_JOB
:
445 validate_job(con
, uri
);
448 case IPP_CREATE_JOB
:
449 create_job(con
, uri
);
452 case IPP_SEND_DOCUMENT
:
453 send_document(con
, uri
);
456 case IPP_CANCEL_JOB
:
457 cancel_job(con
, uri
);
460 case IPP_GET_JOB_ATTRIBUTES
:
461 get_job_attrs(con
, uri
);
468 case IPP_GET_PRINTER_ATTRIBUTES
:
469 get_printer_attrs(con
, uri
);
472 case IPP_GET_PRINTER_SUPPORTED_VALUES
:
473 get_printer_supported(con
, uri
);
480 case IPP_RELEASE_JOB
:
481 release_job(con
, uri
);
484 case IPP_RESTART_JOB
:
485 restart_job(con
, uri
);
488 case IPP_PAUSE_PRINTER
:
489 stop_printer(con
, uri
);
492 case IPP_RESUME_PRINTER
:
493 start_printer(con
, uri
);
496 case IPP_PURGE_JOBS
:
497 case IPP_CANCEL_JOBS
:
498 case IPP_CANCEL_MY_JOBS
:
499 cancel_all_jobs(con
, uri
);
502 case IPP_SET_JOB_ATTRIBUTES
:
503 set_job_attrs(con
, uri
);
506 case IPP_SET_PRINTER_ATTRIBUTES
:
507 set_printer_attrs(con
, uri
);
510 case IPP_HOLD_NEW_JOBS
:
511 hold_new_jobs(con
, uri
);
514 case IPP_RELEASE_HELD_NEW_JOBS
:
515 release_held_new_jobs(con
, uri
);
522 case CUPS_GET_DEFAULT
:
526 case CUPS_GET_PRINTERS
:
527 get_printers(con
, 0);
530 case CUPS_GET_CLASSES
:
531 get_printers(con
, CUPS_PRINTER_CLASS
);
534 case CUPS_ADD_PRINTER
:
535 add_printer(con
, uri
);
538 case CUPS_DELETE_PRINTER
:
539 delete_printer(con
, uri
);
542 case CUPS_ADD_CLASS
:
546 case CUPS_DELETE_CLASS
:
547 delete_printer(con
, uri
);
550 case CUPS_ACCEPT_JOBS
:
551 case IPP_ENABLE_PRINTER
:
552 accept_jobs(con
, uri
);
555 case CUPS_REJECT_JOBS
:
556 case IPP_DISABLE_PRINTER
:
557 reject_jobs(con
, uri
);
560 case CUPS_SET_DEFAULT
:
561 set_default(con
, uri
);
564 case CUPS_GET_DEVICES
:
568 case CUPS_GET_DOCUMENT
:
569 get_document(con
, uri
);
584 case CUPS_AUTHENTICATE_JOB
:
585 authenticate_job(con
, uri
);
588 case IPP_CREATE_PRINTER_SUBSCRIPTION
:
589 case IPP_CREATE_JOB_SUBSCRIPTION
:
590 create_subscription(con
, uri
);
593 case IPP_GET_SUBSCRIPTION_ATTRIBUTES
:
594 get_subscription_attrs(con
, sub_id
);
597 case IPP_GET_SUBSCRIPTIONS
:
598 get_subscriptions(con
, uri
);
601 case IPP_RENEW_SUBSCRIPTION
:
602 renew_subscription(con
, sub_id
);
605 case IPP_CANCEL_SUBSCRIPTION
:
606 cancel_subscription(con
, sub_id
);
609 case IPP_GET_NOTIFICATIONS
:
610 get_notifications(con
);
614 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
615 "%04X %s Operation %04X (%s) not supported",
616 IPP_OPERATION_NOT_SUPPORTED
, con
->http
->hostname
,
617 con
->request
->request
.op
.operation_id
,
618 ippOpString(con
->request
->request
.op
.operation_id
));
620 send_ipp_status(con
, IPP_OPERATION_NOT_SUPPORTED
,
621 _("%s not supported."),
623 con
->request
->request
.op
.operation_id
));
633 * Sending data from the scheduler...
636 cupsdLogMessage(con
->response
->request
.status
.status_code
637 >= IPP_BAD_REQUEST
&&
638 con
->response
->request
.status
.status_code
639 != IPP_NOT_FOUND
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
640 "[Client %d] Returning IPP %s for %s (%s) from %s",
642 ippErrorString(con
->response
->request
.status
.status_code
),
643 ippOpString(con
->request
->request
.op
.operation_id
),
644 uri
? uri
->values
[0].string
.text
: "no URI",
645 con
->http
->hostname
);
647 httpClearFields(con
->http
);
649 #ifdef CUPSD_USE_CHUNKING
651 * Because older versions of CUPS (1.1.17 and older) and some IPP
652 * clients do not implement chunking properly, we cannot use
653 * chunking by default. This may become the default in future
654 * CUPS releases, or we might add a configuration directive for
658 if (con
->http
->version
== HTTP_1_1
)
660 cupsdLogMessage(CUPSD_LOG_DEBUG
,
661 "[Client %d] Transfer-Encoding: chunked",
664 cupsdSetLength(con
->http
, 0);
667 #endif /* CUPSD_USE_CHUNKING */
669 size_t length
; /* Length of response */
672 length
= ippLength(con
->response
);
674 if (con
->file
>= 0 && !con
->pipe_pid
)
676 struct stat fileinfo
; /* File information */
678 if (!fstat(con
->file
, &fileinfo
))
679 length
+= (size_t)fileinfo
.st_size
;
682 cupsdLogMessage(CUPSD_LOG_DEBUG
,
683 "[Client %d] Content-Length: " CUPS_LLFMT
,
684 con
->number
, CUPS_LLCAST length
);
685 httpSetLength(con
->http
, length
);
688 if (cupsdSendHeader(con
, HTTP_OK
, "application/ipp", CUPSD_AUTH_NONE
))
691 * Tell the caller the response header was sent successfully...
694 cupsdAddSelect(httpGetFd(con
->http
), (cupsd_selfunc_t
)cupsdReadClient
,
695 (cupsd_selfunc_t
)cupsdWriteClient
, con
);
702 * Tell the caller the response header could not be sent...
711 * Sending data from a subprocess like cups-deviced; tell the caller
712 * everything is A-OK so far...
721 * 'cupsdTimeoutJob()' - Timeout a job waiting on job files.
724 int /* O - 0 on success, -1 on error */
725 cupsdTimeoutJob(cupsd_job_t
*job
) /* I - Job to timeout */
727 cupsd_printer_t
*printer
; /* Destination printer or class */
728 ipp_attribute_t
*attr
; /* job-sheets attribute */
729 int kbytes
; /* Kilobytes in banner */
732 job
->pending_timeout
= 0;
735 * See if we need to add the ending sheet...
738 if (!cupsdLoadJob(job
))
741 printer
= cupsdFindDest(job
->dest
);
742 attr
= ippFindAttribute(job
->attrs
, "job-sheets", IPP_TAG_NAME
);
744 if (printer
&& !(printer
->type
& CUPS_PRINTER_REMOTE
) &&
745 attr
&& attr
->num_values
> 1)
751 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding end banner page \"%s\".",
752 attr
->values
[1].string
.text
);
754 if ((kbytes
= copy_banner(NULL
, job
, attr
->values
[1].string
.text
)) < 0)
757 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
765 * 'accept_jobs()' - Accept print jobs to a printer.
769 accept_jobs(cupsd_client_t
*con
, /* I - Client connection */
770 ipp_attribute_t
*uri
) /* I - Printer or class URI */
772 http_status_t status
; /* Policy status */
773 cups_ptype_t dtype
; /* Destination type (printer/class) */
774 cupsd_printer_t
*printer
; /* Printer data */
777 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "accept_jobs(%p[%d], %s)", con
,
778 con
->number
, uri
->values
[0].string
.text
);
781 * Is the destination valid?
784 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
790 send_ipp_status(con
, IPP_NOT_FOUND
,
791 _("The printer or class does not exist."));
799 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
801 send_http_error(con
, status
, printer
);
806 * Accept jobs sent to the printer...
809 printer
->accepting
= 1;
810 printer
->state_message
[0] = '\0';
812 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
813 "Now accepting jobs.");
815 if (dtype
& CUPS_PRINTER_CLASS
)
817 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
819 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" now accepting jobs (\"%s\").",
820 printer
->name
, get_username(con
));
824 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
826 cupsdLogMessage(CUPSD_LOG_INFO
,
827 "Printer \"%s\" now accepting jobs (\"%s\").",
828 printer
->name
, get_username(con
));
832 * Everything was ok, so return OK status...
835 con
->response
->request
.status
.status_code
= IPP_OK
;
840 * 'add_class()' - Add a class to the system.
844 add_class(cupsd_client_t
*con
, /* I - Client connection */
845 ipp_attribute_t
*uri
) /* I - URI of class */
847 http_status_t status
; /* Policy status */
848 int i
; /* Looping var */
849 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
850 username
[HTTP_MAX_URI
], /* Username portion of URI */
851 host
[HTTP_MAX_URI
], /* Host portion of URI */
852 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
853 int port
; /* Port portion of URI */
854 cupsd_printer_t
*pclass
, /* Class */
855 *member
; /* Member printer/class */
856 cups_ptype_t dtype
; /* Destination type */
857 ipp_attribute_t
*attr
; /* Printer attribute */
858 int modify
; /* Non-zero if we just modified */
859 int need_restart_job
; /* Need to restart job? */
862 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_class(%p[%d], %s)", con
,
863 con
->number
, uri
->values
[0].string
.text
);
866 * Do we have a valid URI?
869 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
870 sizeof(scheme
), username
, sizeof(username
), host
,
871 sizeof(host
), &port
, resource
, sizeof(resource
));
874 if (strncmp(resource
, "/classes/", 9) || strlen(resource
) == 9)
877 * No, return an error...
880 send_ipp_status(con
, IPP_BAD_REQUEST
,
881 _("The printer-uri must be of the form "
882 "\"ipp://HOSTNAME/classes/CLASSNAME\"."));
887 * Do we have a valid printer name?
890 if (!validate_name(resource
+ 9))
893 * No, return an error...
896 send_ipp_status(con
, IPP_BAD_REQUEST
,
897 _("The printer-uri \"%s\" contains invalid characters."),
898 uri
->values
[0].string
.text
);
903 * See if the class already exists; if not, create a new class...
906 if ((pclass
= cupsdFindClass(resource
+ 9)) == NULL
)
909 * Class doesn't exist; see if we have a printer of the same name...
912 if ((pclass
= cupsdFindPrinter(resource
+ 9)) != NULL
)
915 * Yes, return an error...
918 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
919 _("A printer named \"%s\" already exists."),
925 * No, check the default policy and then add the class...
928 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
930 send_http_error(con
, status
, NULL
);
934 pclass
= cupsdAddClass(resource
+ 9);
937 else if ((status
= cupsdCheckPolicy(pclass
->op_policy_ptr
, con
,
940 send_http_error(con
, status
, pclass
);
947 * Look for attributes and copy them over as needed...
950 need_restart_job
= 0;
952 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
953 IPP_TAG_TEXT
)) != NULL
)
954 cupsdSetString(&pclass
->location
, attr
->values
[0].string
.text
);
956 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
957 IPP_TAG_TEXT
)) != NULL
)
958 cupsdSetString(&pclass
->info
, attr
->values
[0].string
.text
);
960 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
961 IPP_TAG_BOOLEAN
)) != NULL
&&
962 attr
->values
[0].boolean
!= pclass
->accepting
)
964 cupsdLogMessage(CUPSD_LOG_INFO
,
965 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
966 pclass
->name
, attr
->values
[0].boolean
, pclass
->accepting
);
968 pclass
->accepting
= attr
->values
[0].boolean
;
970 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s accepting jobs.",
971 pclass
->accepting
? "Now" : "No longer");
974 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
975 IPP_TAG_BOOLEAN
)) != NULL
)
977 if (pclass
->shared
&& !attr
->values
[0].boolean
)
978 cupsdDeregisterPrinter(pclass
, 1);
980 cupsdLogMessage(CUPSD_LOG_INFO
,
981 "Setting %s printer-is-shared to %d (was %d.)",
982 pclass
->name
, attr
->values
[0].boolean
, pclass
->shared
);
984 pclass
->shared
= attr
->values
[0].boolean
;
987 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
988 IPP_TAG_ENUM
)) != NULL
)
990 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
991 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
993 send_ipp_status(con
, IPP_BAD_REQUEST
,
994 _("Attempt to set %s printer-state to bad value %d."),
995 pclass
->name
, attr
->values
[0].integer
);
999 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
1000 pclass
->name
, attr
->values
[0].integer
, pclass
->state
);
1002 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
1003 cupsdStopPrinter(pclass
, 0);
1006 cupsdSetPrinterState(pclass
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
1007 need_restart_job
= 1;
1010 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
1011 IPP_TAG_TEXT
)) != NULL
)
1013 strlcpy(pclass
->state_message
, attr
->values
[0].string
.text
,
1014 sizeof(pclass
->state_message
));
1016 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s",
1017 pclass
->state_message
);
1019 if ((attr
= ippFindAttribute(con
->request
, "member-uris",
1020 IPP_TAG_URI
)) != NULL
)
1023 * Clear the printer array as needed...
1026 need_restart_job
= 1;
1028 if (pclass
->num_printers
> 0)
1030 free(pclass
->printers
);
1031 pclass
->num_printers
= 0;
1035 * Add each printer or class that is listed...
1038 for (i
= 0; i
< attr
->num_values
; i
++)
1041 * Search for the printer or class URI...
1044 if (!cupsdValidateDest(attr
->values
[i
].string
.text
, &dtype
, &member
))
1050 send_ipp_status(con
, IPP_NOT_FOUND
,
1051 _("The printer or class does not exist."));
1054 else if (dtype
& CUPS_PRINTER_CLASS
)
1056 send_ipp_status(con
, IPP_BAD_REQUEST
,
1057 _("Nested classes are not allowed."));
1062 * Add it to the class...
1065 cupsdAddPrinterToClass(pclass
, member
);
1069 set_printer_defaults(con
, pclass
);
1071 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
1072 IPP_TAG_KEYWORD
)) != NULL
)
1073 cupsdSetAuthInfoRequired(pclass
, NULL
, attr
);
1076 * Update the printer class attributes and return...
1079 cupsdSetPrinterAttrs(pclass
);
1080 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
1082 if (need_restart_job
&& pclass
->job
)
1085 * Reset the current job to a "pending" status...
1088 cupsdSetJobState(pclass
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
1089 "Job restarted because the class was modified.");
1092 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1096 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
1097 pclass
, NULL
, "Class \"%s\" modified by \"%s\".",
1098 pclass
->name
, get_username(con
));
1100 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" modified by \"%s\".",
1101 pclass
->name
, get_username(con
));
1105 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
1106 pclass
, NULL
, "New class \"%s\" added by \"%s\".",
1107 pclass
->name
, get_username(con
));
1109 cupsdLogMessage(CUPSD_LOG_INFO
, "New class \"%s\" added by \"%s\".",
1110 pclass
->name
, get_username(con
));
1113 con
->response
->request
.status
.status_code
= IPP_OK
;
1118 * 'add_file()' - Add a file to a job.
1121 static int /* O - 0 on success, -1 on error */
1122 add_file(cupsd_client_t
*con
, /* I - Connection to client */
1123 cupsd_job_t
*job
, /* I - Job to add to */
1124 mime_type_t
*filetype
, /* I - Type of file */
1125 int compression
) /* I - Compression */
1127 mime_type_t
**filetypes
; /* New filetypes array... */
1128 int *compressions
; /* New compressions array... */
1131 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1132 "add_file(con=%p[%d], job=%d, filetype=%s/%s, "
1133 "compression=%d)", con
, con
? con
->number
: -1, job
->id
,
1134 filetype
->super
, filetype
->type
, compression
);
1137 * Add the file to the job...
1140 if (job
->num_files
== 0)
1142 compressions
= (int *)malloc(sizeof(int));
1143 filetypes
= (mime_type_t
**)malloc(sizeof(mime_type_t
*));
1147 compressions
= (int *)realloc(job
->compressions
,
1148 (size_t)(job
->num_files
+ 1) * sizeof(int));
1149 filetypes
= (mime_type_t
**)realloc(job
->filetypes
,
1150 (size_t)(job
->num_files
+ 1) *
1151 sizeof(mime_type_t
*));
1155 job
->compressions
= compressions
;
1158 job
->filetypes
= filetypes
;
1160 if (!compressions
|| !filetypes
)
1162 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1163 "Job aborted because the scheduler ran out of memory.");
1166 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1167 _("Unable to allocate memory for file types."));
1172 job
->compressions
[job
->num_files
] = compression
;
1173 job
->filetypes
[job
->num_files
] = filetype
;
1178 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1185 * 'add_job()' - Add a job to a print queue.
1188 static cupsd_job_t
* /* O - Job object */
1189 add_job(cupsd_client_t
*con
, /* I - Client connection */
1190 cupsd_printer_t
*printer
, /* I - Destination printer */
1191 mime_type_t
*filetype
) /* I - First print file type, if any */
1193 http_status_t status
; /* Policy status */
1194 ipp_attribute_t
*attr
, /* Current attribute */
1195 *auth_info
; /* auth-info attribute */
1196 const char *mandatory
; /* Current mandatory job attribute */
1197 const char *val
; /* Default option value */
1198 int priority
; /* Job priority */
1199 cupsd_job_t
*job
; /* Current job */
1200 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
1201 int kbytes
; /* Size of print file */
1202 int i
; /* Looping var */
1203 int lowerpagerange
; /* Page range bound */
1204 int exact
; /* Did we have an exact match? */
1205 ipp_attribute_t
*media_col
, /* media-col attribute */
1206 *media_margin
; /* media-*-margin attribute */
1207 ipp_t
*unsup_col
; /* media-col in unsupported response */
1208 static const char * const readonly
[] =/* List of read-only attributes */
1211 "job-k-octets-completed",
1212 "job-impressions-completed",
1213 "job-media-sheets-completed",
1215 "job-state-message",
1216 "job-state-reasons",
1217 "time-at-completed",
1219 "time-at-processing"
1223 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job(%p[%d], %p(%s), %p(%s/%s))",
1224 con
, con
->number
, printer
, printer
->name
,
1225 filetype
, filetype
? filetype
->super
: "none",
1226 filetype
? filetype
->type
: "none");
1229 * Check remote printing to non-shared printer...
1232 if (!printer
->shared
&&
1233 _cups_strcasecmp(con
->http
->hostname
, "localhost") &&
1234 _cups_strcasecmp(con
->http
->hostname
, ServerName
))
1236 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
1237 _("The printer or class is not shared."));
1245 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
1247 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
1249 send_http_error(con
, status
, printer
);
1252 else if (printer
->num_auth_info_required
== 1 &&
1253 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
1256 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
1260 else if (auth_info
&& !con
->http
->tls
&&
1261 !httpAddrLocalhost(con
->http
->hostaddr
))
1264 * Require encryption of auth-info over non-local connections...
1267 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
1270 #endif /* HAVE_SSL */
1273 * See if the printer is accepting jobs...
1276 if (!printer
->accepting
)
1278 send_ipp_status(con
, IPP_NOT_ACCEPTING
,
1279 _("Destination \"%s\" is not accepting jobs."),
1285 * Validate job template attributes; for now just document-format,
1286 * copies, job-sheets, number-up, page-ranges, mandatory attributes, and
1290 for (i
= 0; i
< (int)(sizeof(readonly
) / sizeof(readonly
[0])); i
++)
1292 if ((attr
= ippFindAttribute(con
->request
, readonly
[i
],
1293 IPP_TAG_ZERO
)) != NULL
)
1295 ippDeleteAttribute(con
->request
, attr
);
1297 if (StrictConformance
)
1299 send_ipp_status(con
, IPP_BAD_REQUEST
,
1300 _("The '%s' Job Description attribute cannot be "
1301 "supplied in a job creation request."), readonly
[i
]);
1305 cupsdLogMessage(CUPSD_LOG_INFO
,
1306 "Unexpected '%s' Job Description attribute in a job "
1307 "creation request.", readonly
[i
]);
1313 for (mandatory
= (char *)cupsArrayFirst(printer
->pc
->mandatory
);
1315 mandatory
= (char *)cupsArrayNext(printer
->pc
->mandatory
))
1317 if (!ippFindAttribute(con
->request
, mandatory
, IPP_TAG_ZERO
))
1320 * Missing a required attribute...
1323 send_ipp_status(con
, IPP_CONFLICT
,
1324 _("The \"%s\" attribute is required for print jobs."),
1331 if (filetype
&& printer
->filetypes
&&
1332 !cupsArrayFind(printer
->filetypes
, filetype
))
1334 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
1335 /* MIME media type string */
1338 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
1341 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
1342 _("Unsupported format \"%s\"."), mimetype
);
1344 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
1345 "document-format", NULL
, mimetype
);
1350 if ((attr
= ippFindAttribute(con
->request
, "copies",
1351 IPP_TAG_INTEGER
)) != NULL
)
1353 if (attr
->values
[0].integer
< 1 || attr
->values
[0].integer
> MaxCopies
)
1355 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad copies value %d."),
1356 attr
->values
[0].integer
);
1357 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1358 "copies", attr
->values
[0].integer
);
1363 if ((attr
= ippFindAttribute(con
->request
, "job-sheets",
1364 IPP_TAG_ZERO
)) != NULL
)
1366 if (attr
->value_tag
!= IPP_TAG_KEYWORD
&&
1367 attr
->value_tag
!= IPP_TAG_NAME
)
1369 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value type."));
1373 if (attr
->num_values
> 2)
1375 send_ipp_status(con
, IPP_BAD_REQUEST
,
1376 _("Too many job-sheets values (%d > 2)."),
1381 for (i
= 0; i
< attr
->num_values
; i
++)
1382 if (strcmp(attr
->values
[i
].string
.text
, "none") &&
1383 !cupsdFindBanner(attr
->values
[i
].string
.text
))
1385 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value \"%s\"."),
1386 attr
->values
[i
].string
.text
);
1391 if ((attr
= ippFindAttribute(con
->request
, "number-up",
1392 IPP_TAG_INTEGER
)) != NULL
)
1394 if (attr
->values
[0].integer
!= 1 &&
1395 attr
->values
[0].integer
!= 2 &&
1396 attr
->values
[0].integer
!= 4 &&
1397 attr
->values
[0].integer
!= 6 &&
1398 attr
->values
[0].integer
!= 9 &&
1399 attr
->values
[0].integer
!= 16)
1401 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad number-up value %d."),
1402 attr
->values
[0].integer
);
1403 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1404 "number-up", attr
->values
[0].integer
);
1409 if ((attr
= ippFindAttribute(con
->request
, "page-ranges",
1410 IPP_TAG_RANGE
)) != NULL
)
1412 for (i
= 0, lowerpagerange
= 1; i
< attr
->num_values
; i
++)
1414 if (attr
->values
[i
].range
.lower
< lowerpagerange
||
1415 attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
1417 send_ipp_status(con
, IPP_BAD_REQUEST
,
1418 _("Bad page-ranges values %d-%d."),
1419 attr
->values
[i
].range
.lower
,
1420 attr
->values
[i
].range
.upper
);
1424 lowerpagerange
= attr
->values
[i
].range
.upper
+ 1;
1429 * Do media selection as needed...
1432 if (!ippFindAttribute(con
->request
, "PageRegion", IPP_TAG_ZERO
) &&
1433 !ippFindAttribute(con
->request
, "PageSize", IPP_TAG_ZERO
) &&
1434 _ppdCacheGetPageSize(printer
->pc
, con
->request
, NULL
, &exact
))
1437 (media_col
= ippFindAttribute(con
->request
, "media-col",
1438 IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
1440 send_ipp_status(con
, IPP_OK_SUBST
, _("Unsupported margins."));
1442 unsup_col
= ippNew();
1443 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1444 "media-bottom-margin",
1445 IPP_TAG_INTEGER
)) != NULL
)
1446 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1447 "media-bottom-margin", media_margin
->values
[0].integer
);
1449 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1450 "media-left-margin",
1451 IPP_TAG_INTEGER
)) != NULL
)
1452 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1453 "media-left-margin", media_margin
->values
[0].integer
);
1455 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1456 "media-right-margin",
1457 IPP_TAG_INTEGER
)) != NULL
)
1458 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1459 "media-right-margin", media_margin
->values
[0].integer
);
1461 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1463 IPP_TAG_INTEGER
)) != NULL
)
1464 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1465 "media-top-margin", media_margin
->values
[0].integer
);
1467 ippAddCollection(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, "media-col",
1469 ippDelete(unsup_col
);
1474 * Make sure we aren't over our limit...
1477 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1480 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1482 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Too many active jobs."));
1486 if ((i
= check_quotas(con
, printer
)) < 0)
1488 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
1493 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
1498 * Create the job and set things up...
1501 if ((attr
= ippFindAttribute(con
->request
, "job-priority",
1502 IPP_TAG_INTEGER
)) != NULL
)
1503 priority
= attr
->values
[0].integer
;
1506 if ((val
= cupsGetOption("job-priority", printer
->num_options
,
1507 printer
->options
)) != NULL
)
1508 priority
= atoi(val
);
1512 ippAddInteger(con
->request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-priority",
1516 if ((attr
= ippFindAttribute(con
->request
, "job-name", IPP_TAG_ZERO
)) == NULL
)
1517 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
,
1519 else if ((attr
->value_tag
!= IPP_TAG_NAME
&&
1520 attr
->value_tag
!= IPP_TAG_NAMELANG
) ||
1521 attr
->num_values
!= 1)
1523 send_ipp_status(con
, IPP_ATTRIBUTES
,
1524 _("Bad job-name value: Wrong type or count."));
1525 if ((attr
= ippCopyAttribute(con
->response
, attr
, 0)) != NULL
)
1526 attr
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
1529 else if (!ippValidateAttribute(attr
))
1531 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad job-name value: %s"),
1532 cupsLastErrorString());
1533 if ((attr
= ippCopyAttribute(con
->response
, attr
, 0)) != NULL
)
1534 attr
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
1538 if ((job
= cupsdAddJob(priority
, printer
->name
)) == NULL
)
1540 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1541 _("Unable to add job for destination \"%s\"."),
1546 job
->dtype
= printer
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
1547 job
->attrs
= con
->request
;
1549 con
->request
= ippNewRequest(job
->attrs
->request
.op
.operation_id
);
1551 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1554 apply_printer_defaults(printer
, job
);
1556 attr
= ippFindAttribute(job
->attrs
, "requesting-user-name", IPP_TAG_NAME
);
1558 if (con
->username
[0])
1560 cupsdSetString(&job
->username
, con
->username
);
1563 cupsdSetString(&attr
->values
[0].string
.text
, con
->username
);
1567 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1568 "add_job: requesting-user-name=\"%s\"",
1569 attr
->values
[0].string
.text
);
1571 cupsdSetString(&job
->username
, attr
->values
[0].string
.text
);
1574 cupsdSetString(&job
->username
, "anonymous");
1577 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1578 "job-originating-user-name", NULL
, job
->username
);
1581 attr
->group_tag
= IPP_TAG_JOB
;
1582 _cupsStrFree(attr
->name
);
1583 attr
->name
= _cupsStrAlloc("job-originating-user-name");
1586 if (con
->username
[0] || auth_info
)
1588 save_auth_info(con
, job
, auth_info
);
1591 * Remove the auth-info attribute from the attribute data...
1595 ippDeleteAttribute(job
->attrs
, auth_info
);
1598 if ((attr
= ippFindAttribute(job
->attrs
, "job-originating-host-name",
1599 IPP_TAG_ZERO
)) != NULL
)
1602 * Request contains a job-originating-host-name attribute; validate it...
1605 if (attr
->value_tag
!= IPP_TAG_NAME
||
1606 attr
->num_values
!= 1 ||
1607 strcmp(con
->http
->hostname
, "localhost"))
1610 * Can't override the value if we aren't connected via localhost.
1611 * Also, we can only have 1 value and it must be a name value.
1614 switch (attr
->value_tag
)
1616 case IPP_TAG_STRING
:
1617 case IPP_TAG_TEXTLANG
:
1618 case IPP_TAG_NAMELANG
:
1621 case IPP_TAG_KEYWORD
:
1623 case IPP_TAG_URISCHEME
:
1624 case IPP_TAG_CHARSET
:
1625 case IPP_TAG_LANGUAGE
:
1626 case IPP_TAG_MIMETYPE
:
1628 * Free old strings...
1631 for (i
= 0; i
< attr
->num_values
; i
++)
1633 _cupsStrFree(attr
->values
[i
].string
.text
);
1634 attr
->values
[i
].string
.text
= NULL
;
1635 if (attr
->values
[i
].string
.language
)
1637 _cupsStrFree(attr
->values
[i
].string
.language
);
1638 attr
->values
[i
].string
.language
= NULL
;
1647 * Use the default connection hostname instead...
1650 attr
->value_tag
= IPP_TAG_NAME
;
1651 attr
->num_values
= 1;
1652 attr
->values
[0].string
.text
= _cupsStrAlloc(con
->http
->hostname
);
1655 attr
->group_tag
= IPP_TAG_JOB
;
1660 * No job-originating-host-name attribute, so use the hostname from
1664 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1665 "job-originating-host-name", NULL
, con
->http
->hostname
);
1668 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation",
1670 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1671 "time-at-processing", 0);
1672 attr
->value_tag
= IPP_TAG_NOVALUE
;
1673 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1674 "time-at-completed", 0);
1675 attr
->value_tag
= IPP_TAG_NOVALUE
;
1678 * Add remaining job attributes...
1681 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1682 job
->state
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_ENUM
,
1683 "job-state", IPP_JOB_STOPPED
);
1684 job
->state_value
= (ipp_jstate_t
)job
->state
->values
[0].integer
;
1685 job
->reasons
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1686 "job-state-reasons", NULL
, "job-incoming");
1687 job
->sheets
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1688 "job-media-sheets-completed", 0);
1689 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-printer-uri", NULL
,
1692 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
1693 IPP_TAG_INTEGER
)) != NULL
)
1694 attr
->values
[0].integer
= 0;
1696 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-k-octets", 0);
1698 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
1699 IPP_TAG_KEYWORD
)) == NULL
)
1700 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
1703 if ((val
= cupsGetOption("job-hold-until", printer
->num_options
,
1704 printer
->options
)) == NULL
)
1707 attr
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1708 "job-hold-until", NULL
, val
);
1710 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
1713 * Hold job until specified time...
1716 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
1718 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1719 job
->state_value
= IPP_JOB_HELD
;
1721 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-hold-until-specified");
1723 else if (job
->attrs
->request
.op
.operation_id
== IPP_CREATE_JOB
)
1725 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
1726 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1727 job
->state_value
= IPP_JOB_HELD
;
1731 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1732 job
->state_value
= IPP_JOB_PENDING
;
1734 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
1737 if (!(printer
->type
& CUPS_PRINTER_REMOTE
) || Classification
)
1740 * Add job sheets options...
1743 if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1744 IPP_TAG_ZERO
)) == NULL
)
1746 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1747 "Adding default job-sheets values \"%s,%s\"...",
1748 printer
->job_sheets
[0], printer
->job_sheets
[1]);
1750 attr
= ippAddStrings(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-sheets",
1752 attr
->values
[0].string
.text
= _cupsStrRetain(printer
->job_sheets
[0]);
1753 attr
->values
[1].string
.text
= _cupsStrRetain(printer
->job_sheets
[1]);
1756 job
->job_sheets
= attr
;
1759 * Enforce classification level if set...
1764 cupsdLogMessage(CUPSD_LOG_INFO
,
1765 "Classification=\"%s\", ClassifyOverride=%d",
1766 Classification
? Classification
: "(null)",
1769 if (ClassifyOverride
)
1771 if (!strcmp(attr
->values
[0].string
.text
, "none") &&
1772 (attr
->num_values
== 1 ||
1773 !strcmp(attr
->values
[1].string
.text
, "none")))
1776 * Force the leading banner to have the classification on it...
1779 cupsdSetString(&attr
->values
[0].string
.text
, Classification
);
1781 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1782 "job-sheets=\"%s,none\", "
1783 "job-originating-user-name=\"%s\"",
1784 Classification
, job
->username
);
1786 else if (attr
->num_values
== 2 &&
1787 strcmp(attr
->values
[0].string
.text
,
1788 attr
->values
[1].string
.text
) &&
1789 strcmp(attr
->values
[0].string
.text
, "none") &&
1790 strcmp(attr
->values
[1].string
.text
, "none"))
1793 * Can't put two different security markings on the same document!
1796 cupsdSetString(&attr
->values
[1].string
.text
, attr
->values
[0].string
.text
);
1798 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1799 "job-sheets=\"%s,%s\", "
1800 "job-originating-user-name=\"%s\"",
1801 attr
->values
[0].string
.text
,
1802 attr
->values
[1].string
.text
, job
->username
);
1804 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1805 strcmp(attr
->values
[0].string
.text
, "none") &&
1806 (attr
->num_values
== 1 ||
1807 (strcmp(attr
->values
[1].string
.text
, Classification
) &&
1808 strcmp(attr
->values
[1].string
.text
, "none"))))
1810 if (attr
->num_values
== 1)
1811 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1812 "CLASSIFICATION OVERRIDDEN "
1813 "job-sheets=\"%s\", "
1814 "job-originating-user-name=\"%s\"",
1815 attr
->values
[0].string
.text
, job
->username
);
1817 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1818 "CLASSIFICATION OVERRIDDEN "
1819 "job-sheets=\"%s,%s\",fffff "
1820 "job-originating-user-name=\"%s\"",
1821 attr
->values
[0].string
.text
,
1822 attr
->values
[1].string
.text
, job
->username
);
1825 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1826 (attr
->num_values
== 1 ||
1827 strcmp(attr
->values
[1].string
.text
, Classification
)))
1830 * Force the banner to have the classification on it...
1833 if (attr
->num_values
> 1 &&
1834 !strcmp(attr
->values
[0].string
.text
, attr
->values
[1].string
.text
))
1836 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1837 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1841 if (attr
->num_values
== 1 ||
1842 strcmp(attr
->values
[0].string
.text
, "none"))
1843 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1845 if (attr
->num_values
> 1 &&
1846 strcmp(attr
->values
[1].string
.text
, "none"))
1847 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1850 if (attr
->num_values
> 1)
1851 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1852 "CLASSIFICATION FORCED "
1853 "job-sheets=\"%s,%s\", "
1854 "job-originating-user-name=\"%s\"",
1855 attr
->values
[0].string
.text
,
1856 attr
->values
[1].string
.text
, job
->username
);
1858 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1859 "CLASSIFICATION FORCED "
1860 "job-sheets=\"%s\", "
1861 "job-originating-user-name=\"%s\"",
1862 Classification
, job
->username
);
1867 * See if we need to add the starting sheet...
1870 if (!(printer
->type
& CUPS_PRINTER_REMOTE
))
1872 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding start banner page \"%s\".",
1873 attr
->values
[0].string
.text
);
1875 if ((kbytes
= copy_banner(con
, job
, attr
->values
[0].string
.text
)) < 0)
1877 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1878 "Aborting job because the start banner could not be "
1883 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
1886 else if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1887 IPP_TAG_ZERO
)) != NULL
)
1888 job
->job_sheets
= attr
;
1891 * Fill in the response info...
1894 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
1895 con
->clientname
, con
->clientport
, "/jobs/%d", job
->id
);
1896 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
1899 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1901 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
1903 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons",
1904 NULL
, job
->reasons
->values
[0].string
.text
);
1906 con
->response
->request
.status
.status_code
= IPP_OK
;
1909 * Add any job subscriptions...
1912 add_job_subscriptions(con
, job
);
1915 * Set all but the first two attributes to the job attributes group...
1918 for (attr
= job
->attrs
->attrs
->next
->next
; attr
; attr
= attr
->next
)
1919 attr
->group_tag
= IPP_TAG_JOB
;
1922 * Fire the "job created" event...
1925 cupsdAddEvent(CUPSD_EVENT_JOB_CREATED
, printer
, job
, "Job created.");
1928 * Return the new job...
1936 * 'add_job_subscriptions()' - Add any subscriptions for a job.
1940 add_job_subscriptions(
1941 cupsd_client_t
*con
, /* I - Client connection */
1942 cupsd_job_t
*job
) /* I - Newly created job */
1944 int i
; /* Looping var */
1945 ipp_attribute_t
*prev
, /* Previous attribute */
1946 *next
, /* Next attribute */
1947 *attr
; /* Current attribute */
1948 cupsd_subscription_t
*sub
; /* Subscription object */
1949 const char *recipient
, /* notify-recipient-uri */
1950 *pullmethod
; /* notify-pull-method */
1951 ipp_attribute_t
*user_data
; /* notify-user-data */
1952 int interval
; /* notify-time-interval */
1953 unsigned mask
; /* notify-events */
1957 * Find the first subscription group attribute; return if we have
1961 for (attr
= job
->attrs
->attrs
; attr
; attr
= attr
->next
)
1962 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
1969 * Process the subscription attributes in the request...
1978 mask
= CUPSD_EVENT_NONE
;
1980 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
1982 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
1983 attr
->value_tag
== IPP_TAG_URI
)
1986 * Validate the recipient scheme against the ServerBin/notifier
1990 char notifier
[1024], /* Notifier filename */
1991 scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
1992 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
1993 host
[HTTP_MAX_URI
], /* Host portion of URI */
1994 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
1995 int port
; /* Port portion of URI */
1998 recipient
= attr
->values
[0].string
.text
;
2000 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
2001 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
2002 host
, sizeof(host
), &port
,
2003 resource
, sizeof(resource
)) < HTTP_URI_OK
)
2005 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2006 _("Bad notify-recipient-uri \"%s\"."), recipient
);
2007 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2008 "notify-status-code", IPP_URI_SCHEME
);
2012 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
2014 if (access(notifier
, X_OK
))
2016 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2017 _("notify-recipient-uri URI \"%s\" uses unknown "
2018 "scheme."), recipient
);
2019 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2020 "notify-status-code", IPP_URI_SCHEME
);
2024 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
2026 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2027 _("notify-recipient-uri URI \"%s\" is already used."),
2029 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2030 "notify-status-code", IPP_ATTRIBUTES
);
2034 else if (!strcmp(attr
->name
, "notify-pull-method") &&
2035 attr
->value_tag
== IPP_TAG_KEYWORD
)
2037 pullmethod
= attr
->values
[0].string
.text
;
2039 if (strcmp(pullmethod
, "ippget"))
2041 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2042 _("Bad notify-pull-method \"%s\"."), pullmethod
);
2043 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2044 "notify-status-code", IPP_ATTRIBUTES
);
2048 else if (!strcmp(attr
->name
, "notify-charset") &&
2049 attr
->value_tag
== IPP_TAG_CHARSET
&&
2050 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
2051 strcmp(attr
->values
[0].string
.text
, "utf-8"))
2053 send_ipp_status(con
, IPP_CHARSET
,
2054 _("Character set \"%s\" not supported."),
2055 attr
->values
[0].string
.text
);
2058 else if (!strcmp(attr
->name
, "notify-natural-language") &&
2059 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
2060 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
2062 send_ipp_status(con
, IPP_CHARSET
,
2063 _("Language \"%s\" not supported."),
2064 attr
->values
[0].string
.text
);
2067 else if (!strcmp(attr
->name
, "notify-user-data") &&
2068 attr
->value_tag
== IPP_TAG_STRING
)
2070 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
2072 send_ipp_status(con
, IPP_REQUEST_VALUE
,
2073 _("The notify-user-data value is too large "
2074 "(%d > 63 octets)."),
2075 attr
->values
[0].unknown
.length
);
2081 else if (!strcmp(attr
->name
, "notify-events") &&
2082 attr
->value_tag
== IPP_TAG_KEYWORD
)
2084 for (i
= 0; i
< attr
->num_values
; i
++)
2085 mask
|= cupsdEventValue(attr
->values
[i
].string
.text
);
2087 else if (!strcmp(attr
->name
, "notify-lease-duration"))
2089 send_ipp_status(con
, IPP_BAD_REQUEST
,
2090 _("The notify-lease-duration attribute cannot be "
2091 "used with job subscriptions."));
2094 else if (!strcmp(attr
->name
, "notify-time-interval") &&
2095 attr
->value_tag
== IPP_TAG_INTEGER
)
2096 interval
= attr
->values
[0].integer
;
2101 if (!recipient
&& !pullmethod
)
2104 if (mask
== CUPSD_EVENT_NONE
)
2105 mask
= CUPSD_EVENT_JOB_COMPLETED
;
2107 if ((sub
= cupsdAddSubscription(mask
, cupsdFindDest(job
->dest
), job
,
2108 recipient
, 0)) != NULL
)
2110 sub
->interval
= interval
;
2112 cupsdSetString(&sub
->owner
, job
->username
);
2116 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
2117 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
2118 sub
->user_data_len
);
2121 ippAddSeparator(con
->response
);
2122 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
2123 "notify-subscription-id", sub
->id
);
2125 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
2133 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
2136 * Remove all of the subscription attributes from the job request...
2138 * TODO: Optimize this since subscription groups have to come at the
2139 * end of the request...
2142 for (attr
= job
->attrs
->attrs
, prev
= NULL
; attr
; attr
= next
)
2146 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
||
2147 attr
->group_tag
== IPP_TAG_ZERO
)
2150 * Free and remove this attribute...
2153 ippDeleteAttribute(NULL
, attr
);
2158 job
->attrs
->attrs
= next
;
2164 job
->attrs
->last
= prev
;
2165 job
->attrs
->current
= prev
;
2170 * 'add_job_uuid()' - Add job-uuid attribute to a job.
2172 * See RFC 4122 for the definition of UUIDs and the format.
2176 add_job_uuid(cupsd_job_t
*job
) /* I - Job */
2178 char uuid
[64]; /* job-uuid string */
2182 * Add a job-uuid attribute if none exists...
2185 if (!ippFindAttribute(job
->attrs
, "job-uuid", IPP_TAG_URI
))
2186 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uuid", NULL
,
2187 httpAssembleUUID(ServerName
, RemotePort
, job
->dest
, job
->id
,
2188 uuid
, sizeof(uuid
)));
2193 * 'add_printer()' - Add a printer to the system.
2197 add_printer(cupsd_client_t
*con
, /* I - Client connection */
2198 ipp_attribute_t
*uri
) /* I - URI of printer */
2200 http_status_t status
; /* Policy status */
2201 int i
; /* Looping var */
2202 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
2203 username
[HTTP_MAX_URI
], /* Username portion of URI */
2204 host
[HTTP_MAX_URI
], /* Host portion of URI */
2205 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2206 int port
; /* Port portion of URI */
2207 cupsd_printer_t
*printer
; /* Printer/class */
2208 ipp_attribute_t
*attr
; /* Printer attribute */
2209 cups_file_t
*fp
; /* Script/PPD file */
2210 char line
[1024]; /* Line from file... */
2211 char srcfile
[1024], /* Source Script/PPD file */
2212 dstfile
[1024]; /* Destination Script/PPD file */
2213 int modify
; /* Non-zero if we are modifying */
2214 int changed_driver
, /* Changed the PPD/interface script? */
2215 need_restart_job
, /* Need to restart job? */
2216 set_device_uri
, /* Did we set the device URI? */
2217 set_port_monitor
; /* Did we set the port monitor? */
2220 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer(%p[%d], %s)", con
,
2221 con
->number
, uri
->values
[0].string
.text
);
2224 * Do we have a valid URI?
2227 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
2228 sizeof(scheme
), username
, sizeof(username
), host
,
2229 sizeof(host
), &port
, resource
, sizeof(resource
));
2231 if (strncmp(resource
, "/printers/", 10) || strlen(resource
) == 10)
2234 * No, return an error...
2237 send_ipp_status(con
, IPP_BAD_REQUEST
,
2238 _("The printer-uri must be of the form "
2239 "\"ipp://HOSTNAME/printers/PRINTERNAME\"."));
2244 * Do we have a valid printer name?
2247 if (!validate_name(resource
+ 10))
2250 * No, return an error...
2253 send_ipp_status(con
, IPP_BAD_REQUEST
,
2254 _("The printer-uri \"%s\" contains invalid characters."),
2255 uri
->values
[0].string
.text
);
2260 * See if the printer already exists; if not, create a new printer...
2263 if ((printer
= cupsdFindPrinter(resource
+ 10)) == NULL
)
2266 * Printer doesn't exist; see if we have a class of the same name...
2269 if ((printer
= cupsdFindClass(resource
+ 10)) != NULL
)
2272 * Yes, return an error...
2275 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2276 _("A class named \"%s\" already exists."),
2282 * No, check the default policy then add the printer...
2285 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2287 send_http_error(con
, status
, NULL
);
2291 printer
= cupsdAddPrinter(resource
+ 10);
2294 else if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
2297 send_http_error(con
, status
, printer
);
2304 * Look for attributes and copy them over as needed...
2308 need_restart_job
= 0;
2310 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
2311 IPP_TAG_TEXT
)) != NULL
)
2312 cupsdSetString(&printer
->location
, 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",
2478 IPP_TAG_BOOLEAN
)) != NULL
)
2480 if (attr
->values
[0].boolean
&&
2481 printer
->num_auth_info_required
== 1 &&
2482 !strcmp(printer
->auth_info_required
[0], "negotiate"))
2484 send_ipp_status(con
, IPP_BAD_REQUEST
,
2485 _("Cannot share a remote Kerberized printer."));
2489 if (printer
->shared
&& !attr
->values
[0].boolean
)
2490 cupsdDeregisterPrinter(printer
, 1);
2492 cupsdLogMessage(CUPSD_LOG_INFO
,
2493 "Setting %s printer-is-shared to %d (was %d.)",
2494 printer
->name
, attr
->values
[0].boolean
, printer
->shared
);
2496 printer
->shared
= attr
->values
[0].boolean
;
2499 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
2500 IPP_TAG_ENUM
)) != NULL
)
2502 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
2503 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
2505 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad printer-state value %d."),
2506 attr
->values
[0].integer
);
2510 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
2511 printer
->name
, attr
->values
[0].integer
, printer
->state
);
2513 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
2514 cupsdStopPrinter(printer
, 0);
2517 need_restart_job
= 1;
2518 cupsdSetPrinterState(printer
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
2522 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
2523 IPP_TAG_TEXT
)) != NULL
)
2525 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
2526 sizeof(printer
->state_message
));
2528 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
, "%s",
2529 printer
->state_message
);
2532 if ((attr
= ippFindAttribute(con
->request
, "printer-state-reasons",
2533 IPP_TAG_KEYWORD
)) != NULL
)
2535 if (attr
->num_values
>
2536 (int)(sizeof(printer
->reasons
) / sizeof(printer
->reasons
[0])))
2538 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2539 _("Too many printer-state-reasons values (%d > %d)."),
2541 (int)(sizeof(printer
->reasons
) /
2542 sizeof(printer
->reasons
[0])));
2546 for (i
= 0; i
< printer
->num_reasons
; i
++)
2547 _cupsStrFree(printer
->reasons
[i
]);
2549 printer
->num_reasons
= 0;
2550 for (i
= 0; i
< attr
->num_values
; i
++)
2552 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
2555 printer
->reasons
[printer
->num_reasons
] =
2556 _cupsStrRetain(attr
->values
[i
].string
.text
);
2557 printer
->num_reasons
++;
2559 if (!strcmp(attr
->values
[i
].string
.text
, "paused") &&
2560 printer
->state
!= IPP_PRINTER_STOPPED
)
2562 cupsdLogMessage(CUPSD_LOG_INFO
,
2563 "Setting %s printer-state to %d (was %d.)",
2564 printer
->name
, IPP_PRINTER_STOPPED
, printer
->state
);
2565 cupsdStopPrinter(printer
, 0);
2569 if (PrintcapFormat
== PRINTCAP_PLIST
)
2570 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2572 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2573 "Printer \"%s\" state changed.", printer
->name
);
2576 set_printer_defaults(con
, printer
);
2578 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
2579 IPP_TAG_KEYWORD
)) != NULL
)
2580 cupsdSetAuthInfoRequired(printer
, NULL
, attr
);
2583 * See if we have all required attributes...
2586 if (!printer
->device_uri
)
2587 cupsdSetString(&printer
->device_uri
, "file:///dev/null");
2590 * See if we have an interface script or PPD file attached to the request...
2595 need_restart_job
= 1;
2598 strlcpy(srcfile
, con
->filename
, sizeof(srcfile
));
2600 if ((fp
= cupsFileOpen(srcfile
, "rb")))
2603 * Yes; get the first line from it...
2607 cupsFileGets(fp
, line
, sizeof(line
));
2611 * Then see what kind of file it is...
2614 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2617 if (!strncmp(line
, "*PPD-Adobe", 10))
2620 * The new file is a PPD file, so remove any old interface script
2621 * that might be lying around...
2629 * This must be an interface script, so move the file over to the
2630 * interfaces directory and make it executable...
2633 if (copy_file(srcfile
, dstfile
))
2635 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2636 _("Unable to copy interface script - %s"),
2641 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2642 "Copied interface script successfully");
2643 chmod(dstfile
, 0755);
2646 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2649 if (!strncmp(line
, "*PPD-Adobe", 10))
2652 * The new file is a PPD file, so move the file over to the
2653 * ppd directory and make it readable by all...
2656 if (copy_file(srcfile
, dstfile
))
2658 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2659 _("Unable to copy PPD file - %s"),
2664 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2665 "Copied PPD file successfully");
2666 chmod(dstfile
, 0644);
2671 * This must be an interface script, so remove any old PPD file that
2672 * may be lying around...
2679 else if ((attr
= ippFindAttribute(con
->request
, "ppd-name",
2680 IPP_TAG_NAME
)) != NULL
)
2682 need_restart_job
= 1;
2685 if (!strcmp(attr
->values
[0].string
.text
, "raw"))
2688 * Raw driver, remove any existing PPD or interface script files.
2691 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2695 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2705 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2709 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2712 if (copy_model(con
, attr
->values
[0].string
.text
, dstfile
))
2714 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file."));
2718 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2719 "Copied PPD file successfully");
2720 chmod(dstfile
, 0644);
2727 * If we changed the PPD/interface script, then remove the printer's cache
2728 * file and clear the printer-state-reasons...
2731 char cache_name
[1024]; /* Cache filename for printer attrs */
2733 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.data", CacheDir
,
2737 cupsdSetPrinterReasons(printer
, "none");
2740 * (Re)register color profiles...
2743 cupsdRegisterColor(printer
);
2747 * If we set the device URI but not the port monitor, check which port
2748 * monitor to use by default...
2751 if (set_device_uri
&& !set_port_monitor
)
2753 ppd_file_t
*ppd
; /* PPD file */
2754 ppd_attr_t
*ppdattr
; /* cupsPortMonitor attribute */
2757 httpSeparateURI(HTTP_URI_CODING_ALL
, printer
->device_uri
, scheme
,
2758 sizeof(scheme
), username
, sizeof(username
), host
,
2759 sizeof(host
), &port
, resource
, sizeof(resource
));
2761 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
,
2763 if ((ppd
= _ppdOpenFile(srcfile
, _PPD_LOCALIZATION_NONE
)) != NULL
)
2765 for (ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2767 ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
2768 if (!strcmp(scheme
, ppdattr
->spec
))
2770 cupsdLogMessage(CUPSD_LOG_INFO
,
2771 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2772 printer
->name
, ppdattr
->value
,
2773 printer
->port_monitor
? printer
->port_monitor
2776 if (strcmp(ppdattr
->value
, "none"))
2777 cupsdSetString(&printer
->port_monitor
, ppdattr
->value
);
2779 cupsdClearString(&printer
->port_monitor
);
2789 * Update the printer attributes and return...
2792 cupsdSetPrinterAttrs(printer
);
2793 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2795 if (need_restart_job
&& printer
->job
)
2798 * Restart the current job...
2801 cupsdSetJobState(printer
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
2802 "Job restarted because the printer was modified.");
2805 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2809 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
2810 printer
, NULL
, "Printer \"%s\" modified by \"%s\".",
2811 printer
->name
, get_username(con
));
2813 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" modified by \"%s\".",
2814 printer
->name
, get_username(con
));
2818 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
2819 printer
, NULL
, "New printer \"%s\" added by \"%s\".",
2820 printer
->name
, get_username(con
));
2822 cupsdLogMessage(CUPSD_LOG_INFO
, "New printer \"%s\" added by \"%s\".",
2823 printer
->name
, get_username(con
));
2826 con
->response
->request
.status
.status_code
= IPP_OK
;
2831 * 'add_printer_state_reasons()' - Add the "printer-state-reasons" attribute
2832 * based upon the printer state...
2836 add_printer_state_reasons(
2837 cupsd_client_t
*con
, /* I - Client connection */
2838 cupsd_printer_t
*p
) /* I - Printer info */
2840 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2841 "add_printer_state_reasons(%p[%d], %p[%s])",
2842 con
, con
->number
, p
, p
->name
);
2844 if (p
->num_reasons
== 0)
2845 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2846 "printer-state-reasons", NULL
, "none");
2848 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2849 "printer-state-reasons", p
->num_reasons
, NULL
,
2850 (const char * const *)p
->reasons
);
2855 * 'add_queued_job_count()' - Add the "queued-job-count" attribute for
2856 * the specified printer or class.
2860 add_queued_job_count(
2861 cupsd_client_t
*con
, /* I - Client connection */
2862 cupsd_printer_t
*p
) /* I - Printer or class */
2864 int count
; /* Number of jobs on destination */
2867 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_queued_job_count(%p[%d], %p[%s])",
2868 con
, con
->number
, p
, p
->name
);
2870 count
= cupsdGetPrinterJobCount(p
->name
);
2872 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2873 "queued-job-count", count
);
2878 * 'apply_printer_defaults()' - Apply printer default options to a job.
2882 apply_printer_defaults(
2883 cupsd_printer_t
*printer
, /* I - Printer */
2884 cupsd_job_t
*job
) /* I - Job */
2886 int i
, /* Looping var */
2887 num_options
; /* Number of default options */
2888 cups_option_t
*options
, /* Default options */
2889 *option
; /* Current option */
2893 * Collect all of the default options and add the missing ones to the
2897 for (i
= printer
->num_options
, num_options
= 0, options
= NULL
,
2898 option
= printer
->options
;
2901 if (!ippFindAttribute(job
->attrs
, option
->name
, IPP_TAG_ZERO
))
2903 num_options
= cupsAddOption(option
->name
, option
->value
, num_options
,
2908 * Encode these options as attributes in the job object...
2911 cupsEncodeOptions2(job
->attrs
, num_options
, options
, IPP_TAG_JOB
);
2912 cupsFreeOptions(num_options
, options
);
2917 * 'authenticate_job()' - Set job authentication info.
2921 authenticate_job(cupsd_client_t
*con
, /* I - Client connection */
2922 ipp_attribute_t
*uri
) /* I - Job URI */
2924 ipp_attribute_t
*attr
, /* job-id attribute */
2925 *auth_info
; /* auth-info attribute */
2926 int jobid
; /* Job ID */
2927 cupsd_job_t
*job
; /* Current job */
2928 char scheme
[HTTP_MAX_URI
],
2929 /* Method portion of URI */
2930 username
[HTTP_MAX_URI
],
2931 /* Username portion of URI */
2933 /* Host portion of URI */
2934 resource
[HTTP_MAX_URI
];
2935 /* Resource portion of URI */
2936 int port
; /* Port portion of URI */
2939 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "authenticate_job(%p[%d], %s)",
2940 con
, con
->number
, uri
->values
[0].string
.text
);
2943 * Start with "everything is OK" status...
2946 con
->response
->request
.status
.status_code
= IPP_OK
;
2949 * See if we have a job URI or a printer URI...
2952 if (!strcmp(uri
->name
, "printer-uri"))
2955 * Got a printer URI; see if we also have a job-id attribute...
2958 if ((attr
= ippFindAttribute(con
->request
, "job-id",
2959 IPP_TAG_INTEGER
)) == NULL
)
2961 send_ipp_status(con
, IPP_BAD_REQUEST
,
2962 _("Got a printer-uri attribute but no job-id."));
2966 jobid
= attr
->values
[0].integer
;
2971 * Got a job URI; parse it to get the job ID...
2974 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
2975 sizeof(scheme
), username
, sizeof(username
), host
,
2976 sizeof(host
), &port
, resource
, sizeof(resource
));
2978 if (strncmp(resource
, "/jobs/", 6))
2984 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
2985 uri
->values
[0].string
.text
);
2989 jobid
= atoi(resource
+ 6);
2993 * See if the job exists...
2996 if ((job
= cupsdFindJob(jobid
)) == NULL
)
2999 * Nope - return a "not found" error...
3002 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
3007 * See if the job has been completed...
3010 if (job
->state_value
!= IPP_JOB_HELD
)
3013 * Return a "not-possible" error...
3016 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3017 _("Job #%d is not held for authentication."),
3023 * See if we have already authenticated...
3026 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
3028 if (!con
->username
[0] && !auth_info
)
3030 cupsd_printer_t
*printer
; /* Job destination */
3033 * No auth data. If we need to authenticate via Kerberos, send a
3034 * HTTP auth challenge, otherwise just return an IPP error...
3037 printer
= cupsdFindDest(job
->dest
);
3039 if (printer
&& printer
->num_auth_info_required
> 0 &&
3040 !strcmp(printer
->auth_info_required
[0], "negotiate"))
3041 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
3043 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
3044 _("No authentication information provided."));
3049 * See if the job is owned by the requesting user...
3052 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3054 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3055 cupsdFindDest(job
->dest
));
3060 * Save the authentication information for this job...
3063 save_auth_info(con
, job
, auth_info
);
3066 * Reset the job-hold-until value to "no-hold"...
3069 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
3070 IPP_TAG_KEYWORD
)) == NULL
)
3071 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
3075 attr
->value_tag
= IPP_TAG_KEYWORD
;
3076 cupsdSetString(&(attr
->values
[0].string
.text
), "no-hold");
3080 * Release the job and return...
3083 cupsdReleaseJob(job
);
3085 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, NULL
, job
, "Job authenticated by user");
3087 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Authenticated by \"%s\".", con
->username
);
3094 * 'cancel_all_jobs()' - Cancel all or selected print jobs.
3098 cancel_all_jobs(cupsd_client_t
*con
, /* I - Client connection */
3099 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3101 int i
; /* Looping var */
3102 http_status_t status
; /* Policy status */
3103 cups_ptype_t dtype
; /* Destination type */
3104 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3105 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
3106 hostname
[HTTP_MAX_URI
], /* Host portion of URI */
3107 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3108 int port
; /* Port portion of URI */
3109 ipp_attribute_t
*attr
; /* Attribute in request */
3110 const char *username
= NULL
; /* Username */
3111 cupsd_jobaction_t purge
= CUPSD_JOB_DEFAULT
;
3113 cupsd_printer_t
*printer
; /* Printer */
3114 ipp_attribute_t
*job_ids
; /* job-ids attribute */
3115 cupsd_job_t
*job
; /* Job */
3118 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_all_jobs(%p[%d], %s)", con
,
3119 con
->number
, uri
->values
[0].string
.text
);
3122 * Get the jobs to cancel/purge...
3125 switch (con
->request
->request
.op
.operation_id
)
3127 case IPP_PURGE_JOBS
:
3129 * Get the username (if any) for the jobs we want to cancel (only if
3130 * "my-jobs" is specified...
3133 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
3134 IPP_TAG_BOOLEAN
)) != NULL
&&
3135 attr
->values
[0].boolean
)
3137 if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3138 IPP_TAG_NAME
)) != NULL
)
3139 username
= attr
->values
[0].string
.text
;
3142 send_ipp_status(con
, IPP_BAD_REQUEST
,
3143 _("Missing requesting-user-name attribute."));
3149 * Look for the "purge-jobs" attribute...
3152 if ((attr
= ippFindAttribute(con
->request
, "purge-jobs",
3153 IPP_TAG_BOOLEAN
)) != NULL
)
3154 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
3156 purge
= CUPSD_JOB_PURGE
;
3159 case IPP_CANCEL_MY_JOBS
:
3160 if (con
->username
[0])
3161 username
= con
->username
;
3162 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3163 IPP_TAG_NAME
)) != NULL
)
3164 username
= attr
->values
[0].string
.text
;
3167 send_ipp_status(con
, IPP_BAD_REQUEST
,
3168 _("Missing requesting-user-name attribute."));
3176 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
3179 * See if we have a printer URI...
3182 if (strcmp(uri
->name
, "printer-uri"))
3184 send_ipp_status(con
, IPP_BAD_REQUEST
,
3185 _("The printer-uri attribute is required."));
3190 * And if the destination is valid...
3193 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3199 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
,
3200 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
3201 hostname
, sizeof(hostname
), &port
,
3202 resource
, sizeof(resource
));
3204 if ((!strncmp(resource
, "/printers/", 10) && resource
[10]) ||
3205 (!strncmp(resource
, "/classes/", 9) && resource
[9]))
3207 send_ipp_status(con
, IPP_NOT_FOUND
,
3208 _("The printer or class does not exist."));
3216 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
3218 send_http_error(con
, status
, NULL
);
3224 for (i
= 0; i
< job_ids
->num_values
; i
++)
3226 if ((job
= cupsdFindJob(job_ids
->values
[i
].integer
)) == NULL
)
3229 if (con
->request
->request
.op
.operation_id
== IPP_CANCEL_MY_JOBS
&&
3230 _cups_strcasecmp(job
->username
, username
))
3234 if (i
< job_ids
->num_values
)
3236 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3237 job_ids
->values
[i
].integer
);
3241 for (i
= 0; i
< job_ids
->num_values
; i
++)
3243 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
3245 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3246 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
3247 "Job canceled by user.");
3250 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
3251 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3257 * Cancel all jobs on all printers...
3260 cupsdCancelJobs(NULL
, username
, purge
);
3262 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs were %s by \"%s\".",
3263 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3273 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
3276 send_http_error(con
, status
, printer
);
3282 for (i
= 0; i
< job_ids
->num_values
; i
++)
3284 if ((job
= cupsdFindJob(job_ids
->values
[i
].integer
)) == NULL
||
3285 _cups_strcasecmp(job
->dest
, printer
->name
))
3288 if (con
->request
->request
.op
.operation_id
== IPP_CANCEL_MY_JOBS
&&
3289 _cups_strcasecmp(job
->username
, username
))
3293 if (i
< job_ids
->num_values
)
3295 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3296 job_ids
->values
[i
].integer
);
3300 for (i
= 0; i
< job_ids
->num_values
; i
++)
3302 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
3304 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3305 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
3306 "Job canceled by user.");
3309 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
3310 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3316 * Cancel all of the jobs on the named printer...
3319 cupsdCancelJobs(printer
->name
, username
, purge
);
3321 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs on \"%s\" were %s by \"%s\".",
3323 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3328 con
->response
->request
.status
.status_code
= IPP_OK
;
3333 * 'cancel_job()' - Cancel a print job.
3337 cancel_job(cupsd_client_t
*con
, /* I - Client connection */
3338 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3340 ipp_attribute_t
*attr
; /* Current attribute */
3341 int jobid
; /* Job ID */
3342 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3343 username
[HTTP_MAX_URI
], /* Username portion of URI */
3344 host
[HTTP_MAX_URI
], /* Host portion of URI */
3345 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3346 int port
; /* Port portion of URI */
3347 cupsd_job_t
*job
; /* Job information */
3348 cups_ptype_t dtype
; /* Destination type (printer/class) */
3349 cupsd_printer_t
*printer
; /* Printer data */
3350 cupsd_jobaction_t purge
; /* Purge the job? */
3353 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_job(%p[%d], %s)", con
,
3354 con
->number
, uri
->values
[0].string
.text
);
3357 * See if we have a job URI or a printer URI...
3360 if (!strcmp(uri
->name
, "printer-uri"))
3363 * Got a printer URI; see if we also have a job-id attribute...
3366 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3367 IPP_TAG_INTEGER
)) == NULL
)
3369 send_ipp_status(con
, IPP_BAD_REQUEST
,
3370 _("Got a printer-uri attribute but no job-id."));
3374 if ((jobid
= attr
->values
[0].integer
) == 0)
3377 * Find the current job on the specified printer...
3380 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3386 send_ipp_status(con
, IPP_NOT_FOUND
,
3387 _("The printer or class does not exist."));
3392 * See if there are any pending jobs...
3395 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3397 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3398 if (job
->state_value
<= IPP_JOB_PROCESSING
&&
3399 !_cups_strcasecmp(job
->dest
, printer
->name
))
3407 * No, try stopped jobs...
3410 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3412 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3413 if (job
->state_value
== IPP_JOB_STOPPED
&&
3414 !_cups_strcasecmp(job
->dest
, printer
->name
))
3421 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("No active jobs on %s."),
3431 * Got a job URI; parse it to get the job ID...
3434 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
3435 sizeof(scheme
), username
, sizeof(username
), host
,
3436 sizeof(host
), &port
, resource
, sizeof(resource
));
3438 if (strncmp(resource
, "/jobs/", 6))
3444 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
3445 uri
->values
[0].string
.text
);
3449 jobid
= atoi(resource
+ 6);
3453 * Look for the "purge-job" attribute...
3456 if ((attr
= ippFindAttribute(con
->request
, "purge-job",
3457 IPP_TAG_BOOLEAN
)) != NULL
)
3458 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
3460 purge
= CUPSD_JOB_DEFAULT
;
3463 * See if the job exists...
3466 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3469 * Nope - return a "not found" error...
3472 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
3477 * See if the job is owned by the requesting user...
3480 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3482 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3483 cupsdFindDest(job
->dest
));
3488 * See if the job is already completed, canceled, or aborted; if so,
3489 * we can't cancel...
3492 if (job
->state_value
>= IPP_JOB_CANCELED
&& purge
!= CUPSD_JOB_PURGE
)
3494 switch (job
->state_value
)
3496 case IPP_JOB_CANCELED
:
3497 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3498 _("Job #%d is already canceled - can\'t cancel."),
3502 case IPP_JOB_ABORTED
:
3503 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3504 _("Job #%d is already aborted - can\'t cancel."),
3509 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3510 _("Job #%d is already completed - can\'t cancel."),
3519 * Cancel the job and return...
3522 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3523 purge
== CUPSD_JOB_PURGE
? "Job purged by \"%s\"" :
3524 "Job canceled by \"%s\"",
3528 if (purge
== CUPSD_JOB_PURGE
)
3529 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Purged by \"%s\".", jobid
,
3532 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Canceled by \"%s\".", jobid
,
3535 con
->response
->request
.status
.status_code
= IPP_OK
;
3540 * 'cancel_subscription()' - Cancel a subscription.
3544 cancel_subscription(
3545 cupsd_client_t
*con
, /* I - Client connection */
3546 int sub_id
) /* I - Subscription ID */
3548 http_status_t status
; /* Policy status */
3549 cupsd_subscription_t
*sub
; /* Subscription */
3552 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3553 "cancel_subscription(con=%p[%d], sub_id=%d)",
3554 con
, con
->number
, sub_id
);
3557 * Is the subscription ID valid?
3560 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
3563 * Bad subscription ID...
3566 send_ipp_status(con
, IPP_NOT_FOUND
,
3567 _("Subscription #%d does not exist."), sub_id
);
3575 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
3577 con
, sub
->owner
)) != HTTP_OK
)
3579 send_http_error(con
, status
, sub
->dest
);
3584 * Cancel the subscription...
3587 cupsdDeleteSubscription(sub
, 1);
3589 con
->response
->request
.status
.status_code
= IPP_OK
;
3594 * 'check_rss_recipient()' - Check that we do not have a duplicate RSS feed URI.
3597 static int /* O - 1 if OK, 0 if not */
3598 check_rss_recipient(
3599 const char *recipient
) /* I - Recipient URI */
3601 cupsd_subscription_t
*sub
; /* Current subscription */
3604 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
);
3606 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
3610 * Compare the URIs up to the first ?...
3613 const char *r1
, *r2
;
3615 for (r1
= recipient
, r2
= sub
->recipient
;
3616 *r1
== *r2
&& *r1
&& *r1
!= '?' && *r2
&& *r2
!= '?';
3628 * 'check_quotas()' - Check quotas for a printer and user.
3631 static int /* O - 1 if OK, 0 if forbidden,
3632 -1 if limit reached */
3633 check_quotas(cupsd_client_t
*con
, /* I - Client connection */
3634 cupsd_printer_t
*p
) /* I - Printer or class */
3636 char username
[33], /* Username */
3637 *name
; /* Current user name */
3638 cupsd_quota_t
*q
; /* Quota data */
3639 #ifdef HAVE_MBR_UID_TO_UUID
3641 * Use Apple membership APIs which require that all names represent
3642 * valid user account or group records accessible by the server.
3645 uuid_t usr_uuid
; /* UUID for job requesting user */
3646 uuid_t usr2_uuid
; /* UUID for ACL user name entry */
3647 uuid_t grp_uuid
; /* UUID for ACL group name entry */
3648 int mbr_err
; /* Error from membership function */
3649 int is_member
; /* Is this user a member? */
3652 * Use standard POSIX APIs for checking users and groups...
3655 struct passwd
*pw
; /* User password data */
3656 #endif /* HAVE_MBR_UID_TO_UUID */
3659 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "check_quotas(%p[%d], %p[%s])",
3660 con
, con
->number
, p
, p
->name
);
3663 * Figure out who is printing...
3666 strlcpy(username
, get_username(con
), sizeof(username
));
3668 if ((name
= strchr(username
, '@')) != NULL
)
3669 *name
= '\0'; /* Strip @REALM */
3672 * Check global active job limits for printers and users...
3675 if (MaxJobsPerPrinter
)
3678 * Check if there are too many pending jobs on this printer...
3681 if (cupsdGetPrinterJobCount(p
->name
) >= MaxJobsPerPrinter
)
3683 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for printer \"%s\"...",
3692 * Check if there are too many pending jobs for this user...
3695 if (cupsdGetUserJobCount(username
) >= MaxJobsPerUser
)
3697 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for user \"%s\"...",
3704 * Check against users...
3707 if (cupsArrayCount(p
->users
) == 0 && p
->k_limit
== 0 && p
->page_limit
== 0)
3710 if (cupsArrayCount(p
->users
))
3712 #ifdef HAVE_MBR_UID_TO_UUID
3714 * Get UUID for job requesting user...
3717 if (mbr_user_name_to_uuid((char *)username
, usr_uuid
))
3723 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3724 "check_quotas: UUID lookup failed for user \"%s\"",
3726 cupsdLogMessage(CUPSD_LOG_INFO
,
3727 "Denying user \"%s\" access to printer \"%s\" "
3728 "(unknown user)...",
3734 * Get UID and GID of requesting user...
3737 pw
= getpwnam(username
);
3739 #endif /* HAVE_MBR_UID_TO_UUID */
3741 for (name
= (char *)cupsArrayFirst(p
->users
);
3743 name
= (char *)cupsArrayNext(p
->users
))
3747 * Check group membership...
3750 #ifdef HAVE_MBR_UID_TO_UUID
3753 if (uuid_parse(name
+ 2, grp_uuid
))
3754 uuid_clear(grp_uuid
);
3756 else if ((mbr_err
= mbr_group_name_to_uuid(name
+ 1, grp_uuid
)) != 0)
3759 * Invalid ACL entries are ignored for matching; just record a
3760 * warning in the log...
3763 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3764 "check_quotas: UUID lookup failed for ACL entry "
3765 "\"%s\" (err=%d)", name
, mbr_err
);
3766 cupsdLogMessage(CUPSD_LOG_WARN
,
3767 "Access control entry \"%s\" not a valid group name; "
3768 "entry ignored", name
);
3771 if ((mbr_err
= mbr_check_membership(usr_uuid
, grp_uuid
,
3775 * At this point, there should be no errors, but check anyways...
3778 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3779 "check_quotas: group \"%s\" membership check "
3780 "failed (err=%d)", name
+ 1, mbr_err
);
3785 * Stop if we found a match...
3792 if (cupsdCheckGroup(username
, pw
, name
+ 1))
3794 #endif /* HAVE_MBR_UID_TO_UUID */
3796 #ifdef HAVE_MBR_UID_TO_UUID
3801 if (uuid_parse(name
+ 1, usr2_uuid
))
3802 uuid_clear(usr2_uuid
);
3804 else if ((mbr_err
= mbr_user_name_to_uuid(name
, usr2_uuid
)) != 0)
3807 * Invalid ACL entries are ignored for matching; just record a
3808 * warning in the log...
3811 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3812 "check_quotas: UUID lookup failed for ACL entry "
3813 "\"%s\" (err=%d)", name
, mbr_err
);
3814 cupsdLogMessage(CUPSD_LOG_WARN
,
3815 "Access control entry \"%s\" not a valid user name; "
3816 "entry ignored", name
);
3819 if (!uuid_compare(usr_uuid
, usr2_uuid
))
3823 else if (!_cups_strcasecmp(username
, name
))
3825 #endif /* HAVE_MBR_UID_TO_UUID */
3827 if ((name
!= NULL
) == p
->deny_users
)
3829 cupsdLogMessage(CUPSD_LOG_INFO
,
3830 "Denying user \"%s\" access to printer \"%s\"...",
3840 if (p
->k_limit
|| p
->page_limit
)
3842 if ((q
= cupsdUpdateQuota(p
, username
, 0, 0)) == NULL
)
3844 cupsdLogMessage(CUPSD_LOG_ERROR
,
3845 "Unable to allocate quota data for user \"%s\"",
3850 if ((q
->k_count
>= p
->k_limit
&& p
->k_limit
) ||
3851 (q
->page_count
>= p
->page_limit
&& p
->page_limit
))
3853 cupsdLogMessage(CUPSD_LOG_INFO
, "User \"%s\" is over the quota limit...",
3860 * If we have gotten this far, we're done!
3868 * 'close_job()' - Close a multi-file job.
3872 close_job(cupsd_client_t
*con
, /* I - Client connection */
3873 ipp_attribute_t
*uri
) /* I - Printer URI */
3875 cupsd_job_t
*job
; /* Job */
3876 ipp_attribute_t
*attr
; /* Attribute */
3877 char job_uri
[HTTP_MAX_URI
],
3879 username
[256]; /* User name */
3882 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "close_job(%p[%d], %s)", con
,
3883 con
->number
, uri
->values
[0].string
.text
);
3886 * See if we have a job URI or a printer URI...
3889 if (strcmp(uri
->name
, "printer-uri"))
3892 * job-uri is not supported by Close-Job!
3895 send_ipp_status(con
, IPP_BAD_REQUEST
,
3896 _("Close-Job doesn't support the job-uri attribute."));
3901 * Got a printer URI; see if we also have a job-id attribute...
3904 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3905 IPP_TAG_INTEGER
)) == NULL
)
3907 send_ipp_status(con
, IPP_BAD_REQUEST
,
3908 _("Got a printer-uri attribute but no job-id."));
3912 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
3915 * Nope - return a "not found" error...
3918 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3919 attr
->values
[0].integer
);
3924 * See if the job is owned by the requesting user...
3927 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3929 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3930 cupsdFindDest(job
->dest
));
3935 * Add any ending sheet...
3938 if (cupsdTimeoutJob(job
))
3941 if (job
->state_value
== IPP_JOB_STOPPED
)
3943 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
3944 job
->state_value
= IPP_JOB_PENDING
;
3946 else if (job
->state_value
== IPP_JOB_HELD
)
3948 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
3949 IPP_TAG_KEYWORD
)) == NULL
)
3950 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
3952 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
3954 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
3955 job
->state_value
= IPP_JOB_PENDING
;
3960 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
3963 * Fill in the response info...
3966 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
3967 con
->clientname
, con
->clientport
, "/jobs/%d", job
->id
);
3968 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
3971 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
3973 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
3976 con
->response
->request
.status
.status_code
= IPP_OK
;
3979 * Start the job if necessary...
3987 * 'copy_attrs()' - Copy attributes from one request to another.
3991 copy_attrs(ipp_t
*to
, /* I - Destination request */
3992 ipp_t
*from
, /* I - Source request */
3993 cups_array_t
*ra
, /* I - Requested attributes */
3994 ipp_tag_t group
, /* I - Group to copy */
3995 int quickcopy
, /* I - Do a quick copy? */
3996 cups_array_t
*exclude
) /* I - Attributes to exclude? */
3998 ipp_attribute_t
*fromattr
; /* Source attribute */
4001 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4002 "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)",
4003 to
, from
, ra
, group
, quickcopy
);
4008 for (fromattr
= from
->attrs
; fromattr
; fromattr
= fromattr
->next
)
4011 * Filter attributes as needed...
4014 if ((group
!= IPP_TAG_ZERO
&& fromattr
->group_tag
!= group
&&
4015 fromattr
->group_tag
!= IPP_TAG_ZERO
) || !fromattr
->name
)
4018 if (!strcmp(fromattr
->name
, "document-password") ||
4019 !strcmp(fromattr
->name
, "job-authorization-uri") ||
4020 !strcmp(fromattr
->name
, "job-password") ||
4021 !strcmp(fromattr
->name
, "job-password-encryption") ||
4022 !strcmp(fromattr
->name
, "job-printer-uri"))
4026 (cupsArrayFind(exclude
, fromattr
->name
) ||
4027 cupsArrayFind(exclude
, "all")))
4030 * We need to exclude this attribute for security reasons; we require the
4031 * job-id attribute regardless of the security settings for IPP
4034 * The job-printer-uri attribute is handled by copy_job_attrs().
4036 * Subscription attribute security is handled by copy_subscription_attrs().
4039 if (strcmp(fromattr
->name
, "job-id"))
4043 if (!ra
|| cupsArrayFind(ra
, fromattr
->name
))
4046 * Don't send collection attributes by default to IPP/1.x clients
4047 * since many do not support collections. Also don't send
4048 * media-col-database unless specifically requested by the client.
4051 if (fromattr
->value_tag
== IPP_TAG_BEGIN_COLLECTION
&&
4053 (to
->request
.status
.version
[0] == 1 ||
4054 !strcmp(fromattr
->name
, "media-col-database")))
4057 ippCopyAttribute(to
, fromattr
, quickcopy
);
4064 * 'copy_banner()' - Copy a banner file to the requests directory for the
4068 static int /* O - Size of banner file in kbytes */
4069 copy_banner(cupsd_client_t
*con
, /* I - Client connection */
4070 cupsd_job_t
*job
, /* I - Job information */
4071 const char *name
) /* I - Name of banner */
4073 int i
; /* Looping var */
4074 int kbytes
; /* Size of banner file in kbytes */
4075 char filename
[1024]; /* Job filename */
4076 cupsd_banner_t
*banner
; /* Pointer to banner */
4077 cups_file_t
*in
; /* Input file */
4078 cups_file_t
*out
; /* Output file */
4079 int ch
; /* Character from file */
4080 char attrname
[255], /* Name of attribute */
4081 *s
; /* Pointer into name */
4082 ipp_attribute_t
*attr
; /* Attribute */
4085 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4086 "copy_banner(con=%p[%d], job=%p[%d], name=\"%s\")",
4087 con
, con
? con
->number
: -1, job
, job
->id
,
4088 name
? name
: "(null)");
4091 * Find the banner; return if not found or "none"...
4094 if (!name
|| !strcmp(name
, "none") ||
4095 (banner
= cupsdFindBanner(name
)) == NULL
)
4099 * Open the banner and job files...
4102 if (add_file(con
, job
, banner
->filetype
, 0))
4105 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
4107 if ((out
= cupsFileOpen(filename
, "w")) == NULL
)
4109 cupsdLogMessage(CUPSD_LOG_ERROR
,
4110 "Unable to create banner job file %s - %s",
4111 filename
, strerror(errno
));
4116 fchmod(cupsFileNumber(out
), 0640);
4117 fchown(cupsFileNumber(out
), RunUser
, Group
);
4120 * Try the localized banner file under the subdirectory...
4123 strlcpy(attrname
, job
->attrs
->attrs
->next
->values
[0].string
.text
,
4125 if (strlen(attrname
) > 2 && attrname
[2] == '-')
4128 * Convert ll-cc to ll_CC...
4132 attrname
[3] = (char)toupper(attrname
[3] & 255);
4133 attrname
[4] = (char)toupper(attrname
[4] & 255);
4136 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4139 if (access(filename
, 0) && strlen(attrname
) > 2)
4142 * Wasn't able to find "ll_CC" locale file; try the non-national
4143 * localization banner directory.
4148 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4152 if (access(filename
, 0))
4155 * Use the non-localized banner file.
4158 snprintf(filename
, sizeof(filename
), "%s/banners/%s", DataDir
, name
);
4161 if ((in
= cupsFileOpen(filename
, "r")) == NULL
)
4165 cupsdLogMessage(CUPSD_LOG_ERROR
,
4166 "Unable to open banner template file %s - %s",
4167 filename
, strerror(errno
));
4173 * Parse the file to the end...
4176 while ((ch
= cupsFileGetChar(in
)) != EOF
)
4180 * Get an attribute name...
4183 for (s
= attrname
; (ch
= cupsFileGetChar(in
)) != EOF
;)
4184 if (!isalpha(ch
& 255) && ch
!= '-' && ch
!= '?')
4186 else if (s
< (attrname
+ sizeof(attrname
) - 1))
4196 * Ignore { followed by stuff that is not an attribute name...
4199 cupsFilePrintf(out
, "{%s%c", attrname
, ch
);
4204 * See if it is defined...
4207 if (attrname
[0] == '?')
4212 if (!strcmp(s
, "printer-name"))
4214 cupsFilePuts(out
, job
->dest
);
4217 else if ((attr
= ippFindAttribute(job
->attrs
, s
, IPP_TAG_ZERO
)) == NULL
)
4220 * See if we have a leading question mark...
4223 if (attrname
[0] != '?')
4226 * Nope, write to file as-is; probably a PostScript procedure...
4229 cupsFilePrintf(out
, "{%s}", attrname
);
4236 * Output value(s)...
4239 for (i
= 0; i
< attr
->num_values
; i
++)
4242 cupsFilePutChar(out
, ',');
4244 switch (attr
->value_tag
)
4246 case IPP_TAG_INTEGER
:
4248 if (!strncmp(s
, "time-at-", 8))
4250 struct timeval tv
; /* Time value */
4252 tv
.tv_sec
= attr
->values
[i
].integer
;
4255 cupsFilePuts(out
, cupsdGetDateTime(&tv
, CUPSD_TIME_STANDARD
));
4258 cupsFilePrintf(out
, "%d", attr
->values
[i
].integer
);
4261 case IPP_TAG_BOOLEAN
:
4262 cupsFilePrintf(out
, "%d", attr
->values
[i
].boolean
);
4265 case IPP_TAG_NOVALUE
:
4266 cupsFilePuts(out
, "novalue");
4269 case IPP_TAG_RANGE
:
4270 cupsFilePrintf(out
, "%d-%d", attr
->values
[i
].range
.lower
,
4271 attr
->values
[i
].range
.upper
);
4274 case IPP_TAG_RESOLUTION
:
4275 cupsFilePrintf(out
, "%dx%d%s", attr
->values
[i
].resolution
.xres
,
4276 attr
->values
[i
].resolution
.yres
,
4277 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
4282 case IPP_TAG_STRING
:
4285 case IPP_TAG_KEYWORD
:
4286 case IPP_TAG_CHARSET
:
4287 case IPP_TAG_LANGUAGE
:
4288 if (!_cups_strcasecmp(banner
->filetype
->type
, "postscript"))
4291 * Need to quote strings for PS banners...
4296 for (p
= attr
->values
[i
].string
.text
; *p
; p
++)
4298 if (*p
== '(' || *p
== ')' || *p
== '\\')
4300 cupsFilePutChar(out
, '\\');
4301 cupsFilePutChar(out
, *p
);
4303 else if (*p
< 32 || *p
> 126)
4304 cupsFilePrintf(out
, "\\%03o", *p
& 255);
4306 cupsFilePutChar(out
, *p
);
4310 cupsFilePuts(out
, attr
->values
[i
].string
.text
);
4314 break; /* anti-compiler-warning-code */
4318 else if (ch
== '\\') /* Quoted char */
4320 ch
= cupsFileGetChar(in
);
4322 if (ch
!= '{') /* Only do special handling for \{ */
4323 cupsFilePutChar(out
, '\\');
4325 cupsFilePutChar(out
, ch
);
4328 cupsFilePutChar(out
, ch
);
4332 kbytes
= (cupsFileTell(out
) + 1023) / 1024;
4334 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
4335 IPP_TAG_INTEGER
)) != NULL
)
4336 attr
->values
[0].integer
+= kbytes
;
4345 * 'copy_file()' - Copy a PPD file or interface script...
4348 static int /* O - 0 = success, -1 = error */
4349 copy_file(const char *from
, /* I - Source file */
4350 const char *to
) /* I - Destination file */
4352 cups_file_t
*src
, /* Source file */
4353 *dst
; /* Destination file */
4354 int bytes
; /* Bytes to read/write */
4355 char buffer
[2048]; /* Copy buffer */
4358 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_file(\"%s\", \"%s\")", from
, to
);
4361 * Open the source and destination file for a copy...
4364 if ((src
= cupsFileOpen(from
, "rb")) == NULL
)
4367 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
4374 * Copy the source file to the destination...
4377 while ((bytes
= cupsFileRead(src
, buffer
, sizeof(buffer
))) > 0)
4378 if (cupsFileWrite(dst
, buffer
, (size_t)bytes
) < bytes
)
4386 * Close both files and return...
4391 return (cupsFileClose(dst
));
4396 * 'copy_model()' - Copy a PPD model file, substituting default values
4400 static int /* O - 0 = success, -1 = error */
4401 copy_model(cupsd_client_t
*con
, /* I - Client connection */
4402 const char *from
, /* I - Source file */
4403 const char *to
) /* I - Destination file */
4405 fd_set input
; /* select() input set */
4406 struct timeval timeout
; /* select() timeout */
4407 int maxfd
; /* Max file descriptor for select() */
4408 char tempfile
[1024]; /* Temporary PPD file */
4409 int tempfd
; /* Temporary PPD file descriptor */
4410 int temppid
; /* Process ID of cups-driverd */
4411 int temppipe
[2]; /* Temporary pipes */
4412 char *argv
[4], /* Command-line arguments */
4413 *envp
[MAX_ENV
]; /* Environment */
4414 cups_file_t
*src
, /* Source file */
4415 *dst
; /* Destination file */
4416 ppd_file_t
*ppd
; /* PPD file */
4417 int bytes
, /* Bytes from pipe */
4418 total
; /* Total bytes from pipe */
4419 char buffer
[2048]; /* Copy buffer */
4420 int i
; /* Looping var */
4421 char option
[PPD_MAX_NAME
], /* Option name */
4422 choice
[PPD_MAX_NAME
]; /* Choice name */
4423 ppd_size_t
*size
; /* Default size */
4424 int num_defaults
; /* Number of default options */
4425 cups_option_t
*defaults
; /* Default options */
4426 char cups_protocol
[PPD_MAX_LINE
];
4427 /* cupsProtocol attribute */
4430 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4431 "copy_model(con=%p, from=\"%s\", to=\"%s\")",
4435 * Run cups-driverd to get the PPD file...
4438 argv
[0] = "cups-driverd";
4440 argv
[2] = (char *)from
;
4443 cupsdLoadEnv(envp
, (int)(sizeof(envp
) / sizeof(envp
[0])));
4445 snprintf(buffer
, sizeof(buffer
), "%s/daemon/cups-driverd", ServerBin
);
4446 snprintf(tempfile
, sizeof(tempfile
), "%s/%d.ppd", TempDir
, con
->number
);
4447 tempfd
= open(tempfile
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
4448 if (tempfd
< 0 || cupsdOpenPipe(temppipe
))
4451 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4452 "copy_model: Running \"cups-driverd cat %s\"...", from
);
4454 if (!cupsdStartProcess(buffer
, argv
, envp
, -1, temppipe
[1], CGIPipes
[1],
4455 -1, -1, 0, DefaultProfile
, NULL
, &temppid
))
4466 * Wait up to 30 seconds for the PPD file to be copied...
4471 if (temppipe
[0] > CGIPipes
[0])
4472 maxfd
= temppipe
[0] + 1;
4474 maxfd
= CGIPipes
[0] + 1;
4479 * See if we have data ready...
4483 FD_SET(temppipe
[0], &input
);
4484 FD_SET(CGIPipes
[0], &input
);
4486 timeout
.tv_sec
= 30;
4487 timeout
.tv_usec
= 0;
4489 if ((i
= select(maxfd
, &input
, NULL
, NULL
, &timeout
)) < 0)
4499 * We have timed out...
4505 if (FD_ISSET(temppipe
[0], &input
))
4508 * Read the PPD file from the pipe, and write it to the PPD file.
4511 if ((bytes
= read(temppipe
[0], buffer
, sizeof(buffer
))) > 0)
4513 if (write(tempfd
, buffer
, (size_t)bytes
) < bytes
)
4522 if (FD_ISSET(CGIPipes
[0], &input
))
4532 * No data from cups-deviced...
4535 cupsdLogMessage(CUPSD_LOG_ERROR
, "copy_model: empty PPD file");
4541 * Open the source file for a copy...
4544 if ((src
= cupsFileOpen(tempfile
, "rb")) == NULL
)
4551 * Read the source file and see what page sizes are supported...
4554 if ((ppd
= _ppdOpen(src
, _PPD_LOCALIZATION_NONE
)) == NULL
)
4562 * Open the destination (if possible) and set the default options...
4567 cups_protocol
[0] = '\0';
4569 if ((dst
= cupsFileOpen(to
, "rb")) != NULL
)
4572 * Read all of the default lines from the old PPD...
4575 while (cupsFileGets(dst
, buffer
, sizeof(buffer
)))
4576 if (!strncmp(buffer
, "*Default", 8))
4579 * Add the default option...
4582 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
4583 choice
, sizeof(choice
)))
4585 ppd_option_t
*ppdo
; /* PPD option */
4589 * Only add the default if the default hasn't already been
4590 * set and the choice exists in the new PPD...
4593 if (!cupsGetOption(option
, num_defaults
, defaults
) &&
4594 (ppdo
= ppdFindOption(ppd
, option
)) != NULL
&&
4595 ppdFindChoice(ppdo
, choice
))
4596 num_defaults
= cupsAddOption(option
, choice
, num_defaults
,
4600 else if (!strncmp(buffer
, "*cupsProtocol:", 14))
4601 strlcpy(cups_protocol
, buffer
, sizeof(cups_protocol
));
4605 else if ((size
= ppdPageSize(ppd
, DefaultPaperSize
)) != NULL
)
4608 * Add the default media sizes...
4611 num_defaults
= cupsAddOption("PageSize", size
->name
,
4612 num_defaults
, &defaults
);
4613 num_defaults
= cupsAddOption("PageRegion", size
->name
,
4614 num_defaults
, &defaults
);
4615 num_defaults
= cupsAddOption("PaperDimension", size
->name
,
4616 num_defaults
, &defaults
);
4617 num_defaults
= cupsAddOption("ImageableArea", size
->name
,
4618 num_defaults
, &defaults
);
4624 * Open the destination file for a copy...
4627 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
4629 cupsFreeOptions(num_defaults
, defaults
);
4636 * Copy the source file to the destination...
4639 cupsFileRewind(src
);
4641 while (cupsFileGets(src
, buffer
, sizeof(buffer
)))
4643 if (!strncmp(buffer
, "*Default", 8))
4646 * Check for an previous default option choice...
4649 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
4650 choice
, sizeof(choice
)))
4652 const char *val
; /* Default option value */
4655 if ((val
= cupsGetOption(option
, num_defaults
, defaults
)) != NULL
)
4658 * Substitute the previous choice...
4661 snprintf(buffer
, sizeof(buffer
), "*Default%s: %s", option
, val
);
4666 cupsFilePrintf(dst
, "%s\n", buffer
);
4669 if (cups_protocol
[0])
4670 cupsFilePrintf(dst
, "%s\n", cups_protocol
);
4672 cupsFreeOptions(num_defaults
, defaults
);
4675 * Close both files and return...
4682 return (cupsFileClose(dst
));
4687 * 'copy_job_attrs()' - Copy job attributes.
4691 copy_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
4692 cupsd_job_t
*job
, /* I - Job */
4693 cups_array_t
*ra
, /* I - Requested attributes array */
4694 cups_array_t
*exclude
) /* I - Private attributes array */
4696 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
4700 * Send the requested attributes for each job...
4703 if (!cupsArrayFind(exclude
, "all"))
4705 if ((!exclude
|| !cupsArrayFind(exclude
, "number-of-documents")) &&
4706 (!ra
|| cupsArrayFind(ra
, "number-of-documents")))
4707 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4708 "number-of-documents", job
->num_files
);
4710 if ((!exclude
|| !cupsArrayFind(exclude
, "job-media-progress")) &&
4711 (!ra
|| cupsArrayFind(ra
, "job-media-progress")))
4712 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4713 "job-media-progress", job
->progress
);
4715 if ((!exclude
|| !cupsArrayFind(exclude
, "job-more-info")) &&
4716 (!ra
|| cupsArrayFind(ra
, "job-more-info")))
4718 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "http",
4719 NULL
, con
->clientname
, con
->clientport
, "/jobs/%d",
4721 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4722 "job-more-info", NULL
, job_uri
);
4725 if (job
->state_value
> IPP_JOB_PROCESSING
&&
4726 (!exclude
|| !cupsArrayFind(exclude
, "job-preserved")) &&
4727 (!ra
|| cupsArrayFind(ra
, "job-preserved")))
4728 ippAddBoolean(con
->response
, IPP_TAG_JOB
, "job-preserved",
4729 job
->num_files
> 0);
4731 if ((!exclude
|| !cupsArrayFind(exclude
, "job-printer-up-time")) &&
4732 (!ra
|| cupsArrayFind(ra
, "job-printer-up-time")))
4733 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4734 "job-printer-up-time", time(NULL
));
4737 if (!ra
|| cupsArrayFind(ra
, "job-printer-uri"))
4739 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
4740 con
->clientname
, con
->clientport
,
4741 (job
->dtype
& CUPS_PRINTER_CLASS
) ? "/classes/%s" :
4744 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4745 "job-printer-uri", NULL
, job_uri
);
4748 if (!ra
|| cupsArrayFind(ra
, "job-uri"))
4750 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
4751 con
->clientname
, con
->clientport
, "/jobs/%d",
4753 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4754 "job-uri", NULL
, job_uri
);
4757 copy_attrs(con
->response
, job
->attrs
, ra
, IPP_TAG_JOB
, 0, exclude
);
4762 * 'copy_printer_attrs()' - Copy printer attributes.
4767 cupsd_client_t
*con
, /* I - Client connection */
4768 cupsd_printer_t
*printer
, /* I - Printer */
4769 cups_array_t
*ra
) /* I - Requested attributes array */
4771 char printer_uri
[HTTP_MAX_URI
];
4773 char printer_icons
[HTTP_MAX_URI
];
4775 time_t curtime
; /* Current time */
4776 int i
; /* Looping var */
4780 * Copy the printer attributes to the response using requested-attributes
4781 * and document-format attributes that may be provided by the client.
4784 curtime
= time(NULL
);
4786 if (!ra
|| cupsArrayFind(ra
, "marker-change-time"))
4787 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4788 "marker-change-time", printer
->marker_time
);
4790 if (printer
->num_printers
> 0 &&
4791 (!ra
|| cupsArrayFind(ra
, "member-uris")))
4793 ipp_attribute_t
*member_uris
; /* member-uris attribute */
4794 cupsd_printer_t
*p2
; /* Printer in class */
4795 ipp_attribute_t
*p2_uri
; /* printer-uri-supported for class printer */
4798 if ((member_uris
= ippAddStrings(con
->response
, IPP_TAG_PRINTER
,
4799 IPP_TAG_URI
, "member-uris",
4800 printer
->num_printers
, NULL
,
4803 for (i
= 0; i
< printer
->num_printers
; i
++)
4805 p2
= printer
->printers
[i
];
4807 if ((p2_uri
= ippFindAttribute(p2
->attrs
, "printer-uri-supported",
4808 IPP_TAG_URI
)) != NULL
)
4809 member_uris
->values
[i
].string
.text
=
4810 _cupsStrRetain(p2_uri
->values
[0].string
.text
);
4813 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
,
4814 sizeof(printer_uri
), "ipp", NULL
, con
->clientname
,
4816 (p2
->type
& CUPS_PRINTER_CLASS
) ?
4817 "/classes/%s" : "/printers/%s", p2
->name
);
4818 member_uris
->values
[i
].string
.text
= _cupsStrAlloc(printer_uri
);
4824 if (printer
->alert
&& (!ra
|| cupsArrayFind(ra
, "printer-alert")))
4825 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_STRING
,
4826 "printer-alert", NULL
, printer
->alert
);
4828 if (printer
->alert_description
&&
4829 (!ra
|| cupsArrayFind(ra
, "printer-alert-description")))
4830 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4831 "printer-alert-description", NULL
,
4832 printer
->alert_description
);
4834 if (!ra
|| cupsArrayFind(ra
, "printer-current-time"))
4835 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-current-time",
4836 ippTimeToDate(curtime
));
4838 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
4839 if (!ra
|| cupsArrayFind(ra
, "printer-dns-sd-name"))
4841 if (printer
->reg_name
)
4842 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4843 "printer-dns-sd-name", NULL
, printer
->reg_name
);
4845 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
4846 "printer-dns-sd-name", 0);
4848 #endif /* HAVE_DNSSD || HAVE_AVAHI */
4850 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy"))
4851 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4852 "printer-error-policy", NULL
, printer
->error_policy
);
4854 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy-supported"))
4856 static const char * const errors
[] =/* printer-error-policy-supported values */
4859 "retry-current-job",
4864 if (printer
->type
& CUPS_PRINTER_CLASS
)
4865 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
4866 "printer-error-policy-supported", NULL
, "retry-current-job");
4868 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
4869 "printer-error-policy-supported",
4870 sizeof(errors
) / sizeof(errors
[0]), NULL
, errors
);
4873 if (!ra
|| cupsArrayFind(ra
, "printer-icons"))
4875 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_icons
, sizeof(printer_icons
),
4876 "http", NULL
, con
->clientname
, con
->clientport
,
4877 "/icons/%s.png", printer
->name
);
4878 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-icons",
4879 NULL
, printer_icons
);
4880 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-icons=\"%s\"", printer_icons
);
4883 if (!ra
|| cupsArrayFind(ra
, "printer-is-accepting-jobs"))
4884 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs", (char)printer
->accepting
);
4886 if (!ra
|| cupsArrayFind(ra
, "printer-is-shared"))
4887 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-shared", (char)printer
->shared
);
4889 if (!ra
|| cupsArrayFind(ra
, "printer-more-info"))
4891 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
4892 "http", NULL
, con
->clientname
, con
->clientport
,
4893 (printer
->type
& CUPS_PRINTER_CLASS
) ?
4894 "/classes/%s" : "/printers/%s", printer
->name
);
4895 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
4896 "printer-more-info", NULL
, printer_uri
);
4899 if (!ra
|| cupsArrayFind(ra
, "printer-op-policy"))
4900 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4901 "printer-op-policy", NULL
, printer
->op_policy
);
4903 if (!ra
|| cupsArrayFind(ra
, "printer-state"))
4904 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
4907 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-time"))
4908 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4909 "printer-state-change-time", printer
->state_time
);
4911 if (!ra
|| cupsArrayFind(ra
, "printer-state-message"))
4912 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4913 "printer-state-message", NULL
, printer
->state_message
);
4915 if (!ra
|| cupsArrayFind(ra
, "printer-state-reasons"))
4916 add_printer_state_reasons(con
, printer
);
4918 if (!ra
|| cupsArrayFind(ra
, "printer-type"))
4920 cups_ptype_t type
; /* printer-type value */
4923 * Add the CUPS-specific printer-type attribute...
4926 type
= printer
->type
;
4928 if (printer
== DefaultPrinter
)
4929 type
|= CUPS_PRINTER_DEFAULT
;
4931 if (!printer
->accepting
)
4932 type
|= CUPS_PRINTER_REJECTING
;
4934 if (!printer
->shared
)
4935 type
|= CUPS_PRINTER_NOT_SHARED
;
4937 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-type", (int)type
);
4940 if (!ra
|| cupsArrayFind(ra
, "printer-up-time"))
4941 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4942 "printer-up-time", curtime
);
4944 if (!ra
|| cupsArrayFind(ra
, "printer-uri-supported"))
4946 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
4947 "ipp", NULL
, con
->clientname
, con
->clientport
,
4948 (printer
->type
& CUPS_PRINTER_CLASS
) ?
4949 "/classes/%s" : "/printers/%s", printer
->name
);
4950 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
4951 "printer-uri-supported", NULL
, printer_uri
);
4952 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-uri-supported=\"%s\"",
4956 if (!ra
|| cupsArrayFind(ra
, "queued-job-count"))
4957 add_queued_job_count(con
, printer
);
4959 copy_attrs(con
->response
, printer
->attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
4960 if (printer
->ppd_attrs
)
4961 copy_attrs(con
->response
, printer
->ppd_attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
4962 copy_attrs(con
->response
, CommonData
, ra
, IPP_TAG_ZERO
, IPP_TAG_COPY
, NULL
);
4967 * 'copy_subscription_attrs()' - Copy subscription attributes.
4971 copy_subscription_attrs(
4972 cupsd_client_t
*con
, /* I - Client connection */
4973 cupsd_subscription_t
*sub
, /* I - Subscription */
4974 cups_array_t
*ra
, /* I - Requested attributes array */
4975 cups_array_t
*exclude
) /* I - Private attributes array */
4977 ipp_attribute_t
*attr
; /* Current attribute */
4978 char printer_uri
[HTTP_MAX_URI
];
4980 int count
; /* Number of events */
4981 unsigned mask
; /* Current event mask */
4982 const char *name
; /* Current event name */
4985 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4986 "copy_subscription_attrs(con=%p, sub=%p, ra=%p, exclude=%p)",
4987 con
, sub
, ra
, exclude
);
4990 * Copy the subscription attributes to the response using the
4991 * requested-attributes attribute that may be provided by the client.
4994 if (!exclude
|| !cupsArrayFind(exclude
, "all"))
4996 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-events")) &&
4997 (!ra
|| cupsArrayFind(ra
, "notify-events")))
4999 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_subscription_attrs: notify-events");
5001 if ((name
= cupsdEventName((cupsd_eventmask_t
)sub
->mask
)) != NULL
)
5004 * Simple event list...
5007 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
,
5008 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5009 "notify-events", NULL
, name
);
5014 * Complex event list...
5017 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5018 if (sub
->mask
& mask
)
5021 attr
= ippAddStrings(con
->response
, IPP_TAG_SUBSCRIPTION
,
5022 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5023 "notify-events", count
, NULL
, NULL
);
5025 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5026 if (sub
->mask
& mask
)
5028 attr
->values
[count
].string
.text
=
5029 (char *)cupsdEventName((cupsd_eventmask_t
)mask
);
5036 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-lease-duration")) &&
5037 (!sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-lease-duration"))))
5038 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5039 "notify-lease-duration", sub
->lease
);
5041 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-recipient-uri")) &&
5042 (sub
->recipient
&& (!ra
|| cupsArrayFind(ra
, "notify-recipient-uri"))))
5043 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5044 "notify-recipient-uri", NULL
, sub
->recipient
);
5045 else if ((!exclude
|| !cupsArrayFind(exclude
, "notify-pull-method")) &&
5046 (!ra
|| cupsArrayFind(ra
, "notify-pull-method")))
5047 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_KEYWORD
,
5048 "notify-pull-method", NULL
, "ippget");
5050 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-subscriber-user-name")) &&
5051 (!ra
|| cupsArrayFind(ra
, "notify-subscriber-user-name")))
5052 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_NAME
,
5053 "notify-subscriber-user-name", NULL
, sub
->owner
);
5055 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-time-interval")) &&
5056 (!ra
|| cupsArrayFind(ra
, "notify-time-interval")))
5057 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5058 "notify-time-interval", sub
->interval
);
5060 if (sub
->user_data_len
> 0 &&
5061 (!exclude
|| !cupsArrayFind(exclude
, "notify-user-data")) &&
5062 (!ra
|| cupsArrayFind(ra
, "notify-user-data")))
5063 ippAddOctetString(con
->response
, IPP_TAG_SUBSCRIPTION
, "notify-user-data",
5064 sub
->user_data
, sub
->user_data_len
);
5067 if (sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-job-id")))
5068 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5069 "notify-job-id", sub
->job
->id
);
5071 if (sub
->dest
&& (!ra
|| cupsArrayFind(ra
, "notify-printer-uri")))
5073 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5074 "ipp", NULL
, con
->clientname
, con
->clientport
,
5075 "/printers/%s", sub
->dest
->name
);
5076 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5077 "notify-printer-uri", NULL
, printer_uri
);
5080 if (!ra
|| cupsArrayFind(ra
, "notify-subscription-id"))
5081 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5082 "notify-subscription-id", sub
->id
);
5087 * 'create_job()' - Print a file to a printer or class.
5091 create_job(cupsd_client_t
*con
, /* I - Client connection */
5092 ipp_attribute_t
*uri
) /* I - Printer URI */
5094 int i
; /* Looping var */
5095 cupsd_printer_t
*printer
; /* Printer */
5096 cupsd_job_t
*job
; /* New job */
5097 static const char * const forbidden_attrs
[] =
5098 { /* List of forbidden attributes */
5102 "document-natural-language"
5106 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "create_job(%p[%d], %s)", con
,
5107 con
->number
, uri
->values
[0].string
.text
);
5110 * Is the destination valid?
5113 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
5119 send_ipp_status(con
, IPP_NOT_FOUND
,
5120 _("The printer or class does not exist."));
5125 * Check for invalid Create-Job attributes and log a warning or error depending
5126 * on whether cupsd is running in "strict conformance" mode...
5130 i
< (int)(sizeof(forbidden_attrs
) / sizeof(forbidden_attrs
[0]));
5132 if (ippFindAttribute(con
->request
, forbidden_attrs
[i
], IPP_TAG_ZERO
))
5134 if (StrictConformance
)
5136 send_ipp_status(con
, IPP_BAD_REQUEST
,
5137 _("The '%s' operation attribute cannot be supplied in a "
5138 "Create-Job request."), forbidden_attrs
[i
]);
5142 cupsdLogMessage(CUPSD_LOG_WARN
,
5143 "Unexpected '%s' operation attribute in a Create-Job "
5144 "request.", forbidden_attrs
[i
]);
5148 * Create the job object...
5151 if ((job
= add_job(con
, printer
, NULL
)) == NULL
)
5154 job
->pending_timeout
= 1;
5157 * Save and log the job...
5160 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
5161 job
->dest
, job
->username
);
5166 * 'create_requested_array()' - Create an array for the requested-attributes.
5169 static cups_array_t
* /* O - Array of attributes or NULL */
5170 create_requested_array(ipp_t
*request
) /* I - IPP request */
5172 cups_array_t
*ra
; /* Requested attributes array */
5176 * Create the array for standard attributes...
5179 ra
= ippCreateRequestedArray(request
);
5182 * Add CUPS defaults as needed...
5185 if (cupsArrayFind(ra
, "printer-defaults"))
5188 * Include user-set defaults...
5191 char *name
; /* Option name */
5193 cupsArrayRemove(ra
, "printer-defaults");
5195 for (name
= (char *)cupsArrayFirst(CommonDefaults
);
5197 name
= (char *)cupsArrayNext(CommonDefaults
))
5198 if (!cupsArrayFind(ra
, name
))
5199 cupsArrayAdd(ra
, name
);
5207 * 'create_subscription()' - Create a notification subscription.
5211 create_subscription(
5212 cupsd_client_t
*con
, /* I - Client connection */
5213 ipp_attribute_t
*uri
) /* I - Printer URI */
5215 http_status_t status
; /* Policy status */
5216 int i
; /* Looping var */
5217 ipp_attribute_t
*attr
; /* Current attribute */
5218 cups_ptype_t dtype
; /* Destination type (printer/class) */
5219 char scheme
[HTTP_MAX_URI
],
5220 /* Scheme portion of URI */
5221 userpass
[HTTP_MAX_URI
],
5222 /* Username portion of URI */
5224 /* Host portion of URI */
5225 resource
[HTTP_MAX_URI
];
5226 /* Resource portion of URI */
5227 int port
; /* Port portion of URI */
5228 cupsd_printer_t
*printer
; /* Printer/class */
5229 cupsd_job_t
*job
; /* Job */
5230 int jobid
; /* Job ID */
5231 cupsd_subscription_t
*sub
; /* Subscription object */
5232 const char *username
, /* requesting-user-name or
5233 authenticated username */
5234 *recipient
, /* notify-recipient-uri */
5235 *pullmethod
; /* notify-pull-method */
5236 ipp_attribute_t
*user_data
; /* notify-user-data */
5237 int interval
, /* notify-time-interval */
5238 lease
; /* notify-lease-duration */
5239 unsigned mask
; /* notify-events */
5240 ipp_attribute_t
*notify_events
,/* notify-events(-default) */
5241 *notify_lease
; /* notify-lease-duration(-default) */
5245 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
5247 if (attr
->group_tag
!= IPP_TAG_ZERO
)
5248 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "g%04x v%04x %s", attr
->group_tag
,
5249 attr
->value_tag
, attr
->name
);
5251 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "----SEP----");
5256 * Is the destination valid?
5259 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5260 "cupsdCreateSubscription(con=%p(%d), uri=\"%s\")",
5261 con
, con
->number
, uri
->values
[0].string
.text
);
5263 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
5264 sizeof(scheme
), userpass
, sizeof(userpass
), host
,
5265 sizeof(host
), &port
, resource
, sizeof(resource
));
5267 if (!strcmp(resource
, "/"))
5269 dtype
= (cups_ptype_t
)0;
5272 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
5274 dtype
= (cups_ptype_t
)0;
5277 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
5279 dtype
= CUPS_PRINTER_CLASS
;
5282 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
5288 send_ipp_status(con
, IPP_NOT_FOUND
,
5289 _("The printer or class does not exist."));
5299 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
5302 send_http_error(con
, status
, printer
);
5306 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5308 send_http_error(con
, status
, NULL
);
5313 * Get the user that is requesting the subscription...
5316 username
= get_username(con
);
5319 * Find the first subscription group attribute; return if we have
5323 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
5324 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
5329 send_ipp_status(con
, IPP_BAD_REQUEST
,
5330 _("No subscription attributes in request."));
5335 * Process the subscription attributes in the request...
5338 con
->response
->request
.status
.status_code
= IPP_BAD_REQUEST
;
5346 lease
= DefaultLeaseDuration
;
5348 mask
= CUPSD_EVENT_NONE
;
5352 notify_events
= ippFindAttribute(printer
->attrs
, "notify-events-default",
5354 notify_lease
= ippFindAttribute(printer
->attrs
,
5355 "notify-lease-duration-default",
5359 lease
= notify_lease
->values
[0].integer
;
5363 notify_events
= NULL
;
5364 notify_lease
= NULL
;
5367 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
5369 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
5370 attr
->value_tag
== IPP_TAG_URI
)
5373 * Validate the recipient scheme against the ServerBin/notifier
5377 char notifier
[1024]; /* Notifier filename */
5380 recipient
= attr
->values
[0].string
.text
;
5382 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
5383 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
5384 host
, sizeof(host
), &port
,
5385 resource
, sizeof(resource
)) < HTTP_URI_OK
)
5387 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5388 _("Bad notify-recipient-uri \"%s\"."), recipient
);
5389 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5390 "notify-status-code", IPP_URI_SCHEME
);
5394 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
5396 if (access(notifier
, X_OK
))
5398 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5399 _("notify-recipient-uri URI \"%s\" uses unknown "
5400 "scheme."), recipient
);
5401 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5402 "notify-status-code", IPP_URI_SCHEME
);
5406 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
5408 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5409 _("notify-recipient-uri URI \"%s\" is already used."),
5411 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5412 "notify-status-code", IPP_ATTRIBUTES
);
5416 else if (!strcmp(attr
->name
, "notify-pull-method") &&
5417 attr
->value_tag
== IPP_TAG_KEYWORD
)
5419 pullmethod
= attr
->values
[0].string
.text
;
5421 if (strcmp(pullmethod
, "ippget"))
5423 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5424 _("Bad notify-pull-method \"%s\"."), pullmethod
);
5425 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5426 "notify-status-code", IPP_ATTRIBUTES
);
5430 else if (!strcmp(attr
->name
, "notify-charset") &&
5431 attr
->value_tag
== IPP_TAG_CHARSET
&&
5432 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
5433 strcmp(attr
->values
[0].string
.text
, "utf-8"))
5435 send_ipp_status(con
, IPP_CHARSET
,
5436 _("Character set \"%s\" not supported."),
5437 attr
->values
[0].string
.text
);
5440 else if (!strcmp(attr
->name
, "notify-natural-language") &&
5441 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
5442 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
5444 send_ipp_status(con
, IPP_CHARSET
,
5445 _("Language \"%s\" not supported."),
5446 attr
->values
[0].string
.text
);
5449 else if (!strcmp(attr
->name
, "notify-user-data") &&
5450 attr
->value_tag
== IPP_TAG_STRING
)
5452 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
5454 send_ipp_status(con
, IPP_REQUEST_VALUE
,
5455 _("The notify-user-data value is too large "
5456 "(%d > 63 octets)."),
5457 attr
->values
[0].unknown
.length
);
5463 else if (!strcmp(attr
->name
, "notify-events") &&
5464 attr
->value_tag
== IPP_TAG_KEYWORD
)
5465 notify_events
= attr
;
5466 else if (!strcmp(attr
->name
, "notify-lease-duration") &&
5467 attr
->value_tag
== IPP_TAG_INTEGER
)
5468 lease
= attr
->values
[0].integer
;
5469 else if (!strcmp(attr
->name
, "notify-time-interval") &&
5470 attr
->value_tag
== IPP_TAG_INTEGER
)
5471 interval
= attr
->values
[0].integer
;
5472 else if (!strcmp(attr
->name
, "notify-job-id") &&
5473 attr
->value_tag
== IPP_TAG_INTEGER
)
5474 jobid
= attr
->values
[0].integer
;
5481 for (i
= 0; i
< notify_events
->num_values
; i
++)
5482 mask
|= cupsdEventValue(notify_events
->values
[i
].string
.text
);
5486 cupsdLogMessage(CUPSD_LOG_DEBUG
, "recipient=\"%s\"", recipient
);
5488 cupsdLogMessage(CUPSD_LOG_DEBUG
, "pullmethod=\"%s\"", pullmethod
);
5489 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-lease-duration=%d", lease
);
5490 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-time-interval=%d", interval
);
5492 if (!recipient
&& !pullmethod
)
5495 if (mask
== CUPSD_EVENT_NONE
)
5498 mask
= CUPSD_EVENT_JOB_COMPLETED
;
5500 mask
= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
5503 send_ipp_status(con
, IPP_BAD_REQUEST
,
5504 _("notify-events not specified."));
5509 if (MaxLeaseDuration
&& (lease
== 0 || lease
> MaxLeaseDuration
))
5511 cupsdLogMessage(CUPSD_LOG_INFO
,
5512 "create_subscription: Limiting notify-lease-duration to "
5515 lease
= MaxLeaseDuration
;
5520 if ((job
= cupsdFindJob(jobid
)) == NULL
)
5522 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
5530 if ((sub
= cupsdAddSubscription(mask
, printer
, job
, recipient
, 0)) == NULL
)
5532 send_ipp_status(con
, IPP_TOO_MANY_SUBSCRIPTIONS
,
5533 _("There are too many subscriptions."));
5538 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription #%d for job %d.",
5541 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5542 "Added subscription #%d for printer \"%s\".",
5543 sub
->id
, printer
->name
);
5545 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription #%d for server.",
5548 sub
->interval
= interval
;
5550 sub
->expire
= lease
? time(NULL
) + lease
: 0;
5552 cupsdSetString(&sub
->owner
, username
);
5556 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
5557 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
5558 sub
->user_data_len
);
5561 ippAddSeparator(con
->response
);
5562 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5563 "notify-subscription-id", sub
->id
);
5565 con
->response
->request
.status
.status_code
= IPP_OK
;
5571 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
5576 * 'delete_printer()' - Remove a printer or class from the system.
5580 delete_printer(cupsd_client_t
*con
, /* I - Client connection */
5581 ipp_attribute_t
*uri
) /* I - URI of printer or class */
5583 http_status_t status
; /* Policy status */
5584 cups_ptype_t dtype
; /* Destination type (printer/class) */
5585 cupsd_printer_t
*printer
; /* Printer/class */
5586 char filename
[1024]; /* Script/PPD filename */
5589 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "delete_printer(%p[%d], %s)", con
,
5590 con
->number
, uri
->values
[0].string
.text
);
5593 * Do we have a valid URI?
5596 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
5602 send_ipp_status(con
, IPP_NOT_FOUND
,
5603 _("The printer or class does not exist."));
5611 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5613 send_http_error(con
, status
, NULL
);
5618 * Remove old jobs...
5621 cupsdCancelJobs(printer
->name
, NULL
, 1);
5624 * Remove old subscriptions and send a "deleted printer" event...
5627 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED
, printer
, NULL
,
5628 "%s \"%s\" deleted by \"%s\".",
5629 (dtype
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
5630 printer
->name
, get_username(con
));
5632 cupsdExpireSubscriptions(printer
, NULL
);
5635 * Remove any old PPD or script files...
5638 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
,
5641 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s.O", ServerRoot
,
5645 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
5648 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd.O", ServerRoot
,
5652 snprintf(filename
, sizeof(filename
), "%s/%s.png", CacheDir
, printer
->name
);
5655 snprintf(filename
, sizeof(filename
), "%s/%s.data", CacheDir
, printer
->name
);
5659 * Unregister color profiles...
5662 cupsdUnregisterColor(printer
);
5664 if (dtype
& CUPS_PRINTER_CLASS
)
5666 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" deleted by \"%s\".",
5667 printer
->name
, get_username(con
));
5669 cupsdDeletePrinter(printer
, 0);
5670 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
5674 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" deleted by \"%s\".",
5675 printer
->name
, get_username(con
));
5677 if (cupsdDeletePrinter(printer
, 0))
5678 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
5680 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
5683 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
5686 * Return with no errors...
5689 con
->response
->request
.status
.status_code
= IPP_OK
;
5694 * 'get_default()' - Get the default destination.
5698 get_default(cupsd_client_t
*con
) /* I - Client connection */
5700 http_status_t status
; /* Policy status */
5701 cups_array_t
*ra
; /* Requested attributes array */
5704 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_default(%p[%d])", con
, con
->number
);
5710 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5712 send_http_error(con
, status
, NULL
);
5718 ra
= create_requested_array(con
->request
);
5720 copy_printer_attrs(con
, DefaultPrinter
, ra
);
5722 cupsArrayDelete(ra
);
5724 con
->response
->request
.status
.status_code
= IPP_OK
;
5727 send_ipp_status(con
, IPP_NOT_FOUND
, _("No default printer."));
5732 * 'get_devices()' - Get the list of available devices on the local system.
5736 get_devices(cupsd_client_t
*con
) /* I - Client connection */
5738 http_status_t status
; /* Policy status */
5739 ipp_attribute_t
*limit
, /* limit attribute */
5740 *timeout
, /* timeout attribute */
5741 *requested
, /* requested-attributes attribute */
5742 *exclude
, /* exclude-schemes attribute */
5743 *include
; /* include-schemes attribute */
5744 char command
[1024], /* cups-deviced command */
5745 options
[2048], /* Options to pass to command */
5747 /* String for requested attributes */
5749 /* String for excluded schemes */
5751 /* String for included schemes */
5754 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_devices(%p[%d])", con
, con
->number
);
5760 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5762 send_http_error(con
, status
, NULL
);
5767 * Run cups-deviced command with the given options...
5770 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
5771 timeout
= ippFindAttribute(con
->request
, "timeout", IPP_TAG_INTEGER
);
5772 requested
= ippFindAttribute(con
->request
, "requested-attributes",
5774 exclude
= ippFindAttribute(con
->request
, "exclude-schemes", IPP_TAG_NAME
);
5775 include
= ippFindAttribute(con
->request
, "include-schemes", IPP_TAG_NAME
);
5778 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
5780 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
5783 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
5785 exclude_str
[0] = '\0';
5788 url_encode_attr(include
, include_str
, sizeof(include_str
));
5790 include_str
[0] = '\0';
5792 snprintf(command
, sizeof(command
), "%s/daemon/cups-deviced", ServerBin
);
5793 snprintf(options
, sizeof(options
),
5794 "%d+%d+%d+%d+%s%s%s%s%s",
5795 con
->request
->request
.op
.request_id
,
5796 limit
? limit
->values
[0].integer
: 0,
5797 timeout
? timeout
->values
[0].integer
: 15,
5800 exclude_str
[0] ? "%20" : "", exclude_str
,
5801 include_str
[0] ? "%20" : "", include_str
);
5803 if (cupsdSendCommand(con
, command
, options
, 1))
5806 * Command started successfully, don't send an IPP response here...
5809 ippDelete(con
->response
);
5810 con
->response
= NULL
;
5815 * Command failed, return "internal error" so the user knows something
5819 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
5820 _("cups-deviced failed to execute."));
5826 * 'get_document()' - Get a copy of a job file.
5830 get_document(cupsd_client_t
*con
, /* I - Client connection */
5831 ipp_attribute_t
*uri
) /* I - Job URI */
5833 http_status_t status
; /* Policy status */
5834 ipp_attribute_t
*attr
; /* Current attribute */
5835 int jobid
; /* Job ID */
5836 int docnum
; /* Document number */
5837 cupsd_job_t
*job
; /* Current job */
5838 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
5839 username
[HTTP_MAX_URI
], /* Username portion of URI */
5840 host
[HTTP_MAX_URI
], /* Host portion of URI */
5841 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
5842 int port
; /* Port portion of URI */
5843 char filename
[1024], /* Filename for document */
5844 format
[1024]; /* Format for document */
5847 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_document(%p[%d], %s)", con
,
5848 con
->number
, uri
->values
[0].string
.text
);
5851 * See if we have a job URI or a printer URI...
5854 if (!strcmp(uri
->name
, "printer-uri"))
5857 * Got a printer URI; see if we also have a job-id attribute...
5860 if ((attr
= ippFindAttribute(con
->request
, "job-id",
5861 IPP_TAG_INTEGER
)) == NULL
)
5863 send_ipp_status(con
, IPP_BAD_REQUEST
,
5864 _("Got a printer-uri attribute but no job-id."));
5868 jobid
= attr
->values
[0].integer
;
5873 * Got a job URI; parse it to get the job ID...
5876 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
5877 sizeof(scheme
), username
, sizeof(username
), host
,
5878 sizeof(host
), &port
, resource
, sizeof(resource
));
5880 if (strncmp(resource
, "/jobs/", 6))
5886 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
5887 uri
->values
[0].string
.text
);
5891 jobid
= atoi(resource
+ 6);
5895 * See if the job exists...
5898 if ((job
= cupsdFindJob(jobid
)) == NULL
)
5901 * Nope - return a "not found" error...
5904 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
5912 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
,
5913 job
->username
)) != HTTP_OK
)
5915 send_http_error(con
, status
, NULL
);
5920 * Get the document number...
5923 if ((attr
= ippFindAttribute(con
->request
, "document-number",
5924 IPP_TAG_INTEGER
)) == NULL
)
5926 send_ipp_status(con
, IPP_BAD_REQUEST
,
5927 _("Missing document-number attribute."));
5931 if ((docnum
= attr
->values
[0].integer
) < 1 || docnum
> job
->num_files
||
5932 attr
->num_values
> 1)
5934 send_ipp_status(con
, IPP_NOT_FOUND
,
5935 _("Document #%d does not exist in job #%d."), docnum
,
5940 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, jobid
,
5942 if ((con
->file
= open(filename
, O_RDONLY
)) == -1)
5944 cupsdLogMessage(CUPSD_LOG_ERROR
,
5945 "Unable to open document %d in job %d - %s", docnum
, jobid
,
5947 send_ipp_status(con
, IPP_NOT_FOUND
,
5948 _("Unable to open document #%d in job #%d."), docnum
,
5953 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
5957 snprintf(format
, sizeof(format
), "%s/%s", job
->filetypes
[docnum
- 1]->super
,
5958 job
->filetypes
[docnum
- 1]->type
);
5960 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format",
5962 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "document-number",
5964 if ((attr
= ippFindAttribute(job
->attrs
, "document-name",
5965 IPP_TAG_NAME
)) != NULL
)
5966 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name",
5967 NULL
, attr
->values
[0].string
.text
);
5972 * 'get_job_attrs()' - Get job attributes.
5976 get_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
5977 ipp_attribute_t
*uri
) /* I - Job URI */
5979 http_status_t status
; /* Policy status */
5980 ipp_attribute_t
*attr
; /* Current attribute */
5981 int jobid
; /* Job ID */
5982 cupsd_job_t
*job
; /* Current job */
5983 cupsd_printer_t
*printer
; /* Current printer */
5984 cupsd_policy_t
*policy
; /* Current security policy */
5985 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
5986 username
[HTTP_MAX_URI
], /* Username portion of URI */
5987 host
[HTTP_MAX_URI
], /* Host portion of URI */
5988 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
5989 int port
; /* Port portion of URI */
5990 cups_array_t
*ra
, /* Requested attributes array */
5991 *exclude
; /* Private attributes array */
5994 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_job_attrs(%p[%d], %s)", con
,
5995 con
->number
, uri
->values
[0].string
.text
);
5998 * See if we have a job URI or a printer URI...
6001 if (!strcmp(uri
->name
, "printer-uri"))
6004 * Got a printer URI; see if we also have a job-id attribute...
6007 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6008 IPP_TAG_INTEGER
)) == NULL
)
6010 send_ipp_status(con
, IPP_BAD_REQUEST
,
6011 _("Got a printer-uri attribute but no job-id."));
6015 jobid
= attr
->values
[0].integer
;
6020 * Got a job URI; parse it to get the job ID...
6023 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6024 sizeof(scheme
), username
, sizeof(username
), host
,
6025 sizeof(host
), &port
, resource
, sizeof(resource
));
6027 if (strncmp(resource
, "/jobs/", 6))
6033 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
6034 uri
->values
[0].string
.text
);
6038 jobid
= atoi(resource
+ 6);
6042 * See if the job exists...
6045 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6048 * Nope - return a "not found" error...
6051 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
6059 if ((printer
= job
->printer
) == NULL
)
6060 printer
= cupsdFindDest(job
->dest
);
6063 policy
= printer
->op_policy_ptr
;
6065 policy
= DefaultPolicyPtr
;
6067 if ((status
= cupsdCheckPolicy(policy
, con
, job
->username
)) != HTTP_OK
)
6069 send_http_error(con
, status
, NULL
);
6073 exclude
= cupsdGetPrivateAttrs(policy
, con
, printer
, job
->username
);
6076 * Copy attributes...
6081 ra
= create_requested_array(con
->request
);
6082 copy_job_attrs(con
, job
, ra
, exclude
);
6083 cupsArrayDelete(ra
);
6085 con
->response
->request
.status
.status_code
= IPP_OK
;
6090 * 'get_jobs()' - Get a list of jobs for the specified printer.
6094 get_jobs(cupsd_client_t
*con
, /* I - Client connection */
6095 ipp_attribute_t
*uri
) /* I - Printer URI */
6097 http_status_t status
; /* Policy status */
6098 ipp_attribute_t
*attr
; /* Current attribute */
6099 const char *dest
; /* Destination */
6100 cups_ptype_t dtype
; /* Destination type (printer/class) */
6101 cups_ptype_t dmask
; /* Destination type mask */
6102 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6103 username
[HTTP_MAX_URI
], /* Username portion of URI */
6104 host
[HTTP_MAX_URI
], /* Host portion of URI */
6105 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6106 int port
; /* Port portion of URI */
6107 int job_comparison
; /* Job comparison */
6108 ipp_jstate_t job_state
; /* job-state value */
6109 int first_job_id
; /* First job ID */
6110 int limit
; /* Maximum number of jobs to return */
6111 int count
; /* Number of jobs that match */
6112 ipp_attribute_t
*job_ids
; /* job-ids attribute */
6113 cupsd_job_t
*job
; /* Current job pointer */
6114 cupsd_printer_t
*printer
; /* Printer */
6115 cups_array_t
*list
; /* Which job list... */
6116 cups_array_t
*ra
, /* Requested attributes array */
6117 *exclude
; /* Private attributes array */
6118 cupsd_policy_t
*policy
; /* Current policy */
6121 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs(%p[%d], %s)", con
, con
->number
,
6122 uri
->values
[0].string
.text
);
6125 * Is the destination valid?
6128 if (strcmp(uri
->name
, "printer-uri"))
6130 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No printer-uri in request."));
6134 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6135 sizeof(scheme
), username
, sizeof(username
), host
,
6136 sizeof(host
), &port
, resource
, sizeof(resource
));
6138 if (!strcmp(resource
, "/") || !strcmp(resource
, "/jobs"))
6141 dtype
= (cups_ptype_t
)0;
6142 dmask
= (cups_ptype_t
)0;
6145 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6148 dtype
= (cups_ptype_t
)0;
6149 dmask
= CUPS_PRINTER_CLASS
;
6152 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6155 dtype
= CUPS_PRINTER_CLASS
;
6156 dmask
= CUPS_PRINTER_CLASS
;
6159 else if ((dest
= cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
,
6166 send_ipp_status(con
, IPP_NOT_FOUND
,
6167 _("The printer or class does not exist."));
6172 dtype
&= CUPS_PRINTER_CLASS
;
6173 dmask
= CUPS_PRINTER_CLASS
;
6181 policy
= printer
->op_policy_ptr
;
6183 policy
= DefaultPolicyPtr
;
6185 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
6187 send_http_error(con
, status
, NULL
);
6191 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
6194 * See if the "which-jobs" attribute have been specified...
6197 if ((attr
= ippFindAttribute(con
->request
, "which-jobs",
6198 IPP_TAG_KEYWORD
)) != NULL
&& job_ids
)
6200 send_ipp_status(con
, IPP_CONFLICT
,
6201 _("The %s attribute cannot be provided with job-ids."),
6205 else if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "not-completed"))
6207 job_comparison
= -1;
6208 job_state
= IPP_JOB_STOPPED
;
6211 else if (!strcmp(attr
->values
[0].string
.text
, "completed"))
6214 job_state
= IPP_JOB_CANCELED
;
6217 else if (!strcmp(attr
->values
[0].string
.text
, "aborted"))
6220 job_state
= IPP_JOB_ABORTED
;
6223 else if (!strcmp(attr
->values
[0].string
.text
, "all"))
6226 job_state
= IPP_JOB_PENDING
;
6229 else if (!strcmp(attr
->values
[0].string
.text
, "canceled"))
6232 job_state
= IPP_JOB_CANCELED
;
6235 else if (!strcmp(attr
->values
[0].string
.text
, "pending"))
6238 job_state
= IPP_JOB_PENDING
;
6241 else if (!strcmp(attr
->values
[0].string
.text
, "pending-held"))
6244 job_state
= IPP_JOB_HELD
;
6247 else if (!strcmp(attr
->values
[0].string
.text
, "processing"))
6250 job_state
= IPP_JOB_PROCESSING
;
6251 list
= PrintingJobs
;
6253 else if (!strcmp(attr
->values
[0].string
.text
, "processing-stopped"))
6256 job_state
= IPP_JOB_STOPPED
;
6261 send_ipp_status(con
, IPP_ATTRIBUTES
,
6262 _("The which-jobs value \"%s\" is not supported."),
6263 attr
->values
[0].string
.text
);
6264 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
6265 "which-jobs", NULL
, attr
->values
[0].string
.text
);
6270 * See if they want to limit the number of jobs reported...
6273 if ((attr
= ippFindAttribute(con
->request
, "limit",
6274 IPP_TAG_INTEGER
)) != NULL
)
6278 send_ipp_status(con
, IPP_CONFLICT
,
6279 _("The %s attribute cannot be provided with job-ids."),
6284 limit
= attr
->values
[0].integer
;
6289 if ((attr
= ippFindAttribute(con
->request
, "first-job-id",
6290 IPP_TAG_INTEGER
)) != NULL
)
6294 send_ipp_status(con
, IPP_CONFLICT
,
6295 _("The %s attribute cannot be provided with job-ids."),
6300 first_job_id
= attr
->values
[0].integer
;
6306 * See if we only want to see jobs for a specific user...
6309 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
6310 IPP_TAG_BOOLEAN
)) != NULL
&& job_ids
)
6312 send_ipp_status(con
, IPP_CONFLICT
,
6313 _("The %s attribute cannot be provided with job-ids."),
6317 else if (attr
&& attr
->values
[0].boolean
)
6318 strlcpy(username
, get_username(con
), sizeof(username
));
6322 ra
= create_requested_array(con
->request
);
6325 * OK, build a list of jobs for this printer...
6330 int i
; /* Looping var */
6332 for (i
= 0; i
< job_ids
->num_values
; i
++)
6334 if (!cupsdFindJob(job_ids
->values
[i
].integer
))
6338 if (i
< job_ids
->num_values
)
6340 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
6341 job_ids
->values
[i
].integer
);
6345 for (i
= 0; i
< job_ids
->num_values
; i
++)
6347 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
6353 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d",
6359 ippAddSeparator(con
->response
);
6361 exclude
= cupsdGetPrivateAttrs(job
->printer
?
6362 job
->printer
->op_policy_ptr
:
6363 policy
, con
, job
->printer
,
6366 copy_job_attrs(con
, job
, ra
, exclude
);
6371 for (count
= 0, job
= (cupsd_job_t
*)cupsArrayFirst(list
);
6372 (limit
<= 0 || count
< limit
) && job
;
6373 job
= (cupsd_job_t
*)cupsArrayNext(list
))
6376 * Filter out jobs that don't match...
6379 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
6380 "get_jobs: job->id=%d, dest=\"%s\", username=\"%s\", "
6381 "state_value=%d, attrs=%p", job
->id
, job
->dest
,
6382 job
->username
, job
->state_value
, job
->attrs
);
6384 if (!job
->dest
|| !job
->username
)
6387 if (!job
->dest
|| !job
->username
)
6390 if ((dest
&& strcmp(job
->dest
, dest
)) &&
6391 (!job
->printer
|| !dest
|| strcmp(job
->printer
->name
, dest
)))
6393 if ((job
->dtype
& dmask
) != dtype
&&
6394 (!job
->printer
|| (job
->printer
->type
& dmask
) != dtype
))
6397 if ((job_comparison
< 0 && job
->state_value
> job_state
) ||
6398 (job_comparison
== 0 && job
->state_value
!= job_state
) ||
6399 (job_comparison
> 0 && job
->state_value
< job_state
))
6402 if (job
->id
< first_job_id
)
6409 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d",
6414 if (username
[0] && _cups_strcasecmp(username
, job
->username
))
6418 ippAddSeparator(con
->response
);
6422 exclude
= cupsdGetPrivateAttrs(job
->printer
?
6423 job
->printer
->op_policy_ptr
:
6424 policy
, con
, job
->printer
,
6427 copy_job_attrs(con
, job
, ra
, exclude
);
6430 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: count=%d", count
);
6433 cupsArrayDelete(ra
);
6435 con
->response
->request
.status
.status_code
= IPP_OK
;
6440 * 'get_notifications()' - Get events for a subscription.
6444 get_notifications(cupsd_client_t
*con
) /* I - Client connection */
6446 int i
, j
; /* Looping vars */
6447 http_status_t status
; /* Policy status */
6448 cupsd_subscription_t
*sub
; /* Subscription */
6449 ipp_attribute_t
*ids
, /* notify-subscription-ids */
6450 *sequences
; /* notify-sequence-numbers */
6451 int min_seq
; /* Minimum sequence number */
6452 int interval
; /* Poll interval */
6455 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_notifications(con=%p[%d])",
6459 * Get subscription attributes...
6462 ids
= ippFindAttribute(con
->request
, "notify-subscription-ids",
6464 sequences
= ippFindAttribute(con
->request
, "notify-sequence-numbers",
6469 send_ipp_status(con
, IPP_BAD_REQUEST
,
6470 _("Missing notify-subscription-ids attribute."));
6475 * Are the subscription IDs valid?
6478 for (i
= 0, interval
= 60; i
< ids
->num_values
; i
++)
6480 if ((sub
= cupsdFindSubscription(ids
->values
[i
].integer
)) == NULL
)
6483 * Bad subscription ID...
6486 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
6487 ids
->values
[i
].integer
);
6495 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
6497 con
, sub
->owner
)) != HTTP_OK
)
6499 send_http_error(con
, status
, sub
->dest
);
6504 * Check the subscription type and update the interval accordingly.
6507 if (sub
->job
&& sub
->job
->state_value
== IPP_JOB_PROCESSING
&&
6510 else if (sub
->job
&& sub
->job
->state_value
>= IPP_JOB_STOPPED
)
6512 else if (sub
->dest
&& sub
->dest
->state
== IPP_PRINTER_PROCESSING
&&
6518 * Tell the client to poll again in N seconds...
6522 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
6523 "notify-get-interval", interval
);
6525 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
6526 "printer-up-time", time(NULL
));
6529 * Copy the subscription event attributes to the response.
6532 con
->response
->request
.status
.status_code
=
6533 interval
? IPP_OK
: IPP_OK_EVENTS_COMPLETE
;
6535 for (i
= 0; i
< ids
->num_values
; i
++)
6538 * Get the subscription and sequence number...
6541 sub
= cupsdFindSubscription(ids
->values
[i
].integer
);
6543 if (sequences
&& i
< sequences
->num_values
)
6544 min_seq
= sequences
->values
[i
].integer
;
6549 * If we don't have any new events, nothing to do here...
6552 if (min_seq
> (sub
->first_event_id
+ cupsArrayCount(sub
->events
)))
6556 * Otherwise copy all of the new events...
6559 if (sub
->first_event_id
> min_seq
)
6562 j
= min_seq
- sub
->first_event_id
;
6564 for (; j
< cupsArrayCount(sub
->events
); j
++)
6566 ippAddSeparator(con
->response
);
6568 copy_attrs(con
->response
,
6569 ((cupsd_event_t
*)cupsArrayIndex(sub
->events
, j
))->attrs
, NULL
,
6570 IPP_TAG_EVENT_NOTIFICATION
, 0, NULL
);
6577 * 'get_ppd()' - Get a named PPD from the local system.
6581 get_ppd(cupsd_client_t
*con
, /* I - Client connection */
6582 ipp_attribute_t
*uri
) /* I - Printer URI or PPD name */
6584 http_status_t status
; /* Policy status */
6585 cupsd_printer_t
*dest
; /* Destination */
6586 cups_ptype_t dtype
; /* Destination type */
6589 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppd(%p[%d], %p[%s=%s])", con
,
6590 con
->number
, uri
, uri
->name
, uri
->values
[0].string
.text
);
6592 if (!strcmp(uri
->name
, "ppd-name"))
6595 * Return a PPD file from cups-driverd...
6598 char command
[1024], /* cups-driverd command */
6599 options
[1024], /* Options to pass to command */
6600 ppd_name
[1024]; /* ppd-name */
6607 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6609 send_http_error(con
, status
, NULL
);
6614 * Run cups-driverd command with the given options...
6617 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
6618 url_encode_string(uri
->values
[0].string
.text
, ppd_name
, sizeof(ppd_name
));
6619 snprintf(options
, sizeof(options
), "get+%d+%s",
6620 con
->request
->request
.op
.request_id
, ppd_name
);
6622 if (cupsdSendCommand(con
, command
, options
, 0))
6625 * Command started successfully, don't send an IPP response here...
6628 ippDelete(con
->response
);
6629 con
->response
= NULL
;
6634 * Command failed, return "internal error" so the user knows something
6638 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
6639 _("cups-driverd failed to execute."));
6642 else if (!strcmp(uri
->name
, "printer-uri") &&
6643 cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &dest
))
6645 int i
; /* Looping var */
6646 char filename
[1024]; /* PPD filename */
6653 if ((status
= cupsdCheckPolicy(dest
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
6655 send_http_error(con
, status
, dest
);
6660 * See if we need the PPD for a class or remote printer...
6663 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
6666 if ((dtype
& CUPS_PRINTER_REMOTE
) && access(filename
, 0))
6668 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
6669 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
6670 "printer-uri", NULL
, dest
->uri
);
6673 else if (dtype
& CUPS_PRINTER_CLASS
)
6675 for (i
= 0; i
< dest
->num_printers
; i
++)
6676 if (!(dest
->printers
[i
]->type
& CUPS_PRINTER_CLASS
))
6678 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
6679 dest
->printers
[i
]->name
);
6681 if (!access(filename
, 0))
6685 if (i
< dest
->num_printers
)
6686 dest
= dest
->printers
[i
];
6689 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
6690 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
6691 "printer-uri", NULL
, dest
->printers
[0]->uri
);
6697 * Found the printer with the PPD file, now see if there is one...
6700 if ((con
->file
= open(filename
, O_RDONLY
)) < 0)
6702 send_ipp_status(con
, IPP_NOT_FOUND
,
6703 _("The PPD file \"%s\" could not be opened: %s"),
6704 uri
->values
[0].string
.text
, strerror(errno
));
6708 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
6712 con
->response
->request
.status
.status_code
= IPP_OK
;
6715 send_ipp_status(con
, IPP_NOT_FOUND
,
6716 _("The PPD file \"%s\" could not be found."),
6717 uri
->values
[0].string
.text
);
6722 * 'get_ppds()' - Get the list of PPD files on the local system.
6726 get_ppds(cupsd_client_t
*con
) /* I - Client connection */
6728 http_status_t status
; /* Policy status */
6729 ipp_attribute_t
*limit
, /* Limit attribute */
6730 *device
, /* ppd-device-id attribute */
6731 *language
, /* ppd-natural-language attribute */
6732 *make
, /* ppd-make attribute */
6733 *model
, /* ppd-make-and-model attribute */
6734 *model_number
, /* ppd-model-number attribute */
6735 *product
, /* ppd-product attribute */
6736 *psversion
, /* ppd-psverion attribute */
6737 *type
, /* ppd-type attribute */
6738 *requested
, /* requested-attributes attribute */
6739 *exclude
, /* exclude-schemes attribute */
6740 *include
; /* include-schemes attribute */
6741 char command
[1024], /* cups-driverd command */
6742 options
[4096], /* Options to pass to command */
6743 device_str
[256],/* Escaped ppd-device-id string */
6745 /* Escaped ppd-natural-language */
6746 make_str
[256], /* Escaped ppd-make string */
6747 model_str
[256], /* Escaped ppd-make-and-model string */
6748 model_number_str
[256],
6749 /* ppd-model-number string */
6751 /* Escaped ppd-product string */
6753 /* Escaped ppd-psversion string */
6754 type_str
[256], /* Escaped ppd-type string */
6756 /* String for requested attributes */
6758 /* String for excluded schemes */
6760 /* String for included schemes */
6763 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppds(%p[%d])", con
, con
->number
);
6769 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6771 send_http_error(con
, status
, NULL
);
6776 * Run cups-driverd command with the given options...
6779 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
6780 device
= ippFindAttribute(con
->request
, "ppd-device-id", IPP_TAG_TEXT
);
6781 language
= ippFindAttribute(con
->request
, "ppd-natural-language",
6783 make
= ippFindAttribute(con
->request
, "ppd-make", IPP_TAG_TEXT
);
6784 model
= ippFindAttribute(con
->request
, "ppd-make-and-model",
6786 model_number
= ippFindAttribute(con
->request
, "ppd-model-number",
6788 product
= ippFindAttribute(con
->request
, "ppd-product", IPP_TAG_TEXT
);
6789 psversion
= ippFindAttribute(con
->request
, "ppd-psversion", IPP_TAG_TEXT
);
6790 type
= ippFindAttribute(con
->request
, "ppd-type", IPP_TAG_KEYWORD
);
6791 requested
= ippFindAttribute(con
->request
, "requested-attributes",
6793 exclude
= ippFindAttribute(con
->request
, "exclude-schemes",
6795 include
= ippFindAttribute(con
->request
, "include-schemes",
6799 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
6801 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
6804 url_encode_attr(device
, device_str
, sizeof(device_str
));
6806 device_str
[0] = '\0';
6809 url_encode_attr(language
, language_str
, sizeof(language_str
));
6811 language_str
[0] = '\0';
6814 url_encode_attr(make
, make_str
, sizeof(make_str
));
6819 url_encode_attr(model
, model_str
, sizeof(model_str
));
6821 model_str
[0] = '\0';
6824 snprintf(model_number_str
, sizeof(model_number_str
), "ppd-model-number=%d",
6825 model_number
->values
[0].integer
);
6827 model_number_str
[0] = '\0';
6830 url_encode_attr(product
, product_str
, sizeof(product_str
));
6832 product_str
[0] = '\0';
6835 url_encode_attr(psversion
, psversion_str
, sizeof(psversion_str
));
6837 psversion_str
[0] = '\0';
6840 url_encode_attr(type
, type_str
, sizeof(type_str
));
6845 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
6847 exclude_str
[0] = '\0';
6850 url_encode_attr(include
, include_str
, sizeof(include_str
));
6852 include_str
[0] = '\0';
6854 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
6855 snprintf(options
, sizeof(options
),
6856 "list+%d+%d+%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
6857 con
->request
->request
.op
.request_id
,
6858 limit
? limit
->values
[0].integer
: 0,
6860 device
? "%20" : "", device_str
,
6861 language
? "%20" : "", language_str
,
6862 make
? "%20" : "", make_str
,
6863 model
? "%20" : "", model_str
,
6864 model_number
? "%20" : "", model_number_str
,
6865 product
? "%20" : "", product_str
,
6866 psversion
? "%20" : "", psversion_str
,
6867 type
? "%20" : "", type_str
,
6868 exclude_str
[0] ? "%20" : "", exclude_str
,
6869 include_str
[0] ? "%20" : "", include_str
);
6871 if (cupsdSendCommand(con
, command
, options
, 0))
6874 * Command started successfully, don't send an IPP response here...
6877 ippDelete(con
->response
);
6878 con
->response
= NULL
;
6883 * Command failed, return "internal error" so the user knows something
6887 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
6888 _("cups-driverd failed to execute."));
6894 * 'get_printer_attrs()' - Get printer attributes.
6898 get_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
6899 ipp_attribute_t
*uri
) /* I - Printer URI */
6901 http_status_t status
; /* Policy status */
6902 cups_ptype_t dtype
; /* Destination type (printer/class) */
6903 cupsd_printer_t
*printer
; /* Printer/class */
6904 cups_array_t
*ra
; /* Requested attributes array */
6907 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_attrs(%p[%d], %s)", con
,
6908 con
->number
, uri
->values
[0].string
.text
);
6911 * Is the destination valid?
6914 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6920 send_ipp_status(con
, IPP_NOT_FOUND
,
6921 _("The printer or class does not exist."));
6929 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
6931 send_http_error(con
, status
, printer
);
6936 * Send the attributes...
6939 ra
= create_requested_array(con
->request
);
6941 copy_printer_attrs(con
, printer
, ra
);
6943 cupsArrayDelete(ra
);
6945 con
->response
->request
.status
.status_code
= IPP_OK
;
6950 * 'get_printer_supported()' - Get printer supported values.
6954 get_printer_supported(
6955 cupsd_client_t
*con
, /* I - Client connection */
6956 ipp_attribute_t
*uri
) /* I - Printer URI */
6958 http_status_t status
; /* Policy status */
6959 cups_ptype_t dtype
; /* Destination type (printer/class) */
6960 cupsd_printer_t
*printer
; /* Printer/class */
6963 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_supported(%p[%d], %s)", con
,
6964 con
->number
, uri
->values
[0].string
.text
);
6967 * Is the destination valid?
6970 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6976 send_ipp_status(con
, IPP_NOT_FOUND
,
6977 _("The printer or class does not exist."));
6985 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
6987 send_http_error(con
, status
, printer
);
6992 * Return a list of attributes that can be set via Set-Printer-Attributes.
6995 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
6997 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
6998 "printer-location", 0);
7000 con
->response
->request
.status
.status_code
= IPP_OK
;
7005 * 'get_printers()' - Get a list of printers or classes.
7009 get_printers(cupsd_client_t
*con
, /* I - Client connection */
7010 int type
) /* I - 0 or CUPS_PRINTER_CLASS */
7012 http_status_t status
; /* Policy status */
7013 ipp_attribute_t
*attr
; /* Current attribute */
7014 int limit
; /* Max number of printers to return */
7015 int count
; /* Number of printers that match */
7016 cupsd_printer_t
*printer
; /* Current printer pointer */
7017 cups_ptype_t printer_type
, /* printer-type attribute */
7018 printer_mask
; /* printer-type-mask attribute */
7019 char *location
; /* Location string */
7020 const char *username
; /* Current user */
7021 char *first_printer_name
; /* first-printer-name attribute */
7022 cups_array_t
*ra
; /* Requested attributes array */
7023 int local
; /* Local connection? */
7026 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printers(%p[%d], %x)", con
,
7033 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7035 send_http_error(con
, status
, NULL
);
7040 * Check for printers...
7043 if (!Printers
|| !cupsArrayCount(Printers
))
7045 send_ipp_status(con
, IPP_NOT_FOUND
, _("No destinations added."));
7050 * See if they want to limit the number of printers reported...
7053 if ((attr
= ippFindAttribute(con
->request
, "limit",
7054 IPP_TAG_INTEGER
)) != NULL
)
7055 limit
= attr
->values
[0].integer
;
7059 if ((attr
= ippFindAttribute(con
->request
, "first-printer-name",
7060 IPP_TAG_NAME
)) != NULL
)
7061 first_printer_name
= attr
->values
[0].string
.text
;
7063 first_printer_name
= NULL
;
7066 * Support filtering...
7069 if ((attr
= ippFindAttribute(con
->request
, "printer-type",
7070 IPP_TAG_ENUM
)) != NULL
)
7071 printer_type
= (cups_ptype_t
)attr
->values
[0].integer
;
7073 printer_type
= (cups_ptype_t
)0;
7075 if ((attr
= ippFindAttribute(con
->request
, "printer-type-mask",
7076 IPP_TAG_ENUM
)) != NULL
)
7077 printer_mask
= (cups_ptype_t
)attr
->values
[0].integer
;
7079 printer_mask
= (cups_ptype_t
)0;
7081 local
= httpAddrLocalhost(&(con
->clientaddr
));
7083 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
7084 IPP_TAG_TEXT
)) != NULL
)
7085 location
= attr
->values
[0].string
.text
;
7089 if (con
->username
[0])
7090 username
= con
->username
;
7091 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7092 IPP_TAG_NAME
)) != NULL
)
7093 username
= attr
->values
[0].string
.text
;
7097 ra
= create_requested_array(con
->request
);
7100 * OK, build a list of printers for this printer...
7103 if (first_printer_name
)
7105 if ((printer
= cupsdFindDest(first_printer_name
)) == NULL
)
7106 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7109 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7112 count
< limit
&& printer
;
7113 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
7115 if (!local
&& !printer
->shared
)
7118 if ((!type
|| (printer
->type
& CUPS_PRINTER_CLASS
) == type
) &&
7119 (printer
->type
& printer_mask
) == printer_type
&&
7121 (printer
->location
&& !_cups_strcasecmp(printer
->location
, location
))))
7124 * If a username is specified, see if it is allowed or denied
7128 if (cupsArrayCount(printer
->users
) && username
&&
7129 !user_allowed(printer
, username
))
7133 * Add the group separator as needed...
7137 ippAddSeparator(con
->response
);
7142 * Send the attributes...
7145 copy_printer_attrs(con
, printer
, ra
);
7149 cupsArrayDelete(ra
);
7151 con
->response
->request
.status
.status_code
= IPP_OK
;
7156 * 'get_subscription_attrs()' - Get subscription attributes.
7160 get_subscription_attrs(
7161 cupsd_client_t
*con
, /* I - Client connection */
7162 int sub_id
) /* I - Subscription ID */
7164 http_status_t status
; /* Policy status */
7165 cupsd_subscription_t
*sub
; /* Subscription */
7166 cupsd_policy_t
*policy
; /* Current security policy */
7167 cups_array_t
*ra
, /* Requested attributes array */
7168 *exclude
; /* Private attributes array */
7171 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7172 "get_subscription_attrs(con=%p[%d], sub_id=%d)",
7173 con
, con
->number
, sub_id
);
7176 * Is the subscription ID valid?
7179 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
7182 * Bad subscription ID...
7185 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
7195 policy
= sub
->dest
->op_policy_ptr
;
7197 policy
= DefaultPolicyPtr
;
7199 if ((status
= cupsdCheckPolicy(policy
, con
, sub
->owner
)) != HTTP_OK
)
7201 send_http_error(con
, status
, sub
->dest
);
7205 exclude
= cupsdGetPrivateAttrs(policy
, con
, sub
->dest
, sub
->owner
);
7208 * Copy the subscription attributes to the response using the
7209 * requested-attributes attribute that may be provided by the client.
7212 ra
= create_requested_array(con
->request
);
7214 copy_subscription_attrs(con
, sub
, ra
, exclude
);
7216 cupsArrayDelete(ra
);
7218 con
->response
->request
.status
.status_code
= IPP_OK
;
7223 * 'get_subscriptions()' - Get subscriptions.
7227 get_subscriptions(cupsd_client_t
*con
, /* I - Client connection */
7228 ipp_attribute_t
*uri
) /* I - Printer/job URI */
7230 http_status_t status
; /* Policy status */
7231 int count
; /* Number of subscriptions */
7232 int limit
; /* Limit */
7233 cupsd_subscription_t
*sub
; /* Subscription */
7234 cups_array_t
*ra
; /* Requested attributes array */
7235 ipp_attribute_t
*attr
; /* Attribute */
7236 cups_ptype_t dtype
; /* Destination type (printer/class) */
7237 char scheme
[HTTP_MAX_URI
],
7238 /* Scheme portion of URI */
7239 username
[HTTP_MAX_URI
],
7240 /* Username portion of URI */
7242 /* Host portion of URI */
7243 resource
[HTTP_MAX_URI
];
7244 /* Resource portion of URI */
7245 int port
; /* Port portion of URI */
7246 cupsd_job_t
*job
; /* Job pointer */
7247 cupsd_printer_t
*printer
; /* Printer */
7248 cupsd_policy_t
*policy
; /* Policy */
7249 cups_array_t
*exclude
; /* Private attributes array */
7252 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7253 "get_subscriptions(con=%p[%d], uri=%s)",
7254 con
, con
->number
, uri
->values
[0].string
.text
);
7257 * Is the destination valid?
7260 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7261 sizeof(scheme
), username
, sizeof(username
), host
,
7262 sizeof(host
), &port
, resource
, sizeof(resource
));
7264 if (!strcmp(resource
, "/") ||
7265 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6) ||
7266 (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10) ||
7267 (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9))
7272 else if (!strncmp(resource
, "/jobs/", 6) && resource
[6])
7275 job
= cupsdFindJob(atoi(resource
+ 6));
7279 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
7280 atoi(resource
+ 6));
7284 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7290 send_ipp_status(con
, IPP_NOT_FOUND
,
7291 _("The printer or class does not exist."));
7294 else if ((attr
= ippFindAttribute(con
->request
, "notify-job-id",
7295 IPP_TAG_INTEGER
)) != NULL
)
7297 job
= cupsdFindJob(attr
->values
[0].integer
);
7301 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
7302 attr
->values
[0].integer
);
7314 policy
= printer
->op_policy_ptr
;
7316 policy
= DefaultPolicyPtr
;
7318 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
7320 send_http_error(con
, status
, printer
);
7325 * Copy the subscription attributes to the response using the
7326 * requested-attributes attribute that may be provided by the client.
7329 ra
= create_requested_array(con
->request
);
7331 if ((attr
= ippFindAttribute(con
->request
, "limit",
7332 IPP_TAG_INTEGER
)) != NULL
)
7333 limit
= attr
->values
[0].integer
;
7338 * See if we only want to see subscriptions for a specific user...
7341 if ((attr
= ippFindAttribute(con
->request
, "my-subscriptions",
7342 IPP_TAG_BOOLEAN
)) != NULL
&&
7343 attr
->values
[0].boolean
)
7344 strlcpy(username
, get_username(con
), sizeof(username
));
7348 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
), count
= 0;
7350 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
7351 if ((!printer
|| sub
->dest
== printer
) && (!job
|| sub
->job
== job
) &&
7352 (!username
[0] || !_cups_strcasecmp(username
, sub
->owner
)))
7354 ippAddSeparator(con
->response
);
7356 exclude
= cupsdGetPrivateAttrs(sub
->dest
? sub
->dest
->op_policy_ptr
:
7357 policy
, con
, sub
->dest
,
7360 copy_subscription_attrs(con
, sub
, ra
, exclude
);
7363 if (limit
&& count
>= limit
)
7367 cupsArrayDelete(ra
);
7370 con
->response
->request
.status
.status_code
= IPP_OK
;
7372 send_ipp_status(con
, IPP_NOT_FOUND
, _("No subscriptions found."));
7377 * 'get_username()' - Get the username associated with a request.
7380 static const char * /* O - Username */
7381 get_username(cupsd_client_t
*con
) /* I - Connection */
7383 ipp_attribute_t
*attr
; /* Attribute */
7386 if (con
->username
[0])
7387 return (con
->username
);
7388 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7389 IPP_TAG_NAME
)) != NULL
)
7390 return (attr
->values
[0].string
.text
);
7392 return ("anonymous");
7397 * 'hold_job()' - Hold a print job.
7401 hold_job(cupsd_client_t
*con
, /* I - Client connection */
7402 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
7404 ipp_attribute_t
*attr
; /* Current job-hold-until */
7405 const char *when
; /* New value */
7406 int jobid
; /* Job ID */
7407 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
7408 username
[HTTP_MAX_URI
], /* Username portion of URI */
7409 host
[HTTP_MAX_URI
], /* Host portion of URI */
7410 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7411 int port
; /* Port portion of URI */
7412 cupsd_job_t
*job
; /* Job information */
7415 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_job(%p[%d], %s)", con
, con
->number
,
7416 uri
->values
[0].string
.text
);
7419 * See if we have a job URI or a printer URI...
7422 if (!strcmp(uri
->name
, "printer-uri"))
7425 * Got a printer URI; see if we also have a job-id attribute...
7428 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7429 IPP_TAG_INTEGER
)) == NULL
)
7431 send_ipp_status(con
, IPP_BAD_REQUEST
,
7432 _("Got a printer-uri attribute but no job-id."));
7436 jobid
= attr
->values
[0].integer
;
7441 * Got a job URI; parse it to get the job ID...
7444 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7445 sizeof(scheme
), username
, sizeof(username
), host
,
7446 sizeof(host
), &port
, resource
, sizeof(resource
));
7448 if (strncmp(resource
, "/jobs/", 6))
7454 send_ipp_status(con
, IPP_BAD_REQUEST
,
7455 _("Bad job-uri \"%s\"."),
7456 uri
->values
[0].string
.text
);
7460 jobid
= atoi(resource
+ 6);
7464 * See if the job exists...
7467 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7470 * Nope - return a "not found" error...
7473 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
7478 * See if the job is owned by the requesting user...
7481 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7483 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
7484 cupsdFindDest(job
->dest
));
7489 * See if the job is in a state that allows holding...
7492 if (job
->state_value
> IPP_JOB_STOPPED
)
7495 * Return a "not-possible" error...
7498 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
7499 _("Job #%d is finished and cannot be altered."),
7505 * Hold the job and return...
7508 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
7509 IPP_TAG_KEYWORD
)) == NULL
)
7510 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
7514 when
= attr
->values
[0].string
.text
;
7516 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
7517 "Job job-hold-until value changed by user.");
7520 when
= "indefinite";
7522 cupsdSetJobHoldUntil(job
, when
, 1);
7523 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
, "Job held by \"%s\".",
7526 con
->response
->request
.status
.status_code
= IPP_OK
;
7531 * 'hold_new_jobs()' - Hold pending/new jobs on a printer or class.
7535 hold_new_jobs(cupsd_client_t
*con
, /* I - Connection */
7536 ipp_attribute_t
*uri
) /* I - Printer URI */
7538 http_status_t status
; /* Policy status */
7539 cups_ptype_t dtype
; /* Destination type (printer/class) */
7540 cupsd_printer_t
*printer
; /* Printer data */
7543 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_new_jobs(%p[%d], %s)", con
,
7544 con
->number
, uri
->values
[0].string
.text
);
7547 * Is the destination valid?
7550 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7556 send_ipp_status(con
, IPP_NOT_FOUND
,
7557 _("The printer or class does not exist."));
7565 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7567 send_http_error(con
, status
, printer
);
7572 * Hold pending/new jobs sent to the printer...
7575 printer
->holding_new_jobs
= 1;
7577 cupsdSetPrinterReasons(printer
, "+hold-new-jobs");
7579 if (dtype
& CUPS_PRINTER_CLASS
)
7580 cupsdLogMessage(CUPSD_LOG_INFO
,
7581 "Class \"%s\" now holding pending/new jobs (\"%s\").",
7582 printer
->name
, get_username(con
));
7584 cupsdLogMessage(CUPSD_LOG_INFO
,
7585 "Printer \"%s\" now holding pending/new jobs (\"%s\").",
7586 printer
->name
, get_username(con
));
7589 * Everything was ok, so return OK status...
7592 con
->response
->request
.status
.status_code
= IPP_OK
;
7597 * 'move_job()' - Move a job to a new destination.
7601 move_job(cupsd_client_t
*con
, /* I - Client connection */
7602 ipp_attribute_t
*uri
) /* I - Job URI */
7604 http_status_t status
; /* Policy status */
7605 ipp_attribute_t
*attr
; /* Current attribute */
7606 int jobid
; /* Job ID */
7607 cupsd_job_t
*job
; /* Current job */
7608 const char *src
; /* Source printer/class */
7609 cups_ptype_t stype
, /* Source type (printer or class) */
7610 dtype
; /* Destination type (printer/class) */
7611 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
7612 username
[HTTP_MAX_URI
], /* Username portion of URI */
7613 host
[HTTP_MAX_URI
], /* Host portion of URI */
7614 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7615 int port
; /* Port portion of URI */
7616 cupsd_printer_t
*sprinter
, /* Source printer */
7617 *dprinter
; /* Destination printer */
7620 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "move_job(%p[%d], %s)", con
, con
->number
,
7621 uri
->values
[0].string
.text
);
7624 * Get the new printer or class...
7627 if ((attr
= ippFindAttribute(con
->request
, "job-printer-uri",
7628 IPP_TAG_URI
)) == NULL
)
7631 * Need job-printer-uri...
7634 send_ipp_status(con
, IPP_BAD_REQUEST
,
7635 _("job-printer-uri attribute missing."));
7639 if (!cupsdValidateDest(attr
->values
[0].string
.text
, &dtype
, &dprinter
))
7645 send_ipp_status(con
, IPP_NOT_FOUND
,
7646 _("The printer or class does not exist."));
7651 * See if we have a job URI or a printer URI...
7654 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7655 sizeof(scheme
), username
, sizeof(username
), host
,
7656 sizeof(host
), &port
, resource
, sizeof(resource
));
7658 if (!strcmp(uri
->name
, "printer-uri"))
7661 * Got a printer URI; see if we also have a job-id attribute...
7664 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7665 IPP_TAG_INTEGER
)) == NULL
)
7671 if ((src
= cupsdValidateDest(uri
->values
[0].string
.text
, &stype
,
7672 &sprinter
)) == NULL
)
7678 send_ipp_status(con
, IPP_NOT_FOUND
,
7679 _("The printer or class does not exist."));
7688 * Otherwise, just move a single job...
7691 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
7694 * Nope - return a "not found" error...
7697 send_ipp_status(con
, IPP_NOT_FOUND
,
7698 _("Job #%d does not exist."), attr
->values
[0].integer
);
7704 * Job found, initialize source pointers...
7715 * Got a job URI; parse it to get the job ID...
7718 if (strncmp(resource
, "/jobs/", 6))
7724 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
7725 uri
->values
[0].string
.text
);
7730 * See if the job exists...
7733 jobid
= atoi(resource
+ 6);
7735 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7738 * Nope - return a "not found" error...
7741 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
7747 * Job found, initialize source pointers...
7756 * Check the policy of the destination printer...
7759 if ((status
= cupsdCheckPolicy(dprinter
->op_policy_ptr
, con
,
7760 job
? job
->username
: NULL
)) != HTTP_OK
)
7762 send_http_error(con
, status
, dprinter
);
7767 * Now move the job or jobs...
7773 * See if the job has been completed...
7776 if (job
->state_value
> IPP_JOB_STOPPED
)
7779 * Return a "not-possible" error...
7782 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
7783 _("Job #%d is finished and cannot be altered."),
7789 * See if the job is owned by the requesting user...
7792 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7794 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
7795 cupsdFindDest(job
->dest
));
7800 * Move the job to a different printer or class...
7803 cupsdMoveJob(job
, dprinter
);
7808 * Got the source printer, now look through the jobs...
7811 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
7813 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
7816 * See if the job is pointing at the source printer or has not been
7820 if (_cups_strcasecmp(job
->dest
, src
) ||
7821 job
->state_value
> IPP_JOB_STOPPED
)
7825 * See if the job can be moved by the requesting user...
7828 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7832 * Move the job to a different printer or class...
7835 cupsdMoveJob(job
, dprinter
);
7840 * Start jobs if possible...
7846 * Return with "everything is OK" status...
7849 con
->response
->request
.status
.status_code
= IPP_OK
;
7854 * 'ppd_parse_line()' - Parse a PPD default line.
7857 static int /* O - 0 on success, -1 on failure */
7858 ppd_parse_line(const char *line
, /* I - Line */
7859 char *option
, /* O - Option name */
7860 int olen
, /* I - Size of option name */
7861 char *choice
, /* O - Choice name */
7862 int clen
) /* I - Size of choice name */
7865 * Verify this is a default option line...
7868 if (strncmp(line
, "*Default", 8))
7872 * Read the option name...
7875 for (line
+= 8, olen
--;
7876 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
7887 * Skip everything else up to the colon (:)...
7890 while (*line
&& *line
!= ':')
7899 * Now grab the option choice, skipping leading whitespace...
7902 while (isspace(*line
& 255))
7906 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
7917 * Return with no errors...
7925 * 'print_job()' - Print a file to a printer or class.
7929 print_job(cupsd_client_t
*con
, /* I - Client connection */
7930 ipp_attribute_t
*uri
) /* I - Printer URI */
7932 ipp_attribute_t
*attr
; /* Current attribute */
7933 ipp_attribute_t
*format
; /* Document-format attribute */
7934 const char *default_format
; /* document-format-default value */
7935 cupsd_job_t
*job
; /* New job */
7936 char filename
[1024]; /* Job filename */
7937 mime_type_t
*filetype
; /* Type of file */
7938 char super
[MIME_MAX_SUPER
], /* Supertype of file */
7939 type
[MIME_MAX_TYPE
], /* Subtype of file */
7940 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
7941 /* Textual name of mime type */
7942 cupsd_printer_t
*printer
; /* Printer data */
7943 struct stat fileinfo
; /* File information */
7944 int kbytes
; /* Size of file */
7945 int compression
; /* Document compression */
7948 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "print_job(%p[%d], %s)", con
, con
->number
,
7949 uri
->values
[0].string
.text
);
7952 * Validate print file attributes, for now just document-format and
7953 * compression (CUPS only supports "none" and "gzip")...
7956 compression
= CUPS_FILE_NONE
;
7958 if ((attr
= ippFindAttribute(con
->request
, "compression",
7959 IPP_TAG_KEYWORD
)) != NULL
)
7961 if (strcmp(attr
->values
[0].string
.text
, "none")
7963 && strcmp(attr
->values
[0].string
.text
, "gzip")
7964 #endif /* HAVE_LIBZ */
7967 send_ipp_status(con
, IPP_ATTRIBUTES
,
7968 _("Unsupported compression \"%s\"."),
7969 attr
->values
[0].string
.text
);
7970 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
7971 "compression", NULL
, attr
->values
[0].string
.text
);
7976 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
7977 compression
= CUPS_FILE_GZIP
;
7978 #endif /* HAVE_LIBZ */
7982 * Do we have a file to print?
7987 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file in print request."));
7992 * Is the destination valid?
7995 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
8001 send_ipp_status(con
, IPP_NOT_FOUND
,
8002 _("The printer or class does not exist."));
8007 * Is it a format we support?
8010 if ((format
= ippFindAttribute(con
->request
, "document-format",
8011 IPP_TAG_MIMETYPE
)) != NULL
)
8014 * Grab format from client...
8017 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%255[^;]", super
,
8020 send_ipp_status(con
, IPP_BAD_REQUEST
,
8021 _("Bad document-format \"%s\"."),
8022 format
->values
[0].string
.text
);
8026 else if ((default_format
= cupsGetOption("document-format",
8027 printer
->num_options
,
8028 printer
->options
)) != NULL
)
8031 * Use default document format...
8034 if (sscanf(default_format
, "%15[^/]/%255[^;]", super
, type
) != 2)
8036 send_ipp_status(con
, IPP_BAD_REQUEST
,
8037 _("Bad document-format \"%s\"."),
8048 strlcpy(super
, "application", sizeof(super
));
8049 strlcpy(type
, "octet-stream", sizeof(type
));
8052 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
8055 * Auto-type the file...
8058 ipp_attribute_t
*doc_name
; /* document-name attribute */
8061 cupsdLogMessage(CUPSD_LOG_DEBUG
, "[Job ???] Auto-typing file...");
8063 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
8064 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
8065 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
8069 filetype
= mimeType(MimeDatabase
, super
, type
);
8071 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job ???] Request file type is %s/%s.",
8072 filetype
->super
, filetype
->type
);
8075 filetype
= mimeType(MimeDatabase
, super
, type
);
8079 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
8082 * Replace the document-format attribute value with the auto-typed or
8086 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
8091 _cupsStrFree(format
->values
[0].string
.text
);
8093 format
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
8096 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
8097 "document-format", NULL
, mimetype
);
8101 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
8102 _("Unsupported document-format \"%s\"."),
8103 format
? format
->values
[0].string
.text
:
8104 "application/octet-stream");
8105 cupsdLogMessage(CUPSD_LOG_INFO
,
8106 "Hint: Do you have the raw file printing rules enabled?");
8109 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
8110 "document-format", NULL
, format
->values
[0].string
.text
);
8116 * Read any embedded job ticket info from PS files...
8119 if (!_cups_strcasecmp(filetype
->super
, "application") &&
8120 (!_cups_strcasecmp(filetype
->type
, "postscript") ||
8121 !_cups_strcasecmp(filetype
->type
, "pdf")))
8122 read_job_ticket(con
);
8125 * Create the job object...
8128 if ((job
= add_job(con
, printer
, filetype
)) == NULL
)
8132 * Update quota data...
8135 if (stat(con
->filename
, &fileinfo
))
8138 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
8140 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
8142 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
8143 IPP_TAG_INTEGER
)) != NULL
)
8144 attr
->values
[0].integer
+= kbytes
;
8147 * Add the job file...
8150 if (add_file(con
, job
, filetype
, compression
))
8153 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
8155 rename(con
->filename
, filename
);
8156 cupsdClearString(&con
->filename
);
8159 * See if we need to add the ending sheet...
8162 if (cupsdTimeoutJob(job
))
8166 * Log and save the job...
8169 cupsdLogJob(job
, CUPSD_LOG_INFO
,
8170 "File of type %s/%s queued by \"%s\".",
8171 filetype
->super
, filetype
->type
, job
->username
);
8172 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "hold_until=%d", (int)job
->hold_until
);
8173 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
8174 job
->dest
, job
->username
);
8177 * Start the job if possible...
8185 * 'read_job_ticket()' - Read a job ticket embedded in a print file.
8187 * This function only gets called when printing a single PDF or PostScript
8188 * file using the Print-Job operation. It doesn't work for Create-Job +
8189 * Send-File, since the job attributes need to be set at job creation
8190 * time for banners to work. The embedded job ticket stuff is here
8191 * primarily to allow the Windows printer driver for CUPS to pass in JCL
8192 * options and IPP attributes which otherwise would be lost.
8194 * The format of a job ticket is simple:
8196 * %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
8198 * %cupsJobTicket: attr1=value1
8199 * %cupsJobTicket: attr2=value2
8201 * %cupsJobTicket: attrN=valueN
8203 * Job ticket lines must appear immediately after the first line that
8204 * specifies PostScript (%!PS-Adobe-3.0) or PDF (%PDF) format, and CUPS
8205 * stops looking for job ticket info when it finds a line that does not begin
8206 * with "%cupsJobTicket:".
8208 * The maximum length of a job ticket line, including the prefix, is
8209 * 255 characters to conform with the Adobe DSC.
8211 * Read-only attributes are rejected with a notice to the error log in
8212 * case a malicious user tries anything. Since the job ticket is read
8213 * prior to attribute validation in print_job(), job ticket attributes
8214 * will go through the same validation as IPP attributes...
8218 read_job_ticket(cupsd_client_t
*con
) /* I - Client connection */
8220 cups_file_t
*fp
; /* File to read from */
8221 char line
[256]; /* Line data */
8222 int num_options
; /* Number of options */
8223 cups_option_t
*options
; /* Options */
8224 ipp_t
*ticket
; /* New attributes */
8225 ipp_attribute_t
*attr
, /* Current attribute */
8226 *attr2
, /* Job attribute */
8227 *prev2
; /* Previous job attribute */
8231 * First open the print file...
8234 if ((fp
= cupsFileOpen(con
->filename
, "rb")) == NULL
)
8236 cupsdLogMessage(CUPSD_LOG_ERROR
,
8237 "Unable to open print file for job ticket - %s",
8243 * Skip the first line...
8246 if (cupsFileGets(fp
, line
, sizeof(line
)) == NULL
)
8248 cupsdLogMessage(CUPSD_LOG_ERROR
,
8249 "Unable to read from print file for job ticket - %s",
8255 if (strncmp(line
, "%!PS-Adobe-", 11) && strncmp(line
, "%PDF-", 5))
8258 * Not a DSC-compliant file, so no job ticket info will be available...
8266 * Read job ticket info from the file...
8272 while (cupsFileGets(fp
, line
, sizeof(line
)))
8275 * Stop at the first non-ticket line...
8278 if (strncmp(line
, "%cupsJobTicket:", 15))
8282 * Add the options to the option array...
8285 num_options
= cupsParseOptions(line
+ 15, num_options
, &options
);
8289 * Done with the file; see if we have any options...
8294 if (num_options
== 0)
8298 * OK, convert the options to an attribute list, and apply them to
8303 cupsEncodeOptions(ticket
, num_options
, options
);
8306 * See what the user wants to change.
8309 for (attr
= ticket
->attrs
; attr
; attr
= attr
->next
)
8311 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
8314 if (!strcmp(attr
->name
, "job-originating-host-name") ||
8315 !strcmp(attr
->name
, "job-originating-user-name") ||
8316 !strcmp(attr
->name
, "job-media-sheets-completed") ||
8317 !strcmp(attr
->name
, "job-k-octets") ||
8318 !strcmp(attr
->name
, "job-id") ||
8319 !strncmp(attr
->name
, "job-state", 9) ||
8320 !strncmp(attr
->name
, "time-at-", 8))
8321 continue; /* Read-only attrs */
8323 if ((attr2
= ippFindAttribute(con
->request
, attr
->name
,
8324 IPP_TAG_ZERO
)) != NULL
)
8327 * Some other value; first free the old value...
8330 if (con
->request
->attrs
== attr2
)
8332 con
->request
->attrs
= attr2
->next
;
8337 for (prev2
= con
->request
->attrs
; prev2
; prev2
= prev2
->next
)
8338 if (prev2
->next
== attr2
)
8340 prev2
->next
= attr2
->next
;
8345 if (con
->request
->last
== attr2
)
8346 con
->request
->last
= prev2
;
8348 ippDeleteAttribute(NULL
, attr2
);
8352 * Add new option by copying it...
8355 ippCopyAttribute(con
->request
, attr
, 0);
8359 * Then free the attribute list and option array...
8363 cupsFreeOptions(num_options
, options
);
8368 * 'reject_jobs()' - Reject print jobs to a printer.
8372 reject_jobs(cupsd_client_t
*con
, /* I - Client connection */
8373 ipp_attribute_t
*uri
) /* I - Printer or class URI */
8375 http_status_t status
; /* Policy status */
8376 cups_ptype_t dtype
; /* Destination type (printer/class) */
8377 cupsd_printer_t
*printer
; /* Printer data */
8378 ipp_attribute_t
*attr
; /* printer-state-message text */
8381 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "reject_jobs(%p[%d], %s)", con
,
8382 con
->number
, uri
->values
[0].string
.text
);
8385 * Is the destination valid?
8388 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8394 send_ipp_status(con
, IPP_NOT_FOUND
,
8395 _("The printer or class does not exist."));
8403 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8405 send_http_error(con
, status
, printer
);
8410 * Reject jobs sent to the printer...
8413 printer
->accepting
= 0;
8415 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
8416 IPP_TAG_TEXT
)) == NULL
)
8417 strlcpy(printer
->state_message
, "Rejecting Jobs",
8418 sizeof(printer
->state_message
));
8420 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
8421 sizeof(printer
->state_message
));
8423 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
8424 "No longer accepting jobs.");
8426 if (dtype
& CUPS_PRINTER_CLASS
)
8428 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
8430 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" rejecting jobs (\"%s\").",
8431 printer
->name
, get_username(con
));
8435 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
8437 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" rejecting jobs (\"%s\").",
8438 printer
->name
, get_username(con
));
8442 * Everything was ok, so return OK status...
8445 con
->response
->request
.status
.status_code
= IPP_OK
;
8450 * 'release_held_new_jobs()' - Release pending/new jobs on a printer or class.
8454 release_held_new_jobs(
8455 cupsd_client_t
*con
, /* I - Connection */
8456 ipp_attribute_t
*uri
) /* I - Printer URI */
8458 http_status_t status
; /* Policy status */
8459 cups_ptype_t dtype
; /* Destination type (printer/class) */
8460 cupsd_printer_t
*printer
; /* Printer data */
8463 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_held_new_jobs(%p[%d], %s)", con
,
8464 con
->number
, uri
->values
[0].string
.text
);
8467 * Is the destination valid?
8470 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8476 send_ipp_status(con
, IPP_NOT_FOUND
,
8477 _("The printer or class does not exist."));
8485 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8487 send_http_error(con
, status
, printer
);
8492 * Hold pending/new jobs sent to the printer...
8495 printer
->holding_new_jobs
= 0;
8497 cupsdSetPrinterReasons(printer
, "-hold-new-jobs");
8499 if (dtype
& CUPS_PRINTER_CLASS
)
8500 cupsdLogMessage(CUPSD_LOG_INFO
,
8501 "Class \"%s\" now printing pending/new jobs (\"%s\").",
8502 printer
->name
, get_username(con
));
8504 cupsdLogMessage(CUPSD_LOG_INFO
,
8505 "Printer \"%s\" now printing pending/new jobs (\"%s\").",
8506 printer
->name
, get_username(con
));
8509 * Everything was ok, so return OK status...
8512 con
->response
->request
.status
.status_code
= IPP_OK
;
8517 * 'release_job()' - Release a held print job.
8521 release_job(cupsd_client_t
*con
, /* I - Client connection */
8522 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
8524 ipp_attribute_t
*attr
; /* Current attribute */
8525 int jobid
; /* Job ID */
8526 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
8527 username
[HTTP_MAX_URI
], /* Username portion of URI */
8528 host
[HTTP_MAX_URI
], /* Host portion of URI */
8529 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8530 int port
; /* Port portion of URI */
8531 cupsd_job_t
*job
; /* Job information */
8534 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_job(%p[%d], %s)", con
,
8535 con
->number
, uri
->values
[0].string
.text
);
8538 * See if we have a job URI or a printer URI...
8541 if (!strcmp(uri
->name
, "printer-uri"))
8544 * Got a printer URI; see if we also have a job-id attribute...
8547 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8548 IPP_TAG_INTEGER
)) == NULL
)
8550 send_ipp_status(con
, IPP_BAD_REQUEST
,
8551 _("Got a printer-uri attribute but no job-id."));
8555 jobid
= attr
->values
[0].integer
;
8560 * Got a job URI; parse it to get the job ID...
8563 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8564 sizeof(scheme
), username
, sizeof(username
), host
,
8565 sizeof(host
), &port
, resource
, sizeof(resource
));
8567 if (strncmp(resource
, "/jobs/", 6))
8573 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
8574 uri
->values
[0].string
.text
);
8578 jobid
= atoi(resource
+ 6);
8582 * See if the job exists...
8585 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8588 * Nope - return a "not found" error...
8591 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
8596 * See if job is "held"...
8599 if (job
->state_value
!= IPP_JOB_HELD
)
8602 * Nope - return a "not possible" error...
8605 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not held."), jobid
);
8610 * See if the job is owned by the requesting user...
8613 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8615 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8616 cupsdFindDest(job
->dest
));
8621 * Reset the job-hold-until value to "no-hold"...
8624 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
8625 IPP_TAG_KEYWORD
)) == NULL
)
8626 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
8630 _cupsStrFree(attr
->values
[0].string
.text
);
8632 attr
->value_tag
= IPP_TAG_KEYWORD
;
8633 attr
->values
[0].string
.text
= _cupsStrAlloc("no-hold");
8635 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
8636 "Job job-hold-until value changed by user.");
8637 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
8641 * Release the job and return...
8644 cupsdReleaseJob(job
);
8646 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
8647 "Job released by user.");
8649 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Released by \"%s\".", username
);
8651 con
->response
->request
.status
.status_code
= IPP_OK
;
8658 * 'renew_subscription()' - Renew an existing subscription...
8663 cupsd_client_t
*con
, /* I - Client connection */
8664 int sub_id
) /* I - Subscription ID */
8666 http_status_t status
; /* Policy status */
8667 cupsd_subscription_t
*sub
; /* Subscription */
8668 ipp_attribute_t
*lease
; /* notify-lease-duration */
8671 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
8672 "renew_subscription(con=%p[%d], sub_id=%d)",
8673 con
, con
->number
, sub_id
);
8676 * Is the subscription ID valid?
8679 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
8682 * Bad subscription ID...
8685 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
8693 * Job subscriptions cannot be renewed...
8696 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8697 _("Job subscriptions cannot be renewed."));
8705 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
8707 con
, sub
->owner
)) != HTTP_OK
)
8709 send_http_error(con
, status
, sub
->dest
);
8714 * Renew the subscription...
8717 lease
= ippFindAttribute(con
->request
, "notify-lease-duration",
8720 sub
->lease
= lease
? lease
->values
[0].integer
: DefaultLeaseDuration
;
8722 if (MaxLeaseDuration
&& (sub
->lease
== 0 || sub
->lease
> MaxLeaseDuration
))
8724 cupsdLogMessage(CUPSD_LOG_INFO
,
8725 "renew_subscription: Limiting notify-lease-duration to "
8728 sub
->lease
= MaxLeaseDuration
;
8731 sub
->expire
= sub
->lease
? time(NULL
) + sub
->lease
: 0;
8733 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
8735 con
->response
->request
.status
.status_code
= IPP_OK
;
8737 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
8738 "notify-lease-duration", sub
->lease
);
8743 * 'restart_job()' - Restart an old print job.
8747 restart_job(cupsd_client_t
*con
, /* I - Client connection */
8748 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
8750 ipp_attribute_t
*attr
; /* Current attribute */
8751 int jobid
; /* Job ID */
8752 cupsd_job_t
*job
; /* Job information */
8753 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
8754 username
[HTTP_MAX_URI
], /* Username portion of URI */
8755 host
[HTTP_MAX_URI
], /* Host portion of URI */
8756 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8757 int port
; /* Port portion of URI */
8760 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "restart_job(%p[%d], %s)", con
,
8761 con
->number
, uri
->values
[0].string
.text
);
8764 * See if we have a job URI or a printer URI...
8767 if (!strcmp(uri
->name
, "printer-uri"))
8770 * Got a printer URI; see if we also have a job-id attribute...
8773 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8774 IPP_TAG_INTEGER
)) == NULL
)
8776 send_ipp_status(con
, IPP_BAD_REQUEST
,
8777 _("Got a printer-uri attribute but no job-id."));
8781 jobid
= attr
->values
[0].integer
;
8786 * Got a job URI; parse it to get the job ID...
8789 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8790 sizeof(scheme
), username
, sizeof(username
), host
,
8791 sizeof(host
), &port
, resource
, sizeof(resource
));
8793 if (strncmp(resource
, "/jobs/", 6))
8799 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
8800 uri
->values
[0].string
.text
);
8804 jobid
= atoi(resource
+ 6);
8808 * See if the job exists...
8811 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8814 * Nope - return a "not found" error...
8817 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
8822 * See if job is in any of the "completed" states...
8825 if (job
->state_value
<= IPP_JOB_PROCESSING
)
8828 * Nope - return a "not possible" error...
8831 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not complete."),
8837 * See if we have retained the job files...
8842 if (!job
->attrs
|| job
->num_files
== 0)
8845 * Nope - return a "not possible" error...
8848 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8849 _("Job #%d cannot be restarted - no files."), jobid
);
8854 * See if the job is owned by the requesting user...
8857 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8859 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8860 cupsdFindDest(job
->dest
));
8865 * See if the job-hold-until attribute is specified...
8868 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
8869 IPP_TAG_KEYWORD
)) == NULL
)
8870 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
8872 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
8875 * Return the job to a held state...
8878 cupsdLogJob(job
, CUPSD_LOG_DEBUG
,
8879 "Restarted by \"%s\" with job-hold-until=%s.",
8880 username
, attr
->values
[0].string
.text
);
8881 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
8883 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
,
8884 NULL
, job
, "Job restarted by user with job-hold-until=%s",
8885 attr
->values
[0].string
.text
);
8890 * Restart the job...
8893 cupsdRestartJob(job
);
8897 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Restarted by \"%s\".", username
);
8899 con
->response
->request
.status
.status_code
= IPP_OK
;
8904 * 'save_auth_info()' - Save authentication information for a job.
8909 cupsd_client_t
*con
, /* I - Client connection */
8910 cupsd_job_t
*job
, /* I - Job */
8911 ipp_attribute_t
*auth_info
) /* I - auth-info attribute, if any */
8913 int i
; /* Looping var */
8914 char filename
[1024]; /* Job authentication filename */
8915 cups_file_t
*fp
; /* Job authentication file */
8916 char line
[65536]; /* Line for file */
8917 cupsd_printer_t
*dest
; /* Destination printer/class */
8921 * This function saves the in-memory authentication information for
8922 * a job so that it can be used to authenticate with a remote host.
8923 * The information is stored in a file that is readable only by the
8924 * root user. The fields are Base-64 encoded, each on a separate line,
8925 * followed by random number (up to 1024) of newlines to limit the
8926 * amount of information that is exposed.
8928 * Because of the potential for exposing of authentication information,
8929 * this functionality is only enabled when running cupsd as root.
8931 * This caching only works for the Basic and BasicDigest authentication
8932 * types. Digest authentication cannot be cached this way, and in
8933 * the future Kerberos authentication may make all of this obsolete.
8935 * Authentication information is saved whenever an authenticated
8936 * Print-Job, Create-Job, or CUPS-Authenticate-Job operation is
8939 * This information is deleted after a job is completed or canceled,
8940 * so reprints may require subsequent re-authentication.
8946 if ((dest
= cupsdFindDest(job
->dest
)) == NULL
)
8950 * Create the authentication file and change permissions...
8953 snprintf(filename
, sizeof(filename
), "%s/a%05d", RequestRoot
, job
->id
);
8954 if ((fp
= cupsFileOpen(filename
, "w")) == NULL
)
8956 cupsdLogMessage(CUPSD_LOG_ERROR
,
8957 "Unable to save authentication info to \"%s\" - %s",
8958 filename
, strerror(errno
));
8962 fchown(cupsFileNumber(fp
), 0, 0);
8963 fchmod(cupsFileNumber(fp
), 0400);
8965 cupsFilePuts(fp
, "CUPSD-AUTH-V3\n");
8968 i
< (int)(sizeof(job
->auth_env
) / sizeof(job
->auth_env
[0]));
8970 cupsdClearString(job
->auth_env
+ i
);
8972 if (auth_info
&& auth_info
->num_values
== dest
->num_auth_info_required
)
8975 * Write 1 to 3 auth values...
8979 i
< auth_info
->num_values
&&
8980 i
< (int)(sizeof(job
->auth_env
) / sizeof(job
->auth_env
[0]));
8983 if (strcmp(dest
->auth_info_required
[i
], "negotiate"))
8985 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[i
].string
.text
, (int)strlen(auth_info
->values
[i
].string
.text
));
8986 cupsFilePutConf(fp
, dest
->auth_info_required
[i
], line
);
8989 cupsFilePutConf(fp
, dest
->auth_info_required
[i
],
8990 auth_info
->values
[i
].string
.text
);
8992 if (!strcmp(dest
->auth_info_required
[i
], "username"))
8993 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_USERNAME=%s",
8994 auth_info
->values
[i
].string
.text
);
8995 else if (!strcmp(dest
->auth_info_required
[i
], "domain"))
8996 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_DOMAIN=%s",
8997 auth_info
->values
[i
].string
.text
);
8998 else if (!strcmp(dest
->auth_info_required
[i
], "password"))
8999 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_PASSWORD=%s",
9000 auth_info
->values
[i
].string
.text
);
9001 else if (!strcmp(dest
->auth_info_required
[i
], "negotiate"))
9002 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_NEGOTIATE=%s",
9003 auth_info
->values
[i
].string
.text
);
9008 else if (auth_info
&& auth_info
->num_values
== 2 &&
9009 dest
->num_auth_info_required
== 1 &&
9010 !strcmp(dest
->auth_info_required
[0], "negotiate"))
9013 * Allow fallback to username+password for Kerberized queues...
9016 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[0].string
.text
, (int)strlen(auth_info
->values
[0].string
.text
));
9017 cupsFilePutConf(fp
, "username", line
);
9019 cupsdSetStringf(job
->auth_env
+ 0, "AUTH_USERNAME=%s",
9020 auth_info
->values
[0].string
.text
);
9022 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[1].string
.text
, (int)strlen(auth_info
->values
[1].string
.text
));
9023 cupsFilePutConf(fp
, "password", line
);
9025 cupsdSetStringf(job
->auth_env
+ 1, "AUTH_PASSWORD=%s",
9026 auth_info
->values
[1].string
.text
);
9028 else if (con
->username
[0])
9031 * Write the authenticated username...
9034 httpEncode64_2(line
, sizeof(line
), con
->username
, (int)strlen(con
->username
));
9035 cupsFilePutConf(fp
, "username", line
);
9037 cupsdSetStringf(job
->auth_env
+ 0, "AUTH_USERNAME=%s", con
->username
);
9040 * Write the authenticated password...
9043 httpEncode64_2(line
, sizeof(line
), con
->password
, (int)strlen(con
->password
));
9044 cupsFilePutConf(fp
, "password", line
);
9046 cupsdSetStringf(job
->auth_env
+ 1, "AUTH_PASSWORD=%s", con
->password
);
9050 if (con
->gss_uid
> 0)
9052 cupsFilePrintf(fp
, "uid %d\n", (int)con
->gss_uid
);
9053 cupsdSetStringf(&job
->auth_uid
, "AUTH_UID=%d", (int)con
->gss_uid
);
9055 #endif /* HAVE_GSSAPI */
9058 * Write a random number of newlines to the end of the file...
9061 for (i
= (CUPS_RAND() % 1024); i
>= 0; i
--)
9062 cupsFilePutChar(fp
, '\n');
9065 * Close the file and return...
9073 * 'send_document()' - Send a file to a printer or class.
9077 send_document(cupsd_client_t
*con
, /* I - Client connection */
9078 ipp_attribute_t
*uri
) /* I - Printer URI */
9080 ipp_attribute_t
*attr
; /* Current attribute */
9081 ipp_attribute_t
*format
; /* Request's document-format attribute */
9082 ipp_attribute_t
*jformat
; /* Job's document-format attribute */
9083 const char *default_format
;/* document-format-default value */
9084 int jobid
; /* Job ID number */
9085 cupsd_job_t
*job
; /* Current job */
9086 char job_uri
[HTTP_MAX_URI
],
9088 scheme
[HTTP_MAX_URI
],
9089 /* Method portion of URI */
9090 username
[HTTP_MAX_URI
],
9091 /* Username portion of URI */
9093 /* Host portion of URI */
9094 resource
[HTTP_MAX_URI
];
9095 /* Resource portion of URI */
9096 int port
; /* Port portion of URI */
9097 mime_type_t
*filetype
; /* Type of file */
9098 char super
[MIME_MAX_SUPER
],
9099 /* Supertype of file */
9100 type
[MIME_MAX_TYPE
],
9101 /* Subtype of file */
9102 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
9103 /* Textual name of mime type */
9104 char filename
[1024]; /* Job filename */
9105 cupsd_printer_t
*printer
; /* Current printer */
9106 struct stat fileinfo
; /* File information */
9107 int kbytes
; /* Size of file */
9108 int compression
; /* Type of compression */
9109 int start_job
; /* Start the job? */
9112 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "send_document(%p[%d], %s)", con
,
9113 con
->number
, uri
->values
[0].string
.text
);
9116 * See if we have a job URI or a printer URI...
9119 if (!strcmp(uri
->name
, "printer-uri"))
9122 * Got a printer URI; see if we also have a job-id attribute...
9125 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9126 IPP_TAG_INTEGER
)) == NULL
)
9128 send_ipp_status(con
, IPP_BAD_REQUEST
,
9129 _("Got a printer-uri attribute but no job-id."));
9133 jobid
= attr
->values
[0].integer
;
9138 * Got a job URI; parse it to get the job ID...
9141 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9142 sizeof(scheme
), username
, sizeof(username
), host
,
9143 sizeof(host
), &port
, resource
, sizeof(resource
));
9145 if (strncmp(resource
, "/jobs/", 6))
9151 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9152 uri
->values
[0].string
.text
);
9156 jobid
= atoi(resource
+ 6);
9160 * See if the job exists...
9163 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9166 * Nope - return a "not found" error...
9169 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9173 printer
= cupsdFindDest(job
->dest
);
9176 * See if the job is owned by the requesting user...
9179 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9181 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9182 cupsdFindDest(job
->dest
));
9187 * OK, see if the client is sending the document compressed - CUPS
9188 * only supports "none" and "gzip".
9191 compression
= CUPS_FILE_NONE
;
9193 if ((attr
= ippFindAttribute(con
->request
, "compression",
9194 IPP_TAG_KEYWORD
)) != NULL
)
9196 if (strcmp(attr
->values
[0].string
.text
, "none")
9198 && strcmp(attr
->values
[0].string
.text
, "gzip")
9199 #endif /* HAVE_LIBZ */
9202 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Unsupported compression \"%s\"."),
9203 attr
->values
[0].string
.text
);
9204 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
9205 "compression", NULL
, attr
->values
[0].string
.text
);
9210 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
9211 compression
= CUPS_FILE_GZIP
;
9212 #endif /* HAVE_LIBZ */
9216 * Do we have a file to print?
9219 if ((attr
= ippFindAttribute(con
->request
, "last-document",
9220 IPP_TAG_BOOLEAN
)) == NULL
)
9222 send_ipp_status(con
, IPP_BAD_REQUEST
,
9223 _("Missing last-document attribute in request."));
9230 * Check for an empty request with "last-document" set to true, which is
9231 * used to close an "open" job by RFC 2911, section 3.3.2.
9234 if (job
->num_files
> 0 && attr
->values
[0].boolean
)
9237 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file in print request."));
9242 * Is it a format we support?
9245 if ((format
= ippFindAttribute(con
->request
, "document-format",
9246 IPP_TAG_MIMETYPE
)) != NULL
)
9249 * Grab format from client...
9252 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%255[^;]",
9255 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"."),
9256 format
->values
[0].string
.text
);
9260 else if ((default_format
= cupsGetOption("document-format",
9261 printer
->num_options
,
9262 printer
->options
)) != NULL
)
9265 * Use default document format...
9268 if (sscanf(default_format
, "%15[^/]/%255[^;]", super
, type
) != 2)
9270 send_ipp_status(con
, IPP_BAD_REQUEST
,
9271 _("Bad document-format-default \"%s\"."), default_format
);
9278 * No document format attribute? Auto-type it!
9281 strlcpy(super
, "application", sizeof(super
));
9282 strlcpy(type
, "octet-stream", sizeof(type
));
9285 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
9288 * Auto-type the file...
9291 ipp_attribute_t
*doc_name
; /* document-name attribute */
9294 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Auto-typing file...");
9296 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
9297 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
9298 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
9302 filetype
= mimeType(MimeDatabase
, super
, type
);
9305 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Request file type is %s/%s.",
9306 filetype
->super
, filetype
->type
);
9309 filetype
= mimeType(MimeDatabase
, super
, type
);
9314 * Replace the document-format attribute value with the auto-typed or
9318 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9321 if ((jformat
= ippFindAttribute(job
->attrs
, "document-format",
9322 IPP_TAG_MIMETYPE
)) != NULL
)
9324 _cupsStrFree(jformat
->values
[0].string
.text
);
9326 jformat
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
9329 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
9330 "document-format", NULL
, mimetype
);
9334 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9335 _("Unsupported document-format \"%s/%s\"."), super
, type
);
9336 cupsdLogMessage(CUPSD_LOG_INFO
,
9337 "Hint: Do you have the raw file printing rules enabled?");
9340 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9341 "document-format", NULL
, format
->values
[0].string
.text
);
9346 if (printer
->filetypes
&& !cupsArrayFind(printer
->filetypes
, filetype
))
9348 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9351 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9352 _("Unsupported document-format \"%s\"."), mimetype
);
9354 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9355 "document-format", NULL
, mimetype
);
9361 * Add the file to the job...
9366 if (add_file(con
, job
, filetype
, compression
))
9369 if (stat(con
->filename
, &fileinfo
))
9372 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
9374 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
9376 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
9377 IPP_TAG_INTEGER
)) != NULL
)
9378 attr
->values
[0].integer
+= kbytes
;
9380 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
9382 rename(con
->filename
, filename
);
9384 cupsdClearString(&con
->filename
);
9386 cupsdLogJob(job
, CUPSD_LOG_INFO
, "File of type %s/%s queued by \"%s\".",
9387 filetype
->super
, filetype
->type
, job
->username
);
9390 * Start the job if this is the last document...
9395 if ((attr
= ippFindAttribute(con
->request
, "last-document",
9396 IPP_TAG_BOOLEAN
)) != NULL
&&
9397 attr
->values
[0].boolean
)
9400 * See if we need to add the ending sheet...
9403 if (cupsdTimeoutJob(job
))
9406 if (job
->state_value
== IPP_JOB_STOPPED
)
9408 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9409 job
->state_value
= IPP_JOB_PENDING
;
9411 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
9413 else if (job
->state_value
== IPP_JOB_HELD
)
9415 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9416 IPP_TAG_KEYWORD
)) == NULL
)
9417 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9419 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9421 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9422 job
->state_value
= IPP_JOB_PENDING
;
9424 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
9427 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-hold-until-specified");
9431 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
9437 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9438 IPP_TAG_KEYWORD
)) == NULL
)
9439 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9441 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9443 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
9444 job
->state_value
= IPP_JOB_HELD
;
9445 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
9447 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-incoming");
9450 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
9457 * Fill in the response info...
9460 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
9461 con
->clientname
, con
->clientport
, "/jobs/%d", jobid
);
9462 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
9465 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", jobid
);
9467 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
9469 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons",
9470 NULL
, job
->reasons
->values
[0].string
.text
);
9472 con
->response
->request
.status
.status_code
= IPP_OK
;
9475 * Start the job if necessary...
9484 * 'send_http_error()' - Send a HTTP error back to the IPP client.
9489 cupsd_client_t
*con
, /* I - Client connection */
9490 http_status_t status
, /* I - HTTP status code */
9491 cupsd_printer_t
*printer
) /* I - Printer, if any */
9493 ipp_attribute_t
*uri
; /* Request URI, if any */
9496 if ((uri
= ippFindAttribute(con
->request
, "printer-uri",
9497 IPP_TAG_URI
)) == NULL
)
9498 uri
= ippFindAttribute(con
->request
, "job-uri", IPP_TAG_URI
);
9500 cupsdLogMessage(status
== HTTP_FORBIDDEN
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
9501 "[Client %d] Returning HTTP %s for %s (%s) from %s",
9502 con
->number
, httpStatus(status
),
9504 ippOpString(con
->request
->request
.op
.operation_id
) :
9506 uri
? uri
->values
[0].string
.text
: "no URI",
9507 con
->http
->hostname
);
9511 int auth_type
; /* Type of authentication required */
9514 auth_type
= CUPSD_AUTH_NONE
;
9516 if (status
== HTTP_UNAUTHORIZED
&&
9517 printer
->num_auth_info_required
> 0 &&
9518 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
9520 (con
->request
->request
.op
.operation_id
== IPP_PRINT_JOB
||
9521 con
->request
->request
.op
.operation_id
== IPP_CREATE_JOB
||
9522 con
->request
->request
.op
.operation_id
== CUPS_AUTHENTICATE_JOB
))
9525 * Creating and authenticating jobs requires Kerberos...
9528 auth_type
= CUPSD_AUTH_NEGOTIATE
;
9533 * Use policy/location-defined authentication requirements...
9536 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9537 cupsd_location_t
*auth
; /* Pointer to authentication element */
9540 if (printer
->type
& CUPS_PRINTER_CLASS
)
9541 snprintf(resource
, sizeof(resource
), "/classes/%s", printer
->name
);
9543 snprintf(resource
, sizeof(resource
), "/printers/%s", printer
->name
);
9545 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
9546 auth
->type
== CUPSD_AUTH_NONE
)
9547 auth
= cupsdFindPolicyOp(printer
->op_policy_ptr
,
9549 con
->request
->request
.op
.operation_id
:
9554 if (auth
->type
== CUPSD_AUTH_DEFAULT
)
9555 auth_type
= cupsdDefaultAuthType();
9557 auth_type
= auth
->type
;
9561 cupsdSendError(con
, status
, auth_type
);
9564 cupsdSendError(con
, status
, CUPSD_AUTH_NONE
);
9566 ippDelete(con
->response
);
9567 con
->response
= NULL
;
9574 * 'send_ipp_status()' - Send a status back to the IPP client.
9578 send_ipp_status(cupsd_client_t
*con
, /* I - Client connection */
9579 ipp_status_t status
, /* I - IPP status code */
9580 const char *message
,/* I - Status message */
9581 ...) /* I - Additional args as needed */
9583 va_list ap
; /* Pointer to additional args */
9584 char formatted
[1024]; /* Formatted errror message */
9587 va_start(ap
, message
);
9588 vsnprintf(formatted
, sizeof(formatted
),
9589 _cupsLangString(con
->language
, message
), ap
);
9592 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s: %s",
9593 ippOpString(con
->request
->request
.op
.operation_id
),
9594 ippErrorString(status
), formatted
);
9596 con
->response
->request
.status
.status_code
= status
;
9598 if (ippFindAttribute(con
->response
, "attributes-charset",
9599 IPP_TAG_ZERO
) == NULL
)
9600 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
9601 "attributes-charset", NULL
, "utf-8");
9603 if (ippFindAttribute(con
->response
, "attributes-natural-language",
9604 IPP_TAG_ZERO
) == NULL
)
9605 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
9606 "attributes-natural-language", NULL
, DefaultLanguage
);
9608 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
9609 "status-message", NULL
, formatted
);
9614 * 'set_default()' - Set the default destination...
9618 set_default(cupsd_client_t
*con
, /* I - Client connection */
9619 ipp_attribute_t
*uri
) /* I - Printer URI */
9621 http_status_t status
; /* Policy status */
9622 cups_ptype_t dtype
; /* Destination type (printer/class) */
9623 cupsd_printer_t
*printer
, /* Printer */
9624 *oldprinter
; /* Old default printer */
9627 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_default(%p[%d], %s)", con
,
9628 con
->number
, uri
->values
[0].string
.text
);
9631 * Is the destination valid?
9634 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9640 send_ipp_status(con
, IPP_NOT_FOUND
,
9641 _("The printer or class does not exist."));
9649 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
9651 send_http_error(con
, status
, NULL
);
9656 * Set it as the default...
9659 oldprinter
= DefaultPrinter
;
9660 DefaultPrinter
= printer
;
9663 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, oldprinter
, NULL
,
9664 "%s is no longer the default printer.", oldprinter
->name
);
9666 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
9667 "%s is now the default printer.", printer
->name
);
9669 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
| CUPSD_DIRTY_CLASSES
|
9670 CUPSD_DIRTY_PRINTCAP
);
9672 cupsdLogMessage(CUPSD_LOG_INFO
,
9673 "Default destination set to \"%s\" by \"%s\".",
9674 printer
->name
, get_username(con
));
9677 * Everything was ok, so return OK status...
9680 con
->response
->request
.status
.status_code
= IPP_OK
;
9685 * 'set_job_attrs()' - Set job attributes.
9689 set_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
9690 ipp_attribute_t
*uri
) /* I - Job URI */
9692 ipp_attribute_t
*attr
, /* Current attribute */
9693 *attr2
; /* Job attribute */
9694 int jobid
; /* Job ID */
9695 cupsd_job_t
*job
; /* Current job */
9696 char scheme
[HTTP_MAX_URI
],
9697 /* Method portion of URI */
9698 username
[HTTP_MAX_URI
],
9699 /* Username portion of URI */
9701 /* Host portion of URI */
9702 resource
[HTTP_MAX_URI
];
9703 /* Resource portion of URI */
9704 int port
; /* Port portion of URI */
9705 int event
; /* Events? */
9706 int check_jobs
; /* Check jobs? */
9709 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_job_attrs(%p[%d], %s)", con
,
9710 con
->number
, uri
->values
[0].string
.text
);
9713 * Start with "everything is OK" status...
9716 con
->response
->request
.status
.status_code
= IPP_OK
;
9719 * See if we have a job URI or a printer URI...
9722 if (!strcmp(uri
->name
, "printer-uri"))
9725 * Got a printer URI; see if we also have a job-id attribute...
9728 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9729 IPP_TAG_INTEGER
)) == NULL
)
9731 send_ipp_status(con
, IPP_BAD_REQUEST
,
9732 _("Got a printer-uri attribute but no job-id."));
9736 jobid
= attr
->values
[0].integer
;
9741 * Got a job URI; parse it to get the job ID...
9744 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9745 sizeof(scheme
), username
, sizeof(username
), host
,
9746 sizeof(host
), &port
, resource
, sizeof(resource
));
9748 if (strncmp(resource
, "/jobs/", 6))
9754 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9755 uri
->values
[0].string
.text
);
9759 jobid
= atoi(resource
+ 6);
9763 * See if the job exists...
9766 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9769 * Nope - return a "not found" error...
9772 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9777 * See if the job has been completed...
9780 if (job
->state_value
> IPP_JOB_STOPPED
)
9783 * Return a "not-possible" error...
9786 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9787 _("Job #%d is finished and cannot be altered."), jobid
);
9792 * See if the job is owned by the requesting user...
9795 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9797 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9798 cupsdFindDest(job
->dest
));
9803 * See what the user wants to change.
9811 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
9813 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
9816 if (!strcmp(attr
->name
, "attributes-charset") ||
9817 !strcmp(attr
->name
, "attributes-natural-language") ||
9818 !strcmp(attr
->name
, "document-compression") ||
9819 !strcmp(attr
->name
, "document-format") ||
9820 !strcmp(attr
->name
, "job-detailed-status-messages") ||
9821 !strcmp(attr
->name
, "job-document-access-errors") ||
9822 !strcmp(attr
->name
, "job-id") ||
9823 !strcmp(attr
->name
, "job-impressions-completed") ||
9824 !strcmp(attr
->name
, "job-k-octets") ||
9825 !strcmp(attr
->name
, "job-originating-host-name") ||
9826 !strcmp(attr
->name
, "job-originating-user-name") ||
9827 !strcmp(attr
->name
, "job-printer-up-time") ||
9828 !strcmp(attr
->name
, "job-printer-uri") ||
9829 !strcmp(attr
->name
, "job-sheets") ||
9830 !strcmp(attr
->name
, "job-state-message") ||
9831 !strcmp(attr
->name
, "job-state-reasons") ||
9832 !strcmp(attr
->name
, "job-uri") ||
9833 !strcmp(attr
->name
, "number-of-documents") ||
9834 !strcmp(attr
->name
, "number-of-intervening-jobs") ||
9835 !strcmp(attr
->name
, "output-device-assigned") ||
9836 !strncmp(attr
->name
, "date-time-at-", 13) ||
9837 !strncmp(attr
->name
, "job-k-octets", 12) ||
9838 !strncmp(attr
->name
, "job-media-sheets", 16) ||
9839 !strncmp(attr
->name
, "time-at-", 8))
9845 send_ipp_status(con
, IPP_ATTRIBUTES_NOT_SETTABLE
,
9846 _("%s cannot be changed."), attr
->name
);
9848 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
9849 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
9853 if (!strcmp(attr
->name
, "job-priority"))
9856 * Change the job priority...
9859 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
9861 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-priority value."));
9863 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
9864 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
9866 else if (job
->state_value
>= IPP_JOB_PROCESSING
)
9868 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9869 _("Job is completed and cannot be changed."));
9872 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
9874 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-priority to %d",
9875 attr
->values
[0].integer
);
9876 cupsdSetJobPriority(job
, attr
->values
[0].integer
);
9879 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
|
9880 CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
;
9883 else if (!strcmp(attr
->name
, "job-state"))
9886 * Change the job state...
9889 if (attr
->value_tag
!= IPP_TAG_ENUM
)
9891 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-state value."));
9893 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
9894 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
9898 switch (attr
->values
[0].integer
)
9900 case IPP_JOB_PENDING
:
9902 if (job
->state_value
> IPP_JOB_HELD
)
9904 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9905 _("Job state cannot be changed."));
9908 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
9910 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
9911 attr
->values
[0].integer
);
9912 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
, CUPSD_JOB_DEFAULT
, "Job state changed by \"%s\"", username
);
9917 case IPP_JOB_PROCESSING
:
9918 case IPP_JOB_STOPPED
:
9919 if (job
->state_value
!= attr
->values
[0].integer
)
9921 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9922 _("Job state cannot be changed."));
9927 case IPP_JOB_CANCELED
:
9928 case IPP_JOB_ABORTED
:
9929 case IPP_JOB_COMPLETED
:
9930 if (job
->state_value
> IPP_JOB_PROCESSING
)
9932 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9933 _("Job state cannot be changed."));
9936 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
9938 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
9939 attr
->values
[0].integer
);
9940 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
,
9942 "Job state changed by \"%s\"", username
);
9949 else if (con
->response
->request
.status
.status_code
!= IPP_OK
)
9951 else if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
9952 IPP_TAG_ZERO
)) != NULL
)
9955 * Some other value; first free the old value...
9958 if (job
->attrs
->prev
)
9959 job
->attrs
->prev
->next
= attr2
->next
;
9961 job
->attrs
->attrs
= attr2
->next
;
9963 if (job
->attrs
->last
== attr2
)
9964 job
->attrs
->last
= job
->attrs
->prev
;
9966 ippDeleteAttribute(NULL
, attr2
);
9969 * Then copy the attribute...
9972 ippCopyAttribute(job
->attrs
, attr
, 0);
9975 * See if the job-name or job-hold-until is being changed.
9978 if (!strcmp(attr
->name
, "job-hold-until"))
9980 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-hold-until to %s",
9981 attr
->values
[0].string
.text
);
9982 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
9984 if (!strcmp(attr
->values
[0].string
.text
, "no-hold"))
9986 cupsdReleaseJob(job
);
9990 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
,
9991 "Job held by \"%s\".", username
);
9993 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
;
9996 else if (attr
->value_tag
== IPP_TAG_DELETEATTR
)
9999 * Delete the attribute...
10002 if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10003 IPP_TAG_ZERO
)) != NULL
)
10005 if (job
->attrs
->prev
)
10006 job
->attrs
->prev
->next
= attr2
->next
;
10008 job
->attrs
->attrs
= attr2
->next
;
10010 if (attr2
== job
->attrs
->last
)
10011 job
->attrs
->last
= job
->attrs
->prev
;
10013 ippDeleteAttribute(NULL
, attr2
);
10015 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10021 * Add new option by copying it...
10024 ippCopyAttribute(job
->attrs
, attr
, 0);
10026 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10035 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10038 * Send events as needed...
10041 if (event
& CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
)
10042 cupsdAddEvent(CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
,
10043 cupsdFindDest(job
->dest
), job
,
10044 "Job priority changed by user.");
10046 if (event
& CUPSD_EVENT_JOB_STATE
)
10047 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
10048 job
->state_value
== IPP_JOB_HELD
?
10049 "Job held by user." : "Job restarted by user.");
10051 if (event
& CUPSD_EVENT_JOB_CONFIG_CHANGED
)
10052 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
10053 "Job options changed by user.");
10056 * Start jobs if possible...
10065 * 'set_printer_attrs()' - Set printer attributes.
10069 set_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
10070 ipp_attribute_t
*uri
) /* I - Printer */
10072 http_status_t status
; /* Policy status */
10073 cups_ptype_t dtype
; /* Destination type (printer/class) */
10074 cupsd_printer_t
*printer
; /* Printer/class */
10075 ipp_attribute_t
*attr
; /* Printer attribute */
10076 int changed
= 0; /* Was anything changed? */
10079 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_attrs(%p[%d], %s)", con
,
10080 con
->number
, uri
->values
[0].string
.text
);
10083 * Is the destination valid?
10086 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10092 send_ipp_status(con
, IPP_NOT_FOUND
,
10093 _("The printer or class does not exist."));
10101 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10103 send_http_error(con
, status
, printer
);
10108 * Return a list of attributes that can be set via Set-Printer-Attributes.
10111 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
10112 IPP_TAG_TEXT
)) != NULL
)
10114 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
10118 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
10119 IPP_TAG_TEXT
)) != NULL
)
10121 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
10126 * Update the printer attributes and return...
10131 cupsdSetPrinterAttrs(printer
);
10132 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
10134 cupsdAddEvent(CUPSD_EVENT_PRINTER_CONFIG
, printer
, NULL
,
10135 "Printer \"%s\" description or location changed by \"%s\".",
10136 printer
->name
, get_username(con
));
10138 cupsdLogMessage(CUPSD_LOG_INFO
,
10139 "Printer \"%s\" description or location changed by \"%s\".",
10140 printer
->name
, get_username(con
));
10143 con
->response
->request
.status
.status_code
= IPP_OK
;
10148 * 'set_printer_defaults()' - Set printer default options from a request.
10152 set_printer_defaults(
10153 cupsd_client_t
*con
, /* I - Client connection */
10154 cupsd_printer_t
*printer
) /* I - Printer */
10156 int i
; /* Looping var */
10157 ipp_attribute_t
*attr
; /* Current attribute */
10158 size_t namelen
; /* Length of attribute name */
10159 char name
[256], /* New attribute name */
10160 value
[256]; /* String version of integer attrs */
10163 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10166 * Skip non-printer attributes...
10169 if (attr
->group_tag
!= IPP_TAG_PRINTER
|| !attr
->name
)
10172 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_defaults: %s", attr
->name
);
10174 if (!strcmp(attr
->name
, "job-sheets-default"))
10177 * Only allow keywords and names...
10180 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10184 * Only allow job-sheets-default to be set when running without a
10185 * system high classification level...
10188 if (Classification
)
10191 cupsdSetString(&printer
->job_sheets
[0], attr
->values
[0].string
.text
);
10193 if (attr
->num_values
> 1)
10194 cupsdSetString(&printer
->job_sheets
[1], attr
->values
[1].string
.text
);
10196 cupsdSetString(&printer
->job_sheets
[1], "none");
10198 else if (!strcmp(attr
->name
, "requesting-user-name-allowed"))
10200 cupsdFreeStrings(&(printer
->users
));
10202 printer
->deny_users
= 0;
10204 if (attr
->value_tag
== IPP_TAG_NAME
&&
10205 (attr
->num_values
> 1 ||
10206 strcmp(attr
->values
[0].string
.text
, "all")))
10208 for (i
= 0; i
< attr
->num_values
; i
++)
10209 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
10212 else if (!strcmp(attr
->name
, "requesting-user-name-denied"))
10214 cupsdFreeStrings(&(printer
->users
));
10216 printer
->deny_users
= 1;
10218 if (attr
->value_tag
== IPP_TAG_NAME
&&
10219 (attr
->num_values
> 1 ||
10220 strcmp(attr
->values
[0].string
.text
, "none")))
10222 for (i
= 0; i
< attr
->num_values
; i
++)
10223 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
10226 else if (!strcmp(attr
->name
, "job-quota-period"))
10228 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10231 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-quota-period to %d...",
10232 attr
->values
[0].integer
);
10233 cupsdFreeQuotas(printer
);
10235 printer
->quota_period
= attr
->values
[0].integer
;
10237 else if (!strcmp(attr
->name
, "job-k-limit"))
10239 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10242 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-k-limit to %d...",
10243 attr
->values
[0].integer
);
10244 cupsdFreeQuotas(printer
);
10246 printer
->k_limit
= attr
->values
[0].integer
;
10248 else if (!strcmp(attr
->name
, "job-page-limit"))
10250 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10253 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-page-limit to %d...",
10254 attr
->values
[0].integer
);
10255 cupsdFreeQuotas(printer
);
10257 printer
->page_limit
= attr
->values
[0].integer
;
10259 else if (!strcmp(attr
->name
, "printer-op-policy"))
10261 cupsd_policy_t
*p
; /* Policy */
10264 if (attr
->value_tag
!= IPP_TAG_NAME
)
10267 if ((p
= cupsdFindPolicy(attr
->values
[0].string
.text
)) != NULL
)
10269 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10270 "Setting printer-op-policy to \"%s\"...",
10271 attr
->values
[0].string
.text
);
10272 cupsdSetString(&printer
->op_policy
, attr
->values
[0].string
.text
);
10273 printer
->op_policy_ptr
= p
;
10277 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10278 _("Unknown printer-op-policy \"%s\"."),
10279 attr
->values
[0].string
.text
);
10283 else if (!strcmp(attr
->name
, "printer-error-policy"))
10285 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10288 if (strcmp(attr
->values
[0].string
.text
, "retry-current-job") &&
10289 ((printer
->type
& CUPS_PRINTER_CLASS
) ||
10290 (strcmp(attr
->values
[0].string
.text
, "abort-job") &&
10291 strcmp(attr
->values
[0].string
.text
, "retry-job") &&
10292 strcmp(attr
->values
[0].string
.text
, "stop-printer"))))
10294 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10295 _("Unknown printer-error-policy \"%s\"."),
10296 attr
->values
[0].string
.text
);
10300 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10301 "Setting printer-error-policy to \"%s\"...",
10302 attr
->values
[0].string
.text
);
10303 cupsdSetString(&printer
->error_policy
, attr
->values
[0].string
.text
);
10307 * Skip any other non-default attributes...
10310 namelen
= strlen(attr
->name
);
10311 if (namelen
< 9 || strcmp(attr
->name
+ namelen
- 8, "-default") ||
10312 namelen
> (sizeof(name
) - 1) || attr
->num_values
!= 1)
10316 * OK, anything else must be a user-defined default...
10319 strlcpy(name
, attr
->name
, sizeof(name
));
10320 name
[namelen
- 8] = '\0'; /* Strip "-default" */
10322 switch (attr
->value_tag
)
10324 case IPP_TAG_DELETEATTR
:
10325 printer
->num_options
= cupsRemoveOption(name
,
10326 printer
->num_options
,
10327 &(printer
->options
));
10328 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10329 "Deleting %s", attr
->name
);
10332 case IPP_TAG_NAME
:
10333 case IPP_TAG_TEXT
:
10334 case IPP_TAG_KEYWORD
:
10336 printer
->num_options
= cupsAddOption(name
,
10337 attr
->values
[0].string
.text
,
10338 printer
->num_options
,
10339 &(printer
->options
));
10340 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10341 "Setting %s to \"%s\"...", attr
->name
,
10342 attr
->values
[0].string
.text
);
10345 case IPP_TAG_BOOLEAN
:
10346 printer
->num_options
= cupsAddOption(name
,
10347 attr
->values
[0].boolean
?
10349 printer
->num_options
,
10350 &(printer
->options
));
10351 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10352 "Setting %s to %s...", attr
->name
,
10353 attr
->values
[0].boolean
? "true" : "false");
10356 case IPP_TAG_INTEGER
:
10357 case IPP_TAG_ENUM
:
10358 sprintf(value
, "%d", attr
->values
[0].integer
);
10359 printer
->num_options
= cupsAddOption(name
, value
,
10360 printer
->num_options
,
10361 &(printer
->options
));
10362 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10363 "Setting %s to %s...", attr
->name
, value
);
10366 case IPP_TAG_RANGE
:
10367 sprintf(value
, "%d-%d", attr
->values
[0].range
.lower
,
10368 attr
->values
[0].range
.upper
);
10369 printer
->num_options
= cupsAddOption(name
, value
,
10370 printer
->num_options
,
10371 &(printer
->options
));
10372 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10373 "Setting %s to %s...", attr
->name
, value
);
10376 case IPP_TAG_RESOLUTION
:
10377 sprintf(value
, "%dx%d%s", attr
->values
[0].resolution
.xres
,
10378 attr
->values
[0].resolution
.yres
,
10379 attr
->values
[0].resolution
.units
== IPP_RES_PER_INCH
?
10381 printer
->num_options
= cupsAddOption(name
, value
,
10382 printer
->num_options
,
10383 &(printer
->options
));
10384 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10385 "Setting %s to %s...", attr
->name
, value
);
10389 /* Do nothing for other values */
10397 * 'start_printer()' - Start a printer.
10401 start_printer(cupsd_client_t
*con
, /* I - Client connection */
10402 ipp_attribute_t
*uri
) /* I - Printer URI */
10404 int i
; /* Temporary variable */
10405 http_status_t status
; /* Policy status */
10406 cups_ptype_t dtype
; /* Destination type (printer/class) */
10407 cupsd_printer_t
*printer
; /* Printer data */
10410 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_printer(%p[%d], %s)", con
,
10411 con
->number
, uri
->values
[0].string
.text
);
10414 * Is the destination valid?
10417 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10423 send_ipp_status(con
, IPP_NOT_FOUND
,
10424 _("The printer or class does not exist."));
10432 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10434 send_http_error(con
, status
, printer
);
10439 * Start the printer...
10442 printer
->state_message
[0] = '\0';
10444 cupsdStartPrinter(printer
, 1);
10446 if (dtype
& CUPS_PRINTER_CLASS
)
10447 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" started by \"%s\".",
10448 printer
->name
, get_username(con
));
10450 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" started by \"%s\".",
10451 printer
->name
, get_username(con
));
10459 if ((i
= check_quotas(con
, printer
)) < 0)
10461 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
10466 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
10471 * Everything was ok, so return OK status...
10474 con
->response
->request
.status
.status_code
= IPP_OK
;
10479 * 'stop_printer()' - Stop a printer.
10483 stop_printer(cupsd_client_t
*con
, /* I - Client connection */
10484 ipp_attribute_t
*uri
) /* I - Printer URI */
10486 http_status_t status
; /* Policy status */
10487 cups_ptype_t dtype
; /* Destination type (printer/class) */
10488 cupsd_printer_t
*printer
; /* Printer data */
10489 ipp_attribute_t
*attr
; /* printer-state-message attribute */
10492 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "stop_printer(%p[%d], %s)", con
,
10493 con
->number
, uri
->values
[0].string
.text
);
10496 * Is the destination valid?
10499 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10505 send_ipp_status(con
, IPP_NOT_FOUND
,
10506 _("The printer or class does not exist."));
10514 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10516 send_http_error(con
, status
, printer
);
10521 * Stop the printer...
10524 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
10525 IPP_TAG_TEXT
)) == NULL
)
10526 strlcpy(printer
->state_message
, "Paused", sizeof(printer
->state_message
));
10529 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
10530 sizeof(printer
->state_message
));
10533 cupsdStopPrinter(printer
, 1);
10535 if (dtype
& CUPS_PRINTER_CLASS
)
10536 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" stopped by \"%s\".",
10537 printer
->name
, get_username(con
));
10539 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" stopped by \"%s\".",
10540 printer
->name
, get_username(con
));
10543 * Everything was ok, so return OK status...
10546 con
->response
->request
.status
.status_code
= IPP_OK
;
10551 * 'url_encode_attr()' - URL-encode a string attribute.
10555 url_encode_attr(ipp_attribute_t
*attr
, /* I - Attribute */
10556 char *buffer
,/* I - String buffer */
10557 int bufsize
)/* I - Size of buffer */
10559 int i
; /* Looping var */
10560 char *bufptr
, /* Pointer into buffer */
10561 *bufend
; /* End of buffer */
10564 strlcpy(buffer
, attr
->name
, bufsize
);
10565 bufptr
= buffer
+ strlen(buffer
);
10566 bufend
= buffer
+ bufsize
- 1;
10568 for (i
= 0; i
< attr
->num_values
; i
++)
10570 if (bufptr
>= bufend
)
10578 if (bufptr
>= bufend
)
10583 bufptr
= url_encode_string(attr
->values
[i
].string
.text
,
10584 bufptr
, bufend
- bufptr
+ 1);
10586 if (bufptr
>= bufend
)
10597 * 'url_encode_string()' - URL-encode a string.
10600 static char * /* O - End of string */
10601 url_encode_string(const char *s
, /* I - String */
10602 char *buffer
, /* I - String buffer */
10603 int bufsize
) /* I - Size of buffer */
10605 char *bufptr
, /* Pointer into buffer */
10606 *bufend
; /* End of buffer */
10607 static const char *hex
= "0123456789ABCDEF";
10612 bufend
= buffer
+ bufsize
- 1;
10614 while (*s
&& bufptr
< bufend
)
10616 if (*s
== ' ' || *s
== '%' || *s
== '+')
10618 if (bufptr
>= (bufend
- 2))
10622 *bufptr
++ = hex
[(*s
>> 4) & 15];
10623 *bufptr
++ = hex
[*s
& 15];
10627 else if (*s
== '\'' || *s
== '\\')
10629 if (bufptr
>= (bufend
- 1))
10646 * 'user_allowed()' - See if a user is allowed to print to a queue.
10649 static int /* O - 0 if not allowed, 1 if allowed */
10650 user_allowed(cupsd_printer_t
*p
, /* I - Printer or class */
10651 const char *username
) /* I - Username */
10653 struct passwd
*pw
; /* User password data */
10654 char baseuser
[256], /* Base username */
10655 *baseptr
, /* Pointer to "@" in base username */
10656 *name
; /* Current user name */
10659 if (cupsArrayCount(p
->users
) == 0)
10662 if (!strcmp(username
, "root"))
10665 if (strchr(username
, '@'))
10668 * Strip @REALM for username check...
10671 strlcpy(baseuser
, username
, sizeof(baseuser
));
10673 if ((baseptr
= strchr(baseuser
, '@')) != NULL
)
10676 username
= baseuser
;
10679 pw
= getpwnam(username
);
10682 for (name
= (char *)cupsArrayFirst(p
->users
);
10684 name
= (char *)cupsArrayNext(p
->users
))
10686 if (name
[0] == '@')
10689 * Check group membership...
10692 if (cupsdCheckGroup(username
, pw
, name
+ 1))
10695 else if (name
[0] == '#')
10701 if (cupsdCheckGroup(username
, pw
, name
))
10704 else if (!_cups_strcasecmp(username
, name
))
10708 return ((name
!= NULL
) != p
->deny_users
);
10713 * 'validate_job()' - Validate printer options and destination.
10717 validate_job(cupsd_client_t
*con
, /* I - Client connection */
10718 ipp_attribute_t
*uri
) /* I - Printer URI */
10720 http_status_t status
; /* Policy status */
10721 ipp_attribute_t
*attr
, /* Current attribute */
10722 *auth_info
; /* auth-info attribute */
10723 ipp_attribute_t
*format
, /* Document-format attribute */
10724 *name
; /* Job-name attribute */
10725 cups_ptype_t dtype
; /* Destination type (printer/class) */
10726 char super
[MIME_MAX_SUPER
],
10727 /* Supertype of file */
10728 type
[MIME_MAX_TYPE
];
10729 /* Subtype of file */
10730 cupsd_printer_t
*printer
; /* Printer */
10733 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_job(%p[%d], %s)", con
,
10734 con
->number
, uri
->values
[0].string
.text
);
10737 * OK, see if the client is sending the document compressed - CUPS
10738 * doesn't support compression yet...
10741 if ((attr
= ippFindAttribute(con
->request
, "compression",
10742 IPP_TAG_KEYWORD
)) != NULL
)
10744 if (strcmp(attr
->values
[0].string
.text
, "none")
10746 && strcmp(attr
->values
[0].string
.text
, "gzip")
10747 #endif /* HAVE_LIBZ */
10750 send_ipp_status(con
, IPP_ATTRIBUTES
,
10751 _("Unsupported 'compression' value \"%s\"."),
10752 attr
->values
[0].string
.text
);
10753 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
10754 "compression", NULL
, attr
->values
[0].string
.text
);
10760 * Is it a format we support?
10763 if ((format
= ippFindAttribute(con
->request
, "document-format",
10764 IPP_TAG_MIMETYPE
)) != NULL
)
10766 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%255[^;]",
10769 send_ipp_status(con
, IPP_BAD_REQUEST
,
10770 _("Bad 'document-format' value \"%s\"."),
10771 format
->values
[0].string
.text
);
10775 if ((strcmp(super
, "application") || strcmp(type
, "octet-stream")) &&
10776 !mimeType(MimeDatabase
, super
, type
))
10778 cupsdLogMessage(CUPSD_LOG_INFO
,
10779 "Hint: Do you have the raw file printing rules enabled?");
10780 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
10781 _("Unsupported 'document-format' value \"%s\"."),
10782 format
->values
[0].string
.text
);
10783 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
10784 "document-format", NULL
, format
->values
[0].string
.text
);
10790 * Is the job-name valid?
10793 if ((name
= ippFindAttribute(con
->request
, "job-name", IPP_TAG_ZERO
)) != NULL
)
10795 int bad_name
= 0; /* Is the job-name value bad? */
10797 if ((name
->value_tag
!= IPP_TAG_NAME
&& name
->value_tag
!= IPP_TAG_NAMELANG
) ||
10798 name
->num_values
!= 1)
10805 * Validate that job-name conforms to RFC 5198 (Network Unicode) and
10806 * IPP Everywhere requirements for "name" values...
10809 const unsigned char *nameptr
; /* Pointer into "job-name" attribute */
10811 for (nameptr
= (unsigned char *)name
->values
[0].string
.text
;
10815 if (*nameptr
< ' ' && *nameptr
!= '\t')
10817 else if (*nameptr
== 0x7f)
10819 else if ((*nameptr
& 0xe0) == 0xc0)
10821 if ((nameptr
[1] & 0xc0) != 0x80)
10826 else if ((*nameptr
& 0xf0) == 0xe0)
10828 if ((nameptr
[1] & 0xc0) != 0x80 ||
10829 (nameptr
[2] & 0xc0) != 0x80)
10834 else if ((*nameptr
& 0xf8) == 0xf0)
10836 if ((nameptr
[1] & 0xc0) != 0x80 ||
10837 (nameptr
[2] & 0xc0) != 0x80 ||
10838 (nameptr
[3] & 0xc0) != 0x80)
10843 else if (*nameptr
& 0x80)
10853 if (StrictConformance
)
10855 send_ipp_status(con
, IPP_ATTRIBUTES
,
10856 _("Unsupported 'job-name' value."));
10857 ippCopyAttribute(con
->response
, name
, 0);
10862 cupsdLogMessage(CUPSD_LOG_WARN
,
10863 "Unsupported 'job-name' value, deleting from request.");
10864 ippDeleteAttribute(con
->request
, name
);
10870 * Is the destination valid?
10873 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10879 send_ipp_status(con
, IPP_NOT_FOUND
,
10880 _("The printer or class does not exist."));
10888 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
10890 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10892 send_http_error(con
, status
, printer
);
10895 else if (printer
->num_auth_info_required
== 1 &&
10896 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
10899 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
10903 else if (auth_info
&& !con
->http
->tls
&&
10904 !httpAddrLocalhost(con
->http
->hostaddr
))
10907 * Require encryption of auth-info over non-local connections...
10910 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
10913 #endif /* HAVE_SSL */
10916 * Everything was ok, so return OK status...
10919 con
->response
->request
.status
.status_code
= IPP_OK
;
10924 * 'validate_name()' - Make sure the printer name only contains valid chars.
10927 static int /* O - 0 if name is no good, 1 if good */
10928 validate_name(const char *name
) /* I - Name to check */
10930 const char *ptr
; /* Pointer into name */
10934 * Scan the whole name...
10937 for (ptr
= name
; *ptr
; ptr
++)
10938 if ((*ptr
> 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
10942 * All the characters are good; validate the length, too...
10945 return ((ptr
- name
) < 128);
10950 * 'validate_user()' - Validate the user for the request.
10953 static int /* O - 1 if permitted, 0 otherwise */
10954 validate_user(cupsd_job_t
*job
, /* I - Job */
10955 cupsd_client_t
*con
, /* I - Client connection */
10956 const char *owner
, /* I - Owner of job/resource */
10957 char *username
, /* O - Authenticated username */
10958 int userlen
) /* I - Length of username */
10960 cupsd_printer_t
*printer
; /* Printer for job */
10963 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
10964 "validate_user(job=%d, con=%d, owner=\"%s\", username=%p, "
10966 job
->id
, con
? con
->number
: 0,
10967 owner
? owner
: "(null)", username
, userlen
);
10970 * Validate input...
10973 if (!con
|| !owner
|| !username
|| userlen
<= 0)
10977 * Get the best authenticated username that is available.
10980 strlcpy(username
, get_username(con
), userlen
);
10983 * Check the username against the owner...
10986 printer
= cupsdFindDest(job
->dest
);
10988 return (cupsdCheckPolicy(printer
? printer
->op_policy_ptr
: DefaultPolicyPtr
,
10989 con
, owner
) == HTTP_OK
);