2 * "$Id: ipp.c 7014 2007-10-10 21:57:43Z mike $"
4 * IPP routines for the Common UNIX Printing System (CUPS) scheduler.
6 * Copyright 2007-2008 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 * cupsdProcessIPPRequest() - Process an incoming IPP request.
21 * cupsdTimeoutJob() - Timeout a job waiting on job files.
22 * accept_jobs() - Accept print jobs to a printer.
23 * add_class() - Add a class to the system.
24 * add_file() - Add a file to a job.
25 * add_job() - Add a job to a print queue.
26 * add_job_state_reasons() - Add the "job-state-reasons" attribute based
27 * upon the job and printer state...
28 * add_job_subscriptions() - Add any subcriptions for a job.
29 * add_job_uuid() - Add job-uuid attribute to a job.
30 * add_printer() - Add a printer to the system.
31 * add_printer_state_reasons() - Add the "printer-state-reasons" attribute
32 * based upon the printer state...
33 * add_queued_job_count() - Add the "queued-job-count" attribute for the
34 * specified printer or class.
35 * apple_init_profile() - Initialize a color profile.
36 * apple_register_profiles() - Register color profiles for a printer.
37 * apple_unregister_profiles() - Remove color profiles for the specified
39 * apply_printer_defaults() - Apply printer default options to a job.
40 * authenticate_job() - Set job authentication info.
41 * cancel_all_jobs() - Cancel all print jobs.
42 * cancel_job() - Cancel a print job.
43 * cancel_subscription() - Cancel a subscription.
44 * check_quotas() - Check quotas for a printer and user.
45 * copy_attribute() - Copy a single attribute.
46 * copy_attrs() - Copy attributes from one request to another.
47 * copy_banner() - Copy a banner file to the requests directory
48 * for the specified job.
49 * copy_file() - Copy a PPD file or interface script...
50 * copy_model() - Copy a PPD model file, substituting default
52 * copy_job_attrs() - Copy job attributes.
53 * copy_printer_attrs() - Copy printer attributes.
54 * copy_subscription_attrs() - Copy subscription attributes.
55 * create_job() - Print a file to a printer or class.
56 * create_requested_array() - Create an array for the requested-attributes.
57 * create_subscription() - Create a notification subscription.
58 * delete_printer() - Remove a printer or class from the system.
59 * get_default() - Get the default destination.
60 * get_devices() - Get the list of available devices on the
62 * get_document() - Get a copy of a job file.
63 * get_job_attrs() - Get job attributes.
64 * get_jobs() - Get a list of jobs for the specified printer.
65 * get_notifications() - Get events for a subscription.
66 * get_ppd() - Get a named PPD from the local system.
67 * get_ppds() - Get the list of PPD files on the local
69 * get_printer_attrs() - Get printer attributes.
70 * get_printers() - Get a list of printers or classes.
71 * get_subscription_attrs() - Get subscription attributes.
72 * get_subscriptions() - Get subscriptions.
73 * get_username() - Get the username associated with a request.
74 * hold_job() - Hold a print job.
75 * move_job() - Move a job to a new destination.
76 * ppd_parse_line() - Parse a PPD default line.
77 * print_job() - Print a file to a printer or class.
78 * read_ps_job_ticket() - Reads a job ticket embedded in a PS file.
79 * reject_jobs() - Reject print jobs to a printer.
80 * release_job() - Release a held print job.
81 * renew_subscription() - Renew an existing subscription...
82 * restart_job() - Restart an old print job.
83 * save_auth_info() - Save authentication information for a job.
84 * save_krb5_creds() - Save Kerberos credentials for the job.
85 * send_document() - Send a file to a printer or class.
86 * send_http_error() - Send a HTTP error back to the IPP client.
87 * send_ipp_status() - Send a status back to the IPP client.
88 * set_default() - Set the default destination...
89 * set_job_attrs() - Set job attributes.
90 * set_printer_defaults() - Set printer default options from a request.
91 * start_printer() - Start a printer.
92 * stop_printer() - Stop a printer.
93 * url_encode_attr() - URL-encode a string attribute.
94 * url_encode_string() - URL-encode a string.
95 * user_allowed() - See if a user is allowed to print to a queue.
96 * validate_job() - Validate printer options and destination.
97 * validate_name() - Make sure the printer name only contains
99 * validate_user() - Validate the user for the request.
103 * Include necessary headers...
107 #include <cups/ppd-private.h>
111 #endif /* HAVE_LIBPAPER */
114 # include <ApplicationServices/ApplicationServices.h>
115 # include <CoreFoundation/CoreFoundation.h>
116 # ifdef HAVE_MEMBERSHIP_H
117 # include <membership.h>
118 # endif /* HAVE_MEMBERSHIP_H */
119 # ifdef HAVE_MEMBERSHIPPRIV_H
120 # include <membershipPriv.h>
122 extern int mbr_user_name_to_uuid(const char* name
, uuid_t uu
);
123 extern int mbr_group_name_to_uuid(const char* name
, uuid_t uu
);
124 extern int mbr_check_membership_by_id(uuid_t user
, gid_t group
, int* ismember
);
125 # endif /* HAVE_MEMBERSHIPPRIV_H */
126 #endif /* __APPLE__ */
133 static void accept_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
134 static void add_class(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
135 static int add_file(cupsd_client_t
*con
, cupsd_job_t
*job
,
136 mime_type_t
*filetype
, int compression
);
137 static cupsd_job_t
*add_job(cupsd_client_t
*con
, cupsd_printer_t
*printer
,
138 mime_type_t
*filetype
);
139 static void add_job_state_reasons(cupsd_client_t
*con
, cupsd_job_t
*job
);
140 static void add_job_subscriptions(cupsd_client_t
*con
, cupsd_job_t
*job
);
141 static void add_job_uuid(cupsd_client_t
*con
, cupsd_job_t
*job
);
142 static void add_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
143 static void add_printer_state_reasons(cupsd_client_t
*con
,
145 static void add_queued_job_count(cupsd_client_t
*con
, cupsd_printer_t
*p
);
147 static void apple_init_profile(ppd_file_t
*ppd
, cups_array_t
*languages
,
148 CMDeviceProfileInfo
*profile
, unsigned id
,
149 const char *name
, const char *text
,
150 const char *iccfile
);
151 static void apple_register_profiles(cupsd_printer_t
*p
);
152 static void apple_unregister_profiles(cupsd_printer_t
*p
);
153 #endif /* __APPLE__ */
154 static void apply_printer_defaults(cupsd_printer_t
*printer
,
156 static void authenticate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
157 static void cancel_all_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
158 static void cancel_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
159 static void cancel_subscription(cupsd_client_t
*con
, int id
);
160 static int check_quotas(cupsd_client_t
*con
, cupsd_printer_t
*p
);
161 static ipp_attribute_t
*copy_attribute(ipp_t
*to
, ipp_attribute_t
*attr
,
163 static void copy_attrs(ipp_t
*to
, ipp_t
*from
, cups_array_t
*ra
,
164 ipp_tag_t group
, int quickcopy
);
165 static int copy_banner(cupsd_client_t
*con
, cupsd_job_t
*job
,
167 static int copy_file(const char *from
, const char *to
);
168 static int copy_model(cupsd_client_t
*con
, const char *from
,
170 static void copy_job_attrs(cupsd_client_t
*con
,
173 static void copy_printer_attrs(cupsd_client_t
*con
,
174 cupsd_printer_t
*printer
,
176 static void copy_subscription_attrs(cupsd_client_t
*con
,
177 cupsd_subscription_t
*sub
,
179 static void create_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
180 static cups_array_t
*create_requested_array(ipp_t
*request
);
181 static void create_subscription(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
182 static void delete_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
183 static void get_default(cupsd_client_t
*con
);
184 static void get_devices(cupsd_client_t
*con
);
185 static void get_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
186 static void get_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
187 static void get_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
188 static void get_notifications(cupsd_client_t
*con
);
189 static void get_ppd(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
190 static void get_ppds(cupsd_client_t
*con
);
191 static void get_printers(cupsd_client_t
*con
, int type
);
192 static void get_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
193 static void get_subscription_attrs(cupsd_client_t
*con
, int sub_id
);
194 static void get_subscriptions(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
195 static const char *get_username(cupsd_client_t
*con
);
196 static void hold_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
197 static void move_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
198 static int ppd_parse_line(const char *line
, char *option
, int olen
,
199 char *choice
, int clen
);
200 static void print_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
201 static void read_ps_job_ticket(cupsd_client_t
*con
);
202 static void reject_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
203 static void release_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
204 static void renew_subscription(cupsd_client_t
*con
, int sub_id
);
205 static void restart_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
206 static void save_auth_info(cupsd_client_t
*con
, cupsd_job_t
*job
,
207 ipp_attribute_t
*auth_info
);
208 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
209 static void save_krb5_creds(cupsd_client_t
*con
, cupsd_job_t
*job
);
210 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
211 static void send_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
212 static void send_http_error(cupsd_client_t
*con
, http_status_t status
,
213 cupsd_printer_t
*printer
);
214 static void send_ipp_status(cupsd_client_t
*con
, ipp_status_t status
,
215 const char *message
, ...)
217 __attribute__ ((__format__ (__printf__
, 3, 4)))
218 # endif /* __GNUC__ */
220 static void set_default(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
221 static void set_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
222 static void set_printer_defaults(cupsd_client_t
*con
,
223 cupsd_printer_t
*printer
);
224 static void start_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
225 static void stop_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
226 static void url_encode_attr(ipp_attribute_t
*attr
, char *buffer
,
228 static char *url_encode_string(const char *s
, char *buffer
, int bufsize
);
229 static int user_allowed(cupsd_printer_t
*p
, const char *username
);
230 static void validate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
231 static int validate_name(const char *name
);
232 static int validate_user(cupsd_job_t
*job
, cupsd_client_t
*con
,
233 const char *owner
, char *username
,
238 * 'cupsdProcessIPPRequest()' - Process an incoming IPP request.
241 int /* O - 1 on success, 0 on failure */
242 cupsdProcessIPPRequest(
243 cupsd_client_t
*con
) /* I - Client connection */
245 ipp_tag_t group
; /* Current group tag */
246 ipp_attribute_t
*attr
; /* Current attribute */
247 ipp_attribute_t
*charset
; /* Character set attribute */
248 ipp_attribute_t
*language
; /* Language attribute */
249 ipp_attribute_t
*uri
; /* Printer URI attribute */
250 ipp_attribute_t
*username
; /* requesting-user-name attr */
251 int sub_id
; /* Subscription ID */
254 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
255 "cupsdProcessIPPRequest(%p[%d]): operation_id = %04x",
256 con
, con
->http
.fd
, con
->request
->request
.op
.operation_id
);
259 * First build an empty response message for this request...
262 con
->response
= ippNew();
264 con
->response
->request
.status
.version
[0] =
265 con
->request
->request
.op
.version
[0];
266 con
->response
->request
.status
.version
[1] =
267 con
->request
->request
.op
.version
[1];
268 con
->response
->request
.status
.request_id
=
269 con
->request
->request
.op
.request_id
;
272 * Then validate the request header and required attributes...
275 if (con
->request
->request
.any
.version
[0] != 1)
278 * Return an error, since we only support IPP 1.x.
281 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
282 "%04X %s Bad request version number %d.%d",
283 IPP_VERSION_NOT_SUPPORTED
, con
->http
.hostname
,
284 con
->request
->request
.any
.version
[0],
285 con
->request
->request
.any
.version
[1]);
287 send_ipp_status(con
, IPP_VERSION_NOT_SUPPORTED
,
288 _("Bad request version number %d.%d!"),
289 con
->request
->request
.any
.version
[0],
290 con
->request
->request
.any
.version
[1]);
292 else if (!con
->request
->attrs
)
294 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
295 "%04X %s No attributes in request",
296 IPP_BAD_REQUEST
, con
->http
.hostname
);
298 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No attributes in request!"));
303 * Make sure that the attributes are provided in the correct order and
304 * don't repeat groups...
307 for (attr
= con
->request
->attrs
, group
= attr
->group_tag
;
310 if (attr
->group_tag
< group
&& attr
->group_tag
!= IPP_TAG_ZERO
)
313 * Out of order; return an error...
316 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
317 "%04X %s Attribute groups are out of order",
318 IPP_BAD_REQUEST
, con
->http
.hostname
);
320 send_ipp_status(con
, IPP_BAD_REQUEST
,
321 _("Attribute groups are out of order (%x < %x)!"),
322 attr
->group_tag
, group
);
326 group
= attr
->group_tag
;
331 * Then make sure that the first three attributes are:
334 * attributes-natural-language
335 * printer-uri/job-uri
338 attr
= con
->request
->attrs
;
339 if (attr
&& !strcmp(attr
->name
, "attributes-charset") &&
340 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_CHARSET
)
348 if (attr
&& !strcmp(attr
->name
, "attributes-natural-language") &&
349 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_LANGUAGE
)
354 if ((attr
= ippFindAttribute(con
->request
, "printer-uri",
355 IPP_TAG_URI
)) != NULL
)
357 else if ((attr
= ippFindAttribute(con
->request
, "job-uri",
358 IPP_TAG_URI
)) != NULL
)
360 else if (con
->request
->request
.op
.operation_id
== CUPS_GET_PPD
)
361 uri
= ippFindAttribute(con
->request
, "ppd-name", IPP_TAG_NAME
);
366 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
367 "attributes-charset", NULL
,
368 charset
->values
[0].string
.text
);
370 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
371 "attributes-charset", NULL
, DefaultCharset
);
374 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
375 "attributes-natural-language", NULL
,
376 language
->values
[0].string
.text
);
378 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
379 "attributes-natural-language", NULL
, DefaultLanguage
);
382 strcasecmp(charset
->values
[0].string
.text
, "us-ascii") &&
383 strcasecmp(charset
->values
[0].string
.text
, "utf-8"))
386 * Bad character set...
389 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unsupported character set \"%s\"!",
390 charset
->values
[0].string
.text
);
391 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
392 "%04X %s Unsupported attributes-charset value \"%s\"",
393 IPP_CHARSET
, con
->http
.hostname
,
394 charset
->values
[0].string
.text
);
395 send_ipp_status(con
, IPP_BAD_REQUEST
,
396 _("Unsupported character set \"%s\"!"),
397 charset
->values
[0].string
.text
);
399 else if (!charset
|| !language
||
401 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEFAULT
&&
402 con
->request
->request
.op
.operation_id
!= CUPS_GET_PRINTERS
&&
403 con
->request
->request
.op
.operation_id
!= CUPS_GET_CLASSES
&&
404 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEVICES
&&
405 con
->request
->request
.op
.operation_id
!= CUPS_GET_PPDS
))
408 * Return an error, since attributes-charset,
409 * attributes-natural-language, and printer-uri/job-uri are required
410 * for all operations.
415 cupsdLogMessage(CUPSD_LOG_ERROR
,
416 "Missing attributes-charset attribute!");
418 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
419 "%04X %s Missing attributes-charset attribute",
420 IPP_BAD_REQUEST
, con
->http
.hostname
);
425 cupsdLogMessage(CUPSD_LOG_ERROR
,
426 "Missing attributes-natural-language attribute!");
428 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
429 "%04X %s Missing attributes-natural-language attribute",
430 IPP_BAD_REQUEST
, con
->http
.hostname
);
435 cupsdLogMessage(CUPSD_LOG_ERROR
,
436 "Missing printer-uri, job-uri, or ppd-name "
439 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
440 "%04X %s Missing printer-uri, job-uri, or ppd-name "
441 "attribute", IPP_BAD_REQUEST
, con
->http
.hostname
);
444 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Request attributes follow...");
446 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
447 cupsdLogMessage(CUPSD_LOG_DEBUG
,
448 "attr \"%s\": group_tag = %x, value_tag = %x",
449 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
452 cupsdLogMessage(CUPSD_LOG_DEBUG
, "End of attributes...");
454 send_ipp_status(con
, IPP_BAD_REQUEST
,
455 _("Missing required attributes!"));
460 * OK, all the checks pass so far; make sure requesting-user-name is
461 * not "root" from a remote host...
464 if ((username
= ippFindAttribute(con
->request
, "requesting-user-name",
465 IPP_TAG_NAME
)) != NULL
)
468 * Check for root user...
471 if (!strcmp(username
->values
[0].string
.text
, "root") &&
472 strcasecmp(con
->http
.hostname
, "localhost") &&
473 strcmp(con
->username
, "root"))
476 * Remote unauthenticated user masquerading as local root...
479 _cupsStrFree(username
->values
[0].string
.text
);
480 username
->values
[0].string
.text
= _cupsStrAlloc(RemoteRoot
);
484 if ((attr
= ippFindAttribute(con
->request
, "notify-subscription-id",
485 IPP_TAG_INTEGER
)) != NULL
)
486 sub_id
= attr
->values
[0].integer
;
491 * Then try processing the operation...
495 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s",
496 ippOpString(con
->request
->request
.op
.operation_id
),
497 uri
->values
[0].string
.text
);
499 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s",
500 ippOpString(con
->request
->request
.op
.operation_id
));
502 switch (con
->request
->request
.op
.operation_id
)
508 case IPP_VALIDATE_JOB
:
509 validate_job(con
, uri
);
512 case IPP_CREATE_JOB
:
513 create_job(con
, uri
);
516 case IPP_SEND_DOCUMENT
:
517 send_document(con
, uri
);
520 case IPP_CANCEL_JOB
:
521 cancel_job(con
, uri
);
524 case IPP_GET_JOB_ATTRIBUTES
:
525 get_job_attrs(con
, uri
);
532 case IPP_GET_PRINTER_ATTRIBUTES
:
533 get_printer_attrs(con
, uri
);
540 case IPP_RELEASE_JOB
:
541 release_job(con
, uri
);
544 case IPP_RESTART_JOB
:
545 restart_job(con
, uri
);
548 case IPP_PAUSE_PRINTER
:
549 stop_printer(con
, uri
);
552 case IPP_RESUME_PRINTER
:
553 start_printer(con
, uri
);
556 case IPP_PURGE_JOBS
:
557 cancel_all_jobs(con
, uri
);
560 case IPP_SET_JOB_ATTRIBUTES
:
561 set_job_attrs(con
, uri
);
564 case CUPS_GET_DEFAULT
:
568 case CUPS_GET_PRINTERS
:
569 get_printers(con
, 0);
572 case CUPS_GET_CLASSES
:
573 get_printers(con
, CUPS_PRINTER_CLASS
);
576 case CUPS_ADD_PRINTER
:
577 add_printer(con
, uri
);
580 case CUPS_DELETE_PRINTER
:
581 delete_printer(con
, uri
);
584 case CUPS_ADD_CLASS
:
588 case CUPS_DELETE_CLASS
:
589 delete_printer(con
, uri
);
592 case CUPS_ACCEPT_JOBS
:
593 case IPP_ENABLE_PRINTER
:
594 accept_jobs(con
, uri
);
597 case CUPS_REJECT_JOBS
:
598 case IPP_DISABLE_PRINTER
:
599 reject_jobs(con
, uri
);
602 case CUPS_SET_DEFAULT
:
603 set_default(con
, uri
);
606 case CUPS_GET_DEVICES
:
610 case CUPS_GET_DOCUMENT
:
611 get_document(con
, uri
);
626 case CUPS_AUTHENTICATE_JOB
:
627 authenticate_job(con
, uri
);
630 case IPP_CREATE_PRINTER_SUBSCRIPTION
:
631 case IPP_CREATE_JOB_SUBSCRIPTION
:
632 create_subscription(con
, uri
);
635 case IPP_GET_SUBSCRIPTION_ATTRIBUTES
:
636 get_subscription_attrs(con
, sub_id
);
639 case IPP_GET_SUBSCRIPTIONS
:
640 get_subscriptions(con
, uri
);
643 case IPP_RENEW_SUBSCRIPTION
:
644 renew_subscription(con
, sub_id
);
647 case IPP_CANCEL_SUBSCRIPTION
:
648 cancel_subscription(con
, sub_id
);
651 case IPP_GET_NOTIFICATIONS
:
652 get_notifications(con
);
656 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
657 "%04X %s Operation %04X (%s) not supported",
658 IPP_OPERATION_NOT_SUPPORTED
, con
->http
.hostname
,
659 con
->request
->request
.op
.operation_id
,
660 ippOpString(con
->request
->request
.op
.operation_id
));
662 send_ipp_status(con
, IPP_OPERATION_NOT_SUPPORTED
,
663 _("%s not supported!"),
665 con
->request
->request
.op
.operation_id
));
675 * Sending data from the scheduler...
678 cupsdLogMessage(CUPSD_LOG_DEBUG
,
679 "cupsdProcessIPPRequest: %d status_code=%x (%s)",
680 con
->http
.fd
, con
->response
->request
.status
.status_code
,
681 ippErrorString(con
->response
->request
.status
.status_code
));
683 if (cupsdSendHeader(con
, HTTP_OK
, "application/ipp", CUPSD_AUTH_NONE
))
685 #ifdef CUPSD_USE_CHUNKING
687 * Because older versions of CUPS (1.1.17 and older) and some IPP
688 * clients do not implement chunking properly, we cannot use
689 * chunking by default. This may become the default in future
690 * CUPS releases, or we might add a configuration directive for
694 if (con
->http
.version
== HTTP_1_1
)
696 if (httpPrintf(HTTP(con
), "Transfer-Encoding: chunked\r\n\r\n") < 0)
699 if (cupsdFlushHeader(con
) < 0)
702 con
->http
.data_encoding
= HTTP_ENCODE_CHUNKED
;
705 #endif /* CUPSD_USE_CHUNKING */
707 size_t length
; /* Length of response */
710 length
= ippLength(con
->response
);
712 if (con
->file
>= 0 && !con
->pipe_pid
)
714 struct stat fileinfo
; /* File information */
717 if (!fstat(con
->file
, &fileinfo
))
718 length
+= fileinfo
.st_size
;
721 if (httpPrintf(HTTP(con
), "Content-Length: " CUPS_LLFMT
"\r\n\r\n",
722 CUPS_LLCAST length
) < 0)
725 if (cupsdFlushHeader(con
) < 0)
728 con
->http
.data_encoding
= HTTP_ENCODE_LENGTH
;
729 con
->http
.data_remaining
= length
;
731 if (con
->http
.data_remaining
<= INT_MAX
)
732 con
->http
._data_remaining
= con
->http
.data_remaining
;
734 con
->http
._data_remaining
= INT_MAX
;
737 cupsdAddSelect(con
->http
.fd
, (cupsd_selfunc_t
)cupsdReadClient
,
738 (cupsd_selfunc_t
)cupsdWriteClient
, con
);
741 * Tell the caller the response header was sent successfully...
749 * Tell the caller the response header could not be sent...
758 * Sending data from a subprocess like cups-deviced; tell the caller
759 * everything is A-OK so far...
768 * 'cupsdTimeoutJob()' - Timeout a job waiting on job files.
771 int /* O - 0 on success, -1 on error */
772 cupsdTimeoutJob(cupsd_job_t
*job
) /* I - Job to timeout */
774 cupsd_printer_t
*printer
; /* Destination printer or class */
775 ipp_attribute_t
*attr
; /* job-sheets attribute */
776 int kbytes
; /* Kilobytes in banner */
779 job
->pending_timeout
= 0;
782 * See if we need to add the ending sheet...
785 printer
= cupsdFindDest(job
->dest
);
786 attr
= ippFindAttribute(job
->attrs
, "job-sheets", IPP_TAG_NAME
);
789 !(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)) &&
790 attr
&& attr
->num_values
> 1)
796 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Adding end banner page \"%s\".",
797 job
->id
, attr
->values
[1].string
.text
);
799 if ((kbytes
= copy_banner(NULL
, job
, attr
->values
[1].string
.text
)) < 0)
802 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
810 * 'accept_jobs()' - Accept print jobs to a printer.
814 accept_jobs(cupsd_client_t
*con
, /* I - Client connection */
815 ipp_attribute_t
*uri
) /* I - Printer or class URI */
817 http_status_t status
; /* Policy status */
818 cups_ptype_t dtype
; /* Destination type (printer/class) */
819 cupsd_printer_t
*printer
; /* Printer data */
822 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "accept_jobs(%p[%d], %s)", con
,
823 con
->http
.fd
, uri
->values
[0].string
.text
);
826 * Is the destination valid?
829 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
835 send_ipp_status(con
, IPP_NOT_FOUND
,
836 _("The printer or class was not found."));
844 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
846 send_http_error(con
, status
, printer
);
851 * Accept jobs sent to the printer...
854 printer
->accepting
= 1;
855 printer
->state_message
[0] = '\0';
857 cupsdAddPrinterHistory(printer
);
859 if (dtype
& CUPS_PRINTER_CLASS
)
861 cupsdSaveAllClasses();
863 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" now accepting jobs (\"%s\").",
864 printer
->name
, get_username(con
));
868 cupsdSaveAllPrinters();
870 cupsdLogMessage(CUPSD_LOG_INFO
,
871 "Printer \"%s\" now accepting jobs (\"%s\").",
872 printer
->name
, get_username(con
));
876 * Everything was ok, so return OK status...
879 con
->response
->request
.status
.status_code
= IPP_OK
;
884 * 'add_class()' - Add a class to the system.
888 add_class(cupsd_client_t
*con
, /* I - Client connection */
889 ipp_attribute_t
*uri
) /* I - URI of class */
891 http_status_t status
; /* Policy status */
892 int i
; /* Looping var */
893 char method
[HTTP_MAX_URI
], /* Method portion of URI */
894 username
[HTTP_MAX_URI
], /* Username portion of URI */
895 host
[HTTP_MAX_URI
], /* Host portion of URI */
896 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
897 int port
; /* Port portion of URI */
898 cupsd_printer_t
*pclass
, /* Class */
899 *member
; /* Member printer/class */
900 cups_ptype_t dtype
; /* Destination type */
901 ipp_attribute_t
*attr
; /* Printer attribute */
902 int modify
; /* Non-zero if we just modified */
903 char newname
[IPP_MAX_NAME
]; /* New class name */
904 int need_restart_job
; /* Need to restart job? */
907 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_class(%p[%d], %s)", con
,
908 con
->http
.fd
, uri
->values
[0].string
.text
);
911 * Do we have a valid URI?
914 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
915 sizeof(method
), username
, sizeof(username
), host
,
916 sizeof(host
), &port
, resource
, sizeof(resource
));
919 if (strncmp(resource
, "/classes/", 9) || strlen(resource
) == 9)
922 * No, return an error...
925 send_ipp_status(con
, IPP_BAD_REQUEST
,
926 _("The printer-uri must be of the form "
927 "\"ipp://HOSTNAME/classes/CLASSNAME\"."));
932 * Do we have a valid printer name?
935 if (!validate_name(resource
+ 9))
938 * No, return an error...
941 send_ipp_status(con
, IPP_BAD_REQUEST
,
942 _("The printer-uri \"%s\" contains invalid characters."),
943 uri
->values
[0].string
.text
);
948 * See if the class already exists; if not, create a new class...
951 if ((pclass
= cupsdFindClass(resource
+ 9)) == NULL
)
954 * Class doesn't exist; see if we have a printer of the same name...
957 if ((pclass
= cupsdFindPrinter(resource
+ 9)) != NULL
&&
958 !(pclass
->type
& CUPS_PRINTER_DISCOVERED
))
961 * Yes, return an error...
964 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
965 _("A printer named \"%s\" already exists!"),
971 * No, check the default policy and then add the class...
974 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
976 send_http_error(con
, status
, NULL
);
980 pclass
= cupsdAddClass(resource
+ 9);
983 else if (pclass
->type
& CUPS_PRINTER_IMPLICIT
)
986 * Check the default policy, then rename the implicit class to "AnyClass"
990 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
992 send_http_error(con
, status
, NULL
);
996 if (ImplicitAnyClasses
)
998 snprintf(newname
, sizeof(newname
), "Any%s", resource
+ 9);
999 cupsdRenamePrinter(pclass
, newname
);
1002 cupsdDeletePrinter(pclass
, 1);
1005 * Add the class as a new local class...
1008 pclass
= cupsdAddClass(resource
+ 9);
1011 else if (pclass
->type
& CUPS_PRINTER_DISCOVERED
)
1014 * Check the default policy, then rename the remote class to "Class"...
1017 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1019 send_http_error(con
, status
, NULL
);
1023 snprintf(newname
, sizeof(newname
), "%s@%s", resource
+ 9, pclass
->hostname
);
1024 cupsdRenamePrinter(pclass
, newname
);
1027 * Add the class as a new local class...
1030 pclass
= cupsdAddClass(resource
+ 9);
1033 else if ((status
= cupsdCheckPolicy(pclass
->op_policy_ptr
, con
,
1036 send_http_error(con
, status
, pclass
);
1043 * Look for attributes and copy them over as needed...
1046 need_restart_job
= 0;
1048 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
1049 IPP_TAG_TEXT
)) != NULL
)
1050 cupsdSetString(&pclass
->location
, attr
->values
[0].string
.text
);
1052 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
1053 IPP_TAG_TEXT
)) != NULL
)
1054 cupsdSetString(&pclass
->info
, attr
->values
[0].string
.text
);
1056 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
1057 IPP_TAG_BOOLEAN
)) != NULL
)
1059 cupsdLogMessage(CUPSD_LOG_INFO
,
1060 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
1061 pclass
->name
, attr
->values
[0].boolean
, pclass
->accepting
);
1063 pclass
->accepting
= attr
->values
[0].boolean
;
1064 cupsdAddPrinterHistory(pclass
);
1067 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
1068 IPP_TAG_BOOLEAN
)) != NULL
)
1070 if (pclass
->shared
&& !attr
->values
[0].boolean
)
1071 cupsdDeregisterPrinter(pclass
, 1);
1073 cupsdLogMessage(CUPSD_LOG_INFO
,
1074 "Setting %s printer-is-shared to %d (was %d.)",
1075 pclass
->name
, attr
->values
[0].boolean
, pclass
->shared
);
1077 pclass
->shared
= attr
->values
[0].boolean
;
1080 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
1081 IPP_TAG_ENUM
)) != NULL
)
1083 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
1084 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
1086 send_ipp_status(con
, IPP_BAD_REQUEST
,
1087 _("Attempt to set %s printer-state to bad value %d!"),
1088 pclass
->name
, attr
->values
[0].integer
);
1092 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
1093 pclass
->name
, attr
->values
[0].integer
, pclass
->state
);
1095 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
1096 cupsdStopPrinter(pclass
, 0);
1099 cupsdSetPrinterState(pclass
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
1100 need_restart_job
= 1;
1103 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
1104 IPP_TAG_TEXT
)) != NULL
)
1106 strlcpy(pclass
->state_message
, attr
->values
[0].string
.text
,
1107 sizeof(pclass
->state_message
));
1108 cupsdAddPrinterHistory(pclass
);
1110 if ((attr
= ippFindAttribute(con
->request
, "member-uris",
1111 IPP_TAG_URI
)) != NULL
)
1114 * Clear the printer array as needed...
1117 need_restart_job
= 1;
1119 if (pclass
->num_printers
> 0)
1121 free(pclass
->printers
);
1122 pclass
->num_printers
= 0;
1126 * Add each printer or class that is listed...
1129 for (i
= 0; i
< attr
->num_values
; i
++)
1132 * Search for the printer or class URI...
1135 if (!cupsdValidateDest(attr
->values
[i
].string
.text
, &dtype
, &member
))
1141 send_ipp_status(con
, IPP_NOT_FOUND
,
1142 _("The printer or class was not found."));
1147 * Add it to the class...
1150 cupsdAddPrinterToClass(pclass
, member
);
1154 set_printer_defaults(con
, pclass
);
1156 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
1157 IPP_TAG_KEYWORD
)) != NULL
)
1158 cupsdSetAuthInfoRequired(pclass
, NULL
, attr
);
1161 * Update the printer class attributes and return...
1164 cupsdSetPrinterAttrs(pclass
);
1165 cupsdSaveAllClasses();
1167 if (need_restart_job
&& pclass
->job
)
1172 * Stop the current job and then restart it below...
1175 job
= (cupsd_job_t
*)pclass
->job
;
1177 cupsdStopJob(job
, 1);
1179 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1180 job
->state_value
= IPP_JOB_PENDING
;
1183 if (need_restart_job
)
1186 cupsdWritePrintcap();
1190 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
, pclass
, NULL
,
1191 "Class \"%s\" modified by \"%s\".", pclass
->name
,
1194 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" modified by \"%s\".",
1195 pclass
->name
, get_username(con
));
1199 cupsdAddPrinterHistory(pclass
);
1201 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
, pclass
, NULL
,
1202 "New class \"%s\" added by \"%s\".", pclass
->name
,
1205 cupsdLogMessage(CUPSD_LOG_INFO
, "New class \"%s\" added by \"%s\".",
1206 pclass
->name
, get_username(con
));
1209 con
->response
->request
.status
.status_code
= IPP_OK
;
1214 * 'add_file()' - Add a file to a job.
1217 static int /* O - 0 on success, -1 on error */
1218 add_file(cupsd_client_t
*con
, /* I - Connection to client */
1219 cupsd_job_t
*job
, /* I - Job to add to */
1220 mime_type_t
*filetype
, /* I - Type of file */
1221 int compression
) /* I - Compression */
1223 mime_type_t
**filetypes
; /* New filetypes array... */
1224 int *compressions
; /* New compressions array... */
1227 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1228 "add_file(con=%p[%d], job=%d, filetype=%s/%s, "
1229 "compression=%d)", con
, con
? con
->http
.fd
: -1, job
->id
,
1230 filetype
->super
, filetype
->type
, compression
);
1233 * Add the file to the job...
1236 if (job
->num_files
== 0)
1238 compressions
= (int *)malloc(sizeof(int));
1239 filetypes
= (mime_type_t
**)malloc(sizeof(mime_type_t
*));
1243 compressions
= (int *)realloc(job
->compressions
,
1244 (job
->num_files
+ 1) * sizeof(int));
1245 filetypes
= (mime_type_t
**)realloc(job
->filetypes
,
1246 (job
->num_files
+ 1) *
1247 sizeof(mime_type_t
*));
1250 if (!compressions
|| !filetypes
)
1252 cupsdCancelJob(job
, 1, IPP_JOB_ABORTED
);
1255 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1256 _("Unable to allocate memory for file types!"));
1261 job
->compressions
= compressions
;
1262 job
->compressions
[job
->num_files
] = compression
;
1263 job
->filetypes
= filetypes
;
1264 job
->filetypes
[job
->num_files
] = filetype
;
1273 * 'add_job()' - Add a job to a print queue.
1276 static cupsd_job_t
* /* O - Job object */
1277 add_job(cupsd_client_t
*con
, /* I - Client connection */
1278 cupsd_printer_t
*printer
, /* I - Destination printer */
1279 mime_type_t
*filetype
) /* I - First print file type, if any */
1281 http_status_t status
; /* Policy status */
1282 ipp_attribute_t
*attr
, /* Current attribute */
1283 *auth_info
; /* auth-info attribute */
1284 const char *val
; /* Default option value */
1285 int priority
; /* Job priority */
1286 char *title
; /* Job name/title */
1287 cupsd_job_t
*job
; /* Current job */
1288 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
1289 int kbytes
; /* Size of print file */
1290 int i
; /* Looping var */
1291 int lowerpagerange
; /* Page range bound */
1294 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job(%p[%d], %p(%s), %p(%s/%s))",
1295 con
, con
->http
.fd
, printer
, printer
->name
,
1296 filetype
, filetype
? filetype
->super
: "none",
1297 filetype
? filetype
->type
: "none");
1300 * Check remote printing to non-shared printer...
1303 if (!printer
->shared
&&
1304 strcasecmp(con
->http
.hostname
, "localhost") &&
1305 strcasecmp(con
->http
.hostname
, ServerName
))
1307 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
1308 _("The printer or class is not shared!"));
1316 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
1318 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
1320 send_http_error(con
, status
, printer
);
1323 else if ((printer
->type
& CUPS_PRINTER_AUTHENTICATED
) &&
1324 !con
->username
[0] && !auth_info
)
1326 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
1330 else if (auth_info
&& !con
->http
.tls
&&
1331 !httpAddrLocalhost(con
->http
.hostaddr
))
1334 * Require encryption of auth-info over non-local connections...
1337 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
1340 #endif /* HAVE_SSL */
1343 * See if the printer is accepting jobs...
1346 if (!printer
->accepting
)
1348 send_ipp_status(con
, IPP_NOT_ACCEPTING
,
1349 _("Destination \"%s\" is not accepting jobs."),
1355 * Validate job template attributes; for now just document-format,
1356 * copies, number-up, and page-ranges...
1359 if (filetype
&& printer
->filetypes
&&
1360 !cupsArrayFind(printer
->filetypes
, filetype
))
1362 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
1363 /* MIME media type string */
1366 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
1369 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
1370 _("Unsupported format \'%s\'!"), mimetype
);
1372 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
1373 "document-format", NULL
, mimetype
);
1378 if ((attr
= ippFindAttribute(con
->request
, "copies",
1379 IPP_TAG_INTEGER
)) != NULL
)
1381 if (attr
->values
[0].integer
< 1 || attr
->values
[0].integer
> MaxCopies
)
1383 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad copies value %d."),
1384 attr
->values
[0].integer
);
1385 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1386 "copies", attr
->values
[0].integer
);
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 * Make sure we aren't over our limit...
1432 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1435 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1437 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
1438 _("Too many active jobs."));
1442 if ((i
= check_quotas(con
, printer
)) < 0)
1444 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
1449 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
1454 * Create the job and set things up...
1457 if ((attr
= ippFindAttribute(con
->request
, "job-priority",
1458 IPP_TAG_INTEGER
)) != NULL
)
1459 priority
= attr
->values
[0].integer
;
1462 if ((val
= cupsGetOption("job-priority", printer
->num_options
,
1463 printer
->options
)) != NULL
)
1464 priority
= atoi(val
);
1468 ippAddInteger(con
->request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-priority",
1472 if ((attr
= ippFindAttribute(con
->request
, "job-name",
1473 IPP_TAG_NAME
)) != NULL
)
1474 title
= attr
->values
[0].string
.text
;
1476 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
,
1477 title
= "Untitled");
1479 if ((job
= cupsdAddJob(priority
, printer
->name
)) == NULL
)
1481 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1482 _("Unable to add job for destination \"%s\"!"),
1487 job
->dtype
= printer
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
1488 CUPS_PRINTER_REMOTE
);
1489 job
->attrs
= con
->request
;
1490 con
->request
= ippNewRequest(job
->attrs
->request
.op
.operation_id
);
1492 add_job_uuid(con
, job
);
1493 apply_printer_defaults(printer
, job
);
1495 attr
= ippFindAttribute(job
->attrs
, "requesting-user-name", IPP_TAG_NAME
);
1497 if (con
->username
[0])
1499 cupsdSetString(&job
->username
, con
->username
);
1502 cupsdSetString(&attr
->values
[0].string
.text
, con
->username
);
1506 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1507 "add_job: requesting-user-name=\"%s\"",
1508 attr
->values
[0].string
.text
);
1510 cupsdSetString(&job
->username
, attr
->values
[0].string
.text
);
1513 cupsdSetString(&job
->username
, "anonymous");
1516 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1517 "job-originating-user-name", NULL
, job
->username
);
1520 attr
->group_tag
= IPP_TAG_JOB
;
1521 _cupsStrFree(attr
->name
);
1522 attr
->name
= _cupsStrAlloc("job-originating-user-name");
1525 if (con
->username
[0] || auth_info
)
1527 save_auth_info(con
, job
, auth_info
);
1530 * Remove the auth-info attribute from the attribute data...
1534 ippDeleteAttribute(job
->attrs
, auth_info
);
1537 if ((attr
= ippFindAttribute(job
->attrs
, "job-originating-host-name",
1538 IPP_TAG_ZERO
)) != NULL
)
1541 * Request contains a job-originating-host-name attribute; validate it...
1544 if (attr
->value_tag
!= IPP_TAG_NAME
||
1545 attr
->num_values
!= 1 ||
1546 strcmp(con
->http
.hostname
, "localhost"))
1549 * Can't override the value if we aren't connected via localhost.
1550 * Also, we can only have 1 value and it must be a name value.
1553 switch (attr
->value_tag
)
1555 case IPP_TAG_STRING
:
1556 case IPP_TAG_TEXTLANG
:
1557 case IPP_TAG_NAMELANG
:
1560 case IPP_TAG_KEYWORD
:
1562 case IPP_TAG_URISCHEME
:
1563 case IPP_TAG_CHARSET
:
1564 case IPP_TAG_LANGUAGE
:
1565 case IPP_TAG_MIMETYPE
:
1567 * Free old strings...
1570 for (i
= 0; i
< attr
->num_values
; i
++)
1572 _cupsStrFree(attr
->values
[i
].string
.text
);
1573 attr
->values
[i
].string
.text
= NULL
;
1574 if (attr
->values
[i
].string
.charset
)
1576 _cupsStrFree(attr
->values
[i
].string
.charset
);
1577 attr
->values
[i
].string
.charset
= NULL
;
1586 * Use the default connection hostname instead...
1589 attr
->value_tag
= IPP_TAG_NAME
;
1590 attr
->num_values
= 1;
1591 attr
->values
[0].string
.text
= _cupsStrAlloc(con
->http
.hostname
);
1594 attr
->group_tag
= IPP_TAG_JOB
;
1599 * No job-originating-host-name attribute, so use the hostname from
1603 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1604 "job-originating-host-name", NULL
, con
->http
.hostname
);
1607 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation",
1609 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1610 "time-at-processing", 0);
1611 attr
->value_tag
= IPP_TAG_NOVALUE
;
1612 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1613 "time-at-completed", 0);
1614 attr
->value_tag
= IPP_TAG_NOVALUE
;
1617 * Add remaining job attributes...
1620 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1621 job
->state
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_ENUM
,
1622 "job-state", IPP_JOB_STOPPED
);
1623 job
->state_value
= (ipp_jstate_t
)job
->state
->values
[0].integer
;
1624 job
->sheets
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1625 "job-media-sheets-completed", 0);
1626 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-printer-uri", NULL
,
1628 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
,
1631 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
1632 IPP_TAG_INTEGER
)) != NULL
)
1633 attr
->values
[0].integer
= 0;
1635 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1638 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
1639 IPP_TAG_KEYWORD
)) == NULL
)
1640 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
1643 if ((val
= cupsGetOption("job-hold-until", printer
->num_options
,
1644 printer
->options
)) == NULL
)
1647 attr
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1648 "job-hold-until", NULL
, val
);
1650 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold") &&
1651 !(printer
->type
& CUPS_PRINTER_REMOTE
))
1654 * Hold job until specified time...
1657 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
);
1659 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1660 job
->state_value
= IPP_JOB_HELD
;
1662 else if (job
->attrs
->request
.op
.operation_id
== IPP_CREATE_JOB
)
1664 job
->hold_until
= time(NULL
) + 60;
1665 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1666 job
->state_value
= IPP_JOB_HELD
;
1670 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1671 job
->state_value
= IPP_JOB_PENDING
;
1674 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)) ||
1678 * Add job sheets options...
1681 if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1682 IPP_TAG_ZERO
)) == NULL
)
1684 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1685 "Adding default job-sheets values \"%s,%s\"...",
1686 printer
->job_sheets
[0], printer
->job_sheets
[1]);
1688 attr
= ippAddStrings(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-sheets",
1690 attr
->values
[0].string
.text
= _cupsStrAlloc(printer
->job_sheets
[0]);
1691 attr
->values
[1].string
.text
= _cupsStrAlloc(printer
->job_sheets
[1]);
1694 job
->job_sheets
= attr
;
1697 * Enforce classification level if set...
1702 cupsdLogMessage(CUPSD_LOG_INFO
,
1703 "Classification=\"%s\", ClassifyOverride=%d",
1704 Classification
? Classification
: "(null)",
1707 if (ClassifyOverride
)
1709 if (!strcmp(attr
->values
[0].string
.text
, "none") &&
1710 (attr
->num_values
== 1 ||
1711 !strcmp(attr
->values
[1].string
.text
, "none")))
1714 * Force the leading banner to have the classification on it...
1717 cupsdSetString(&attr
->values
[0].string
.text
, Classification
);
1719 cupsdLogMessage(CUPSD_LOG_NOTICE
, "[Job %d] CLASSIFICATION FORCED "
1720 "job-sheets=\"%s,none\", "
1721 "job-originating-user-name=\"%s\"",
1722 job
->id
, Classification
, job
->username
);
1724 else if (attr
->num_values
== 2 &&
1725 strcmp(attr
->values
[0].string
.text
,
1726 attr
->values
[1].string
.text
) &&
1727 strcmp(attr
->values
[0].string
.text
, "none") &&
1728 strcmp(attr
->values
[1].string
.text
, "none"))
1731 * Can't put two different security markings on the same document!
1734 cupsdSetString(&attr
->values
[1].string
.text
, attr
->values
[0].string
.text
);
1736 cupsdLogMessage(CUPSD_LOG_NOTICE
, "[Job %d] CLASSIFICATION FORCED "
1737 "job-sheets=\"%s,%s\", "
1738 "job-originating-user-name=\"%s\"",
1739 job
->id
, attr
->values
[0].string
.text
,
1740 attr
->values
[1].string
.text
, job
->username
);
1742 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1743 strcmp(attr
->values
[0].string
.text
, "none") &&
1744 (attr
->num_values
== 1 ||
1745 (strcmp(attr
->values
[1].string
.text
, Classification
) &&
1746 strcmp(attr
->values
[1].string
.text
, "none"))))
1748 if (attr
->num_values
== 1)
1749 cupsdLogMessage(CUPSD_LOG_NOTICE
,
1750 "[Job %d] CLASSIFICATION OVERRIDDEN "
1751 "job-sheets=\"%s\", "
1752 "job-originating-user-name=\"%s\"",
1753 job
->id
, attr
->values
[0].string
.text
, job
->username
);
1755 cupsdLogMessage(CUPSD_LOG_NOTICE
,
1756 "[Job %d] CLASSIFICATION OVERRIDDEN "
1757 "job-sheets=\"%s,%s\",fffff "
1758 "job-originating-user-name=\"%s\"",
1759 job
->id
, attr
->values
[0].string
.text
,
1760 attr
->values
[1].string
.text
, job
->username
);
1763 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1764 (attr
->num_values
== 1 ||
1765 strcmp(attr
->values
[1].string
.text
, Classification
)))
1768 * Force the banner to have the classification on it...
1771 if (attr
->num_values
> 1 &&
1772 !strcmp(attr
->values
[0].string
.text
, attr
->values
[1].string
.text
))
1774 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1775 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1779 if (attr
->num_values
== 1 ||
1780 strcmp(attr
->values
[0].string
.text
, "none"))
1781 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1783 if (attr
->num_values
> 1 &&
1784 strcmp(attr
->values
[1].string
.text
, "none"))
1785 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1788 if (attr
->num_values
> 1)
1789 cupsdLogMessage(CUPSD_LOG_NOTICE
,
1790 "[Job %d] CLASSIFICATION FORCED "
1791 "job-sheets=\"%s,%s\", "
1792 "job-originating-user-name=\"%s\"",
1793 job
->id
, attr
->values
[0].string
.text
,
1794 attr
->values
[1].string
.text
, job
->username
);
1796 cupsdLogMessage(CUPSD_LOG_NOTICE
,
1797 "[Job %d] CLASSIFICATION FORCED "
1798 "job-sheets=\"%s\", "
1799 "job-originating-user-name=\"%s\"",
1800 job
->id
, Classification
, job
->username
);
1805 * See if we need to add the starting sheet...
1808 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)))
1810 cupsdLogMessage(CUPSD_LOG_INFO
,
1811 "[Job %d] Adding start banner page \"%s\".",
1812 job
->id
, attr
->values
[0].string
.text
);
1814 if ((kbytes
= copy_banner(con
, job
, attr
->values
[0].string
.text
)) < 0)
1817 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
1820 else if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1821 IPP_TAG_ZERO
)) != NULL
)
1825 * Fill in the response info...
1828 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
1829 LocalPort
, job
->id
);
1831 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
1834 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1836 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
1838 add_job_state_reasons(con
, job
);
1840 con
->response
->request
.status
.status_code
= IPP_OK
;
1843 * Add any job subscriptions...
1846 add_job_subscriptions(con
, job
);
1849 * Set all but the first two attributes to the job attributes group...
1852 for (attr
= job
->attrs
->attrs
->next
->next
; attr
; attr
= attr
->next
)
1853 attr
->group_tag
= IPP_TAG_JOB
;
1856 * Fire the "job created" event...
1859 cupsdAddEvent(CUPSD_EVENT_JOB_CREATED
, printer
, job
, "Job created.");
1862 * Return the new job...
1870 * 'add_job_state_reasons()' - Add the "job-state-reasons" attribute based
1871 * upon the job and printer state...
1875 add_job_state_reasons(
1876 cupsd_client_t
*con
, /* I - Client connection */
1877 cupsd_job_t
*job
) /* I - Job info */
1879 cupsd_printer_t
*dest
; /* Destination printer */
1882 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job_state_reasons(%p[%d], %d)",
1883 con
, con
->http
.fd
, job
? job
->id
: 0);
1885 switch (job
? job
->state_value
: IPP_JOB_CANCELED
)
1887 case IPP_JOB_PENDING
:
1888 dest
= cupsdFindDest(job
->dest
);
1890 if (dest
&& dest
->state
== IPP_PRINTER_STOPPED
)
1891 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1892 "job-state-reasons", NULL
, "printer-stopped");
1894 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1895 "job-state-reasons", NULL
, "none");
1899 if (ippFindAttribute(job
->attrs
, "job-hold-until",
1900 IPP_TAG_KEYWORD
) != NULL
||
1901 ippFindAttribute(job
->attrs
, "job-hold-until",
1902 IPP_TAG_NAME
) != NULL
)
1903 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1904 "job-state-reasons", NULL
, "job-hold-until-specified");
1906 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1907 "job-state-reasons", NULL
, "job-incoming");
1910 case IPP_JOB_PROCESSING
:
1911 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1912 "job-state-reasons", NULL
, "job-printing");
1915 case IPP_JOB_STOPPED
:
1916 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1917 "job-state-reasons", NULL
, "job-stopped");
1920 case IPP_JOB_CANCELED
:
1921 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1922 "job-state-reasons", NULL
, "job-canceled-by-user");
1925 case IPP_JOB_ABORTED
:
1926 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1927 "job-state-reasons", NULL
, "aborted-by-system");
1930 case IPP_JOB_COMPLETED
:
1931 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1932 "job-state-reasons", NULL
, "job-completed-successfully");
1939 * 'add_job_subscriptions()' - Add any subcriptions for a job.
1943 add_job_subscriptions(
1944 cupsd_client_t
*con
, /* I - Client connection */
1945 cupsd_job_t
*job
) /* I - Newly created job */
1947 int i
; /* Looping var */
1948 ipp_attribute_t
*prev
, /* Previous attribute */
1949 *next
, /* Next attribute */
1950 *attr
; /* Current attribute */
1951 cupsd_subscription_t
*sub
; /* Subscription object */
1952 const char *recipient
, /* notify-recipient-uri */
1953 *pullmethod
; /* notify-pull-method */
1954 ipp_attribute_t
*user_data
; /* notify-user-data */
1955 int interval
; /* notify-time-interval */
1956 unsigned mask
; /* notify-events */
1960 * Find the first subscription group attribute; return if we have
1964 for (attr
= job
->attrs
->attrs
, prev
= NULL
;
1966 prev
= attr
, attr
= attr
->next
)
1967 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
1974 * Process the subscription attributes in the request...
1983 mask
= CUPSD_EVENT_NONE
;
1985 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
1987 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
1988 attr
->value_tag
== IPP_TAG_URI
)
1989 recipient
= attr
->values
[0].string
.text
;
1990 else if (!strcmp(attr
->name
, "notify-pull-method") &&
1991 attr
->value_tag
== IPP_TAG_KEYWORD
)
1992 pullmethod
= attr
->values
[0].string
.text
;
1993 else if (!strcmp(attr
->name
, "notify-charset") &&
1994 attr
->value_tag
== IPP_TAG_CHARSET
&&
1995 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
1996 strcmp(attr
->values
[0].string
.text
, "utf-8"))
1998 send_ipp_status(con
, IPP_CHARSET
,
1999 _("Character set \"%s\" not supported!"),
2000 attr
->values
[0].string
.text
);
2003 else if (!strcmp(attr
->name
, "notify-natural-language") &&
2004 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
2005 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
2007 send_ipp_status(con
, IPP_CHARSET
,
2008 _("Language \"%s\" not supported!"),
2009 attr
->values
[0].string
.text
);
2012 else if (!strcmp(attr
->name
, "notify-user-data") &&
2013 attr
->value_tag
== IPP_TAG_STRING
)
2015 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
2017 send_ipp_status(con
, IPP_REQUEST_VALUE
,
2018 _("The notify-user-data value is too large "
2019 "(%d > 63 octets)!"),
2020 attr
->values
[0].unknown
.length
);
2026 else if (!strcmp(attr
->name
, "notify-events") &&
2027 attr
->value_tag
== IPP_TAG_KEYWORD
)
2029 for (i
= 0; i
< attr
->num_values
; i
++)
2030 mask
|= cupsdEventValue(attr
->values
[i
].string
.text
);
2032 else if (!strcmp(attr
->name
, "notify-lease-duration"))
2034 send_ipp_status(con
, IPP_BAD_REQUEST
,
2035 _("The notify-lease-duration attribute cannot be "
2036 "used with job subscriptions."));
2039 else if (!strcmp(attr
->name
, "notify-time-interval") &&
2040 attr
->value_tag
== IPP_TAG_INTEGER
)
2041 interval
= attr
->values
[0].integer
;
2046 if (!recipient
&& !pullmethod
)
2049 if (mask
== CUPSD_EVENT_NONE
)
2050 mask
= CUPSD_EVENT_JOB_COMPLETED
;
2052 sub
= cupsdAddSubscription(mask
, cupsdFindDest(job
->dest
), job
, recipient
,
2055 sub
->interval
= interval
;
2057 cupsdSetString(&sub
->owner
, job
->username
);
2061 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
2062 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
2063 sub
->user_data_len
);
2066 ippAddSeparator(con
->response
);
2067 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
2068 "notify-subscription-id", sub
->id
);
2074 cupsdSaveAllSubscriptions();
2077 * Remove all of the subscription attributes from the job request...
2080 for (attr
= job
->attrs
->attrs
, prev
= NULL
; attr
; attr
= next
)
2084 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
||
2085 attr
->group_tag
== IPP_TAG_ZERO
)
2088 * Free and remove this attribute...
2096 job
->attrs
->attrs
= next
;
2102 job
->attrs
->last
= prev
;
2103 job
->attrs
->current
= prev
;
2108 * 'add_job_uuid()' - Add job-uuid attribute to a job.
2110 * See RFC 4122 for the definition of UUIDs and the format.
2114 add_job_uuid(cupsd_client_t
*con
, /* I - Client connection */
2115 cupsd_job_t
*job
) /* I - Job */
2117 char uuid
[1024]; /* job-uuid string */
2118 _cups_md5_state_t md5state
; /* MD5 state */
2119 unsigned char md5sum
[16]; /* MD5 digest/sum */
2123 * First see if the job already has a job-uuid attribute; if so, return...
2126 if (ippFindAttribute(job
->attrs
, "job-uuid", IPP_TAG_URI
))
2130 * No job-uuid attribute, so build a version 3 UUID with the local job
2131 * ID at the end; see RFC 4122 for details. Start with the MD5 sum of
2132 * the ServerName, server name and port that the client connected to,
2133 * and local job ID...
2136 snprintf(uuid
, sizeof(uuid
), "%s:%s:%d:%d", ServerName
, con
->servername
,
2137 con
->serverport
, job
->id
);
2139 _cupsMD5Init(&md5state
);
2140 _cupsMD5Append(&md5state
, (unsigned char *)uuid
, strlen(uuid
));
2141 _cupsMD5Finish(&md5state
, md5sum
);
2144 * Format the UUID URI using the MD5 sum and job ID.
2147 snprintf(uuid
, sizeof(uuid
),
2148 "urn:uuid:%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-"
2149 "%02x%02x%02x%02x%02x%02x",
2150 md5sum
[0], md5sum
[1], md5sum
[2], md5sum
[3], md5sum
[4], md5sum
[5],
2151 (md5sum
[6] & 15) | 0x30, md5sum
[7], (md5sum
[8] & 0x3f) | 0x40,
2152 md5sum
[9], md5sum
[10], md5sum
[11], md5sum
[12], md5sum
[13],
2153 md5sum
[14], md5sum
[15]);
2155 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uuid", NULL
, uuid
);
2160 * 'add_printer()' - Add a printer to the system.
2164 add_printer(cupsd_client_t
*con
, /* I - Client connection */
2165 ipp_attribute_t
*uri
) /* I - URI of printer */
2167 http_status_t status
; /* Policy status */
2168 int i
; /* Looping var */
2169 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
2170 username
[HTTP_MAX_URI
], /* Username portion of URI */
2171 host
[HTTP_MAX_URI
], /* Host portion of URI */
2172 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2173 int port
; /* Port portion of URI */
2174 cupsd_printer_t
*printer
; /* Printer/class */
2175 ipp_attribute_t
*attr
; /* Printer attribute */
2176 cups_file_t
*fp
; /* Script/PPD file */
2177 char line
[1024]; /* Line from file... */
2178 char srcfile
[1024], /* Source Script/PPD file */
2179 dstfile
[1024]; /* Destination Script/PPD file */
2180 int modify
; /* Non-zero if we are modifying */
2181 char newname
[IPP_MAX_NAME
]; /* New printer name */
2182 int need_restart_job
; /* Need to restart job? */
2183 int set_device_uri
, /* Did we set the device URI? */
2184 set_port_monitor
; /* Did we set the port monitor? */
2187 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer(%p[%d], %s)", con
,
2188 con
->http
.fd
, uri
->values
[0].string
.text
);
2191 * Do we have a valid URI?
2194 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
2195 sizeof(scheme
), username
, sizeof(username
), host
,
2196 sizeof(host
), &port
, resource
, sizeof(resource
));
2198 if (strncmp(resource
, "/printers/", 10) || strlen(resource
) == 10)
2201 * No, return an error...
2204 send_ipp_status(con
, IPP_BAD_REQUEST
,
2205 _("The printer-uri must be of the form "
2206 "\"ipp://HOSTNAME/printers/PRINTERNAME\"."));
2211 * Do we have a valid printer name?
2214 if (!validate_name(resource
+ 10))
2217 * No, return an error...
2220 send_ipp_status(con
, IPP_BAD_REQUEST
,
2221 _("The printer-uri \"%s\" contains invalid characters."),
2222 uri
->values
[0].string
.text
);
2227 * See if the printer already exists; if not, create a new printer...
2230 if ((printer
= cupsdFindPrinter(resource
+ 10)) == NULL
)
2233 * Printer doesn't exist; see if we have a class of the same name...
2236 if ((printer
= cupsdFindClass(resource
+ 10)) != NULL
&&
2237 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
2240 * Yes, return an error...
2243 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2244 _("A class named \"%s\" already exists!"),
2250 * No, check the default policy then add the printer...
2253 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2255 send_http_error(con
, status
, NULL
);
2259 printer
= cupsdAddPrinter(resource
+ 10);
2262 else if (printer
->type
& CUPS_PRINTER_IMPLICIT
)
2265 * Check the default policy, then rename the implicit printer to
2266 * "AnyPrinter" or delete it...
2269 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2271 send_http_error(con
, status
, NULL
);
2275 if (ImplicitAnyClasses
)
2277 snprintf(newname
, sizeof(newname
), "Any%s", resource
+ 10);
2278 cupsdRenamePrinter(printer
, newname
);
2281 cupsdDeletePrinter(printer
, 1);
2284 * Add the printer as a new local printer...
2287 printer
= cupsdAddPrinter(resource
+ 10);
2290 else if (printer
->type
& CUPS_PRINTER_DISCOVERED
)
2293 * Check the default policy, then rename the remote printer to
2294 * "Printer@server"...
2297 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2299 send_http_error(con
, status
, NULL
);
2303 snprintf(newname
, sizeof(newname
), "%s@%s", resource
+ 10,
2305 cupsdRenamePrinter(printer
, newname
);
2308 * Add the printer as a new local printer...
2311 printer
= cupsdAddPrinter(resource
+ 10);
2314 else if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
2317 send_http_error(con
, status
, printer
);
2324 * Look for attributes and copy them over as needed...
2327 need_restart_job
= 0;
2329 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
2330 IPP_TAG_TEXT
)) != NULL
)
2331 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
2333 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
2334 IPP_TAG_TEXT
)) != NULL
)
2335 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
2339 if ((attr
= ippFindAttribute(con
->request
, "device-uri",
2340 IPP_TAG_URI
)) != NULL
)
2343 * Do we have a valid device URI?
2346 http_uri_status_t uri_status
; /* URI separation status */
2349 need_restart_job
= 1;
2351 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
,
2352 attr
->values
[0].string
.text
,
2353 scheme
, sizeof(scheme
),
2354 username
, sizeof(username
),
2355 host
, sizeof(host
), &port
,
2356 resource
, sizeof(resource
));
2358 if (uri_status
< HTTP_URI_OK
)
2360 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri \"%s\"!"),
2361 attr
->values
[0].string
.text
);
2362 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2363 "add_printer: httpSeparateURI returned %d", uri_status
);
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/cupsd.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
, _("Bad device-uri \"%s\"!"),
2401 attr
->values
[0].string
.text
);
2406 cupsdLogMessage(CUPSD_LOG_INFO
,
2407 "Setting %s device-uri to \"%s\" (was \"%s\".)",
2409 cupsdSanitizeURI(attr
->values
[0].string
.text
, line
,
2411 cupsdSanitizeURI(printer
->device_uri
, resource
,
2414 cupsdSetString(&printer
->device_uri
, attr
->values
[0].string
.text
);
2418 set_port_monitor
= 0;
2420 if ((attr
= ippFindAttribute(con
->request
, "port-monitor",
2421 IPP_TAG_NAME
)) != NULL
)
2423 ipp_attribute_t
*supported
; /* port-monitor-supported attribute */
2426 need_restart_job
= 1;
2428 supported
= ippFindAttribute(printer
->attrs
, "port-monitor-supported",
2432 for (i
= 0; i
< supported
->num_values
; i
++)
2433 if (!strcmp(supported
->values
[i
].string
.text
,
2434 attr
->values
[0].string
.text
))
2438 if (!supported
|| i
>= supported
->num_values
)
2440 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad port-monitor \"%s\"!"),
2441 attr
->values
[0].string
.text
);
2445 cupsdLogMessage(CUPSD_LOG_INFO
,
2446 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2447 printer
->name
, attr
->values
[0].string
.text
,
2448 printer
->port_monitor
? printer
->port_monitor
: "none");
2450 if (strcmp(attr
->values
[0].string
.text
, "none"))
2451 cupsdSetString(&printer
->port_monitor
, attr
->values
[0].string
.text
);
2453 cupsdClearString(&printer
->port_monitor
);
2455 set_port_monitor
= 1;
2458 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
2459 IPP_TAG_BOOLEAN
)) != NULL
)
2461 cupsdLogMessage(CUPSD_LOG_INFO
,
2462 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
2463 printer
->name
, attr
->values
[0].boolean
, printer
->accepting
);
2465 printer
->accepting
= attr
->values
[0].boolean
;
2466 cupsdAddPrinterHistory(printer
);
2469 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
2470 IPP_TAG_BOOLEAN
)) != NULL
)
2472 if (printer
->shared
&& !attr
->values
[0].boolean
)
2473 cupsdDeregisterPrinter(printer
, 1);
2475 cupsdLogMessage(CUPSD_LOG_INFO
,
2476 "Setting %s printer-is-shared to %d (was %d.)",
2477 printer
->name
, attr
->values
[0].boolean
, printer
->shared
);
2479 printer
->shared
= attr
->values
[0].boolean
;
2482 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
2483 IPP_TAG_ENUM
)) != NULL
)
2485 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
2486 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
2488 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad printer-state value %d!"),
2489 attr
->values
[0].integer
);
2493 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
2494 printer
->name
, attr
->values
[0].integer
, printer
->state
);
2496 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
2497 cupsdStopPrinter(printer
, 0);
2500 need_restart_job
= 1;
2501 cupsdSetPrinterState(printer
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
2504 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
2505 IPP_TAG_TEXT
)) != NULL
)
2507 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
2508 sizeof(printer
->state_message
));
2509 cupsdAddPrinterHistory(printer
);
2512 set_printer_defaults(con
, printer
);
2514 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
2515 IPP_TAG_KEYWORD
)) != NULL
)
2516 cupsdSetAuthInfoRequired(printer
, NULL
, attr
);
2519 * See if we have all required attributes...
2522 if (!printer
->device_uri
)
2523 cupsdSetString(&printer
->device_uri
, "file:///dev/null");
2526 * See if we have an interface script or PPD file attached to the request...
2531 need_restart_job
= 1;
2533 strlcpy(srcfile
, con
->filename
, sizeof(srcfile
));
2535 if ((fp
= cupsFileOpen(srcfile
, "rb")))
2538 * Yes; get the first line from it...
2542 cupsFileGets(fp
, line
, sizeof(line
));
2546 * Then see what kind of file it is...
2549 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2552 if (!strncmp(line
, "*PPD-Adobe", 10))
2555 * The new file is a PPD file, so remove any old interface script
2556 * that might be lying around...
2564 * This must be an interface script, so move the file over to the
2565 * interfaces directory and make it executable...
2568 if (copy_file(srcfile
, dstfile
))
2570 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2571 _("Unable to copy interface script - %s!"),
2576 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2577 "Copied interface script successfully!");
2578 chmod(dstfile
, 0755);
2581 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2584 if (!strncmp(line
, "*PPD-Adobe", 10))
2587 * The new file is a PPD file, so move the file over to the
2588 * ppd directory and make it readable by all...
2591 if (copy_file(srcfile
, dstfile
))
2593 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2594 _("Unable to copy PPD file - %s!"),
2599 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2600 "Copied PPD file successfully!");
2601 chmod(dstfile
, 0644);
2605 * (Re)register color profiles...
2608 apple_unregister_profiles(printer
);
2609 apple_register_profiles(printer
);
2610 #endif /* __APPLE__ */
2615 * This must be an interface script, so remove any old PPD file that
2616 * may be lying around...
2623 else if ((attr
= ippFindAttribute(con
->request
, "ppd-name",
2624 IPP_TAG_NAME
)) != NULL
)
2626 need_restart_job
= 1;
2628 if (!strcmp(attr
->values
[0].string
.text
, "raw"))
2631 * Raw driver, remove any existing PPD or interface script files.
2634 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2638 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2648 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2652 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2655 if (copy_model(con
, attr
->values
[0].string
.text
, dstfile
))
2657 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file!"));
2661 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2662 "Copied PPD file successfully!");
2663 chmod(dstfile
, 0644);
2667 * (Re)register color profiles...
2670 apple_unregister_profiles(printer
);
2671 apple_register_profiles(printer
);
2672 #endif /* __APPLE__ */
2677 * If we set the device URI but not the port monitor, check which port
2678 * monitor to use by default...
2681 if (set_device_uri
&& !set_port_monitor
)
2683 ppd_file_t
*ppd
; /* PPD file */
2684 ppd_attr_t
*ppdattr
; /* cupsPortMonitor attribute */
2687 httpSeparateURI(HTTP_URI_CODING_ALL
, printer
->device_uri
, scheme
,
2688 sizeof(scheme
), username
, sizeof(username
), host
,
2689 sizeof(host
), &port
, resource
, sizeof(resource
));
2691 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
,
2693 if ((ppd
= ppdOpenFile(srcfile
)) != NULL
)
2695 for (ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2697 ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
2698 if (!strcmp(scheme
, ppdattr
->spec
))
2700 cupsdLogMessage(CUPSD_LOG_INFO
,
2701 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2702 printer
->name
, ppdattr
->value
,
2703 printer
->port_monitor
? printer
->port_monitor
2706 if (strcmp(ppdattr
->value
, "none"))
2707 cupsdSetString(&printer
->port_monitor
, ppdattr
->value
);
2709 cupsdClearString(&printer
->port_monitor
);
2719 * Update the printer attributes and return...
2722 cupsdSetPrinterAttrs(printer
);
2723 cupsdSaveAllPrinters();
2725 if (need_restart_job
&& printer
->job
)
2730 * Stop the current job and then restart it below...
2733 job
= (cupsd_job_t
*)printer
->job
;
2735 cupsdStopJob(job
, 1);
2737 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
2738 job
->state_value
= IPP_JOB_PENDING
;
2741 if (need_restart_job
)
2744 cupsdWritePrintcap();
2748 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
, printer
, NULL
,
2749 "Printer \"%s\" modified by \"%s\".", printer
->name
,
2752 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" modified by \"%s\".",
2753 printer
->name
, get_username(con
));
2757 cupsdAddPrinterHistory(printer
);
2759 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
, printer
, NULL
,
2760 "New printer \"%s\" added by \"%s\".", printer
->name
,
2763 cupsdLogMessage(CUPSD_LOG_INFO
, "New printer \"%s\" added by \"%s\".",
2764 printer
->name
, get_username(con
));
2767 con
->response
->request
.status
.status_code
= IPP_OK
;
2772 * 'add_printer_state_reasons()' - Add the "printer-state-reasons" attribute
2773 * based upon the printer state...
2777 add_printer_state_reasons(
2778 cupsd_client_t
*con
, /* I - Client connection */
2779 cupsd_printer_t
*p
) /* I - Printer info */
2781 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2782 "add_printer_state_reasons(%p[%d], %p[%s])",
2783 con
, con
->http
.fd
, p
, p
->name
);
2785 if (p
->num_reasons
== 0)
2786 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2787 "printer-state-reasons", NULL
,
2788 p
->state
== IPP_PRINTER_STOPPED
? "paused" : "none");
2790 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2791 "printer-state-reasons", p
->num_reasons
, NULL
,
2792 (const char * const *)p
->reasons
);
2797 * 'add_queued_job_count()' - Add the "queued-job-count" attribute for
2798 * the specified printer or class.
2802 add_queued_job_count(
2803 cupsd_client_t
*con
, /* I - Client connection */
2804 cupsd_printer_t
*p
) /* I - Printer or class */
2806 int count
; /* Number of jobs on destination */
2809 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_queued_job_count(%p[%d], %p[%s])",
2810 con
, con
->http
.fd
, p
, p
->name
);
2812 count
= cupsdGetPrinterJobCount(p
->name
);
2814 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2815 "queued-job-count", count
);
2821 * 'apple_init_profile()' - Initialize a color profile.
2826 ppd_file_t
*ppd
, /* I - PPD file */
2827 cups_array_t
*languages
, /* I - Languages in the PPD file */
2828 CMDeviceProfileInfo
*profile
, /* I - Profile record */
2829 unsigned id
, /* I - Profile ID */
2830 const char *name
, /* I - Profile name */
2831 const char *text
, /* I - Profile UI text */
2832 const char *iccfile
) /* I - ICC filename */
2834 char url
[1024]; /* URL for profile filename */
2835 CFMutableDictionaryRef dict
; /* Dictionary for name */
2836 char *language
; /* Current language */
2837 ppd_attr_t
*attr
; /* Profile attribute */
2838 CFStringRef cflang
, /* Language string */
2839 cftext
; /* Localized text */
2843 * Build the profile name dictionary...
2846 dict
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
2847 &kCFTypeDictionaryKeyCallBacks
,
2848 &kCFTypeDictionaryValueCallBacks
);
2850 cftext
= CFStringCreateWithCString(kCFAllocatorDefault
, text
,
2851 kCFStringEncodingUTF8
);
2855 CFDictionarySetValue(dict
, CFSTR("en"), cftext
);
2862 * Find localized names for the color profiles...
2865 cupsArraySave(ppd
->sorted_attrs
);
2867 for (language
= (char *)cupsArrayFirst(languages
);
2869 language
= (char *)cupsArrayNext(languages
))
2872 attr
= _ppdLocalizedAttr(ppd
, "cupsICCProfile", name
, language
);
2874 attr
= _ppdLocalizedAttr(ppd
, "ColorModel", name
, language
);
2876 if (attr
&& attr
->text
[0])
2878 cflang
= CFStringCreateWithCString(kCFAllocatorDefault
, language
,
2879 kCFStringEncodingUTF8
);
2880 cftext
= CFStringCreateWithCString(kCFAllocatorDefault
, attr
->text
,
2881 kCFStringEncodingUTF8
);
2883 if (cflang
&& cftext
)
2884 CFDictionarySetValue(dict
, cflang
, cftext
);
2894 cupsArrayRestore(ppd
->sorted_attrs
);
2898 * Fill in the profile data...
2902 httpAssembleURI(HTTP_URI_CODING_ALL
, url
, sizeof(url
), "file", NULL
, "", 0,
2905 profile
->dataVersion
= cmDeviceProfileInfoVersion1
;
2906 profile
->profileID
= id
;
2907 profile
->profileLoc
.locType
= iccfile
? cmPathBasedProfile
: cmNoProfileBase
;
2908 profile
->profileName
= dict
;
2911 strlcpy(profile
->profileLoc
.u
.pathLoc
.path
, iccfile
,
2912 sizeof(profile
->profileLoc
.u
.pathLoc
.path
));
2917 * 'apple_register_profiles()' - Register color profiles for a printer.
2921 apple_register_profiles(
2922 cupsd_printer_t
*p
) /* I - Printer */
2924 int i
; /* Looping var */
2925 char ppdfile
[1024], /* PPD filename */
2926 iccfile
[1024], /* ICC filename */
2927 selector
[PPD_MAX_NAME
];
2928 /* Profile selection string */
2929 ppd_file_t
*ppd
; /* PPD file */
2930 ppd_attr_t
*attr
, /* cupsICCProfile attributes */
2931 *profileid_attr
;/* cupsProfileID attribute */
2932 ppd_option_t
*cm_option
; /* Color model option */
2933 ppd_choice_t
*cm_choice
, /* Color model choice */
2934 *q1_choice
, /* ColorModel (or other) qualifier */
2935 *q2_choice
, /* MediaType (or other) qualifier */
2936 *q3_choice
; /* Resolution (or other) qualifier */
2937 int num_profiles
; /* Number of profiles */
2938 CMError error
; /* Last error */
2939 unsigned device_id
, /* Printer device ID */
2940 profile_id
, /* Profile ID */
2941 default_profile_id
= 0;
2942 /* Default profile ID */
2943 CFMutableDictionaryRef device_name
; /* Printer device name dictionary */
2944 CFStringRef printer_name
; /* Printer name string */
2945 CMDeviceScope scope
= /* Scope of the registration */
2947 kCFPreferencesAnyUser
,
2948 kCFPreferencesCurrentHost
2950 CMDeviceProfileArrayPtr profiles
; /* Profiles */
2951 CMDeviceProfileInfo
*profile
; /* Current profile */
2952 cups_array_t
*languages
; /* Languages array */
2956 * Make sure ColorSync is available...
2959 if (CMRegisterColorDevice
== NULL
)
2963 * Try opening the PPD file for this printer...
2966 snprintf(ppdfile
, sizeof(ppdfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
2967 if ((ppd
= ppdOpenFile(ppdfile
)) == NULL
)
2970 ppdMarkDefaults(ppd
);
2973 * See if we have any profiles...
2976 for (num_profiles
= 0, attr
= ppdFindAttr(ppd
, "cupsICCProfile", NULL
);
2978 attr
= ppdFindNextAttr(ppd
, "cupsICCProfile", NULL
))
2979 if (attr
->spec
[0] && attr
->value
&& attr
->value
[0])
2981 if (attr
->value
[0] != '/')
2982 snprintf(iccfile
, sizeof(iccfile
), "%s/profiles/%s", DataDir
,
2985 strlcpy(iccfile
, attr
->value
, sizeof(iccfile
));
2987 if (access(iccfile
, 0))
2994 * If we have profiles, add them...
2997 if (num_profiles
> 0)
3000 * Figure out the default profile selectors...
3003 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier1", NULL
)) != NULL
&&
3004 attr
->value
&& attr
->value
[0])
3005 q1_choice
= ppdFindMarkedChoice(ppd
, attr
->value
);
3007 q1_choice
= ppdFindMarkedChoice(ppd
, "ColorModel");
3009 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier2", NULL
)) != NULL
&&
3010 attr
->value
&& attr
->value
[0])
3011 q2_choice
= ppdFindMarkedChoice(ppd
, attr
->value
);
3013 q2_choice
= ppdFindMarkedChoice(ppd
, "MediaType");
3015 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier3", NULL
)) != NULL
&&
3016 attr
->value
&& attr
->value
[0])
3017 q3_choice
= ppdFindMarkedChoice(ppd
, attr
->value
);
3019 q3_choice
= ppdFindMarkedChoice(ppd
, "Resolution");
3022 * Build the array of profiles...
3024 * Note: This calloc actually requests slightly more memory than needed.
3027 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3029 cupsdLogMessage(CUPSD_LOG_ERROR
,
3030 "Unable to allocate memory for %d profiles!",
3036 profiles
->profileCount
= num_profiles
;
3037 languages
= _ppdGetLanguages(ppd
);
3039 for (profile
= profiles
->profiles
,
3040 attr
= ppdFindAttr(ppd
, "cupsICCProfile", NULL
);
3042 attr
= ppdFindNextAttr(ppd
, "cupsICCProfile", NULL
))
3043 if (attr
->spec
[0] && attr
->value
&& attr
->value
[0])
3046 * Add this profile...
3049 if (attr
->value
[0] != '/')
3050 snprintf(iccfile
, sizeof(iccfile
), "%s/profiles/%s", DataDir
,
3053 strlcpy(iccfile
, attr
->value
, sizeof(iccfile
));
3055 if (access(iccfile
, 0))
3058 cupsArraySave(ppd
->sorted_attrs
);
3060 if ((profileid_attr
= ppdFindAttr(ppd
, "cupsProfileID",
3061 attr
->spec
)) != NULL
&&
3062 profileid_attr
->value
&& isdigit(profileid_attr
->value
[0] & 255))
3063 profile_id
= (unsigned)strtoul(profileid_attr
->value
, NULL
, 10);
3065 profile_id
= _ppdHashName(attr
->spec
);
3067 cupsArrayRestore(ppd
->sorted_attrs
);
3069 apple_init_profile(ppd
, languages
, profile
, profile_id
, attr
->spec
,
3070 attr
->text
[0] ? attr
->text
: attr
->spec
, iccfile
);
3075 * See if this is the default profile...
3078 if (!default_profile_id
&& q1_choice
)
3084 snprintf(selector
, sizeof(selector
), "%s.%s.%s",
3085 q1_choice
->choice
, q2_choice
->choice
, q3_choice
->choice
);
3086 if (!strcmp(selector
, attr
->spec
))
3087 default_profile_id
= profile_id
;
3090 if (!default_profile_id
)
3092 snprintf(selector
, sizeof(selector
), "%s.%s.", q1_choice
->choice
,
3094 if (!strcmp(selector
, attr
->spec
))
3095 default_profile_id
= profile_id
;
3099 if (!default_profile_id
&& q3_choice
)
3101 snprintf(selector
, sizeof(selector
), "%s..%s", q1_choice
->choice
,
3103 if (!strcmp(selector
, attr
->spec
))
3104 default_profile_id
= profile_id
;
3107 if (!default_profile_id
)
3109 snprintf(selector
, sizeof(selector
), "%s..", q1_choice
->choice
);
3110 if (!strcmp(selector
, attr
->spec
))
3111 default_profile_id
= profile_id
;
3116 _ppdFreeLanguages(languages
);
3118 else if ((cm_option
= ppdFindOption(ppd
, "ColorModel")) != NULL
)
3121 * Extract profiles from ColorModel option...
3124 const char *profile_name
; /* Name of generic profile */
3127 num_profiles
= cm_option
->num_choices
;
3129 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3131 cupsdLogMessage(CUPSD_LOG_ERROR
,
3132 "Unable to allocate memory for %d profiles!",
3138 profiles
->profileCount
= num_profiles
;
3140 for (profile
= profiles
->profiles
, i
= cm_option
->num_choices
,
3141 cm_choice
= cm_option
->choices
;
3143 i
--, cm_choice
++, profile
++)
3145 if (!strcmp(cm_choice
->choice
, "Gray") ||
3146 !strcmp(cm_choice
->choice
, "Black"))
3147 profile_name
= "Gray";
3148 else if (!strcmp(cm_choice
->choice
, "RGB") ||
3149 !strcmp(cm_choice
->choice
, "CMY"))
3150 profile_name
= "RGB";
3151 else if (!strcmp(cm_choice
->choice
, "CMYK") ||
3152 !strcmp(cm_choice
->choice
, "KCMY"))
3153 profile_name
= "CMYK";
3155 profile_name
= "DeviceN";
3157 snprintf(selector
, sizeof(selector
), "%s..", profile_name
);
3158 profile_id
= _ppdHashName(selector
);
3160 apple_init_profile(ppd
, NULL
, profile
, profile_id
, cm_choice
->choice
,
3161 cm_choice
->text
, NULL
);
3163 if (cm_choice
->marked
)
3164 default_profile_id
= profile_id
;
3170 * Use the default colorspace...
3173 num_profiles
= 1 + ppd
->colorspace
!= PPD_CS_GRAY
;
3175 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3177 cupsdLogMessage(CUPSD_LOG_ERROR
,
3178 "Unable to allocate memory for %d profiles!",
3184 profiles
->profileCount
= num_profiles
;
3186 apple_init_profile(ppd
, NULL
, profiles
->profiles
, _ppdHashName("Gray.."),
3187 "Gray", "Gray", NULL
);
3189 switch (ppd
->colorspace
)
3193 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1,
3194 _ppdHashName("RGB.."), "RGB", "RGB", NULL
);
3198 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1,
3199 _ppdHashName("CMYK.."), "CMYK", "CMYK", NULL
);
3203 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1,
3204 _ppdHashName("DeviceN.."), "DeviceN", "DeviceN",
3213 if (num_profiles
> 0)
3216 * Make sure we have a default profile ID...
3219 if (!default_profile_id
)
3220 default_profile_id
= profiles
->profiles
[num_profiles
- 1].profileID
;
3223 * Get the device ID hash and pathelogical name dictionary.
3226 cupsdLogMessage(CUPSD_LOG_INFO
, "Registering ICC color profiles for \"%s\"",
3229 device_id
= _ppdHashName(p
->name
);
3230 device_name
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3231 &kCFTypeDictionaryKeyCallBacks
,
3232 &kCFTypeDictionaryValueCallBacks
);
3233 printer_name
= CFStringCreateWithCString(kCFAllocatorDefault
, p
->name
,
3234 kCFStringEncodingUTF8
);
3236 if (device_name
&& printer_name
)
3238 CFDictionarySetValue(device_name
, CFSTR("en"), printer_name
);
3241 * Register the device with ColorSync...
3244 error
= CMRegisterColorDevice(cmPrinterDeviceClass
, device_id
,
3245 device_name
, &scope
);
3248 * Register the profiles...
3252 error
= CMSetDeviceFactoryProfiles(cmPrinterDeviceClass
, device_id
,
3253 default_profile_id
, profiles
);
3263 cupsdLogMessage(CUPSD_LOG_ERROR
,
3264 "Unable to register ICC color profiles for \"%s\" - %d",
3265 p
->name
, (int)error
);
3267 for (profile
= profiles
->profiles
;
3269 profile
++, num_profiles
--)
3270 CFRelease(profile
->profileName
);
3275 CFRelease(printer_name
);
3278 CFRelease(device_name
);
3286 * 'apple_unregister_profiles()' - Remove color profiles for the specified
3291 apple_unregister_profiles(
3292 cupsd_printer_t
*p
) /* I - Printer */
3295 * Make sure ColorSync is available...
3298 if (CMUnregisterColorDevice
!= NULL
)
3299 CMUnregisterColorDevice(cmPrinterDeviceClass
, _ppdHashName(p
->name
));
3301 #endif /* __APPLE__ */
3304 * 'apply_printer_defaults()' - Apply printer default options to a job.
3308 apply_printer_defaults(
3309 cupsd_printer_t
*printer
, /* I - Printer */
3310 cupsd_job_t
*job
) /* I - Job */
3312 int i
, /* Looping var */
3313 num_options
; /* Number of default options */
3314 cups_option_t
*options
, /* Default options */
3315 *option
; /* Current option */
3319 * Collect all of the default options and add the missing ones to the
3323 for (i
= printer
->num_options
, num_options
= 0, option
= printer
->options
;
3326 if (!ippFindAttribute(job
->attrs
, option
->name
, IPP_TAG_ZERO
))
3328 num_options
= cupsAddOption(option
->name
, option
->value
, num_options
,
3333 * Encode these options as attributes in the job object...
3336 cupsEncodeOptions2(job
->attrs
, num_options
, options
, IPP_TAG_JOB
);
3337 cupsFreeOptions(num_options
, options
);
3342 * 'authenticate_job()' - Set job authentication info.
3346 authenticate_job(cupsd_client_t
*con
, /* I - Client connection */
3347 ipp_attribute_t
*uri
) /* I - Job URI */
3349 ipp_attribute_t
*attr
, /* job-id attribute */
3350 *auth_info
; /* auth-info attribute */
3351 int jobid
; /* Job ID */
3352 cupsd_job_t
*job
; /* Current job */
3353 char method
[HTTP_MAX_URI
],
3354 /* Method portion of URI */
3355 username
[HTTP_MAX_URI
],
3356 /* Username portion of URI */
3358 /* Host portion of URI */
3359 resource
[HTTP_MAX_URI
];
3360 /* Resource portion of URI */
3361 int port
; /* Port portion of URI */
3364 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "authenticate_job(%p[%d], %s)",
3365 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
3368 * Start with "everything is OK" status...
3371 con
->response
->request
.status
.status_code
= IPP_OK
;
3374 * See if we have a job URI or a printer URI...
3377 if (!strcmp(uri
->name
, "printer-uri"))
3380 * Got a printer URI; see if we also have a job-id attribute...
3383 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3384 IPP_TAG_INTEGER
)) == NULL
)
3386 send_ipp_status(con
, IPP_BAD_REQUEST
,
3387 _("Got a printer-uri attribute but no job-id!"));
3391 jobid
= attr
->values
[0].integer
;
3396 * Got a job URI; parse it to get the job ID...
3399 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
3400 sizeof(method
), username
, sizeof(username
), host
,
3401 sizeof(host
), &port
, resource
, sizeof(resource
));
3403 if (strncmp(resource
, "/jobs/", 6))
3409 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri attribute \"%s\"!"),
3410 uri
->values
[0].string
.text
);
3414 jobid
= atoi(resource
+ 6);
3418 * See if the job exists...
3421 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3424 * Nope - return a "not found" error...
3427 send_ipp_status(con
, IPP_NOT_FOUND
,
3428 _("Job #%d does not exist!"), jobid
);
3433 * See if the job has been completed...
3436 if (job
->state_value
!= IPP_JOB_HELD
)
3439 * Return a "not-possible" error...
3442 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3443 _("Job #%d is not held for authentication!"),
3449 * See if we have already authenticated...
3452 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
3454 if (!con
->username
[0] && !auth_info
)
3456 cupsd_printer_t
*printer
; /* Job destination */
3460 * No auth data. If we need to authenticate via Kerberos, send a
3461 * HTTP auth challenge, otherwise just return an IPP error...
3464 printer
= cupsdFindDest(job
->dest
);
3466 if (printer
&& printer
->num_auth_info_required
> 0 &&
3467 !strcmp(printer
->auth_info_required
[0], "negotiate"))
3468 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
3470 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
3471 _("No authentication information provided!"));
3476 * See if the job is owned by the requesting user...
3479 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3481 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
3486 * Save the authentication information for this job...
3489 save_auth_info(con
, job
, auth_info
);
3492 * Reset the job-hold-until value to "no-hold"...
3495 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
3496 IPP_TAG_KEYWORD
)) == NULL
)
3497 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
3501 attr
->value_tag
= IPP_TAG_KEYWORD
;
3502 cupsdSetString(&(attr
->values
[0].string
.text
), "no-hold");
3506 * Release the job and return...
3509 cupsdReleaseJob(job
);
3511 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Authenticated by \"%s\".", jobid
,
3517 * 'cancel_all_jobs()' - Cancel all print jobs.
3521 cancel_all_jobs(cupsd_client_t
*con
, /* I - Client connection */
3522 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3524 http_status_t status
; /* Policy status */
3525 cups_ptype_t dtype
; /* Destination type */
3526 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3527 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
3528 hostname
[HTTP_MAX_URI
], /* Host portion of URI */
3529 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3530 int port
; /* Port portion of URI */
3531 ipp_attribute_t
*attr
; /* Attribute in request */
3532 const char *username
; /* Username */
3533 int purge
; /* Purge? */
3534 cupsd_printer_t
*printer
; /* Printer */
3537 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_all_jobs(%p[%d], %s)", con
,
3538 con
->http
.fd
, uri
->values
[0].string
.text
);
3541 * See if we have a printer URI...
3544 if (strcmp(uri
->name
, "printer-uri"))
3546 send_ipp_status(con
, IPP_BAD_REQUEST
,
3547 _("The printer-uri attribute is required!"));
3552 * Get the username (if any) for the jobs we want to cancel (only if
3553 * "my-jobs" is specified...
3556 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
3557 IPP_TAG_BOOLEAN
)) != NULL
&&
3558 attr
->values
[0].boolean
)
3560 if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3561 IPP_TAG_NAME
)) != NULL
)
3562 username
= attr
->values
[0].string
.text
;
3565 send_ipp_status(con
, IPP_BAD_REQUEST
,
3566 _("Missing requesting-user-name attribute!"));
3574 * Look for the "purge-jobs" attribute...
3577 if ((attr
= ippFindAttribute(con
->request
, "purge-jobs",
3578 IPP_TAG_BOOLEAN
)) != NULL
)
3579 purge
= attr
->values
[0].boolean
;
3584 * And if the destination is valid...
3587 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3593 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
,
3594 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
3595 hostname
, sizeof(hostname
), &port
,
3596 resource
, sizeof(resource
));
3598 if ((!strncmp(resource
, "/printers/", 10) && resource
[10]) ||
3599 (!strncmp(resource
, "/classes/", 9) && resource
[9]))
3601 send_ipp_status(con
, IPP_NOT_FOUND
,
3602 _("The printer or class was not found."));
3610 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
3612 send_http_error(con
, status
, NULL
);
3617 * Cancel all jobs on all printers...
3620 cupsdCancelJobs(NULL
, username
, purge
);
3622 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs were %s by \"%s\".",
3623 purge
? "purged" : "canceled", get_username(con
));
3631 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
3634 send_http_error(con
, status
, printer
);
3639 * Cancel all of the jobs on the named printer...
3642 cupsdCancelJobs(printer
->name
, username
, purge
);
3644 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs on \"%s\" were %s by \"%s\".",
3645 printer
->name
, purge
? "purged" : "canceled",
3649 con
->response
->request
.status
.status_code
= IPP_OK
;
3654 * 'cancel_job()' - Cancel a print job.
3658 cancel_job(cupsd_client_t
*con
, /* I - Client connection */
3659 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3661 ipp_attribute_t
*attr
; /* Current attribute */
3662 int jobid
; /* Job ID */
3663 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3664 username
[HTTP_MAX_URI
], /* Username portion of URI */
3665 host
[HTTP_MAX_URI
], /* Host portion of URI */
3666 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3667 int port
; /* Port portion of URI */
3668 cupsd_job_t
*job
; /* Job information */
3669 cups_ptype_t dtype
; /* Destination type (printer/class) */
3670 cupsd_printer_t
*printer
; /* Printer data */
3671 int purge
; /* Purge the job? */
3674 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_job(%p[%d], %s)", con
,
3675 con
->http
.fd
, uri
->values
[0].string
.text
);
3678 * See if we have a job URI or a printer URI...
3681 if (!strcmp(uri
->name
, "printer-uri"))
3684 * Got a printer URI; see if we also have a job-id attribute...
3687 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3688 IPP_TAG_INTEGER
)) == NULL
)
3690 send_ipp_status(con
, IPP_BAD_REQUEST
,
3691 _("Got a printer-uri attribute but no job-id!"));
3695 if ((jobid
= attr
->values
[0].integer
) == 0)
3698 * Find the current job on the specified printer...
3701 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3707 send_ipp_status(con
, IPP_NOT_FOUND
,
3708 _("The printer or class was not found."));
3713 * See if the printer is currently printing a job...
3717 jobid
= ((cupsd_job_t
*)printer
->job
)->id
;
3721 * No, see if there are any pending jobs...
3724 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3726 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3727 if (job
->state_value
<= IPP_JOB_PROCESSING
&&
3728 !strcasecmp(job
->dest
, printer
->name
))
3735 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3737 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3738 if (job
->state_value
== IPP_JOB_STOPPED
&&
3739 !strcasecmp(job
->dest
, printer
->name
))
3746 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("No active jobs on %s!"),
3757 * Got a job URI; parse it to get the job ID...
3760 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
3761 sizeof(scheme
), username
, sizeof(username
), host
,
3762 sizeof(host
), &port
, resource
, sizeof(resource
));
3764 if (strncmp(resource
, "/jobs/", 6))
3770 send_ipp_status(con
, IPP_BAD_REQUEST
,
3771 _("Bad job-uri attribute \"%s\"!"),
3772 uri
->values
[0].string
.text
);
3776 jobid
= atoi(resource
+ 6);
3780 * Look for the "purge-job" attribute...
3783 if ((attr
= ippFindAttribute(con
->request
, "purge-job",
3784 IPP_TAG_BOOLEAN
)) != NULL
)
3785 purge
= attr
->values
[0].boolean
;
3790 * See if the job exists...
3793 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3796 * Nope - return a "not found" error...
3799 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
3804 * See if the job is owned by the requesting user...
3807 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3809 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
3814 * See if the job is already completed, canceled, or aborted; if so,
3815 * we can't cancel...
3818 if (job
->state_value
>= IPP_JOB_CANCELED
&& !purge
)
3820 switch (job
->state_value
)
3822 case IPP_JOB_CANCELED
:
3823 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3824 _("Job #%d is already canceled - can\'t cancel."),
3828 case IPP_JOB_ABORTED
:
3829 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3830 _("Job #%d is already aborted - can\'t cancel."),
3835 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3836 _("Job #%d is already completed - can\'t cancel."),
3845 * Cancel the job and return...
3848 cupsdCancelJob(job
, purge
, IPP_JOB_CANCELED
);
3852 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Purged by \"%s\".", jobid
,
3855 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Canceled by \"%s\".", jobid
,
3858 con
->response
->request
.status
.status_code
= IPP_OK
;
3863 * 'cancel_subscription()' - Cancel a subscription.
3867 cancel_subscription(
3868 cupsd_client_t
*con
, /* I - Client connection */
3869 int sub_id
) /* I - Subscription ID */
3871 http_status_t status
; /* Policy status */
3872 cupsd_subscription_t
*sub
; /* Subscription */
3875 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3876 "cancel_subscription(con=%p[%d], sub_id=%d)",
3877 con
, con
->http
.fd
, sub_id
);
3880 * Is the subscription ID valid?
3883 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
3886 * Bad subscription ID...
3889 send_ipp_status(con
, IPP_NOT_FOUND
,
3890 _("notify-subscription-id %d no good!"), sub_id
);
3898 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
3900 con
, sub
->owner
)) != HTTP_OK
)
3902 send_http_error(con
, status
, sub
->dest
);
3907 * Cancel the subscription...
3910 cupsdDeleteSubscription(sub
, 1);
3912 con
->response
->request
.status
.status_code
= IPP_OK
;
3917 * 'check_quotas()' - Check quotas for a printer and user.
3920 static int /* O - 1 if OK, 0 if not */
3921 check_quotas(cupsd_client_t
*con
, /* I - Client connection */
3922 cupsd_printer_t
*p
) /* I - Printer or class */
3924 int i
; /* Looping var */
3925 char username
[33]; /* Username */
3926 cupsd_quota_t
*q
; /* Quota data */
3927 #ifdef HAVE_MBR_UID_TO_UUID
3929 * Use Apple membership APIs which require that all names represent
3930 * valid user account or group records accessible by the server.
3933 uuid_t usr_uuid
; /* UUID for job requesting user */
3934 uuid_t usr2_uuid
; /* UUID for ACL user name entry */
3935 uuid_t grp_uuid
; /* UUID for ACL group name entry */
3936 int mbr_err
; /* Error from membership function */
3937 int is_member
; /* Is this user a member? */
3940 * Use standard POSIX APIs for checking users and groups...
3943 struct passwd
*pw
; /* User password data */
3944 #endif /* HAVE_MBR_UID_TO_UUID */
3947 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "check_quotas(%p[%d], %p[%s])",
3948 con
, con
->http
.fd
, p
, p
->name
);
3951 * Figure out who is printing...
3954 strlcpy(username
, get_username(con
), sizeof(username
));
3957 * Check global active job limits for printers and users...
3960 if (MaxJobsPerPrinter
)
3963 * Check if there are too many pending jobs on this printer...
3966 if (cupsdGetPrinterJobCount(p
->name
) >= MaxJobsPerPrinter
)
3968 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for printer \"%s\"...",
3977 * Check if there are too many pending jobs for this user...
3980 if (cupsdGetUserJobCount(username
) >= MaxJobsPerUser
)
3982 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for user \"%s\"...",
3989 * Check against users...
3992 if (p
->num_users
== 0 && p
->k_limit
== 0 && p
->page_limit
== 0)
3997 #ifdef HAVE_MBR_UID_TO_UUID
3999 * Get UUID for job requesting user...
4002 if (mbr_user_name_to_uuid((char *)username
, usr_uuid
))
4008 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4009 "check_quotas: UUID lookup failed for user \"%s\"",
4011 cupsdLogMessage(CUPSD_LOG_INFO
,
4012 "Denying user \"%s\" access to printer \"%s\" "
4013 "(unknown user)...",
4019 * Get UID and GID of requesting user...
4022 pw
= getpwnam(username
);
4024 #endif /* HAVE_MBR_UID_TO_UUID */
4026 for (i
= 0; i
< p
->num_users
; i
++)
4027 if (p
->users
[i
][0] == '@')
4030 * Check group membership...
4033 #ifdef HAVE_MBR_UID_TO_UUID
4034 if ((mbr_err
= mbr_group_name_to_uuid((char *)p
->users
[i
] + 1,
4038 * Invalid ACL entries are ignored for matching; just record a
4039 * warning in the log...
4042 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4043 "check_quotas: UUID lookup failed for ACL entry "
4044 "\"%s\" (err=%d)", p
->users
[i
], mbr_err
);
4045 cupsdLogMessage(CUPSD_LOG_WARN
,
4046 "Access control entry \"%s\" not a valid group name; "
4047 "entry ignored", p
->users
[i
]);
4051 if ((mbr_err
= mbr_check_membership(usr_uuid
, grp_uuid
,
4055 * At this point, there should be no errors, but check anyways...
4058 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4059 "check_quotas: group \"%s\" membership check "
4060 "failed (err=%d)", p
->users
[i
] + 1, mbr_err
);
4065 * Stop if we found a match...
4072 if (cupsdCheckGroup(username
, pw
, p
->users
[i
] + 1))
4074 #endif /* HAVE_MBR_UID_TO_UUID */
4076 #ifdef HAVE_MBR_UID_TO_UUID
4079 if ((mbr_err
= mbr_user_name_to_uuid((char *)p
->users
[i
],
4083 * Invalid ACL entries are ignored for matching; just record a
4084 * warning in the log...
4087 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4088 "check_quotas: UUID lookup failed for ACL entry "
4089 "\"%s\" (err=%d)", p
->users
[i
], mbr_err
);
4090 cupsdLogMessage(CUPSD_LOG_WARN
,
4091 "Access control entry \"%s\" not a valid user name; "
4092 "entry ignored", p
->users
[i
]);
4096 if ((mbr_err
= mbr_check_membership(usr_uuid
, usr2_uuid
,
4099 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4100 "check_quotas: User \"%s\" identity check failed "
4101 "(err=%d)", p
->users
[i
], mbr_err
);
4110 else if (!strcasecmp(username
, p
->users
[i
]))
4112 #endif /* HAVE_MBR_UID_TO_UUID */
4114 if ((i
< p
->num_users
) == p
->deny_users
)
4116 cupsdLogMessage(CUPSD_LOG_INFO
,
4117 "Denying user \"%s\" access to printer \"%s\"...",
4128 if (AppleQuotas
&& (q
= cupsdFindQuota(p
, username
)) != NULL
)
4131 * TODO: Define these special page count values as constants!
4134 if (q
->page_count
== -4) /* special case: unlimited user */
4136 cupsdLogMessage(CUPSD_LOG_INFO
,
4137 "User \"%s\" request approved for printer %s (%s): "
4139 username
, p
->name
, p
->info
);
4140 q
->page_count
= 0; /* allow user to print */
4143 else if (q
->page_count
== -3) /* quota exceeded */
4145 cupsdLogMessage(CUPSD_LOG_INFO
,
4146 "User \"%s\" request denied for printer %s (%s): "
4147 "quota limit exceeded.",
4148 username
, p
->name
, p
->info
);
4149 q
->page_count
= 2; /* force quota exceeded failure */
4152 else if (q
->page_count
== -2) /* quota disabled for user */
4154 cupsdLogMessage(CUPSD_LOG_INFO
,
4155 "User \"%s\" request denied for printer %s (%s): "
4156 "printing disabled for user.",
4157 username
, p
->name
, p
->info
);
4158 q
->page_count
= 2; /* force quota exceeded failure */
4161 else if (q
->page_count
== -1) /* quota access error */
4163 cupsdLogMessage(CUPSD_LOG_INFO
,
4164 "User \"%s\" request denied for printer %s (%s): "
4165 "unable to determine quota limit.",
4166 username
, p
->name
, p
->info
);
4167 q
->page_count
= 2; /* force quota exceeded failure */
4170 else if (q
->page_count
< 0) /* user not found or other error */
4172 cupsdLogMessage(CUPSD_LOG_INFO
,
4173 "User \"%s\" request denied for printer %s (%s): "
4174 "user disabled / missing quota.",
4175 username
, p
->name
, p
->info
);
4176 q
->page_count
= 2; /* force quota exceeded failure */
4179 else /* page within user limits */
4181 q
->page_count
= 0; /* allow user to print */
4186 #endif /* __APPLE__ */
4187 if (p
->k_limit
|| p
->page_limit
)
4189 if ((q
= cupsdUpdateQuota(p
, username
, 0, 0)) == NULL
)
4191 cupsdLogMessage(CUPSD_LOG_ERROR
,
4192 "Unable to allocate quota data for user \"%s\"!",
4197 if ((q
->k_count
>= p
->k_limit
&& p
->k_limit
) ||
4198 (q
->page_count
>= p
->page_limit
&& p
->page_limit
))
4200 cupsdLogMessage(CUPSD_LOG_INFO
, "User \"%s\" is over the quota limit...",
4207 * If we have gotten this far, we're done!
4215 * 'copy_attribute()' - Copy a single attribute.
4218 static ipp_attribute_t
* /* O - New attribute */
4220 ipp_t
*to
, /* O - Destination request/response */
4221 ipp_attribute_t
*attr
, /* I - Attribute to copy */
4222 int quickcopy
) /* I - Do a quick copy? */
4224 int i
; /* Looping var */
4225 ipp_attribute_t
*toattr
; /* Destination attribute */
4228 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4229 "copy_attribute(%p, %p[%s,%x,%x])", to
, attr
,
4230 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
4233 switch (attr
->value_tag
& ~IPP_TAG_COPY
)
4236 toattr
= ippAddSeparator(to
);
4239 case IPP_TAG_INTEGER
:
4241 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
4242 attr
->name
, attr
->num_values
, NULL
);
4244 for (i
= 0; i
< attr
->num_values
; i
++)
4245 toattr
->values
[i
].integer
= attr
->values
[i
].integer
;
4248 case IPP_TAG_BOOLEAN
:
4249 toattr
= ippAddBooleans(to
, attr
->group_tag
, attr
->name
,
4250 attr
->num_values
, NULL
);
4252 for (i
= 0; i
< attr
->num_values
; i
++)
4253 toattr
->values
[i
].boolean
= attr
->values
[i
].boolean
;
4256 case IPP_TAG_STRING
:
4259 case IPP_TAG_KEYWORD
:
4261 case IPP_TAG_URISCHEME
:
4262 case IPP_TAG_CHARSET
:
4263 case IPP_TAG_LANGUAGE
:
4264 case IPP_TAG_MIMETYPE
:
4265 toattr
= ippAddStrings(to
, attr
->group_tag
,
4266 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
4267 attr
->name
, attr
->num_values
, NULL
, NULL
);
4271 for (i
= 0; i
< attr
->num_values
; i
++)
4272 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
4276 for (i
= 0; i
< attr
->num_values
; i
++)
4277 toattr
->values
[i
].string
.text
=
4278 _cupsStrAlloc(attr
->values
[i
].string
.text
);
4283 toattr
= ippAddDate(to
, attr
->group_tag
, attr
->name
,
4284 attr
->values
[0].date
);
4287 case IPP_TAG_RESOLUTION
:
4288 toattr
= ippAddResolutions(to
, attr
->group_tag
, attr
->name
,
4289 attr
->num_values
, IPP_RES_PER_INCH
,
4292 for (i
= 0; i
< attr
->num_values
; i
++)
4294 toattr
->values
[i
].resolution
.xres
= attr
->values
[i
].resolution
.xres
;
4295 toattr
->values
[i
].resolution
.yres
= attr
->values
[i
].resolution
.yres
;
4296 toattr
->values
[i
].resolution
.units
= attr
->values
[i
].resolution
.units
;
4300 case IPP_TAG_RANGE
:
4301 toattr
= ippAddRanges(to
, attr
->group_tag
, attr
->name
,
4302 attr
->num_values
, NULL
, NULL
);
4304 for (i
= 0; i
< attr
->num_values
; i
++)
4306 toattr
->values
[i
].range
.lower
= attr
->values
[i
].range
.lower
;
4307 toattr
->values
[i
].range
.upper
= attr
->values
[i
].range
.upper
;
4311 case IPP_TAG_TEXTLANG
:
4312 case IPP_TAG_NAMELANG
:
4313 toattr
= ippAddStrings(to
, attr
->group_tag
,
4314 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
4315 attr
->name
, attr
->num_values
, NULL
, NULL
);
4319 for (i
= 0; i
< attr
->num_values
; i
++)
4321 toattr
->values
[i
].string
.charset
= attr
->values
[i
].string
.charset
;
4322 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
4327 for (i
= 0; i
< attr
->num_values
; i
++)
4330 toattr
->values
[i
].string
.charset
=
4331 _cupsStrAlloc(attr
->values
[i
].string
.charset
);
4333 toattr
->values
[i
].string
.charset
=
4334 toattr
->values
[0].string
.charset
;
4336 toattr
->values
[i
].string
.text
=
4337 _cupsStrAlloc(attr
->values
[i
].string
.text
);
4342 case IPP_TAG_BEGIN_COLLECTION
:
4343 toattr
= ippAddCollections(to
, attr
->group_tag
, attr
->name
,
4344 attr
->num_values
, NULL
);
4346 for (i
= 0; i
< attr
->num_values
; i
++)
4348 toattr
->values
[i
].collection
= ippNew();
4349 copy_attrs(toattr
->values
[i
].collection
, attr
->values
[i
].collection
,
4350 NULL
, IPP_TAG_ZERO
, 0);
4355 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
4356 attr
->name
, attr
->num_values
, NULL
);
4358 for (i
= 0; i
< attr
->num_values
; i
++)
4360 toattr
->values
[i
].unknown
.length
= attr
->values
[i
].unknown
.length
;
4362 if (toattr
->values
[i
].unknown
.length
> 0)
4364 if ((toattr
->values
[i
].unknown
.data
=
4365 malloc(toattr
->values
[i
].unknown
.length
)) == NULL
)
4366 toattr
->values
[i
].unknown
.length
= 0;
4368 memcpy(toattr
->values
[i
].unknown
.data
,
4369 attr
->values
[i
].unknown
.data
,
4370 toattr
->values
[i
].unknown
.length
);
4373 break; /* anti-compiler-warning-code */
4381 * 'copy_attrs()' - Copy attributes from one request to another.
4385 copy_attrs(ipp_t
*to
, /* I - Destination request */
4386 ipp_t
*from
, /* I - Source request */
4387 cups_array_t
*ra
, /* I - Requested attributes */
4388 ipp_tag_t group
, /* I - Group to copy */
4389 int quickcopy
) /* I - Do a quick copy? */
4391 ipp_attribute_t
*fromattr
; /* Source attribute */
4394 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4395 "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)",
4396 to
, from
, ra
, group
, quickcopy
);
4401 for (fromattr
= from
->attrs
; fromattr
; fromattr
= fromattr
->next
)
4404 * Filter attributes as needed...
4407 if ((group
!= IPP_TAG_ZERO
&& fromattr
->group_tag
!= group
&&
4408 fromattr
->group_tag
!= IPP_TAG_ZERO
) || !fromattr
->name
)
4411 if (!ra
|| cupsArrayFind(ra
, fromattr
->name
))
4412 copy_attribute(to
, fromattr
, quickcopy
);
4418 * 'copy_banner()' - Copy a banner file to the requests directory for the
4422 static int /* O - Size of banner file in kbytes */
4423 copy_banner(cupsd_client_t
*con
, /* I - Client connection */
4424 cupsd_job_t
*job
, /* I - Job information */
4425 const char *name
) /* I - Name of banner */
4427 int i
; /* Looping var */
4428 int kbytes
; /* Size of banner file in kbytes */
4429 char filename
[1024]; /* Job filename */
4430 cupsd_banner_t
*banner
; /* Pointer to banner */
4431 cups_file_t
*in
; /* Input file */
4432 cups_file_t
*out
; /* Output file */
4433 int ch
; /* Character from file */
4434 char attrname
[255], /* Name of attribute */
4435 *s
; /* Pointer into name */
4436 ipp_attribute_t
*attr
; /* Attribute */
4439 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_banner(%p[%d], %p[%d], %s)",
4440 con
, con
? con
->http
.fd
: -1, job
, job
->id
,
4441 name
? name
: "(null)");
4444 * Find the banner; return if not found or "none"...
4447 if (!name
|| !strcmp(name
, "none") ||
4448 (banner
= cupsdFindBanner(name
)) == NULL
)
4452 * Open the banner and job files...
4455 if (add_file(con
, job
, banner
->filetype
, 0))
4458 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
4460 if ((out
= cupsFileOpen(filename
, "w")) == NULL
)
4462 cupsdLogMessage(CUPSD_LOG_ERROR
,
4463 "copy_banner: Unable to create banner job file %s - %s",
4464 filename
, strerror(errno
));
4469 fchmod(cupsFileNumber(out
), 0640);
4470 fchown(cupsFileNumber(out
), RunUser
, Group
);
4473 * Try the localized banner file under the subdirectory...
4476 strlcpy(attrname
, job
->attrs
->attrs
->next
->values
[0].string
.text
,
4478 if (strlen(attrname
) > 2 && attrname
[2] == '-')
4481 * Convert ll-cc to ll_CC...
4485 attrname
[3] = toupper(attrname
[3] & 255);
4486 attrname
[4] = toupper(attrname
[4] & 255);
4489 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4492 if (access(filename
, 0) && strlen(attrname
) > 2)
4495 * Wasn't able to find "ll_CC" locale file; try the non-national
4496 * localization banner directory.
4501 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4505 if (access(filename
, 0))
4508 * Use the non-localized banner file.
4511 snprintf(filename
, sizeof(filename
), "%s/banners/%s", DataDir
, name
);
4514 if ((in
= cupsFileOpen(filename
, "r")) == NULL
)
4518 cupsdLogMessage(CUPSD_LOG_ERROR
,
4519 "copy_banner: Unable to open banner template file %s - %s",
4520 filename
, strerror(errno
));
4526 * Parse the file to the end...
4529 while ((ch
= cupsFileGetChar(in
)) != EOF
)
4533 * Get an attribute name...
4536 for (s
= attrname
; (ch
= cupsFileGetChar(in
)) != EOF
;)
4537 if (!isalpha(ch
& 255) && ch
!= '-' && ch
!= '?')
4539 else if (s
< (attrname
+ sizeof(attrname
) - 1))
4549 * Ignore { followed by stuff that is not an attribute name...
4552 cupsFilePrintf(out
, "{%s%c", attrname
, ch
);
4557 * See if it is defined...
4560 if (attrname
[0] == '?')
4565 if (!strcmp(s
, "printer-name"))
4567 cupsFilePuts(out
, job
->dest
);
4570 else if ((attr
= ippFindAttribute(job
->attrs
, s
, IPP_TAG_ZERO
)) == NULL
)
4573 * See if we have a leading question mark...
4576 if (attrname
[0] != '?')
4579 * Nope, write to file as-is; probably a PostScript procedure...
4582 cupsFilePrintf(out
, "{%s}", attrname
);
4589 * Output value(s)...
4592 for (i
= 0; i
< attr
->num_values
; i
++)
4595 cupsFilePutChar(out
, ',');
4597 switch (attr
->value_tag
)
4599 case IPP_TAG_INTEGER
:
4601 if (!strncmp(s
, "time-at-", 8))
4602 cupsFilePuts(out
, cupsdGetDateTime(attr
->values
[i
].integer
));
4604 cupsFilePrintf(out
, "%d", attr
->values
[i
].integer
);
4607 case IPP_TAG_BOOLEAN
:
4608 cupsFilePrintf(out
, "%d", attr
->values
[i
].boolean
);
4611 case IPP_TAG_NOVALUE
:
4612 cupsFilePuts(out
, "novalue");
4615 case IPP_TAG_RANGE
:
4616 cupsFilePrintf(out
, "%d-%d", attr
->values
[i
].range
.lower
,
4617 attr
->values
[i
].range
.upper
);
4620 case IPP_TAG_RESOLUTION
:
4621 cupsFilePrintf(out
, "%dx%d%s", attr
->values
[i
].resolution
.xres
,
4622 attr
->values
[i
].resolution
.yres
,
4623 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
4628 case IPP_TAG_STRING
:
4631 case IPP_TAG_KEYWORD
:
4632 case IPP_TAG_CHARSET
:
4633 case IPP_TAG_LANGUAGE
:
4634 if (!strcasecmp(banner
->filetype
->type
, "postscript"))
4637 * Need to quote strings for PS banners...
4642 for (p
= attr
->values
[i
].string
.text
; *p
; p
++)
4644 if (*p
== '(' || *p
== ')' || *p
== '\\')
4646 cupsFilePutChar(out
, '\\');
4647 cupsFilePutChar(out
, *p
);
4649 else if (*p
< 32 || *p
> 126)
4650 cupsFilePrintf(out
, "\\%03o", *p
& 255);
4652 cupsFilePutChar(out
, *p
);
4656 cupsFilePuts(out
, attr
->values
[i
].string
.text
);
4660 break; /* anti-compiler-warning-code */
4664 else if (ch
== '\\') /* Quoted char */
4666 ch
= cupsFileGetChar(in
);
4668 if (ch
!= '{') /* Only do special handling for \{ */
4669 cupsFilePutChar(out
, '\\');
4671 cupsFilePutChar(out
, ch
);
4674 cupsFilePutChar(out
, ch
);
4678 kbytes
= (cupsFileTell(out
) + 1023) / 1024;
4680 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
4681 IPP_TAG_INTEGER
)) != NULL
)
4682 attr
->values
[0].integer
+= kbytes
;
4691 * 'copy_file()' - Copy a PPD file or interface script...
4694 static int /* O - 0 = success, -1 = error */
4695 copy_file(const char *from
, /* I - Source file */
4696 const char *to
) /* I - Destination file */
4698 cups_file_t
*src
, /* Source file */
4699 *dst
; /* Destination file */
4700 int bytes
; /* Bytes to read/write */
4701 char buffer
[2048]; /* Copy buffer */
4704 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_file(\"%s\", \"%s\")", from
, to
);
4707 * Open the source and destination file for a copy...
4710 if ((src
= cupsFileOpen(from
, "rb")) == NULL
)
4713 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
4720 * Copy the source file to the destination...
4723 while ((bytes
= cupsFileRead(src
, buffer
, sizeof(buffer
))) > 0)
4724 if (cupsFileWrite(dst
, buffer
, bytes
) < bytes
)
4732 * Close both files and return...
4737 return (cupsFileClose(dst
));
4742 * 'copy_model()' - Copy a PPD model file, substituting default values
4746 static int /* O - 0 = success, -1 = error */
4747 copy_model(cupsd_client_t
*con
, /* I - Client connection */
4748 const char *from
, /* I - Source file */
4749 const char *to
) /* I - Destination file */
4751 fd_set input
; /* select() input set */
4752 struct timeval timeout
; /* select() timeout */
4753 int maxfd
; /* Max file descriptor for select() */
4754 char tempfile
[1024]; /* Temporary PPD file */
4755 int tempfd
; /* Temporary PPD file descriptor */
4756 int temppid
; /* Process ID of cups-driverd */
4757 int temppipe
[2]; /* Temporary pipes */
4758 char *argv
[4], /* Command-line arguments */
4759 *envp
[MAX_ENV
]; /* Environment */
4760 cups_file_t
*src
, /* Source file */
4761 *dst
; /* Destination file */
4762 ppd_file_t
*ppd
; /* PPD file */
4763 int bytes
, /* Bytes from pipe */
4764 total
; /* Total bytes from pipe */
4765 char buffer
[2048]; /* Copy buffer */
4766 int i
; /* Looping var */
4767 char option
[PPD_MAX_NAME
], /* Option name */
4768 choice
[PPD_MAX_NAME
]; /* Choice name */
4769 int num_defaults
; /* Number of default options */
4770 cups_option_t
*defaults
; /* Default options */
4771 char cups_protocol
[PPD_MAX_LINE
];
4772 /* cupsProtocol attribute */
4773 int have_letter
, /* Have Letter size */
4774 have_a4
; /* Have A4 size */
4775 #ifdef HAVE_LIBPAPER
4776 char *paper_result
; /* Paper size name from libpaper */
4777 char system_paper
[64]; /* Paper size name buffer */
4778 #endif /* HAVE_LIBPAPER */
4781 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4782 "copy_model(con=%p, from=\"%s\", to=\"%s\")",
4786 * Run cups-driverd to get the PPD file...
4789 argv
[0] = "cups-driverd";
4791 argv
[2] = (char *)from
;
4794 cupsdLoadEnv(envp
, (int)(sizeof(envp
) / sizeof(envp
[0])));
4796 snprintf(buffer
, sizeof(buffer
), "%s/daemon/cups-driverd", ServerBin
);
4797 snprintf(tempfile
, sizeof(tempfile
), "%s/%d.ppd", TempDir
, con
->http
.fd
);
4798 tempfd
= open(tempfile
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
4802 cupsdOpenPipe(temppipe
);
4804 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4805 "copy_model: Running \"cups-driverd cat %s\"...", from
);
4807 if (!cupsdStartProcess(buffer
, argv
, envp
, -1, temppipe
[1], CGIPipes
[1],
4808 -1, -1, 0, DefaultProfile
, &temppid
))
4819 * Wait up to 30 seconds for the PPD file to be copied...
4824 if (temppipe
[0] > CGIPipes
[0])
4825 maxfd
= temppipe
[0] + 1;
4827 maxfd
= CGIPipes
[0] + 1;
4832 * See if we have data ready...
4838 FD_SET(temppipe
[0], &input
);
4839 FD_SET(CGIPipes
[0], &input
);
4841 timeout
.tv_sec
= 30;
4842 timeout
.tv_usec
= 0;
4844 if ((i
= select(maxfd
, &input
, NULL
, NULL
, &timeout
)) < 0)
4854 * We have timed out...
4860 if (FD_ISSET(temppipe
[0], &input
))
4863 * Read the PPD file from the pipe, and write it to the PPD file.
4866 if ((bytes
= read(temppipe
[0], buffer
, sizeof(buffer
))) > 0)
4868 if (write(tempfd
, buffer
, bytes
) < bytes
)
4877 if (FD_ISSET(CGIPipes
[0], &input
))
4887 * No data from cups-deviced...
4890 cupsdLogMessage(CUPSD_LOG_ERROR
, "copy_model: empty PPD file!");
4896 * Read the source file and see what page sizes are supported...
4899 if ((ppd
= ppdOpenFile(tempfile
)) == NULL
)
4905 have_letter
= ppdPageSize(ppd
, "Letter") != NULL
;
4906 have_a4
= ppdPageSize(ppd
, "A4") != NULL
;
4909 * Open the destination (if possible) and set the default options...
4914 cups_protocol
[0] = '\0';
4916 if ((dst
= cupsFileOpen(to
, "rb")) != NULL
)
4919 * Read all of the default lines from the old PPD...
4922 while (cupsFileGets(dst
, buffer
, sizeof(buffer
)))
4923 if (!strncmp(buffer
, "*Default", 8))
4926 * Add the default option...
4929 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
4930 choice
, sizeof(choice
)))
4932 ppd_option_t
*ppdo
; /* PPD option */
4936 * Only add the default if the default hasn't already been
4937 * set and the choice exists in the new PPD...
4940 if (!cupsGetOption(option
, num_defaults
, defaults
) &&
4941 (ppdo
= ppdFindOption(ppd
, option
)) != NULL
&&
4942 ppdFindChoice(ppdo
, choice
))
4943 num_defaults
= cupsAddOption(option
, choice
, num_defaults
,
4947 else if (!strncmp(buffer
, "*cupsProtocol:", 14))
4948 strlcpy(cups_protocol
, buffer
, sizeof(cups_protocol
));
4952 #ifdef HAVE_LIBPAPER
4953 else if ((paper_result
= systempapername()) != NULL
)
4956 * Set the default media sizes from the systemwide default...
4959 strlcpy(system_paper
, paper_result
, sizeof(system_paper
));
4960 system_paper
[0] = toupper(system_paper
[0] & 255);
4962 if ((!strcmp(system_paper
, "Letter") && have_letter
) ||
4963 (!strcmp(system_paper
, "A4") && have_a4
))
4965 num_defaults
= cupsAddOption("PageSize", system_paper
,
4966 num_defaults
, &defaults
);
4967 num_defaults
= cupsAddOption("PageRegion", system_paper
,
4968 num_defaults
, &defaults
);
4969 num_defaults
= cupsAddOption("PaperDimension", system_paper
,
4970 num_defaults
, &defaults
);
4971 num_defaults
= cupsAddOption("ImageableArea", system_paper
,
4972 num_defaults
, &defaults
);
4975 #endif /* HAVE_LIBPAPER */
4979 * Add the default media sizes...
4981 * Note: These values are generally not valid for large-format devices
4982 * like plotters, however it is probably safe to say that those
4983 * users will configure the media size after initially adding
4984 * the device anyways...
4987 if (!DefaultLanguage
||
4988 !strcasecmp(DefaultLanguage
, "C") ||
4989 !strcasecmp(DefaultLanguage
, "POSIX") ||
4990 !strcasecmp(DefaultLanguage
, "en") ||
4991 !strncasecmp(DefaultLanguage
, "en.", 3) ||
4992 !strncasecmp(DefaultLanguage
, "en_US", 5) ||
4993 !strncasecmp(DefaultLanguage
, "en_CA", 5) ||
4994 !strncasecmp(DefaultLanguage
, "fr_CA", 5))
4997 * These are the only locales that will default to "letter" size...
5002 num_defaults
= cupsAddOption("PageSize", "Letter", num_defaults
,
5004 num_defaults
= cupsAddOption("PageRegion", "Letter", num_defaults
,
5006 num_defaults
= cupsAddOption("PaperDimension", "Letter", num_defaults
,
5008 num_defaults
= cupsAddOption("ImageableArea", "Letter", num_defaults
,
5015 * The rest default to "a4" size...
5018 num_defaults
= cupsAddOption("PageSize", "A4", num_defaults
,
5020 num_defaults
= cupsAddOption("PageRegion", "A4", num_defaults
,
5022 num_defaults
= cupsAddOption("PaperDimension", "A4", num_defaults
,
5024 num_defaults
= cupsAddOption("ImageableArea", "A4", num_defaults
,
5032 * Open the source file for a copy...
5035 if ((src
= cupsFileOpen(tempfile
, "rb")) == NULL
)
5037 cupsFreeOptions(num_defaults
, defaults
);
5043 * Open the destination file for a copy...
5046 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
5048 cupsFreeOptions(num_defaults
, defaults
);
5055 * Copy the source file to the destination...
5058 while (cupsFileGets(src
, buffer
, sizeof(buffer
)))
5060 if (!strncmp(buffer
, "*Default", 8))
5063 * Check for an previous default option choice...
5066 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
5067 choice
, sizeof(choice
)))
5069 const char *val
; /* Default option value */
5072 if ((val
= cupsGetOption(option
, num_defaults
, defaults
)) != NULL
)
5075 * Substitute the previous choice...
5078 snprintf(buffer
, sizeof(buffer
), "*Default%s: %s", option
, val
);
5083 cupsFilePrintf(dst
, "%s\n", buffer
);
5086 if (cups_protocol
[0])
5087 cupsFilePrintf(dst
, "%s\n", cups_protocol
);
5089 cupsFreeOptions(num_defaults
, defaults
);
5092 * Close both files and return...
5099 return (cupsFileClose(dst
));
5104 * 'copy_job_attrs()' - Copy job attributes.
5108 copy_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
5109 cupsd_job_t
*job
, /* I - Job */
5110 cups_array_t
*ra
) /* I - Requested attributes array */
5112 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
5116 * Send the requested attributes for each job...
5119 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
5120 con
->servername
, con
->serverport
, "/jobs/%d",
5123 if (!ra
|| cupsArrayFind(ra
, "document-count"))
5124 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5125 "document-count", job
->num_files
);
5127 if (!ra
|| cupsArrayFind(ra
, "job-more-info"))
5128 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5129 "job-more-info", NULL
, job_uri
);
5131 if (job
->state_value
> IPP_JOB_PROCESSING
&&
5132 (!ra
|| cupsArrayFind(ra
, "job-preserved")))
5133 ippAddBoolean(con
->response
, IPP_TAG_JOB
, "job-preserved",
5134 job
->num_files
> 0);
5136 if (!ra
|| cupsArrayFind(ra
, "job-printer-up-time"))
5137 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5138 "job-printer-up-time", time(NULL
));
5140 if (!ra
|| cupsArrayFind(ra
, "job-state-reasons"))
5141 add_job_state_reasons(con
, job
);
5143 if (!ra
|| cupsArrayFind(ra
, "job-uri"))
5144 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5145 "job-uri", NULL
, job_uri
);
5147 copy_attrs(con
->response
, job
->attrs
, ra
, IPP_TAG_JOB
, 0);
5152 * 'copy_printer_attrs()' - Copy printer attributes.
5157 cupsd_client_t
*con
, /* I - Client connection */
5158 cupsd_printer_t
*printer
, /* I - Printer */
5159 cups_array_t
*ra
) /* I - Requested attributes array */
5161 char printer_uri
[HTTP_MAX_URI
];
5163 time_t curtime
; /* Current time */
5164 int i
; /* Looping var */
5165 ipp_attribute_t
*history
; /* History collection */
5169 * Copy the printer attributes to the response using requested-attributes
5170 * and document-format attributes that may be provided by the client.
5173 curtime
= time(NULL
);
5176 if ((!ra
|| cupsArrayFind(ra
, "com.apple.print.recoverable-message")) &&
5177 printer
->recoverable
)
5178 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5179 "com.apple.print.recoverable-message", NULL
,
5180 printer
->recoverable
);
5181 #endif /* __APPLE__ */
5183 if (!ra
|| cupsArrayFind(ra
, "marker-change-time"))
5184 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5185 "marker-change-time", printer
->marker_time
);
5187 if (printer
->alert
&& (!ra
|| cupsArrayFind(ra
, "printer-alert")))
5188 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_STRING
,
5189 "printer-alert", NULL
, printer
->alert
);
5191 if (printer
->alert_description
&&
5192 (!ra
|| cupsArrayFind(ra
, "printer-alert-description")))
5193 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5194 "printer-alert-description", NULL
,
5195 printer
->alert_description
);
5197 if (!ra
|| cupsArrayFind(ra
, "printer-current-time"))
5198 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-current-time",
5199 ippTimeToDate(curtime
));
5202 if (!ra
|| cupsArrayFind(ra
, "printer-dns-sd-name"))
5204 if (printer
->reg_name
)
5205 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5206 "printer-dns-sd-name", NULL
, printer
->reg_name
);
5208 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
5209 "printer-dns-sd-name", 0);
5211 #endif /* HAVE_DNSSD */
5213 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy"))
5214 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5215 "printer-error-policy", NULL
, printer
->error_policy
);
5217 if (!ra
|| cupsArrayFind(ra
, "printer-is-accepting-jobs"))
5218 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
5219 printer
->accepting
);
5221 if (!ra
|| cupsArrayFind(ra
, "printer-is-shared"))
5222 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-shared",
5225 if (!ra
|| cupsArrayFind(ra
, "printer-op-policy"))
5226 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5227 "printer-op-policy", NULL
, printer
->op_policy
);
5229 if (!ra
|| cupsArrayFind(ra
, "printer-state"))
5230 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
5233 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-time"))
5234 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5235 "printer-state-change-time", printer
->state_time
);
5237 if (MaxPrinterHistory
> 0 && printer
->num_history
> 0 &&
5238 cupsArrayFind(ra
, "printer-state-history"))
5241 * Printer history is only sent if specifically requested, so that
5242 * older CUPS/IPP clients won't barf on the collection attributes.
5245 history
= ippAddCollections(con
->response
, IPP_TAG_PRINTER
,
5246 "printer-state-history",
5247 printer
->num_history
, NULL
);
5249 for (i
= 0; i
< printer
->num_history
; i
++)
5250 copy_attrs(history
->values
[i
].collection
= ippNew(), printer
->history
[i
],
5251 NULL
, IPP_TAG_ZERO
, 0);
5254 if (!ra
|| cupsArrayFind(ra
, "printer-state-message"))
5255 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5256 "printer-state-message", NULL
, printer
->state_message
);
5258 if (!ra
|| cupsArrayFind(ra
, "printer-state-reasons"))
5259 add_printer_state_reasons(con
, printer
);
5261 if (!ra
|| cupsArrayFind(ra
, "printer-type"))
5263 int type
; /* printer-type value */
5267 * Add the CUPS-specific printer-type attribute...
5270 type
= printer
->type
;
5272 if (printer
== DefaultPrinter
)
5273 type
|= CUPS_PRINTER_DEFAULT
;
5275 if (!printer
->accepting
)
5276 type
|= CUPS_PRINTER_REJECTING
;
5278 if (!printer
->shared
)
5279 type
|= CUPS_PRINTER_NOT_SHARED
;
5281 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-type",
5285 if (!ra
|| cupsArrayFind(ra
, "printer-up-time"))
5286 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5287 "printer-up-time", curtime
);
5289 if ((!ra
|| cupsArrayFind(ra
, "printer-uri-supported")) &&
5290 !ippFindAttribute(printer
->attrs
, "printer-uri-supported",
5293 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5294 "ipp", NULL
, con
->servername
, con
->serverport
,
5295 (printer
->type
& CUPS_PRINTER_CLASS
) ?
5296 "/classes/%s" : "/printers/%s", printer
->name
);
5297 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5298 "printer-uri-supported", NULL
, printer_uri
);
5299 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-uri-supported=\"%s\"",
5303 if (!ra
|| cupsArrayFind(ra
, "queued-job-count"))
5304 add_queued_job_count(con
, printer
);
5306 copy_attrs(con
->response
, printer
->attrs
, ra
, IPP_TAG_ZERO
, 0);
5307 copy_attrs(con
->response
, CommonData
, ra
, IPP_TAG_ZERO
, IPP_TAG_COPY
);
5312 * 'copy_subscription_attrs()' - Copy subscription attributes.
5316 copy_subscription_attrs(
5317 cupsd_client_t
*con
, /* I - Client connection */
5318 cupsd_subscription_t
*sub
, /* I - Subscription */
5319 cups_array_t
*ra
) /* I - Requested attributes array */
5321 ipp_attribute_t
*attr
; /* Current attribute */
5322 char printer_uri
[HTTP_MAX_URI
];
5324 int count
; /* Number of events */
5325 unsigned mask
; /* Current event mask */
5326 const char *name
; /* Current event name */
5330 * Copy the subscription attributes to the response using the
5331 * requested-attributes attribute that may be provided by the client.
5334 if (!ra
|| cupsArrayFind(ra
, "notify-events"))
5336 if ((name
= cupsdEventName((cupsd_eventmask_t
)sub
->mask
)) != NULL
)
5339 * Simple event list...
5342 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
,
5343 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5344 "notify-events", NULL
, name
);
5349 * Complex event list...
5352 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5353 if (sub
->mask
& mask
)
5356 attr
= ippAddStrings(con
->response
, IPP_TAG_SUBSCRIPTION
,
5357 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5358 "notify-events", count
, NULL
, NULL
);
5360 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5361 if (sub
->mask
& mask
)
5363 attr
->values
[count
].string
.text
=
5364 (char *)cupsdEventName((cupsd_eventmask_t
)mask
);
5371 if (sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-job-id")))
5372 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5373 "notify-job-id", sub
->job
->id
);
5375 if (!sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-lease-duration")))
5376 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5377 "notify-lease-duration", sub
->lease
);
5379 if (sub
->dest
&& (!ra
|| cupsArrayFind(ra
, "notify-printer-uri")))
5381 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5382 "ipp", NULL
, con
->servername
, con
->serverport
,
5383 "/printers/%s", sub
->dest
->name
);
5384 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5385 "notify-printer-uri", NULL
, printer_uri
);
5388 if (sub
->recipient
&& (!ra
|| cupsArrayFind(ra
, "notify-recipient-uri")))
5389 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5390 "notify-recipient-uri", NULL
, sub
->recipient
);
5391 else if (!ra
|| cupsArrayFind(ra
, "notify-pull-method"))
5392 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_KEYWORD
,
5393 "notify-pull-method", NULL
, "ippget");
5395 if (!ra
|| cupsArrayFind(ra
, "notify-subscriber-user-name"))
5396 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_NAME
,
5397 "notify-subscriber-user-name", NULL
, sub
->owner
);
5399 if (!ra
|| cupsArrayFind(ra
, "notify-subscription-id"))
5400 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5401 "notify-subscription-id", sub
->id
);
5403 if (!ra
|| cupsArrayFind(ra
, "notify-time-interval"))
5404 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5405 "notify-time-interval", sub
->interval
);
5407 if (sub
->user_data_len
> 0 && (!ra
|| cupsArrayFind(ra
, "notify-user-data")))
5408 ippAddOctetString(con
->response
, IPP_TAG_SUBSCRIPTION
, "notify-user-data",
5409 sub
->user_data
, sub
->user_data_len
);
5414 * 'create_job()' - Print a file to a printer or class.
5418 create_job(cupsd_client_t
*con
, /* I - Client connection */
5419 ipp_attribute_t
*uri
) /* I - Printer URI */
5421 cupsd_printer_t
*printer
; /* Printer */
5422 cupsd_job_t
*job
; /* New job */
5425 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "create_job(%p[%d], %s)", con
,
5426 con
->http
.fd
, uri
->values
[0].string
.text
);
5429 * Is the destination valid?
5432 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
5438 send_ipp_status(con
, IPP_NOT_FOUND
,
5439 _("The printer or class was not found."));
5444 * Create the job object...
5447 if ((job
= add_job(con
, printer
, NULL
)) == NULL
)
5450 job
->pending_timeout
= 1;
5453 * Save and log the job...
5458 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Queued on \"%s\" by \"%s\".",
5459 job
->id
, job
->dest
, job
->username
);
5464 * 'create_requested_array()' - Create an array for the requested-attributes.
5467 static cups_array_t
* /* O - Array of attributes or NULL */
5468 create_requested_array(ipp_t
*request
) /* I - IPP request */
5470 int i
; /* Looping var */
5471 ipp_attribute_t
*requested
; /* requested-attributes attribute */
5472 cups_array_t
*ra
; /* Requested attributes array */
5473 char *value
; /* Current value */
5477 * Get the requested-attributes attribute, and return NULL if we don't
5481 if ((requested
= ippFindAttribute(request
, "requested-attributes",
5482 IPP_TAG_KEYWORD
)) == NULL
)
5486 * If the attribute contains a single "all" keyword, return NULL...
5489 if (requested
->num_values
== 1 &&
5490 !strcmp(requested
->values
[0].string
.text
, "all"))
5494 * Create an array using "strcmp" as the comparison function...
5497 ra
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
5499 for (i
= 0; i
< requested
->num_values
; i
++)
5501 value
= requested
->values
[i
].string
.text
;
5503 if (!strcmp(value
, "job-template"))
5505 cupsArrayAdd(ra
, "copies");
5506 cupsArrayAdd(ra
, "copies-default");
5507 cupsArrayAdd(ra
, "copies-supported");
5508 cupsArrayAdd(ra
, "finishings");
5509 cupsArrayAdd(ra
, "finishings-default");
5510 cupsArrayAdd(ra
, "finishings-supported");
5511 cupsArrayAdd(ra
, "job-hold-until");
5512 cupsArrayAdd(ra
, "job-hold-until-default");
5513 cupsArrayAdd(ra
, "job-hold-until-supported");
5514 cupsArrayAdd(ra
, "job-priority");
5515 cupsArrayAdd(ra
, "job-priority-default");
5516 cupsArrayAdd(ra
, "job-priority-supported");
5517 cupsArrayAdd(ra
, "job-sheets");
5518 cupsArrayAdd(ra
, "job-sheets-default");
5519 cupsArrayAdd(ra
, "job-sheets-supported");
5520 cupsArrayAdd(ra
, "media");
5521 cupsArrayAdd(ra
, "media-default");
5522 cupsArrayAdd(ra
, "media-supported");
5523 cupsArrayAdd(ra
, "multiple-document-handling");
5524 cupsArrayAdd(ra
, "multiple-document-handling-default");
5525 cupsArrayAdd(ra
, "multiple-document-handling-supported");
5526 cupsArrayAdd(ra
, "number-up");
5527 cupsArrayAdd(ra
, "number-up-default");
5528 cupsArrayAdd(ra
, "number-up-supported");
5529 cupsArrayAdd(ra
, "orientation-requested");
5530 cupsArrayAdd(ra
, "orientation-requested-default");
5531 cupsArrayAdd(ra
, "orientation-requested-supported");
5532 cupsArrayAdd(ra
, "page-ranges");
5533 cupsArrayAdd(ra
, "page-ranges-supported");
5534 cupsArrayAdd(ra
, "printer-resolution");
5535 cupsArrayAdd(ra
, "printer-resolution-default");
5536 cupsArrayAdd(ra
, "printer-resolution-supported");
5537 cupsArrayAdd(ra
, "print-quality");
5538 cupsArrayAdd(ra
, "print-quality-default");
5539 cupsArrayAdd(ra
, "print-quality-supported");
5540 cupsArrayAdd(ra
, "sides");
5541 cupsArrayAdd(ra
, "sides-default");
5542 cupsArrayAdd(ra
, "sides-supported");
5544 else if (!strcmp(value
, "job-description"))
5546 cupsArrayAdd(ra
, "date-time-at-completed");
5547 cupsArrayAdd(ra
, "date-time-at-creation");
5548 cupsArrayAdd(ra
, "date-time-at-processing");
5549 cupsArrayAdd(ra
, "job-detailed-status-message");
5550 cupsArrayAdd(ra
, "job-document-access-errors");
5551 cupsArrayAdd(ra
, "job-id");
5552 cupsArrayAdd(ra
, "job-impressions");
5553 cupsArrayAdd(ra
, "job-impressions-completed");
5554 cupsArrayAdd(ra
, "job-k-octets");
5555 cupsArrayAdd(ra
, "job-k-octets-processed");
5556 cupsArrayAdd(ra
, "job-media-sheets");
5557 cupsArrayAdd(ra
, "job-media-sheets-completed");
5558 cupsArrayAdd(ra
, "job-message-from-operator");
5559 cupsArrayAdd(ra
, "job-more-info");
5560 cupsArrayAdd(ra
, "job-name");
5561 cupsArrayAdd(ra
, "job-originating-user-name");
5562 cupsArrayAdd(ra
, "job-printer-up-time");
5563 cupsArrayAdd(ra
, "job-printer-uri");
5564 cupsArrayAdd(ra
, "job-state");
5565 cupsArrayAdd(ra
, "job-state-message");
5566 cupsArrayAdd(ra
, "job-state-reasons");
5567 cupsArrayAdd(ra
, "job-uri");
5568 cupsArrayAdd(ra
, "number-of-documents");
5569 cupsArrayAdd(ra
, "number-of-intervening-jobs");
5570 cupsArrayAdd(ra
, "output-device-assigned");
5571 cupsArrayAdd(ra
, "time-at-completed");
5572 cupsArrayAdd(ra
, "time-at-creation");
5573 cupsArrayAdd(ra
, "time-at-processing");
5575 else if (!strcmp(value
, "printer-description"))
5577 cupsArrayAdd(ra
, "charset-configured");
5578 cupsArrayAdd(ra
, "charset-supported");
5579 cupsArrayAdd(ra
, "color-supported");
5580 cupsArrayAdd(ra
, "compression-supported");
5581 cupsArrayAdd(ra
, "document-format-default");
5582 cupsArrayAdd(ra
, "document-format-supported");
5583 cupsArrayAdd(ra
, "generated-natural-language-supported");
5584 cupsArrayAdd(ra
, "ipp-versions-supported");
5585 cupsArrayAdd(ra
, "job-impressions-supported");
5586 cupsArrayAdd(ra
, "job-k-octets-supported");
5587 cupsArrayAdd(ra
, "job-media-sheets-supported");
5588 cupsArrayAdd(ra
, "multiple-document-jobs-supported");
5589 cupsArrayAdd(ra
, "multiple-operation-time-out");
5590 cupsArrayAdd(ra
, "natural-language-configured");
5591 cupsArrayAdd(ra
, "notify-attributes-supported");
5592 cupsArrayAdd(ra
, "notify-lease-duration-default");
5593 cupsArrayAdd(ra
, "notify-lease-duration-supported");
5594 cupsArrayAdd(ra
, "notify-max-events-supported");
5595 cupsArrayAdd(ra
, "notify-events-default");
5596 cupsArrayAdd(ra
, "notify-events-supported");
5597 cupsArrayAdd(ra
, "notify-pull-method-supported");
5598 cupsArrayAdd(ra
, "notify-schemes-supported");
5599 cupsArrayAdd(ra
, "operations-supported");
5600 cupsArrayAdd(ra
, "pages-per-minute");
5601 cupsArrayAdd(ra
, "pages-per-minute-color");
5602 cupsArrayAdd(ra
, "pdl-override-supported");
5603 cupsArrayAdd(ra
, "printer-alert");
5604 cupsArrayAdd(ra
, "printer-alert-description");
5605 cupsArrayAdd(ra
, "printer-current-time");
5606 cupsArrayAdd(ra
, "printer-driver-installer");
5607 cupsArrayAdd(ra
, "printer-info");
5608 cupsArrayAdd(ra
, "printer-is-accepting-jobs");
5609 cupsArrayAdd(ra
, "printer-location");
5610 cupsArrayAdd(ra
, "printer-make-and-model");
5611 cupsArrayAdd(ra
, "printer-message-from-operator");
5612 cupsArrayAdd(ra
, "printer-more-info");
5613 cupsArrayAdd(ra
, "printer-more-info-manufacturer");
5614 cupsArrayAdd(ra
, "printer-name");
5615 cupsArrayAdd(ra
, "printer-state");
5616 cupsArrayAdd(ra
, "printer-state-message");
5617 cupsArrayAdd(ra
, "printer-state-reasons");
5618 cupsArrayAdd(ra
, "printer-up-time");
5619 cupsArrayAdd(ra
, "printer-uri-supported");
5620 cupsArrayAdd(ra
, "queued-job-count");
5621 cupsArrayAdd(ra
, "reference-uri-schemes-supported");
5622 cupsArrayAdd(ra
, "uri-authentication-supported");
5623 cupsArrayAdd(ra
, "uri-security-supported");
5625 else if (!strcmp(value
, "printer-defaults"))
5627 char *name
; /* Option name */
5630 for (name
= (char *)cupsArrayFirst(CommonDefaults
);
5632 name
= (char *)cupsArrayNext(CommonDefaults
))
5633 cupsArrayAdd(ra
, name
);
5635 else if (!strcmp(value
, "subscription-template"))
5637 cupsArrayAdd(ra
, "notify-attributes");
5638 cupsArrayAdd(ra
, "notify-charset");
5639 cupsArrayAdd(ra
, "notify-events");
5640 cupsArrayAdd(ra
, "notify-lease-duration");
5641 cupsArrayAdd(ra
, "notify-natural-language");
5642 cupsArrayAdd(ra
, "notify-pull-method");
5643 cupsArrayAdd(ra
, "notify-recipient-uri");
5644 cupsArrayAdd(ra
, "notify-time-interval");
5645 cupsArrayAdd(ra
, "notify-user-data");
5648 cupsArrayAdd(ra
, value
);
5656 * 'create_subscription()' - Create a notification subscription.
5660 create_subscription(
5661 cupsd_client_t
*con
, /* I - Client connection */
5662 ipp_attribute_t
*uri
) /* I - Printer URI */
5664 http_status_t status
; /* Policy status */
5665 int i
; /* Looping var */
5666 ipp_attribute_t
*attr
; /* Current attribute */
5667 cups_ptype_t dtype
; /* Destination type (printer/class) */
5668 char scheme
[HTTP_MAX_URI
],
5669 /* Scheme portion of URI */
5670 userpass
[HTTP_MAX_URI
],
5671 /* Username portion of URI */
5673 /* Host portion of URI */
5674 resource
[HTTP_MAX_URI
];
5675 /* Resource portion of URI */
5676 int port
; /* Port portion of URI */
5677 cupsd_printer_t
*printer
; /* Printer/class */
5678 cupsd_job_t
*job
; /* Job */
5679 int jobid
; /* Job ID */
5680 cupsd_subscription_t
*sub
; /* Subscription object */
5681 const char *username
, /* requesting-user-name or
5682 authenticated username */
5683 *recipient
, /* notify-recipient-uri */
5684 *pullmethod
; /* notify-pull-method */
5685 ipp_attribute_t
*user_data
; /* notify-user-data */
5686 int interval
, /* notify-time-interval */
5687 lease
; /* notify-lease-duration */
5688 unsigned mask
; /* notify-events */
5689 ipp_attribute_t
*notify_events
,/* notify-events(-default) */
5690 *notify_lease
; /* notify-lease-duration(-default) */
5694 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
5696 if (attr
->group_tag
!= IPP_TAG_ZERO
)
5697 cupsdLogMessage(CUPSD_LOG_DEBUG
, "g%04x v%04x %s", attr
->group_tag
,
5698 attr
->value_tag
, attr
->name
);
5700 cupsdLogMessage(CUPSD_LOG_DEBUG
, "----SEP----");
5705 * Is the destination valid?
5708 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5709 "cupsdCreateSubscription(con=%p(%d), uri=\"%s\")",
5710 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
5712 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
5713 sizeof(scheme
), userpass
, sizeof(userpass
), host
,
5714 sizeof(host
), &port
, resource
, sizeof(resource
));
5716 if (!strcmp(resource
, "/"))
5718 dtype
= (cups_ptype_t
)0;
5721 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
5723 dtype
= (cups_ptype_t
)0;
5726 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
5728 dtype
= CUPS_PRINTER_CLASS
;
5731 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
5737 send_ipp_status(con
, IPP_NOT_FOUND
,
5738 _("The printer or class was not found."));
5748 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
5751 send_http_error(con
, status
, printer
);
5755 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5757 send_http_error(con
, status
, NULL
);
5762 * Get the user that is requesting the subscription...
5765 username
= get_username(con
);
5768 * Find the first subscription group attribute; return if we have
5772 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
5773 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
5778 send_ipp_status(con
, IPP_BAD_REQUEST
,
5779 _("No subscription attributes in request!"));
5784 * Process the subscription attributes in the request...
5787 con
->response
->request
.status
.status_code
= IPP_BAD_REQUEST
;
5795 lease
= DefaultLeaseDuration
;
5797 mask
= CUPSD_EVENT_NONE
;
5801 notify_events
= ippFindAttribute(printer
->attrs
, "notify-events-default",
5803 notify_lease
= ippFindAttribute(printer
->attrs
,
5804 "notify-lease-duration-default",
5808 lease
= notify_lease
->values
[0].integer
;
5812 notify_events
= NULL
;
5813 notify_lease
= NULL
;
5816 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
5818 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
5819 attr
->value_tag
== IPP_TAG_URI
)
5822 * Validate the recipient scheme against the ServerBin/notifier
5826 char notifier
[1024]; /* Notifier filename */
5829 recipient
= attr
->values
[0].string
.text
;
5831 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
5832 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
5833 host
, sizeof(host
), &port
,
5834 resource
, sizeof(resource
)) < HTTP_URI_OK
)
5836 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5837 _("Bad notify-recipient-uri URI \"%s\"!"), recipient
);
5838 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5839 "notify-status-code", IPP_URI_SCHEME
);
5843 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
5845 if (access(notifier
, X_OK
))
5847 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5848 _("notify-recipient-uri URI \"%s\" uses unknown "
5849 "scheme!"), recipient
);
5850 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5851 "notify-status-code", IPP_URI_SCHEME
);
5855 else if (!strcmp(attr
->name
, "notify-pull-method") &&
5856 attr
->value_tag
== IPP_TAG_KEYWORD
)
5858 pullmethod
= attr
->values
[0].string
.text
;
5860 if (strcmp(pullmethod
, "ippget"))
5862 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5863 _("Bad notify-pull-method \"%s\"!"), pullmethod
);
5864 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5865 "notify-status-code", IPP_ATTRIBUTES
);
5869 else if (!strcmp(attr
->name
, "notify-charset") &&
5870 attr
->value_tag
== IPP_TAG_CHARSET
&&
5871 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
5872 strcmp(attr
->values
[0].string
.text
, "utf-8"))
5874 send_ipp_status(con
, IPP_CHARSET
,
5875 _("Character set \"%s\" not supported!"),
5876 attr
->values
[0].string
.text
);
5879 else if (!strcmp(attr
->name
, "notify-natural-language") &&
5880 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
5881 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
5883 send_ipp_status(con
, IPP_CHARSET
,
5884 _("Language \"%s\" not supported!"),
5885 attr
->values
[0].string
.text
);
5888 else if (!strcmp(attr
->name
, "notify-user-data") &&
5889 attr
->value_tag
== IPP_TAG_STRING
)
5891 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
5893 send_ipp_status(con
, IPP_REQUEST_VALUE
,
5894 _("The notify-user-data value is too large "
5895 "(%d > 63 octets)!"),
5896 attr
->values
[0].unknown
.length
);
5902 else if (!strcmp(attr
->name
, "notify-events") &&
5903 attr
->value_tag
== IPP_TAG_KEYWORD
)
5904 notify_events
= attr
;
5905 else if (!strcmp(attr
->name
, "notify-lease-duration") &&
5906 attr
->value_tag
== IPP_TAG_INTEGER
)
5907 lease
= attr
->values
[0].integer
;
5908 else if (!strcmp(attr
->name
, "notify-time-interval") &&
5909 attr
->value_tag
== IPP_TAG_INTEGER
)
5910 interval
= attr
->values
[0].integer
;
5911 else if (!strcmp(attr
->name
, "notify-job-id") &&
5912 attr
->value_tag
== IPP_TAG_INTEGER
)
5913 jobid
= attr
->values
[0].integer
;
5920 for (i
= 0; i
< notify_events
->num_values
; i
++)
5921 mask
|= cupsdEventValue(notify_events
->values
[i
].string
.text
);
5925 cupsdLogMessage(CUPSD_LOG_DEBUG
, "recipient=\"%s\"", recipient
);
5927 cupsdLogMessage(CUPSD_LOG_DEBUG
, "pullmethod=\"%s\"", pullmethod
);
5928 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-lease-duration=%d", lease
);
5929 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-time-interval=%d", interval
);
5931 if (!recipient
&& !pullmethod
)
5934 if (mask
== CUPSD_EVENT_NONE
)
5937 mask
= CUPSD_EVENT_JOB_COMPLETED
;
5939 mask
= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
5942 send_ipp_status(con
, IPP_BAD_REQUEST
,
5943 _("notify-events not specified!"));
5948 if (MaxLeaseDuration
&& (lease
== 0 || lease
> MaxLeaseDuration
))
5950 cupsdLogMessage(CUPSD_LOG_INFO
,
5951 "create_subscription: Limiting notify-lease-duration to "
5954 lease
= MaxLeaseDuration
;
5959 if ((job
= cupsdFindJob(jobid
)) == NULL
)
5961 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job %d not found!"), jobid
);
5968 sub
= cupsdAddSubscription(mask
, printer
, job
, recipient
, 0);
5971 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
5974 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5975 "Added subscription %d for printer \"%s\"",
5976 sub
->id
, printer
->name
);
5978 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for server",
5981 sub
->interval
= interval
;
5983 sub
->expire
= lease
? time(NULL
) + lease
: 0;
5985 cupsdSetString(&sub
->owner
, username
);
5989 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
5990 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
5991 sub
->user_data_len
);
5994 ippAddSeparator(con
->response
);
5995 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5996 "notify-subscription-id", sub
->id
);
5998 con
->response
->request
.status
.status_code
= IPP_OK
;
6004 cupsdSaveAllSubscriptions();
6010 * 'delete_printer()' - Remove a printer or class from the system.
6014 delete_printer(cupsd_client_t
*con
, /* I - Client connection */
6015 ipp_attribute_t
*uri
) /* I - URI of printer or class */
6017 http_status_t status
; /* Policy status */
6018 cups_ptype_t dtype
; /* Destination type (printer/class) */
6019 cupsd_printer_t
*printer
; /* Printer/class */
6020 char filename
[1024]; /* Script/PPD filename */
6023 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "delete_printer(%p[%d], %s)", con
,
6024 con
->http
.fd
, uri
->values
[0].string
.text
);
6027 * Do we have a valid URI?
6030 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6036 send_ipp_status(con
, IPP_NOT_FOUND
,
6037 _("The printer or class was not found."));
6045 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6047 send_http_error(con
, status
, NULL
);
6052 * Remove old jobs...
6055 cupsdCancelJobs(printer
->name
, NULL
, 1);
6058 * Remove old subscriptions and send a "deleted printer" event...
6061 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED
, printer
, NULL
,
6062 "%s \"%s\" deleted by \"%s\".",
6063 (dtype
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
6064 printer
->name
, get_username(con
));
6066 cupsdExpireSubscriptions(printer
, NULL
);
6069 * Remove any old PPD or script files...
6072 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
,
6076 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
6082 * Unregister color profiles...
6085 apple_unregister_profiles(printer
);
6086 #endif /* __APPLE__ */
6088 if (dtype
& CUPS_PRINTER_CLASS
)
6090 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" deleted by \"%s\".",
6091 printer
->name
, get_username(con
));
6093 cupsdDeletePrinter(printer
, 0);
6094 cupsdSaveAllClasses();
6098 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" deleted by \"%s\".",
6099 printer
->name
, get_username(con
));
6101 cupsdDeletePrinter(printer
, 0);
6102 cupsdSaveAllPrinters();
6105 cupsdWritePrintcap();
6108 * Return with no errors...
6111 con
->response
->request
.status
.status_code
= IPP_OK
;
6116 * 'get_default()' - Get the default destination.
6120 get_default(cupsd_client_t
*con
) /* I - Client connection */
6122 http_status_t status
; /* Policy status */
6123 cups_array_t
*ra
; /* Requested attributes array */
6126 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_default(%p[%d])", con
, con
->http
.fd
);
6132 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6134 send_http_error(con
, status
, NULL
);
6140 ra
= create_requested_array(con
->request
);
6142 copy_printer_attrs(con
, DefaultPrinter
, ra
);
6144 cupsArrayDelete(ra
);
6146 con
->response
->request
.status
.status_code
= IPP_OK
;
6149 send_ipp_status(con
, IPP_NOT_FOUND
, _("No default printer"));
6154 * 'get_devices()' - Get the list of available devices on the local system.
6158 get_devices(cupsd_client_t
*con
) /* I - Client connection */
6160 http_status_t status
; /* Policy status */
6161 ipp_attribute_t
*limit
, /* Limit attribute */
6162 *requested
; /* requested-attributes attribute */
6163 char command
[1024], /* cups-deviced command */
6164 options
[1024], /* Options to pass to command */
6166 /* String for requested attributes */
6169 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_devices(%p[%d])", con
, con
->http
.fd
);
6175 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6177 send_http_error(con
, status
, NULL
);
6182 * Run cups-deviced command with the given options...
6185 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
6186 requested
= ippFindAttribute(con
->request
, "requested-attributes",
6190 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
6192 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
6194 snprintf(command
, sizeof(command
), "%s/daemon/cups-deviced", ServerBin
);
6195 snprintf(options
, sizeof(options
),
6197 con
->request
->request
.op
.request_id
,
6198 limit
? limit
->values
[0].integer
: 0, (int)User
,
6201 if (cupsdSendCommand(con
, command
, options
, 1))
6204 * Command started successfully, don't send an IPP response here...
6207 ippDelete(con
->response
);
6208 con
->response
= NULL
;
6213 * Command failed, return "internal error" so the user knows something
6217 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
6218 _("cups-deviced failed to execute."));
6224 * 'get_document()' - Get a copy of a job file.
6228 get_document(cupsd_client_t
*con
, /* I - Client connection */
6229 ipp_attribute_t
*uri
) /* I - Job URI */
6231 http_status_t status
; /* Policy status */
6232 ipp_attribute_t
*attr
; /* Current attribute */
6233 int jobid
; /* Job ID */
6234 int docnum
; /* Document number */
6235 cupsd_job_t
*job
; /* Current job */
6236 char method
[HTTP_MAX_URI
], /* Method portion of URI */
6237 username
[HTTP_MAX_URI
], /* Username portion of URI */
6238 host
[HTTP_MAX_URI
], /* Host portion of URI */
6239 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6240 int port
; /* Port portion of URI */
6241 char filename
[1024], /* Filename for document */
6242 format
[1024]; /* Format for document */
6245 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_document(%p[%d], %s)", con
,
6246 con
->http
.fd
, uri
->values
[0].string
.text
);
6249 * See if we have a job URI or a printer URI...
6252 if (!strcmp(uri
->name
, "printer-uri"))
6255 * Got a printer URI; see if we also have a job-id attribute...
6258 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6259 IPP_TAG_INTEGER
)) == NULL
)
6261 send_ipp_status(con
, IPP_BAD_REQUEST
,
6262 _("Got a printer-uri attribute but no job-id!"));
6266 jobid
= attr
->values
[0].integer
;
6271 * Got a job URI; parse it to get the job ID...
6274 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
6275 sizeof(method
), username
, sizeof(username
), host
,
6276 sizeof(host
), &port
, resource
, sizeof(resource
));
6278 if (strncmp(resource
, "/jobs/", 6))
6284 send_ipp_status(con
, IPP_BAD_REQUEST
,
6285 _("Bad job-uri attribute \"%s\"!"),
6286 uri
->values
[0].string
.text
);
6290 jobid
= atoi(resource
+ 6);
6294 * See if the job exists...
6297 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6300 * Nope - return a "not found" error...
6303 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
6311 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6313 send_http_error(con
, status
, NULL
);
6318 * Get the document number...
6321 if ((attr
= ippFindAttribute(con
->request
, "document-number",
6322 IPP_TAG_INTEGER
)) == NULL
)
6324 send_ipp_status(con
, IPP_BAD_REQUEST
,
6325 _("Missing document-number attribute!"));
6329 if ((docnum
= attr
->values
[0].integer
) < 1 || docnum
> job
->num_files
||
6330 attr
->num_values
> 1)
6332 send_ipp_status(con
, IPP_NOT_FOUND
, _("Document %d not found in job %d."),
6337 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, jobid
,
6339 if ((con
->file
= open(filename
, O_RDONLY
)) == -1)
6341 cupsdLogMessage(CUPSD_LOG_ERROR
,
6342 "Unable to open document %d in job %d - %s", docnum
, jobid
,
6344 send_ipp_status(con
, IPP_NOT_FOUND
,
6345 _("Unable to open document %d in job %d!"), docnum
, jobid
);
6349 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
6353 snprintf(format
, sizeof(format
), "%s/%s", job
->filetypes
[docnum
- 1]->super
,
6354 job
->filetypes
[docnum
- 1]->type
);
6356 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format",
6358 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "document-number",
6360 if ((attr
= ippFindAttribute(job
->attrs
, "document-name",
6361 IPP_TAG_NAME
)) != NULL
)
6362 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name",
6363 NULL
, attr
->values
[0].string
.text
);
6368 * 'get_job_attrs()' - Get job attributes.
6372 get_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
6373 ipp_attribute_t
*uri
) /* I - Job URI */
6375 http_status_t status
; /* Policy status */
6376 ipp_attribute_t
*attr
; /* Current attribute */
6377 int jobid
; /* Job ID */
6378 cupsd_job_t
*job
; /* Current job */
6379 char method
[HTTP_MAX_URI
], /* Method portion of URI */
6380 username
[HTTP_MAX_URI
], /* Username portion of URI */
6381 host
[HTTP_MAX_URI
], /* Host portion of URI */
6382 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6383 int port
; /* Port portion of URI */
6384 cups_array_t
*ra
; /* Requested attributes array */
6387 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_job_attrs(%p[%d], %s)", con
,
6388 con
->http
.fd
, uri
->values
[0].string
.text
);
6391 * See if we have a job URI or a printer URI...
6394 if (!strcmp(uri
->name
, "printer-uri"))
6397 * Got a printer URI; see if we also have a job-id attribute...
6400 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6401 IPP_TAG_INTEGER
)) == NULL
)
6403 send_ipp_status(con
, IPP_BAD_REQUEST
,
6404 _("Got a printer-uri attribute but no job-id!"));
6408 jobid
= attr
->values
[0].integer
;
6413 * Got a job URI; parse it to get the job ID...
6416 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
6417 sizeof(method
), username
, sizeof(username
), host
,
6418 sizeof(host
), &port
, resource
, sizeof(resource
));
6420 if (strncmp(resource
, "/jobs/", 6))
6426 send_ipp_status(con
, IPP_BAD_REQUEST
,
6427 _("Bad job-uri attribute \"%s\"!"),
6428 uri
->values
[0].string
.text
);
6432 jobid
= atoi(resource
+ 6);
6436 * See if the job exists...
6439 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6442 * Nope - return a "not found" error...
6445 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
6453 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6455 send_http_error(con
, status
, NULL
);
6460 * Copy attributes...
6465 ra
= create_requested_array(con
->request
);
6466 copy_job_attrs(con
, job
, ra
);
6467 cupsArrayDelete(ra
);
6469 con
->response
->request
.status
.status_code
= IPP_OK
;
6474 * 'get_jobs()' - Get a list of jobs for the specified printer.
6478 get_jobs(cupsd_client_t
*con
, /* I - Client connection */
6479 ipp_attribute_t
*uri
) /* I - Printer URI */
6481 http_status_t status
; /* Policy status */
6482 ipp_attribute_t
*attr
; /* Current attribute */
6483 const char *dest
; /* Destination */
6484 cups_ptype_t dtype
; /* Destination type (printer/class) */
6485 cups_ptype_t dmask
; /* Destination type mask */
6486 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6487 username
[HTTP_MAX_URI
], /* Username portion of URI */
6488 host
[HTTP_MAX_URI
], /* Host portion of URI */
6489 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6490 int port
; /* Port portion of URI */
6491 int completed
; /* Completed jobs? */
6492 int first_job_id
; /* First job ID */
6493 int limit
; /* Maximum number of jobs to return */
6494 int count
; /* Number of jobs that match */
6495 cupsd_job_t
*job
; /* Current job pointer */
6496 cupsd_printer_t
*printer
; /* Printer */
6497 cups_array_t
*list
; /* Which job list... */
6498 cups_array_t
*ra
; /* Requested attributes array */
6501 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs(%p[%d], %s)", con
, con
->http
.fd
,
6502 uri
->values
[0].string
.text
);
6505 * Is the destination valid?
6508 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6509 sizeof(scheme
), username
, sizeof(username
), host
,
6510 sizeof(host
), &port
, resource
, sizeof(resource
));
6512 if (!strcmp(resource
, "/") ||
6513 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6))
6516 dtype
= (cups_ptype_t
)0;
6517 dmask
= (cups_ptype_t
)0;
6520 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6523 dtype
= (cups_ptype_t
)0;
6524 dmask
= CUPS_PRINTER_CLASS
;
6527 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6530 dtype
= CUPS_PRINTER_CLASS
;
6531 dmask
= CUPS_PRINTER_CLASS
;
6534 else if ((dest
= cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
,
6541 send_ipp_status(con
, IPP_NOT_FOUND
,
6542 _("The printer or class was not found."));
6547 dtype
&= CUPS_PRINTER_CLASS
;
6548 dmask
= CUPS_PRINTER_CLASS
;
6557 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
6560 send_http_error(con
, status
, printer
);
6564 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6566 send_http_error(con
, status
, NULL
);
6571 * See if the "which-jobs" attribute have been specified...
6574 if ((attr
= ippFindAttribute(con
->request
, "which-jobs",
6575 IPP_TAG_KEYWORD
)) != NULL
&&
6576 !strcmp(attr
->values
[0].string
.text
, "completed"))
6581 else if (attr
&& !strcmp(attr
->values
[0].string
.text
, "all"))
6593 * See if they want to limit the number of jobs reported...
6596 if ((attr
= ippFindAttribute(con
->request
, "limit",
6597 IPP_TAG_INTEGER
)) != NULL
)
6598 limit
= attr
->values
[0].integer
;
6602 if ((attr
= ippFindAttribute(con
->request
, "first-job-id",
6603 IPP_TAG_INTEGER
)) != NULL
)
6604 first_job_id
= attr
->values
[0].integer
;
6609 * See if we only want to see jobs for a specific user...
6612 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
6613 IPP_TAG_BOOLEAN
)) != NULL
&&
6614 attr
->values
[0].boolean
)
6615 strlcpy(username
, get_username(con
), sizeof(username
));
6619 ra
= create_requested_array(con
->request
);
6622 * OK, build a list of jobs for this printer...
6625 for (count
= 0, job
= (cupsd_job_t
*)cupsArrayFirst(list
);
6626 count
< limit
&& job
;
6627 job
= (cupsd_job_t
*)cupsArrayNext(list
))
6630 * Filter out jobs that don't match...
6633 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: job->id = %d", job
->id
);
6635 if (!job
->dest
|| !job
->username
)
6638 if (!job
->dest
|| !job
->username
)
6641 if ((dest
&& strcmp(job
->dest
, dest
)) &&
6642 (!job
->printer
|| !dest
|| strcmp(job
->printer
->name
, dest
)))
6644 if ((job
->dtype
& dmask
) != dtype
&&
6645 (!job
->printer
|| (job
->printer
->type
& dmask
) != dtype
))
6647 if (completed
&& job
->state_value
<= IPP_JOB_STOPPED
)
6650 if (job
->id
< first_job_id
)
6658 if (username
[0] && strcasecmp(username
, job
->username
))
6662 ippAddSeparator(con
->response
);
6666 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: count = %d", count
);
6668 copy_job_attrs(con
, job
, ra
);
6671 cupsArrayDelete(ra
);
6673 con
->response
->request
.status
.status_code
= IPP_OK
;
6678 * 'get_notifications()' - Get events for a subscription.
6682 get_notifications(cupsd_client_t
*con
) /* I - Client connection */
6684 int i
, j
; /* Looping vars */
6685 http_status_t status
; /* Policy status */
6686 cupsd_subscription_t
*sub
; /* Subscription */
6687 ipp_attribute_t
*ids
, /* notify-subscription-ids */
6688 *sequences
; /* notify-sequence-numbers */
6689 int min_seq
; /* Minimum sequence number */
6690 int interval
; /* Poll interval */
6693 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_notifications(con=%p[%d])",
6697 * Get subscription attributes...
6700 ids
= ippFindAttribute(con
->request
, "notify-subscription-ids",
6702 sequences
= ippFindAttribute(con
->request
, "notify-sequence-numbers",
6707 send_ipp_status(con
, IPP_BAD_REQUEST
,
6708 _("Missing notify-subscription-ids attribute!"));
6713 * Are the subscription IDs valid?
6716 for (i
= 0, interval
= 60; i
< ids
->num_values
; i
++)
6718 if ((sub
= cupsdFindSubscription(ids
->values
[i
].integer
)) == NULL
)
6721 * Bad subscription ID...
6724 send_ipp_status(con
, IPP_NOT_FOUND
,
6725 _("notify-subscription-id %d no good!"),
6726 ids
->values
[i
].integer
);
6734 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
6736 con
, sub
->owner
)) != HTTP_OK
)
6738 send_http_error(con
, status
, sub
->dest
);
6743 * Check the subscription type and update the interval accordingly.
6746 if (sub
->job
&& sub
->job
->state_value
== IPP_JOB_PROCESSING
&&
6749 else if (sub
->job
&& sub
->job
->state_value
>= IPP_JOB_STOPPED
)
6751 else if (sub
->dest
&& sub
->dest
->state
== IPP_PRINTER_PROCESSING
&&
6757 * Tell the client to poll again in N seconds...
6761 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
6762 "notify-get-interval", interval
);
6764 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
6765 "printer-up-time", time(NULL
));
6768 * Copy the subscription event attributes to the response.
6771 con
->response
->request
.status
.status_code
=
6772 interval
? IPP_OK
: IPP_OK_EVENTS_COMPLETE
;
6774 for (i
= 0; i
< ids
->num_values
; i
++)
6777 * Get the subscription and sequence number...
6780 sub
= cupsdFindSubscription(ids
->values
[i
].integer
);
6782 if (sequences
&& i
< sequences
->num_values
)
6783 min_seq
= sequences
->values
[i
].integer
;
6788 * If we don't have any new events, nothing to do here...
6791 if (min_seq
> (sub
->first_event_id
+ sub
->num_events
))
6795 * Otherwise copy all of the new events...
6798 if (sub
->first_event_id
> min_seq
)
6801 j
= min_seq
- sub
->first_event_id
;
6803 for (; j
< sub
->num_events
; j
++)
6805 ippAddSeparator(con
->response
);
6807 copy_attrs(con
->response
, sub
->events
[j
]->attrs
, NULL
,
6808 IPP_TAG_EVENT_NOTIFICATION
, 0);
6815 * 'get_ppd()' - Get a named PPD from the local system.
6819 get_ppd(cupsd_client_t
*con
, /* I - Client connection */
6820 ipp_attribute_t
*uri
) /* I - Printer URI or PPD name */
6822 http_status_t status
; /* Policy status */
6823 cupsd_printer_t
*dest
; /* Destination */
6824 cups_ptype_t dtype
; /* Destination type */
6827 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppd(%p[%d], %p[%s=%s])", con
,
6828 con
->http
.fd
, uri
, uri
->name
, uri
->values
[0].string
.text
);
6830 if (!strcmp(uri
->name
, "ppd-name"))
6833 * Return a PPD file from cups-driverd...
6836 char command
[1024], /* cups-driverd command */
6837 options
[1024], /* Options to pass to command */
6838 ppd_name
[1024]; /* ppd-name */
6845 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6847 send_http_error(con
, status
, NULL
);
6852 * Run cups-driverd command with the given options...
6855 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
6856 url_encode_string(uri
->values
[0].string
.text
, ppd_name
, sizeof(ppd_name
));
6857 snprintf(options
, sizeof(options
), "get+%d+%s",
6858 con
->request
->request
.op
.request_id
, ppd_name
);
6860 if (cupsdSendCommand(con
, command
, options
, 0))
6863 * Command started successfully, don't send an IPP response here...
6866 ippDelete(con
->response
);
6867 con
->response
= NULL
;
6872 * Command failed, return "internal error" so the user knows something
6876 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
6877 _("cups-driverd failed to execute."));
6880 else if (!strcmp(uri
->name
, "printer-uri") &&
6881 cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &dest
))
6883 int i
; /* Looping var */
6884 char filename
[1024]; /* PPD filename */
6891 if ((status
= cupsdCheckPolicy(dest
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
6893 send_http_error(con
, status
, dest
);
6898 * See if we need the PPD for a class or remote printer...
6901 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
6904 if ((dtype
& CUPS_PRINTER_REMOTE
) && access(filename
, 0))
6906 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
6907 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
6908 "printer-uri", NULL
, dest
->uri
);
6911 else if (dtype
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
6913 for (i
= 0; i
< dest
->num_printers
; i
++)
6914 if (!(dest
->printers
[i
]->type
&
6915 (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
)))
6917 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
6918 dest
->printers
[i
]->name
);
6920 if (!access(filename
, 0))
6924 if (i
< dest
->num_printers
)
6925 dest
= dest
->printers
[i
];
6928 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
6929 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
6930 "printer-uri", NULL
, dest
->printers
[0]->uri
);
6936 * Found the printer with the PPD file, now see if there is one...
6939 if ((con
->file
= open(filename
, O_RDONLY
)) < 0)
6941 send_ipp_status(con
, IPP_NOT_FOUND
,
6942 _("The PPD file \"%s\" could not be opened: %s"),
6943 uri
->values
[0].string
.text
, strerror(errno
));
6947 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
6951 con
->response
->request
.status
.status_code
= IPP_OK
;
6954 send_ipp_status(con
, IPP_NOT_FOUND
,
6955 _("The PPD file \"%s\" could not be found."),
6956 uri
->values
[0].string
.text
);
6961 * 'get_ppds()' - Get the list of PPD files on the local system.
6965 get_ppds(cupsd_client_t
*con
) /* I - Client connection */
6967 http_status_t status
; /* Policy status */
6968 ipp_attribute_t
*limit
, /* Limit attribute */
6969 *device
, /* ppd-device-id attribute */
6970 *language
, /* ppd-natural-language attribute */
6971 *make
, /* ppd-make attribute */
6972 *model
, /* ppd-make-and-model attribute */
6973 *model_number
, /* ppd-model-number attribute */
6974 *product
, /* ppd-product attribute */
6975 *psversion
, /* ppd-psverion attribute */
6976 *type
, /* ppd-type attribute */
6977 *requested
; /* requested-attributes attribute */
6978 char command
[1024], /* cups-driverd command */
6979 options
[1024], /* Options to pass to command */
6980 device_str
[256],/* Escaped ppd-device-id string */
6982 /* Escaped ppd-natural-language */
6983 make_str
[256], /* Escaped ppd-make string */
6984 model_str
[256], /* Escaped ppd-make-and-model string */
6985 model_number_str
[256],
6986 /* ppd-model-number string */
6988 /* Escaped ppd-product string */
6990 /* Escaped ppd-psversion string */
6991 type_str
[256], /* Escaped ppd-type string */
6993 /* String for requested attributes */
6996 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppds(%p[%d])", con
, con
->http
.fd
);
7002 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7004 send_http_error(con
, status
, NULL
);
7009 * Run cups-driverd command with the given options...
7012 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
7013 device
= ippFindAttribute(con
->request
, "ppd-device-id", IPP_TAG_TEXT
);
7014 language
= ippFindAttribute(con
->request
, "ppd-natural-language",
7016 make
= ippFindAttribute(con
->request
, "ppd-make", IPP_TAG_TEXT
);
7017 model
= ippFindAttribute(con
->request
, "ppd-make-and-model",
7019 model_number
= ippFindAttribute(con
->request
, "ppd-model-number",
7021 product
= ippFindAttribute(con
->request
, "ppd-product", IPP_TAG_TEXT
);
7022 psversion
= ippFindAttribute(con
->request
, "ppd-psversion", IPP_TAG_TEXT
);
7023 type
= ippFindAttribute(con
->request
, "ppd-type", IPP_TAG_KEYWORD
);
7024 requested
= ippFindAttribute(con
->request
, "requested-attributes",
7028 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
7030 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
7033 url_encode_attr(device
, device_str
, sizeof(device_str
));
7035 device_str
[0] = '\0';
7038 url_encode_attr(language
, language_str
, sizeof(language_str
));
7040 language_str
[0] = '\0';
7043 url_encode_attr(make
, make_str
, sizeof(make_str
));
7048 url_encode_attr(model
, model_str
, sizeof(model_str
));
7050 model_str
[0] = '\0';
7053 snprintf(model_number_str
, sizeof(model_number_str
), "ppd-model-number=%d",
7054 model_number
->values
[0].integer
);
7056 model_number_str
[0] = '\0';
7059 url_encode_attr(product
, product_str
, sizeof(product_str
));
7061 product_str
[0] = '\0';
7064 url_encode_attr(psversion
, psversion_str
, sizeof(psversion_str
));
7066 psversion_str
[0] = '\0';
7069 url_encode_attr(type
, type_str
, sizeof(type_str
));
7073 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7074 snprintf(options
, sizeof(options
),
7075 "list+%d+%d+%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
7076 con
->request
->request
.op
.request_id
,
7077 limit
? limit
->values
[0].integer
: 0,
7079 device
? "%20" : "", device_str
,
7080 language
? "%20" : "", language_str
,
7081 make
? "%20" : "", make_str
,
7082 model
? "%20" : "", model_str
,
7083 model_number
? "%20" : "", model_number_str
,
7084 product
? "%20" : "", product_str
,
7085 psversion
? "%20" : "", psversion_str
,
7086 type
? "%20" : "", type_str
);
7088 if (cupsdSendCommand(con
, command
, options
, 0))
7091 * Command started successfully, don't send an IPP response here...
7094 ippDelete(con
->response
);
7095 con
->response
= NULL
;
7100 * Command failed, return "internal error" so the user knows something
7104 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7105 _("cups-driverd failed to execute."));
7111 * 'get_printer_attrs()' - Get printer attributes.
7115 get_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
7116 ipp_attribute_t
*uri
) /* I - Printer URI */
7118 http_status_t status
; /* Policy status */
7119 cups_ptype_t dtype
; /* Destination type (printer/class) */
7120 cupsd_printer_t
*printer
; /* Printer/class */
7121 cups_array_t
*ra
; /* Requested attributes array */
7124 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_attrs(%p[%d], %s)", con
,
7125 con
->http
.fd
, uri
->values
[0].string
.text
);
7128 * Is the destination valid?
7131 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7137 send_ipp_status(con
, IPP_NOT_FOUND
,
7138 _("The printer or class was not found."));
7146 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7148 send_http_error(con
, status
, printer
);
7153 * Send the attributes...
7156 ra
= create_requested_array(con
->request
);
7158 copy_printer_attrs(con
, printer
, ra
);
7160 cupsArrayDelete(ra
);
7162 con
->response
->request
.status
.status_code
= IPP_OK
;
7167 * 'get_printers()' - Get a list of printers or classes.
7171 get_printers(cupsd_client_t
*con
, /* I - Client connection */
7172 int type
) /* I - 0 or CUPS_PRINTER_CLASS */
7174 http_status_t status
; /* Policy status */
7175 ipp_attribute_t
*attr
; /* Current attribute */
7176 int limit
; /* Max number of printers to return */
7177 int count
; /* Number of printers that match */
7178 cupsd_printer_t
*printer
; /* Current printer pointer */
7179 int printer_type
, /* printer-type attribute */
7180 printer_mask
; /* printer-type-mask attribute */
7181 char *location
; /* Location string */
7182 const char *username
; /* Current user */
7183 char *first_printer_name
; /* first-printer-name attribute */
7184 cups_array_t
*ra
; /* Requested attributes array */
7187 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printers(%p[%d], %x)", con
,
7188 con
->http
.fd
, type
);
7194 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7196 send_http_error(con
, status
, NULL
);
7201 * Check for printers...
7204 if (!Printers
|| !cupsArrayCount(Printers
))
7206 send_ipp_status(con
, IPP_NOT_FOUND
, _("No destinations added."));
7211 * See if they want to limit the number of printers reported...
7214 if ((attr
= ippFindAttribute(con
->request
, "limit",
7215 IPP_TAG_INTEGER
)) != NULL
)
7216 limit
= attr
->values
[0].integer
;
7220 if ((attr
= ippFindAttribute(con
->request
, "first-printer-name",
7221 IPP_TAG_NAME
)) != NULL
)
7222 first_printer_name
= attr
->values
[0].string
.text
;
7224 first_printer_name
= NULL
;
7227 * Support filtering...
7230 if ((attr
= ippFindAttribute(con
->request
, "printer-type",
7231 IPP_TAG_ENUM
)) != NULL
)
7232 printer_type
= attr
->values
[0].integer
;
7236 if ((attr
= ippFindAttribute(con
->request
, "printer-type-mask",
7237 IPP_TAG_ENUM
)) != NULL
)
7238 printer_mask
= attr
->values
[0].integer
;
7242 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
7243 IPP_TAG_TEXT
)) != NULL
)
7244 location
= attr
->values
[0].string
.text
;
7248 if (con
->username
[0])
7249 username
= con
->username
;
7250 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7251 IPP_TAG_NAME
)) != NULL
)
7252 username
= attr
->values
[0].string
.text
;
7256 ra
= create_requested_array(con
->request
);
7259 * OK, build a list of printers for this printer...
7262 if (first_printer_name
)
7264 if ((printer
= cupsdFindDest(first_printer_name
)) == NULL
)
7265 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7268 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7271 count
< limit
&& printer
;
7272 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
7274 if ((!type
|| (printer
->type
& CUPS_PRINTER_CLASS
) == type
) &&
7275 (printer
->type
& printer_mask
) == printer_type
&&
7276 (!location
|| !printer
->location
||
7277 !strcasecmp(printer
->location
, location
)))
7280 * If HideImplicitMembers is enabled, see if this printer or class
7281 * is a member of an implicit class...
7284 if (ImplicitClasses
&& HideImplicitMembers
&&
7285 printer
->in_implicit_class
)
7289 * If a username is specified, see if it is allowed or denied
7293 if (printer
->num_users
&& username
&& !user_allowed(printer
, username
))
7297 * Add the group separator as needed...
7301 ippAddSeparator(con
->response
);
7306 * Send the attributes...
7309 copy_printer_attrs(con
, printer
, ra
);
7313 cupsArrayDelete(ra
);
7315 con
->response
->request
.status
.status_code
= IPP_OK
;
7320 * 'get_subscription_attrs()' - Get subscription attributes.
7324 get_subscription_attrs(
7325 cupsd_client_t
*con
, /* I - Client connection */
7326 int sub_id
) /* I - Subscription ID */
7328 http_status_t status
; /* Policy status */
7329 cupsd_subscription_t
*sub
; /* Subscription */
7330 cups_array_t
*ra
; /* Requested attributes array */
7333 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7334 "get_subscription_attrs(con=%p[%d], sub_id=%d)",
7335 con
, con
->http
.fd
, sub_id
);
7338 * Is the subscription ID valid?
7341 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
7344 * Bad subscription ID...
7347 send_ipp_status(con
, IPP_NOT_FOUND
,
7348 _("notify-subscription-id %d no good!"), sub_id
);
7356 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
7358 con
, sub
->owner
)) != HTTP_OK
)
7360 send_http_error(con
, status
, sub
->dest
);
7365 * Copy the subscription attributes to the response using the
7366 * requested-attributes attribute that may be provided by the client.
7369 ra
= create_requested_array(con
->request
);
7371 copy_subscription_attrs(con
, sub
, ra
);
7373 cupsArrayDelete(ra
);
7375 con
->response
->request
.status
.status_code
= IPP_OK
;
7380 * 'get_subscriptions()' - Get subscriptions.
7384 get_subscriptions(cupsd_client_t
*con
, /* I - Client connection */
7385 ipp_attribute_t
*uri
) /* I - Printer/job URI */
7387 http_status_t status
; /* Policy status */
7388 int count
; /* Number of subscriptions */
7389 int limit
; /* Limit */
7390 cupsd_subscription_t
*sub
; /* Subscription */
7391 cups_array_t
*ra
; /* Requested attributes array */
7392 ipp_attribute_t
*attr
; /* Attribute */
7393 cups_ptype_t dtype
; /* Destination type (printer/class) */
7394 char scheme
[HTTP_MAX_URI
],
7395 /* Scheme portion of URI */
7396 username
[HTTP_MAX_URI
],
7397 /* Username portion of URI */
7399 /* Host portion of URI */
7400 resource
[HTTP_MAX_URI
];
7401 /* Resource portion of URI */
7402 int port
; /* Port portion of URI */
7403 cupsd_job_t
*job
; /* Job pointer */
7404 cupsd_printer_t
*printer
; /* Printer */
7407 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7408 "get_subscriptions(con=%p[%d], uri=%s)",
7409 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
7412 * Is the destination valid?
7415 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7416 sizeof(scheme
), username
, sizeof(username
), host
,
7417 sizeof(host
), &port
, resource
, sizeof(resource
));
7419 if (!strcmp(resource
, "/") ||
7420 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6) ||
7421 (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10) ||
7422 (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9))
7427 else if (!strncmp(resource
, "/jobs/", 6) && resource
[6])
7430 job
= cupsdFindJob(atoi(resource
+ 6));
7434 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%s does not exist!"),
7439 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7445 send_ipp_status(con
, IPP_NOT_FOUND
,
7446 _("The printer or class was not found."));
7449 else if ((attr
= ippFindAttribute(con
->request
, "notify-job-id",
7450 IPP_TAG_INTEGER
)) != NULL
)
7452 job
= cupsdFindJob(attr
->values
[0].integer
);
7456 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"),
7457 attr
->values
[0].integer
);
7468 if ((status
= cupsdCheckPolicy(printer
? printer
->op_policy_ptr
:
7470 con
, NULL
)) != HTTP_OK
)
7472 send_http_error(con
, status
, printer
);
7477 * Copy the subscription attributes to the response using the
7478 * requested-attributes attribute that may be provided by the client.
7481 ra
= create_requested_array(con
->request
);
7483 if ((attr
= ippFindAttribute(con
->request
, "limit",
7484 IPP_TAG_INTEGER
)) != NULL
)
7485 limit
= attr
->values
[0].integer
;
7490 * See if we only want to see subscriptions for a specific user...
7493 if ((attr
= ippFindAttribute(con
->request
, "my-subscriptions",
7494 IPP_TAG_BOOLEAN
)) != NULL
&&
7495 attr
->values
[0].boolean
)
7496 strlcpy(username
, get_username(con
), sizeof(username
));
7500 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
), count
= 0;
7502 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
7503 if ((!printer
|| sub
->dest
== printer
) && (!job
|| sub
->job
== job
) &&
7504 (!username
[0] || !strcasecmp(username
, sub
->owner
)))
7506 ippAddSeparator(con
->response
);
7507 copy_subscription_attrs(con
, sub
, ra
);
7510 if (limit
&& count
>= limit
)
7514 cupsArrayDelete(ra
);
7517 con
->response
->request
.status
.status_code
= IPP_OK
;
7519 send_ipp_status(con
, IPP_NOT_FOUND
, _("No subscriptions found."));
7524 * 'get_username()' - Get the username associated with a request.
7527 static const char * /* O - Username */
7528 get_username(cupsd_client_t
*con
) /* I - Connection */
7530 ipp_attribute_t
*attr
; /* Attribute */
7533 if (con
->username
[0])
7534 return (con
->username
);
7535 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7536 IPP_TAG_NAME
)) != NULL
)
7537 return (attr
->values
[0].string
.text
);
7539 return ("anonymous");
7544 * 'hold_job()' - Hold a print job.
7548 hold_job(cupsd_client_t
*con
, /* I - Client connection */
7549 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
7551 ipp_attribute_t
*attr
, /* Current job-hold-until */
7552 *newattr
; /* New job-hold-until */
7553 int jobid
; /* Job ID */
7554 char method
[HTTP_MAX_URI
], /* Method portion of URI */
7555 username
[HTTP_MAX_URI
], /* Username portion of URI */
7556 host
[HTTP_MAX_URI
], /* Host portion of URI */
7557 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7558 int port
; /* Port portion of URI */
7559 cupsd_job_t
*job
; /* Job information */
7562 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_job(%p[%d], %s)", con
, con
->http
.fd
,
7563 uri
->values
[0].string
.text
);
7566 * See if we have a job URI or a printer URI...
7569 if (!strcmp(uri
->name
, "printer-uri"))
7572 * Got a printer URI; see if we also have a job-id attribute...
7575 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7576 IPP_TAG_INTEGER
)) == NULL
)
7578 send_ipp_status(con
, IPP_BAD_REQUEST
,
7579 _("Got a printer-uri attribute but no job-id!"));
7583 jobid
= attr
->values
[0].integer
;
7588 * Got a job URI; parse it to get the job ID...
7591 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
7592 sizeof(method
), username
, sizeof(username
), host
,
7593 sizeof(host
), &port
, resource
, sizeof(resource
));
7595 if (strncmp(resource
, "/jobs/", 6))
7601 send_ipp_status(con
, IPP_BAD_REQUEST
,
7602 _("Bad job-uri attribute \"%s\"!"),
7603 uri
->values
[0].string
.text
);
7607 jobid
= atoi(resource
+ 6);
7611 * See if the job exists...
7614 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7617 * Nope - return a "not found" error...
7620 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
7625 * See if the job is owned by the requesting user...
7628 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7630 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
7635 * Hold the job and return...
7640 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, job
->printer
, job
,
7641 "Job held by user.");
7643 if ((newattr
= ippFindAttribute(con
->request
, "job-hold-until",
7644 IPP_TAG_KEYWORD
)) == NULL
)
7645 newattr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
7647 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
7648 IPP_TAG_KEYWORD
)) == NULL
)
7649 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
7654 * Free the old hold value and copy the new one over...
7657 _cupsStrFree(attr
->values
[0].string
.text
);
7661 attr
->value_tag
= newattr
->value_tag
;
7662 attr
->values
[0].string
.text
=
7663 _cupsStrAlloc(newattr
->values
[0].string
.text
);
7667 attr
->value_tag
= IPP_TAG_KEYWORD
;
7668 attr
->values
[0].string
.text
= _cupsStrAlloc("indefinite");
7672 * Hold job until specified time...
7675 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
);
7677 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, job
->printer
, job
,
7678 "Job job-hold-until value changed by user.");
7681 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Held by \"%s\".", jobid
,
7684 con
->response
->request
.status
.status_code
= IPP_OK
;
7689 * 'move_job()' - Move a job to a new destination.
7693 move_job(cupsd_client_t
*con
, /* I - Client connection */
7694 ipp_attribute_t
*uri
) /* I - Job URI */
7696 http_status_t status
; /* Policy status */
7697 ipp_attribute_t
*attr
; /* Current attribute */
7698 int jobid
; /* Job ID */
7699 cupsd_job_t
*job
; /* Current job */
7700 const char *src
; /* Source printer/class */
7701 cups_ptype_t stype
, /* Source type (printer or class) */
7702 dtype
; /* Destination type (printer/class) */
7703 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
7704 username
[HTTP_MAX_URI
], /* Username portion of URI */
7705 host
[HTTP_MAX_URI
], /* Host portion of URI */
7706 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7707 int port
; /* Port portion of URI */
7708 cupsd_printer_t
*sprinter
, /* Source printer */
7709 *dprinter
; /* Destination printer */
7712 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "move_job(%p[%d], %s)", con
, con
->http
.fd
,
7713 uri
->values
[0].string
.text
);
7716 * Get the new printer or class...
7719 if ((attr
= ippFindAttribute(con
->request
, "job-printer-uri",
7720 IPP_TAG_URI
)) == NULL
)
7723 * Need job-printer-uri...
7726 send_ipp_status(con
, IPP_BAD_REQUEST
,
7727 _("job-printer-uri attribute missing!"));
7731 if (!cupsdValidateDest(attr
->values
[0].string
.text
, &dtype
, &dprinter
))
7737 send_ipp_status(con
, IPP_NOT_FOUND
,
7738 _("The printer or class was not found."));
7743 * See if we have a job URI or a printer URI...
7746 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7747 sizeof(scheme
), username
, sizeof(username
), host
,
7748 sizeof(host
), &port
, resource
, sizeof(resource
));
7750 if (!strcmp(uri
->name
, "printer-uri"))
7753 * Got a printer URI; see if we also have a job-id attribute...
7756 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7757 IPP_TAG_INTEGER
)) == NULL
)
7763 if ((src
= cupsdValidateDest(uri
->values
[0].string
.text
, &stype
,
7764 &sprinter
)) == NULL
)
7770 send_ipp_status(con
, IPP_NOT_FOUND
,
7771 _("The printer or class was not found."));
7780 * Otherwise, just move a single job...
7783 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
7786 * Nope - return a "not found" error...
7789 send_ipp_status(con
, IPP_NOT_FOUND
,
7790 _("Job #%d does not exist!"), attr
->values
[0].integer
);
7796 * Job found, initialize source pointers...
7807 * Got a job URI; parse it to get the job ID...
7810 if (strncmp(resource
, "/jobs/", 6))
7816 send_ipp_status(con
, IPP_BAD_REQUEST
,
7817 _("Bad job-uri attribute \"%s\"!"),
7818 uri
->values
[0].string
.text
);
7823 * See if the job exists...
7826 jobid
= atoi(resource
+ 6);
7828 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7831 * Nope - return a "not found" error...
7834 send_ipp_status(con
, IPP_NOT_FOUND
,
7835 _("Job #%d does not exist!"), jobid
);
7841 * Job found, initialize source pointers...
7850 * Check the policy of the destination printer...
7853 if ((status
= cupsdCheckPolicy(dprinter
->op_policy_ptr
, con
,
7854 job
? job
->username
: NULL
)) != HTTP_OK
)
7856 send_http_error(con
, status
, dprinter
);
7861 * Now move the job or jobs...
7867 * See if the job has been completed...
7870 if (job
->state_value
> IPP_JOB_STOPPED
)
7873 * Return a "not-possible" error...
7876 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
7877 _("Job #%d is finished and cannot be altered!"),
7883 * See if the job is owned by the requesting user...
7886 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7888 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
7893 * Move the job to a different printer or class...
7896 cupsdMoveJob(job
, dprinter
);
7901 * Got the source printer, now look through the jobs...
7904 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
7906 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
7909 * See if the job is pointing at the source printer or has not been
7913 if (strcasecmp(job
->dest
, src
) ||
7914 job
->state_value
> IPP_JOB_STOPPED
)
7918 * See if the job can be moved by the requesting user...
7921 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7925 * Move the job to a different printer or class...
7928 cupsdMoveJob(job
, dprinter
);
7933 * Start jobs if possible...
7939 * Return with "everything is OK" status...
7942 con
->response
->request
.status
.status_code
= IPP_OK
;
7947 * 'ppd_parse_line()' - Parse a PPD default line.
7950 static int /* O - 0 on success, -1 on failure */
7951 ppd_parse_line(const char *line
, /* I - Line */
7952 char *option
, /* O - Option name */
7953 int olen
, /* I - Size of option name */
7954 char *choice
, /* O - Choice name */
7955 int clen
) /* I - Size of choice name */
7958 * Verify this is a default option line...
7961 if (strncmp(line
, "*Default", 8))
7965 * Read the option name...
7968 for (line
+= 8, olen
--; isalnum(*line
& 255); line
++)
7978 * Skip everything else up to the colon (:)...
7981 while (*line
&& *line
!= ':')
7990 * Now grab the option choice, skipping leading whitespace...
7993 while (isspace(*line
& 255))
7996 for (clen
--; isalnum(*line
& 255); line
++)
8006 * Return with no errors...
8014 * 'print_job()' - Print a file to a printer or class.
8018 print_job(cupsd_client_t
*con
, /* I - Client connection */
8019 ipp_attribute_t
*uri
) /* I - Printer URI */
8021 ipp_attribute_t
*attr
; /* Current attribute */
8022 ipp_attribute_t
*format
; /* Document-format attribute */
8023 const char *default_format
; /* document-format-default value */
8024 cupsd_job_t
*job
; /* New job */
8025 char filename
[1024]; /* Job filename */
8026 mime_type_t
*filetype
; /* Type of file */
8027 char super
[MIME_MAX_SUPER
], /* Supertype of file */
8028 type
[MIME_MAX_TYPE
], /* Subtype of file */
8029 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
8030 /* Textual name of mime type */
8031 cupsd_printer_t
*printer
; /* Printer data */
8032 struct stat fileinfo
; /* File information */
8033 int kbytes
; /* Size of file */
8034 int compression
; /* Document compression */
8037 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "print_job(%p[%d], %s)", con
, con
->http
.fd
,
8038 uri
->values
[0].string
.text
);
8041 * Validate print file attributes, for now just document-format and
8042 * compression (CUPS only supports "none" and "gzip")...
8045 compression
= CUPS_FILE_NONE
;
8047 if ((attr
= ippFindAttribute(con
->request
, "compression",
8048 IPP_TAG_KEYWORD
)) != NULL
)
8050 if (strcmp(attr
->values
[0].string
.text
, "none")
8052 && strcmp(attr
->values
[0].string
.text
, "gzip")
8053 #endif /* HAVE_LIBZ */
8056 send_ipp_status(con
, IPP_ATTRIBUTES
,
8057 _("Unsupported compression \"%s\"!"),
8058 attr
->values
[0].string
.text
);
8059 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
8060 "compression", NULL
, attr
->values
[0].string
.text
);
8065 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
8066 compression
= CUPS_FILE_GZIP
;
8067 #endif /* HAVE_LIBZ */
8071 * Do we have a file to print?
8076 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file!?!"));
8081 * Is the destination valid?
8084 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
8090 send_ipp_status(con
, IPP_NOT_FOUND
,
8091 _("The printer or class was not found."));
8096 * Is it a format we support?
8099 if ((format
= ippFindAttribute(con
->request
, "document-format",
8100 IPP_TAG_MIMETYPE
)) != NULL
)
8103 * Grab format from client...
8106 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]", super
,
8109 send_ipp_status(con
, IPP_BAD_REQUEST
,
8110 _("Could not scan type \"%s\"!"),
8111 format
->values
[0].string
.text
);
8115 else if ((default_format
= cupsGetOption("document-format",
8116 printer
->num_options
,
8117 printer
->options
)) != NULL
)
8120 * Use default document format...
8123 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
8125 send_ipp_status(con
, IPP_BAD_REQUEST
,
8126 _("Could not scan type \"%s\"!"),
8137 strcpy(super
, "application");
8138 strcpy(type
, "octet-stream");
8141 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
8144 * Auto-type the file...
8147 ipp_attribute_t
*doc_name
; /* document-name attribute */
8150 cupsdLogMessage(CUPSD_LOG_DEBUG
, "print_job: auto-typing file...");
8152 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
8153 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
8154 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
8158 filetype
= mimeType(MimeDatabase
, super
, type
);
8161 filetype
= mimeType(MimeDatabase
, super
, type
);
8165 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
8168 * Replace the document-format attribute value with the auto-typed or
8172 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
8177 _cupsStrFree(format
->values
[0].string
.text
);
8179 format
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
8182 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
8183 "document-format", NULL
, mimetype
);
8187 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
8188 _("Unsupported format \'%s/%s\'!"), super
, type
);
8189 cupsdLogMessage(CUPSD_LOG_INFO
,
8190 "Hint: Do you have the raw file printing rules enabled?");
8193 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
8194 "document-format", NULL
, format
->values
[0].string
.text
);
8200 * Read any embedded job ticket info from PS files...
8203 if (!strcasecmp(filetype
->super
, "application") &&
8204 !strcasecmp(filetype
->type
, "postscript"))
8205 read_ps_job_ticket(con
);
8208 * Create the job object...
8211 if ((job
= add_job(con
, printer
, filetype
)) == NULL
)
8214 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Adding job file of type %s/%s.",
8215 job
->id
, filetype
->super
, filetype
->type
);
8218 * Update quota data...
8221 if (stat(con
->filename
, &fileinfo
))
8224 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
8226 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
8228 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
8229 IPP_TAG_INTEGER
)) != NULL
)
8230 attr
->values
[0].integer
+= kbytes
;
8233 * Add the job file...
8236 if (add_file(con
, job
, filetype
, compression
))
8239 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
8241 rename(con
->filename
, filename
);
8242 cupsdClearString(&con
->filename
);
8245 * See if we need to add the ending sheet...
8248 if (cupsdTimeoutJob(job
))
8252 * Log and save the job...
8255 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Queued on \"%s\" by \"%s\".",
8256 job
->id
, job
->dest
, job
->username
);
8257 cupsdLogMessage(CUPSD_LOG_DEBUG
, "[Job %d] hold_until = %d", job
->id
,
8258 (int)job
->hold_until
);
8263 * Start the job if possible...
8271 * 'read_ps_job_ticket()' - Reads a job ticket embedded in a PS file.
8273 * This function only gets called when printing a single PostScript
8274 * file using the Print-Job operation. It doesn't work for Create-Job +
8275 * Send-File, since the job attributes need to be set at job creation
8276 * time for banners to work. The embedded PS job ticket stuff is here
8277 * only to allow the Windows printer driver for CUPS to pass in JCL
8278 * options and IPP attributes which otherwise would be lost.
8280 * The format of a PS job ticket is simple:
8282 * %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
8284 * %cupsJobTicket: attr1=value1
8285 * %cupsJobTicket: attr2=value2
8287 * %cupsJobTicket: attrN=valueN
8289 * Job ticket lines must appear immediately after the first line that
8290 * specifies PostScript format (%!PS-Adobe-3.0), and CUPS will stop
8291 * looking for job ticket info when it finds a line that does not begin
8292 * with "%cupsJobTicket:".
8294 * The maximum length of a job ticket line, including the prefix, is
8295 * 255 characters to conform with the Adobe DSC.
8297 * Read-only attributes are rejected with a notice to the error log in
8298 * case a malicious user tries anything. Since the job ticket is read
8299 * prior to attribute validation in print_job(), job ticket attributes
8300 * will go through the same validation as IPP attributes...
8304 read_ps_job_ticket(cupsd_client_t
*con
) /* I - Client connection */
8306 cups_file_t
*fp
; /* File to read from */
8307 char line
[256]; /* Line data */
8308 int num_options
; /* Number of options */
8309 cups_option_t
*options
; /* Options */
8310 ipp_t
*ticket
; /* New attributes */
8311 ipp_attribute_t
*attr
, /* Current attribute */
8312 *attr2
, /* Job attribute */
8313 *prev2
; /* Previous job attribute */
8317 * First open the print file...
8320 if ((fp
= cupsFileOpen(con
->filename
, "rb")) == NULL
)
8322 cupsdLogMessage(CUPSD_LOG_ERROR
,
8323 "read_ps_job_ticket: Unable to open PostScript print file "
8330 * Skip the first line...
8333 if (cupsFileGets(fp
, line
, sizeof(line
)) == NULL
)
8335 cupsdLogMessage(CUPSD_LOG_ERROR
,
8336 "read_ps_job_ticket: Unable to read from PostScript print "
8343 if (strncmp(line
, "%!PS-Adobe-", 11))
8346 * Not a DSC-compliant file, so no job ticket info will be available...
8354 * Read job ticket info from the file...
8360 while (cupsFileGets(fp
, line
, sizeof(line
)))
8363 * Stop at the first non-ticket line...
8366 if (strncmp(line
, "%cupsJobTicket:", 15))
8370 * Add the options to the option array...
8373 num_options
= cupsParseOptions(line
+ 15, num_options
, &options
);
8377 * Done with the file; see if we have any options...
8382 if (num_options
== 0)
8386 * OK, convert the options to an attribute list, and apply them to
8391 cupsEncodeOptions(ticket
, num_options
, options
);
8394 * See what the user wants to change.
8397 for (attr
= ticket
->attrs
; attr
; attr
= attr
->next
)
8399 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
8402 if (!strcmp(attr
->name
, "job-originating-host-name") ||
8403 !strcmp(attr
->name
, "job-originating-user-name") ||
8404 !strcmp(attr
->name
, "job-media-sheets-completed") ||
8405 !strcmp(attr
->name
, "job-k-octets") ||
8406 !strcmp(attr
->name
, "job-id") ||
8407 !strncmp(attr
->name
, "job-state", 9) ||
8408 !strncmp(attr
->name
, "time-at-", 8))
8409 continue; /* Read-only attrs */
8411 if ((attr2
= ippFindAttribute(con
->request
, attr
->name
,
8412 IPP_TAG_ZERO
)) != NULL
)
8415 * Some other value; first free the old value...
8418 if (con
->request
->attrs
== attr2
)
8420 con
->request
->attrs
= attr2
->next
;
8425 for (prev2
= con
->request
->attrs
; prev2
; prev2
= prev2
->next
)
8426 if (prev2
->next
== attr2
)
8428 prev2
->next
= attr2
->next
;
8433 if (con
->request
->last
== attr2
)
8434 con
->request
->last
= prev2
;
8436 _ippFreeAttr(attr2
);
8440 * Add new option by copying it...
8443 copy_attribute(con
->request
, attr
, 0);
8447 * Then free the attribute list and option array...
8451 cupsFreeOptions(num_options
, options
);
8456 * 'reject_jobs()' - Reject print jobs to a printer.
8460 reject_jobs(cupsd_client_t
*con
, /* I - Client connection */
8461 ipp_attribute_t
*uri
) /* I - Printer or class URI */
8463 http_status_t status
; /* Policy status */
8464 cups_ptype_t dtype
; /* Destination type (printer/class) */
8465 cupsd_printer_t
*printer
; /* Printer data */
8466 ipp_attribute_t
*attr
; /* printer-state-message text */
8469 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "reject_jobs(%p[%d], %s)", con
,
8470 con
->http
.fd
, uri
->values
[0].string
.text
);
8473 * Is the destination valid?
8476 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8482 send_ipp_status(con
, IPP_NOT_FOUND
,
8483 _("The printer or class was not found."));
8491 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8493 send_http_error(con
, status
, printer
);
8498 * Reject jobs sent to the printer...
8501 printer
->accepting
= 0;
8503 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
8504 IPP_TAG_TEXT
)) == NULL
)
8505 strcpy(printer
->state_message
, "Rejecting Jobs");
8507 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
8508 sizeof(printer
->state_message
));
8510 cupsdAddPrinterHistory(printer
);
8512 if (dtype
& CUPS_PRINTER_CLASS
)
8514 cupsdSaveAllClasses();
8516 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" rejecting jobs (\"%s\").",
8517 printer
->name
, get_username(con
));
8521 cupsdSaveAllPrinters();
8523 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" rejecting jobs (\"%s\").",
8524 printer
->name
, get_username(con
));
8528 * Everything was ok, so return OK status...
8531 con
->response
->request
.status
.status_code
= IPP_OK
;
8536 * 'release_job()' - Release a held print job.
8540 release_job(cupsd_client_t
*con
, /* I - Client connection */
8541 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
8543 ipp_attribute_t
*attr
; /* Current attribute */
8544 int jobid
; /* Job ID */
8545 char method
[HTTP_MAX_URI
], /* Method portion of URI */
8546 username
[HTTP_MAX_URI
], /* Username portion of URI */
8547 host
[HTTP_MAX_URI
], /* Host portion of URI */
8548 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8549 int port
; /* Port portion of URI */
8550 cupsd_job_t
*job
; /* Job information */
8553 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_job(%p[%d], %s)", con
,
8554 con
->http
.fd
, uri
->values
[0].string
.text
);
8557 * See if we have a job URI or a printer URI...
8560 if (!strcmp(uri
->name
, "printer-uri"))
8563 * Got a printer URI; see if we also have a job-id attribute...
8566 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8567 IPP_TAG_INTEGER
)) == NULL
)
8569 send_ipp_status(con
, IPP_BAD_REQUEST
,
8570 _("Got a printer-uri attribute but no job-id!"));
8574 jobid
= attr
->values
[0].integer
;
8579 * Got a job URI; parse it to get the job ID...
8582 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
8583 sizeof(method
), username
, sizeof(username
), host
,
8584 sizeof(host
), &port
, resource
, sizeof(resource
));
8586 if (strncmp(resource
, "/jobs/", 6))
8592 send_ipp_status(con
, IPP_BAD_REQUEST
,
8593 _("Bad job-uri attribute \"%s\"!"),
8594 uri
->values
[0].string
.text
);
8598 jobid
= atoi(resource
+ 6);
8602 * See if the job exists...
8605 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8608 * Nope - return a "not found" error...
8611 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
8616 * See if job is "held"...
8619 if (job
->state_value
!= IPP_JOB_HELD
)
8622 * Nope - return a "not possible" error...
8625 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not held!"), jobid
);
8630 * See if the job is owned by the requesting user...
8633 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8635 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
8640 * Reset the job-hold-until value to "no-hold"...
8643 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
8644 IPP_TAG_KEYWORD
)) == NULL
)
8645 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
8649 _cupsStrFree(attr
->values
[0].string
.text
);
8651 attr
->value_tag
= IPP_TAG_KEYWORD
;
8652 attr
->values
[0].string
.text
= _cupsStrAlloc("no-hold");
8654 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, job
->printer
, job
,
8655 "Job job-hold-until value changed by user.");
8659 * Release the job and return...
8662 cupsdReleaseJob(job
);
8664 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, job
->printer
, job
,
8665 "Job released by user.");
8667 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Released by \"%s\".", jobid
,
8670 con
->response
->request
.status
.status_code
= IPP_OK
;
8675 * 'renew_subscription()' - Renew an existing subscription...
8680 cupsd_client_t
*con
, /* I - Client connection */
8681 int sub_id
) /* I - Subscription ID */
8683 http_status_t status
; /* Policy status */
8684 cupsd_subscription_t
*sub
; /* Subscription */
8685 ipp_attribute_t
*lease
; /* notify-lease-duration */
8688 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
8689 "renew_subscription(con=%p[%d], sub_id=%d)",
8690 con
, con
->http
.fd
, sub_id
);
8693 * Is the subscription ID valid?
8696 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
8699 * Bad subscription ID...
8702 send_ipp_status(con
, IPP_NOT_FOUND
,
8703 _("notify-subscription-id %d no good!"), sub_id
);
8710 * Job subscriptions cannot be renewed...
8713 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8714 _("Job subscriptions cannot be renewed!"));
8722 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
8724 con
, sub
->owner
)) != HTTP_OK
)
8726 send_http_error(con
, status
, sub
->dest
);
8731 * Renew the subscription...
8734 lease
= ippFindAttribute(con
->request
, "notify-lease-duration",
8737 sub
->lease
= lease
? lease
->values
[0].integer
: DefaultLeaseDuration
;
8739 if (MaxLeaseDuration
&& (sub
->lease
== 0 || sub
->lease
> MaxLeaseDuration
))
8741 cupsdLogMessage(CUPSD_LOG_INFO
,
8742 "renew_subscription: Limiting notify-lease-duration to "
8745 sub
->lease
= MaxLeaseDuration
;
8748 sub
->expire
= sub
->lease
? time(NULL
) + sub
->lease
: 0;
8750 cupsdSaveAllSubscriptions();
8752 con
->response
->request
.status
.status_code
= IPP_OK
;
8754 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
8755 "notify-lease-duration", sub
->lease
);
8760 * 'restart_job()' - Restart an old print job.
8764 restart_job(cupsd_client_t
*con
, /* I - Client connection */
8765 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
8767 ipp_attribute_t
*attr
; /* Current attribute */
8768 int jobid
; /* Job ID */
8769 char method
[HTTP_MAX_URI
], /* Method portion of URI */
8770 username
[HTTP_MAX_URI
], /* Username portion of URI */
8771 host
[HTTP_MAX_URI
], /* Host portion of URI */
8772 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8773 int port
; /* Port portion of URI */
8774 cupsd_job_t
*job
; /* Job information */
8777 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "restart_job(%p[%d], %s)", con
,
8778 con
->http
.fd
, uri
->values
[0].string
.text
);
8781 * See if we have a job URI or a printer URI...
8784 if (!strcmp(uri
->name
, "printer-uri"))
8787 * Got a printer URI; see if we also have a job-id attribute...
8790 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8791 IPP_TAG_INTEGER
)) == NULL
)
8793 send_ipp_status(con
, IPP_BAD_REQUEST
,
8794 _("Got a printer-uri attribute but no job-id!"));
8798 jobid
= attr
->values
[0].integer
;
8803 * Got a job URI; parse it to get the job ID...
8806 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
8807 sizeof(method
), username
, sizeof(username
), host
,
8808 sizeof(host
), &port
, resource
, sizeof(resource
));
8810 if (strncmp(resource
, "/jobs/", 6))
8816 send_ipp_status(con
, IPP_BAD_REQUEST
,
8817 _("Bad job-uri attribute \"%s\"!"),
8818 uri
->values
[0].string
.text
);
8822 jobid
= atoi(resource
+ 6);
8826 * See if the job exists...
8829 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8832 * Nope - return a "not found" error...
8835 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
8840 * See if job is in any of the "completed" states...
8843 if (job
->state_value
<= IPP_JOB_PROCESSING
)
8846 * Nope - return a "not possible" error...
8849 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not complete!"),
8855 * See if we have retained the job files...
8860 if (!job
->attrs
|| job
->num_files
== 0)
8863 * Nope - return a "not possible" error...
8866 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8867 _("Job #%d cannot be restarted - no files!"), jobid
);
8872 * See if the job is owned by the requesting user...
8875 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8877 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
8882 * Restart the job and return...
8885 cupsdRestartJob(job
);
8887 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Restarted by \"%s\".", jobid
,
8890 con
->response
->request
.status
.status_code
= IPP_OK
;
8895 * 'save_auth_info()' - Save authentication information for a job.
8900 cupsd_client_t
*con
, /* I - Client connection */
8901 cupsd_job_t
*job
, /* I - Job */
8902 ipp_attribute_t
*auth_info
) /* I - auth-info attribute, if any */
8904 int i
; /* Looping var */
8905 char filename
[1024]; /* Job authentication filename */
8906 cups_file_t
*fp
; /* Job authentication file */
8907 char line
[2048]; /* Line for file */
8908 cupsd_printer_t
*dest
; /* Destination printer/class */
8912 * This function saves the in-memory authentication information for
8913 * a job so that it can be used to authenticate with a remote host.
8914 * The information is stored in a file that is readable only by the
8915 * root user. The fields are Base-64 encoded, each on a separate line,
8916 * followed by random number (up to 1024) of newlines to limit the
8917 * amount of information that is exposed.
8919 * Because of the potential for exposing of authentication information,
8920 * this functionality is only enabled when running cupsd as root.
8922 * This caching only works for the Basic and BasicDigest authentication
8923 * types. Digest authentication cannot be cached this way, and in
8924 * the future Kerberos authentication may make all of this obsolete.
8926 * Authentication information is saved whenever an authenticated
8927 * Print-Job, Create-Job, or CUPS-Authenticate-Job operation is
8930 * This information is deleted after a job is completed or canceled,
8931 * so reprints may require subsequent re-authentication.
8937 if ((dest
= cupsdFindDest(job
->dest
)) == NULL
)
8941 * Create the authentication file and change permissions...
8944 snprintf(filename
, sizeof(filename
), "%s/a%05d", RequestRoot
, job
->id
);
8945 if ((fp
= cupsFileOpen(filename
, "w")) == NULL
)
8947 cupsdLogMessage(CUPSD_LOG_ERROR
,
8948 "Unable to save authentication info to \"%s\" - %s",
8949 filename
, strerror(errno
));
8953 fchown(cupsFileNumber(fp
), 0, 0);
8954 fchmod(cupsFileNumber(fp
), 0400);
8956 if (auth_info
&& auth_info
->num_values
== dest
->num_auth_info_required
)
8959 * Write 1 to 3 auth values...
8962 cupsdClearString(&job
->auth_username
);
8963 cupsdClearString(&job
->auth_domain
);
8964 cupsdClearString(&job
->auth_password
);
8966 for (i
= 0; i
< auth_info
->num_values
; i
++)
8968 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[i
].string
.text
,
8969 strlen(auth_info
->values
[i
].string
.text
));
8970 cupsFilePrintf(fp
, "%s\n", line
);
8972 if (!strcmp(dest
->auth_info_required
[i
], "username"))
8973 cupsdSetStringf(&job
->auth_username
, "AUTH_USERNAME=%s",
8974 auth_info
->values
[i
].string
.text
);
8975 else if (!strcmp(dest
->auth_info_required
[i
], "domain"))
8976 cupsdSetStringf(&job
->auth_domain
, "AUTH_DOMAIN=%s",
8977 auth_info
->values
[i
].string
.text
);
8978 else if (!strcmp(dest
->auth_info_required
[i
], "password"))
8979 cupsdSetStringf(&job
->auth_password
, "AUTH_PASSWORD=%s",
8980 auth_info
->values
[i
].string
.text
);
8983 else if (con
->username
[0])
8986 * Write the authenticated username...
8989 httpEncode64_2(line
, sizeof(line
), con
->username
, strlen(con
->username
));
8990 cupsFilePrintf(fp
, "%s\n", line
);
8992 cupsdSetStringf(&job
->auth_username
, "AUTH_USERNAME=%s", con
->username
);
8993 cupsdClearString(&job
->auth_domain
);
8996 * Write the authenticated password...
8999 httpEncode64_2(line
, sizeof(line
), con
->password
, strlen(con
->password
));
9000 cupsFilePrintf(fp
, "%s\n", line
);
9002 cupsdSetStringf(&job
->auth_password
, "AUTH_PASSWORD=%s", con
->password
);
9006 * Write a random number of newlines to the end of the file...
9009 for (i
= (rand() % 1024); i
>= 0; i
--)
9010 cupsFilePutChar(fp
, '\n');
9013 * Close the file and return...
9018 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
9019 if (con
->gss_have_creds
)
9020 save_krb5_creds(con
, job
);
9021 else if (job
->ccname
)
9022 cupsdClearString(&(job
->ccname
));
9023 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
9027 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
9029 * 'save_krb5_creds()' - Save Kerberos credentials for the job.
9033 save_krb5_creds(cupsd_client_t
*con
, /* I - Client connection */
9034 cupsd_job_t
*job
) /* I - Job */
9036 # if !defined(HAVE_KRB5_CC_NEW_UNIQUE) && !defined(HAVE_HEIMDAL)
9037 cupsdLogMessage(CUPSD_LOG_INFO
,
9038 "Sorry, your version of Kerberos does not support delegated "
9043 krb5_error_code error
; /* Kerberos error code */
9044 OM_uint32 major_status
, /* Major status code */
9045 minor_status
; /* Minor status code */
9046 krb5_principal principal
; /* Kerberos principal */
9051 * If the weak-linked GSSAPI/Kerberos library is not present, don't try
9055 if (krb5_init_context
== NULL
)
9057 # endif /* __APPLE__ */
9060 * We MUST create a file-based cache because memory-based caches are
9061 * only valid for the current process/address space.
9063 * Due to various bugs/features in different versions of Kerberos, we
9064 * need either the krb5_cc_new_unique() function or Heimdal's version
9065 * of krb5_cc_gen_new() to create a new FILE: credential cache that
9066 * can be passed to the backend. These functions create a temporary
9067 * file (typically in /tmp) containing the cached credentials, which
9068 * are removed when we have successfully printed a job.
9071 # ifdef HAVE_KRB5_CC_NEW_UNIQUE
9072 if ((error
= krb5_cc_new_unique(KerberosContext
, "FILE", NULL
,
9073 &(job
->ccache
))) != 0)
9074 # else /* HAVE_HEIMDAL */
9075 if ((error
= krb5_cc_gen_new(KerberosContext
, &krb5_fcc_ops
,
9076 &(job
->ccache
))) != 0)
9077 # endif /* HAVE_KRB5_CC_NEW_UNIQUE */
9079 cupsdLogMessage(CUPSD_LOG_ERROR
,
9080 "Unable to create new credentials cache (%d/%s)",
9081 error
, strerror(errno
));
9086 if ((error
= krb5_parse_name(KerberosContext
, con
->username
, &principal
)) != 0)
9088 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to parse kerberos username (%d/%s)",
9089 error
, strerror(errno
));
9090 krb5_cc_destroy(KerberosContext
, job
->ccache
);
9095 if ((error
= krb5_cc_initialize(KerberosContext
, job
->ccache
, principal
)))
9097 cupsdLogMessage(CUPSD_LOG_ERROR
,
9098 "Unable to initialize credentials cache (%d/%s)", error
,
9100 krb5_cc_destroy(KerberosContext
, job
->ccache
);
9101 krb5_free_principal(KerberosContext
, principal
);
9106 krb5_free_principal(KerberosContext
, principal
);
9109 * Copy the user's credentials to the new cache file...
9112 major_status
= gss_krb5_copy_ccache(&minor_status
, con
->gss_delegated_cred
,
9115 if (GSS_ERROR(major_status
))
9117 cupsdLogGSSMessage(CUPSD_LOG_ERROR
, major_status
, minor_status
,
9118 "Unable to import client credentials cache");
9119 krb5_cc_destroy(KerberosContext
, job
->ccache
);
9125 * Add the KRB5CCNAME environment variable to the job so that the
9126 * backend can use the credentials when printing.
9129 cupsdSetStringf(&(job
->ccname
), "KRB5CCNAME=FILE:%s",
9130 krb5_cc_get_name(KerberosContext
, job
->ccache
));
9132 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "[Job %d] save_krb5_creds: %s", job
->id
,
9134 # endif /* HAVE_KRB5_CC_NEW_UNIQUE || HAVE_HEIMDAL */
9136 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
9140 * 'send_document()' - Send a file to a printer or class.
9144 send_document(cupsd_client_t
*con
, /* I - Client connection */
9145 ipp_attribute_t
*uri
) /* I - Printer URI */
9147 ipp_attribute_t
*attr
; /* Current attribute */
9148 ipp_attribute_t
*format
; /* Document-format attribute */
9149 const char *default_format
;/* document-format-default value */
9150 int jobid
; /* Job ID number */
9151 cupsd_job_t
*job
; /* Current job */
9152 char job_uri
[HTTP_MAX_URI
],
9154 method
[HTTP_MAX_URI
],
9155 /* Method portion of URI */
9156 username
[HTTP_MAX_URI
],
9157 /* Username portion of URI */
9159 /* Host portion of URI */
9160 resource
[HTTP_MAX_URI
];
9161 /* Resource portion of URI */
9162 int port
; /* Port portion of URI */
9163 mime_type_t
*filetype
; /* Type of file */
9164 char super
[MIME_MAX_SUPER
],
9165 /* Supertype of file */
9166 type
[MIME_MAX_TYPE
],
9167 /* Subtype of file */
9168 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
9169 /* Textual name of mime type */
9170 char filename
[1024]; /* Job filename */
9171 cupsd_printer_t
*printer
; /* Current printer */
9172 struct stat fileinfo
; /* File information */
9173 int kbytes
; /* Size of file */
9174 int compression
; /* Type of compression */
9177 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "send_document(%p[%d], %s)", con
,
9178 con
->http
.fd
, uri
->values
[0].string
.text
);
9181 * See if we have a job URI or a printer URI...
9184 if (!strcmp(uri
->name
, "printer-uri"))
9187 * Got a printer URI; see if we also have a job-id attribute...
9190 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9191 IPP_TAG_INTEGER
)) == NULL
)
9193 send_ipp_status(con
, IPP_BAD_REQUEST
,
9194 _("Got a printer-uri attribute but no job-id!"));
9198 jobid
= attr
->values
[0].integer
;
9203 * Got a job URI; parse it to get the job ID...
9206 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
9207 sizeof(method
), username
, sizeof(username
), host
,
9208 sizeof(host
), &port
, resource
, sizeof(resource
));
9210 if (strncmp(resource
, "/jobs/", 6))
9216 send_ipp_status(con
, IPP_BAD_REQUEST
,
9217 _("Bad job-uri attribute \"%s\"!"),
9218 uri
->values
[0].string
.text
);
9222 jobid
= atoi(resource
+ 6);
9226 * See if the job exists...
9229 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9232 * Nope - return a "not found" error...
9235 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
9239 printer
= cupsdFindDest(job
->dest
);
9242 * See if the job is owned by the requesting user...
9245 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9247 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
9252 * OK, see if the client is sending the document compressed - CUPS
9253 * only supports "none" and "gzip".
9256 compression
= CUPS_FILE_NONE
;
9258 if ((attr
= ippFindAttribute(con
->request
, "compression",
9259 IPP_TAG_KEYWORD
)) != NULL
)
9261 if (strcmp(attr
->values
[0].string
.text
, "none")
9263 && strcmp(attr
->values
[0].string
.text
, "gzip")
9264 #endif /* HAVE_LIBZ */
9267 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Unsupported compression \"%s\"!"),
9268 attr
->values
[0].string
.text
);
9269 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
9270 "compression", NULL
, attr
->values
[0].string
.text
);
9275 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
9276 compression
= CUPS_FILE_GZIP
;
9277 #endif /* HAVE_LIBZ */
9281 * Do we have a file to print?
9286 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file!?!"));
9291 * Is it a format we support?
9294 if ((format
= ippFindAttribute(con
->request
, "document-format",
9295 IPP_TAG_MIMETYPE
)) != NULL
)
9298 * Grab format from client...
9301 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
9304 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"!"),
9305 format
->values
[0].string
.text
);
9309 else if ((default_format
= cupsGetOption("document-format",
9310 printer
->num_options
,
9311 printer
->options
)) != NULL
)
9314 * Use default document format...
9317 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
9319 send_ipp_status(con
, IPP_BAD_REQUEST
,
9320 _("Could not scan type \"%s\"!"),
9328 * No document format attribute? Auto-type it!
9331 strcpy(super
, "application");
9332 strcpy(type
, "octet-stream");
9335 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
9338 * Auto-type the file...
9341 ipp_attribute_t
*doc_name
; /* document-name attribute */
9344 cupsdLogMessage(CUPSD_LOG_DEBUG
, "send_document: auto-typing file...");
9346 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
9347 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
9348 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
9352 filetype
= mimeType(MimeDatabase
, super
, type
);
9355 filetype
= mimeType(MimeDatabase
, super
, type
);
9359 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
9362 * Replace the document-format attribute value with the auto-typed or
9366 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9371 _cupsStrFree(format
->values
[0].string
.text
);
9373 format
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
9376 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
9377 "document-format", NULL
, mimetype
);
9381 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9382 _("Unsupported format \'%s/%s\'!"), super
, type
);
9383 cupsdLogMessage(CUPSD_LOG_INFO
,
9384 "Hint: Do you have the raw file printing rules enabled?");
9387 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9388 "document-format", NULL
, format
->values
[0].string
.text
);
9393 if (printer
->filetypes
&& !cupsArrayFind(printer
->filetypes
, filetype
))
9395 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9398 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9399 _("Unsupported format \'%s\'!"), mimetype
);
9401 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9402 "document-format", NULL
, mimetype
);
9407 cupsdLogMessage(CUPSD_LOG_DEBUG
,
9408 "send_document: request file type is %s/%s.",
9409 filetype
->super
, filetype
->type
);
9412 * Add the file to the job...
9417 if (add_file(con
, job
, filetype
, compression
))
9420 if (stat(con
->filename
, &fileinfo
))
9423 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
9425 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
9427 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
9428 IPP_TAG_INTEGER
)) != NULL
)
9429 attr
->values
[0].integer
+= kbytes
;
9431 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
9433 rename(con
->filename
, filename
);
9435 cupsdClearString(&con
->filename
);
9437 cupsdLogMessage(CUPSD_LOG_INFO
,
9438 "File of type %s/%s queued in job #%d by \"%s\".",
9439 filetype
->super
, filetype
->type
, job
->id
, job
->username
);
9442 * Start the job if this is the last document...
9445 if ((attr
= ippFindAttribute(con
->request
, "last-document",
9446 IPP_TAG_BOOLEAN
)) != NULL
&&
9447 attr
->values
[0].boolean
)
9450 * See if we need to add the ending sheet...
9453 if (cupsdTimeoutJob(job
))
9456 if (job
->state_value
== IPP_JOB_STOPPED
)
9458 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9459 job
->state_value
= IPP_JOB_PENDING
;
9461 else if (job
->state_value
== IPP_JOB_HELD
)
9463 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9464 IPP_TAG_KEYWORD
)) == NULL
)
9465 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9467 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9469 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9470 job
->state_value
= IPP_JOB_PENDING
;
9477 * Start the job if possible... Since cupsdCheckJobs() can cancel a
9478 * job if it doesn't print, we need to re-find the job afterwards...
9485 job
= cupsdFindJob(jobid
);
9489 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9490 IPP_TAG_KEYWORD
)) == NULL
)
9491 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9493 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9495 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
9496 job
->state_value
= IPP_JOB_HELD
;
9497 job
->hold_until
= time(NULL
) + 60;
9503 * Fill in the response info...
9506 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
9509 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
9512 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", jobid
);
9514 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
9515 job
? job
->state_value
: IPP_JOB_CANCELED
);
9516 add_job_state_reasons(con
, job
);
9518 con
->response
->request
.status
.status_code
= IPP_OK
;
9523 * 'send_http_error()' - Send a HTTP error back to the IPP client.
9528 cupsd_client_t
*con
, /* I - Client connection */
9529 http_status_t status
, /* I - HTTP status code */
9530 cupsd_printer_t
*printer
) /* I - Printer, if any */
9532 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: %s",
9533 ippOpString(con
->request
->request
.op
.operation_id
),
9534 httpStatus(status
));
9536 if (status
== HTTP_UNAUTHORIZED
&&
9537 printer
&& printer
->num_auth_info_required
> 0 &&
9538 !strcmp(printer
->auth_info_required
[0], "negotiate"))
9539 cupsdSendError(con
, status
, CUPSD_AUTH_NEGOTIATE
);
9542 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9543 cupsd_location_t
*auth
; /* Pointer to authentication element */
9544 int auth_type
; /* Type of authentication required */
9547 if (printer
->type
& CUPS_PRINTER_CLASS
)
9548 snprintf(resource
, sizeof(resource
), "/classes/%s", printer
->name
);
9550 snprintf(resource
, sizeof(resource
), "/printers/%s", printer
->name
);
9552 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
9553 auth
->type
== CUPSD_AUTH_NONE
)
9554 auth
= cupsdFindPolicyOp(printer
->op_policy_ptr
,
9556 con
->request
->request
.op
.operation_id
:
9560 auth_type
= CUPSD_AUTH_NONE
;
9561 else if (auth
->type
== CUPSD_AUTH_DEFAULT
)
9562 auth_type
= DefaultAuthType
;
9564 auth_type
= auth
->type
;
9566 cupsdSendError(con
, status
, auth_type
);
9569 cupsdSendError(con
, status
, CUPSD_AUTH_NONE
);
9571 ippDelete(con
->response
);
9572 con
->response
= NULL
;
9579 * 'send_ipp_status()' - Send a status back to the IPP client.
9583 send_ipp_status(cupsd_client_t
*con
, /* I - Client connection */
9584 ipp_status_t status
, /* I - IPP status code */
9585 const char *message
, /* I - Status message */
9586 ...) /* I - Additional args as needed */
9588 va_list ap
; /* Pointer to additional args */
9589 char formatted
[1024]; /* Formatted errror message */
9592 va_start(ap
, message
);
9593 vsnprintf(formatted
, sizeof(formatted
),
9594 _cupsLangString(con
->language
, message
), ap
);
9597 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s: %s",
9598 ippOpString(con
->request
->request
.op
.operation_id
),
9599 ippErrorString(status
), formatted
);
9601 con
->response
->request
.status
.status_code
= status
;
9603 if (ippFindAttribute(con
->response
, "attributes-charset",
9604 IPP_TAG_ZERO
) == NULL
)
9605 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
9606 "attributes-charset", NULL
, DefaultCharset
);
9608 if (ippFindAttribute(con
->response
, "attributes-natural-language",
9609 IPP_TAG_ZERO
) == NULL
)
9610 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
9611 "attributes-natural-language", NULL
, DefaultLanguage
);
9613 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
9614 "status-message", NULL
, formatted
);
9619 * 'set_default()' - Set the default destination...
9623 set_default(cupsd_client_t
*con
, /* I - Client connection */
9624 ipp_attribute_t
*uri
) /* I - Printer URI */
9626 http_status_t status
; /* Policy status */
9627 cups_ptype_t dtype
; /* Destination type (printer/class) */
9628 cupsd_printer_t
*printer
; /* Printer */
9631 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_default(%p[%d], %s)", con
,
9632 con
->http
.fd
, uri
->values
[0].string
.text
);
9635 * Is the destination valid?
9638 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9644 send_ipp_status(con
, IPP_NOT_FOUND
,
9645 _("The printer or class was not found."));
9653 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
9655 send_http_error(con
, status
, NULL
);
9660 * Set it as the default...
9663 DefaultPrinter
= printer
;
9665 cupsdSaveAllPrinters();
9666 cupsdSaveAllClasses();
9668 cupsdWritePrintcap();
9670 cupsdLogMessage(CUPSD_LOG_INFO
,
9671 "Default destination set to \"%s\" by \"%s\".",
9672 printer
->name
, get_username(con
));
9675 * Everything was ok, so return OK status...
9678 con
->response
->request
.status
.status_code
= IPP_OK
;
9683 * 'set_job_attrs()' - Set job attributes.
9687 set_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
9688 ipp_attribute_t
*uri
) /* I - Job URI */
9690 ipp_attribute_t
*attr
, /* Current attribute */
9691 *attr2
; /* Job attribute */
9692 int jobid
; /* Job ID */
9693 cupsd_job_t
*job
; /* Current job */
9694 char method
[HTTP_MAX_URI
],
9695 /* Method portion of URI */
9696 username
[HTTP_MAX_URI
],
9697 /* Username portion of URI */
9699 /* Host portion of URI */
9700 resource
[HTTP_MAX_URI
];
9701 /* Resource portion of URI */
9702 int port
; /* Port portion of URI */
9703 int event
; /* Events? */
9706 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_job_attrs(%p[%d], %s)", con
,
9707 con
->http
.fd
, uri
->values
[0].string
.text
);
9710 * Start with "everything is OK" status...
9713 con
->response
->request
.status
.status_code
= IPP_OK
;
9716 * See if we have a job URI or a printer URI...
9719 if (!strcmp(uri
->name
, "printer-uri"))
9722 * Got a printer URI; see if we also have a job-id attribute...
9725 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9726 IPP_TAG_INTEGER
)) == NULL
)
9728 send_ipp_status(con
, IPP_BAD_REQUEST
,
9729 _("Got a printer-uri attribute but no job-id!"));
9733 jobid
= attr
->values
[0].integer
;
9738 * Got a job URI; parse it to get the job ID...
9741 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
9742 sizeof(method
), username
, sizeof(username
), host
,
9743 sizeof(host
), &port
, resource
, sizeof(resource
));
9745 if (strncmp(resource
, "/jobs/", 6))
9751 send_ipp_status(con
, IPP_BAD_REQUEST
,
9752 _("Bad job-uri attribute \"%s\"!"),
9753 uri
->values
[0].string
.text
);
9757 jobid
= atoi(resource
+ 6);
9761 * See if the job exists...
9764 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9767 * Nope - return a "not found" error...
9770 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
9775 * See if the job has been completed...
9778 if (job
->state_value
> IPP_JOB_STOPPED
)
9781 * Return a "not-possible" error...
9784 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9785 _("Job #%d is finished and cannot be altered!"), jobid
);
9790 * See if the job is owned by the requesting user...
9793 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9795 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
9800 * See what the user wants to change.
9807 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
9809 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
9812 if (!strcmp(attr
->name
, "attributes-charset") ||
9813 !strcmp(attr
->name
, "attributes-natural-language") ||
9814 !strcmp(attr
->name
, "document-compression") ||
9815 !strcmp(attr
->name
, "document-format") ||
9816 !strcmp(attr
->name
, "job-detailed-status-messages") ||
9817 !strcmp(attr
->name
, "job-document-access-errors") ||
9818 !strcmp(attr
->name
, "job-id") ||
9819 !strcmp(attr
->name
, "job-k-octets") ||
9820 !strcmp(attr
->name
, "job-originating-host-name") ||
9821 !strcmp(attr
->name
, "job-originating-user-name") ||
9822 !strcmp(attr
->name
, "job-printer-up-time") ||
9823 !strcmp(attr
->name
, "job-printer-uri") ||
9824 !strcmp(attr
->name
, "job-sheets") ||
9825 !strcmp(attr
->name
, "job-state-message") ||
9826 !strcmp(attr
->name
, "job-state-reasons") ||
9827 !strcmp(attr
->name
, "job-uri") ||
9828 !strcmp(attr
->name
, "number-of-documents") ||
9829 !strcmp(attr
->name
, "number-of-intervening-jobs") ||
9830 !strcmp(attr
->name
, "output-device-assigned") ||
9831 !strncmp(attr
->name
, "date-time-at-", 13) ||
9832 !strncmp(attr
->name
, "job-impressions", 15) ||
9833 !strncmp(attr
->name
, "job-k-octets", 12) ||
9834 !strncmp(attr
->name
, "job-media-sheets", 16) ||
9835 !strncmp(attr
->name
, "time-at-", 8))
9841 send_ipp_status(con
, IPP_ATTRIBUTES_NOT_SETTABLE
,
9842 _("%s cannot be changed."), attr
->name
);
9844 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
9845 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
9850 if (!strcmp(attr
->name
, "job-priority"))
9853 * Change the job priority...
9856 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
9858 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-priority value!"));
9860 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
9861 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
9863 else if (job
->state_value
>= IPP_JOB_PROCESSING
)
9865 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9866 _("Job is completed and cannot be changed."));
9869 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
9871 cupsdSetJobPriority(job
, attr
->values
[0].integer
);
9872 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
|
9873 CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
;
9876 else if (!strcmp(attr
->name
, "job-state"))
9879 * Change the job state...
9882 if (attr
->value_tag
!= IPP_TAG_ENUM
)
9884 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-state value!"));
9886 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
9887 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
9891 switch (attr
->values
[0].integer
)
9893 case IPP_JOB_PENDING
:
9895 if (job
->state_value
> IPP_JOB_HELD
)
9897 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9898 _("Job state cannot be changed."));
9901 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
9903 job
->state
->values
[0].integer
= attr
->values
[0].integer
;
9904 job
->state_value
= (ipp_jstate_t
)attr
->values
[0].integer
;
9906 event
|= CUPSD_EVENT_JOB_STATE
;
9910 case IPP_JOB_PROCESSING
:
9911 case IPP_JOB_STOPPED
:
9912 if (job
->state_value
!= attr
->values
[0].integer
)
9914 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9915 _("Job state cannot be changed."));
9920 case IPP_JOB_CANCELED
:
9921 case IPP_JOB_ABORTED
:
9922 case IPP_JOB_COMPLETED
:
9923 if (job
->state_value
> IPP_JOB_PROCESSING
)
9925 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9926 _("Job state cannot be changed."));
9929 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
9930 cupsdCancelJob(job
, 0, (ipp_jstate_t
)attr
->values
[0].integer
);
9935 else if (con
->response
->request
.status
.status_code
!= IPP_OK
)
9937 else if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
9938 IPP_TAG_ZERO
)) != NULL
)
9941 * Some other value; first free the old value...
9944 if (job
->attrs
->prev
)
9945 job
->attrs
->prev
->next
= attr2
->next
;
9947 job
->attrs
->attrs
= attr2
->next
;
9949 if (job
->attrs
->last
== attr2
)
9950 job
->attrs
->last
= job
->attrs
->prev
;
9952 _ippFreeAttr(attr2
);
9955 * Then copy the attribute...
9958 copy_attribute(job
->attrs
, attr
, 0);
9961 * See if the job-name or job-hold-until is being changed.
9964 if (!strcmp(attr
->name
, "job-hold-until"))
9966 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
);
9968 if (!strcmp(attr
->values
[0].string
.text
, "no-hold"))
9969 cupsdReleaseJob(job
);
9973 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
;
9976 else if (attr
->value_tag
== IPP_TAG_DELETEATTR
)
9979 * Delete the attribute...
9982 if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
9983 IPP_TAG_ZERO
)) != NULL
)
9985 if (job
->attrs
->prev
)
9986 job
->attrs
->prev
->next
= attr2
->next
;
9988 job
->attrs
->attrs
= attr2
->next
;
9990 if (attr2
== job
->attrs
->last
)
9991 job
->attrs
->last
= job
->attrs
->prev
;
9993 _ippFreeAttr(attr2
);
9995 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10001 * Add new option by copying it...
10004 copy_attribute(job
->attrs
, attr
, 0);
10006 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10017 * Send events as needed...
10020 if (event
& CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
)
10021 cupsdAddEvent(CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
, job
->printer
, job
,
10022 "Job priority changed by user.");
10024 if (event
& CUPSD_EVENT_JOB_STATE
)
10025 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, job
->printer
, job
,
10026 job
->state_value
== IPP_JOB_HELD
?
10027 "Job held by user." : "Job restarted by user.");
10029 if (event
& CUPSD_EVENT_JOB_CONFIG_CHANGED
)
10030 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, job
->printer
, job
,
10031 "Job options changed by user.");
10034 * Start jobs if possible...
10042 * 'set_printer_defaults()' - Set printer default options from a request.
10046 set_printer_defaults(
10047 cupsd_client_t
*con
, /* I - Client connection */
10048 cupsd_printer_t
*printer
) /* I - Printer */
10050 int i
; /* Looping var */
10051 ipp_attribute_t
*attr
; /* Current attribute */
10052 int namelen
; /* Length of attribute name */
10053 char name
[256], /* New attribute name */
10054 value
[256]; /* String version of integer attrs */
10057 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10060 * Skip non-printer attributes...
10063 if (attr
->group_tag
!= IPP_TAG_PRINTER
|| !attr
->name
)
10066 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_defaults: %s", attr
->name
);
10068 if (!strcmp(attr
->name
, "job-sheets-default"))
10071 * Only allow keywords and names...
10074 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10078 * Only allow job-sheets-default to be set when running without a
10079 * system high classification level...
10082 if (Classification
)
10085 cupsdSetString(&printer
->job_sheets
[0], attr
->values
[0].string
.text
);
10087 if (attr
->num_values
> 1)
10088 cupsdSetString(&printer
->job_sheets
[1], attr
->values
[1].string
.text
);
10090 cupsdSetString(&printer
->job_sheets
[1], "none");
10092 else if (!strcmp(attr
->name
, "requesting-user-name-allowed"))
10094 cupsdFreePrinterUsers(printer
);
10096 printer
->deny_users
= 0;
10098 if (attr
->value_tag
== IPP_TAG_NAME
&&
10099 (attr
->num_values
> 1 ||
10100 strcmp(attr
->values
[0].string
.text
, "all")))
10102 for (i
= 0; i
< attr
->num_values
; i
++)
10103 cupsdAddPrinterUser(printer
, attr
->values
[i
].string
.text
);
10106 else if (!strcmp(attr
->name
, "requesting-user-name-denied"))
10108 cupsdFreePrinterUsers(printer
);
10110 printer
->deny_users
= 1;
10112 if (attr
->value_tag
== IPP_TAG_NAME
&&
10113 (attr
->num_values
> 1 ||
10114 strcmp(attr
->values
[0].string
.text
, "none")))
10116 for (i
= 0; i
< attr
->num_values
; i
++)
10117 cupsdAddPrinterUser(printer
, attr
->values
[i
].string
.text
);
10120 else if (!strcmp(attr
->name
, "job-quota-period"))
10122 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10125 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-quota-period to %d...",
10126 attr
->values
[0].integer
);
10127 cupsdFreeQuotas(printer
);
10129 printer
->quota_period
= attr
->values
[0].integer
;
10131 else if (!strcmp(attr
->name
, "job-k-limit"))
10133 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10136 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-k-limit to %d...",
10137 attr
->values
[0].integer
);
10138 cupsdFreeQuotas(printer
);
10140 printer
->k_limit
= attr
->values
[0].integer
;
10142 else if (!strcmp(attr
->name
, "job-page-limit"))
10144 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10147 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-page-limit to %d...",
10148 attr
->values
[0].integer
);
10149 cupsdFreeQuotas(printer
);
10151 printer
->page_limit
= attr
->values
[0].integer
;
10153 else if (!strcmp(attr
->name
, "printer-op-policy"))
10155 cupsd_policy_t
*p
; /* Policy */
10158 if (attr
->value_tag
!= IPP_TAG_NAME
)
10161 if ((p
= cupsdFindPolicy(attr
->values
[0].string
.text
)) != NULL
)
10163 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10164 "Setting printer-op-policy to \"%s\"...",
10165 attr
->values
[0].string
.text
);
10166 cupsdSetString(&printer
->op_policy
, attr
->values
[0].string
.text
);
10167 printer
->op_policy_ptr
= p
;
10171 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10172 _("Unknown printer-op-policy \"%s\"."),
10173 attr
->values
[0].string
.text
);
10177 else if (!strcmp(attr
->name
, "printer-error-policy"))
10179 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10182 if (strcmp(attr
->values
[0].string
.text
, "abort-job") &&
10183 strcmp(attr
->values
[0].string
.text
, "retry-job") &&
10184 strcmp(attr
->values
[0].string
.text
, "stop-printer"))
10186 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10187 _("Unknown printer-error-policy \"%s\"."),
10188 attr
->values
[0].string
.text
);
10192 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10193 "Setting printer-error-policy to \"%s\"...",
10194 attr
->values
[0].string
.text
);
10195 cupsdSetString(&printer
->error_policy
, attr
->values
[0].string
.text
);
10199 * Skip any other non-default attributes...
10202 namelen
= strlen(attr
->name
);
10203 if (namelen
< 9 || strcmp(attr
->name
+ namelen
- 8, "-default") ||
10204 namelen
> (sizeof(name
) - 1) || attr
->num_values
!= 1)
10208 * OK, anything else must be a user-defined default...
10211 strlcpy(name
, attr
->name
, sizeof(name
));
10212 name
[namelen
- 8] = '\0'; /* Strip "-default" */
10214 switch (attr
->value_tag
)
10216 case IPP_TAG_DELETEATTR
:
10217 printer
->num_options
= cupsRemoveOption(name
,
10218 printer
->num_options
,
10219 &(printer
->options
));
10220 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10221 "Deleting %s", attr
->name
);
10224 case IPP_TAG_NAME
:
10225 case IPP_TAG_KEYWORD
:
10227 printer
->num_options
= cupsAddOption(name
,
10228 attr
->values
[0].string
.text
,
10229 printer
->num_options
,
10230 &(printer
->options
));
10231 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10232 "Setting %s to \"%s\"...", attr
->name
,
10233 attr
->values
[0].string
.text
);
10236 case IPP_TAG_BOOLEAN
:
10237 printer
->num_options
= cupsAddOption(name
,
10238 attr
->values
[0].boolean
?
10240 printer
->num_options
,
10241 &(printer
->options
));
10242 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10243 "Setting %s to %s...", attr
->name
,
10244 attr
->values
[0].boolean
? "true" : "false");
10247 case IPP_TAG_INTEGER
:
10248 case IPP_TAG_ENUM
:
10249 sprintf(value
, "%d", attr
->values
[0].integer
);
10250 printer
->num_options
= cupsAddOption(name
, value
,
10251 printer
->num_options
,
10252 &(printer
->options
));
10253 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10254 "Setting %s to %s...", attr
->name
, value
);
10257 case IPP_TAG_RANGE
:
10258 sprintf(value
, "%d-%d", attr
->values
[0].range
.lower
,
10259 attr
->values
[0].range
.upper
);
10260 printer
->num_options
= cupsAddOption(name
, value
,
10261 printer
->num_options
,
10262 &(printer
->options
));
10263 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10264 "Setting %s to %s...", attr
->name
, value
);
10267 case IPP_TAG_RESOLUTION
:
10268 sprintf(value
, "%dx%d%s", attr
->values
[0].resolution
.xres
,
10269 attr
->values
[0].resolution
.yres
,
10270 attr
->values
[0].resolution
.units
== IPP_RES_PER_INCH
?
10272 printer
->num_options
= cupsAddOption(name
, value
,
10273 printer
->num_options
,
10274 &(printer
->options
));
10275 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10276 "Setting %s to %s...", attr
->name
, value
);
10280 /* Do nothing for other values */
10288 * 'start_printer()' - Start a printer.
10292 start_printer(cupsd_client_t
*con
, /* I - Client connection */
10293 ipp_attribute_t
*uri
) /* I - Printer URI */
10295 http_status_t status
; /* Policy status */
10296 cups_ptype_t dtype
; /* Destination type (printer/class) */
10297 cupsd_printer_t
*printer
; /* Printer data */
10300 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_printer(%p[%d], %s)", con
,
10301 con
->http
.fd
, uri
->values
[0].string
.text
);
10304 * Is the destination valid?
10307 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10313 send_ipp_status(con
, IPP_NOT_FOUND
,
10314 _("The printer or class was not found."));
10322 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10324 send_http_error(con
, status
, printer
);
10329 * Start the printer...
10332 printer
->state_message
[0] = '\0';
10334 cupsdStartPrinter(printer
, 1);
10336 if (dtype
& CUPS_PRINTER_CLASS
)
10337 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" started by \"%s\".",
10338 printer
->name
, get_username(con
));
10340 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" started by \"%s\".",
10341 printer
->name
, get_username(con
));
10346 * Everything was ok, so return OK status...
10349 con
->response
->request
.status
.status_code
= IPP_OK
;
10354 * 'stop_printer()' - Stop a printer.
10358 stop_printer(cupsd_client_t
*con
, /* I - Client connection */
10359 ipp_attribute_t
*uri
) /* I - Printer URI */
10361 http_status_t status
; /* Policy status */
10362 cups_ptype_t dtype
; /* Destination type (printer/class) */
10363 cupsd_printer_t
*printer
; /* Printer data */
10364 ipp_attribute_t
*attr
; /* printer-state-message attribute */
10367 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "stop_printer(%p[%d], %s)", con
,
10368 con
->http
.fd
, uri
->values
[0].string
.text
);
10371 * Is the destination valid?
10374 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10380 send_ipp_status(con
, IPP_NOT_FOUND
,
10381 _("The printer or class was not found."));
10389 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10391 send_http_error(con
, status
, printer
);
10396 * Stop the printer...
10399 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
10400 IPP_TAG_TEXT
)) == NULL
)
10401 strcpy(printer
->state_message
, "Paused");
10404 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
10405 sizeof(printer
->state_message
));
10408 cupsdStopPrinter(printer
, 1);
10410 if (dtype
& CUPS_PRINTER_CLASS
)
10411 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" stopped by \"%s\".",
10412 printer
->name
, get_username(con
));
10414 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" stopped by \"%s\".",
10415 printer
->name
, get_username(con
));
10418 * Everything was ok, so return OK status...
10421 con
->response
->request
.status
.status_code
= IPP_OK
;
10426 * 'url_encode_attr()' - URL-encode a string attribute.
10430 url_encode_attr(ipp_attribute_t
*attr
, /* I - Attribute */
10431 char *buffer
,/* I - String buffer */
10432 int bufsize
)/* I - Size of buffer */
10434 int i
; /* Looping var */
10435 char *bufptr
, /* Pointer into buffer */
10436 *bufend
; /* End of buffer */
10439 strlcpy(buffer
, attr
->name
, bufsize
);
10440 bufptr
= buffer
+ strlen(buffer
);
10441 bufend
= buffer
+ bufsize
- 1;
10443 for (i
= 0; i
< attr
->num_values
; i
++)
10445 if (bufptr
>= bufend
)
10453 if (bufptr
>= bufend
)
10458 bufptr
= url_encode_string(attr
->values
[i
].string
.text
,
10459 bufptr
, bufend
- bufptr
+ 1);
10461 if (bufptr
>= bufend
)
10472 * 'url_encode_string()' - URL-encode a string.
10475 static char * /* O - End of string */
10476 url_encode_string(const char *s
, /* I - String */
10477 char *buffer
, /* I - String buffer */
10478 int bufsize
) /* I - Size of buffer */
10480 char *bufptr
, /* Pointer into buffer */
10481 *bufend
; /* End of buffer */
10482 static const char *hex
= "0123456789ABCDEF";
10487 bufend
= buffer
+ bufsize
- 1;
10489 while (*s
&& bufptr
< bufend
)
10491 if (*s
== ' ' || *s
== '%')
10493 if (bufptr
>= (bufend
- 2))
10497 *bufptr
++ = hex
[(*s
>> 4) & 15];
10498 *bufptr
++ = hex
[*s
& 15];
10502 else if (*s
== '\'' || *s
== '\\')
10504 if (bufptr
>= (bufend
- 1))
10521 * 'user_allowed()' - See if a user is allowed to print to a queue.
10524 static int /* O - 0 if not allowed, 1 if allowed */
10525 user_allowed(cupsd_printer_t
*p
, /* I - Printer or class */
10526 const char *username
) /* I - Username */
10528 int i
; /* Looping var */
10529 struct passwd
*pw
; /* User password data */
10530 char baseuser
[256], /* Base username */
10531 *baseptr
; /* Pointer to "@" in base username */
10534 if (p
->num_users
== 0)
10537 if (!strcmp(username
, "root"))
10540 if (strchr(username
, '@'))
10543 * Strip @REALM for username check...
10546 strlcpy(baseuser
, username
, sizeof(baseuser
));
10548 if ((baseptr
= strchr(baseuser
, '@')) != NULL
)
10551 username
= baseuser
;
10554 pw
= getpwnam(username
);
10557 for (i
= 0; i
< p
->num_users
; i
++)
10559 if (p
->users
[i
][0] == '@')
10562 * Check group membership...
10565 if (cupsdCheckGroup(username
, pw
, p
->users
[i
] + 1))
10568 else if (!strcasecmp(username
, p
->users
[i
]))
10572 return ((i
< p
->num_users
) != p
->deny_users
);
10577 * 'validate_job()' - Validate printer options and destination.
10581 validate_job(cupsd_client_t
*con
, /* I - Client connection */
10582 ipp_attribute_t
*uri
) /* I - Printer URI */
10584 http_status_t status
; /* Policy status */
10585 ipp_attribute_t
*attr
; /* Current attribute */
10586 ipp_attribute_t
*format
; /* Document-format attribute */
10587 cups_ptype_t dtype
; /* Destination type (printer/class) */
10588 char super
[MIME_MAX_SUPER
],
10589 /* Supertype of file */
10590 type
[MIME_MAX_TYPE
];
10591 /* Subtype of file */
10592 cupsd_printer_t
*printer
; /* Printer */
10595 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_job(%p[%d], %s)", con
,
10596 con
->http
.fd
, uri
->values
[0].string
.text
);
10599 * OK, see if the client is sending the document compressed - CUPS
10600 * doesn't support compression yet...
10603 if ((attr
= ippFindAttribute(con
->request
, "compression",
10604 IPP_TAG_KEYWORD
)) != NULL
&&
10605 !strcmp(attr
->values
[0].string
.text
, "none"))
10607 send_ipp_status(con
, IPP_ATTRIBUTES
,
10608 _("Unsupported compression attribute %s!"),
10609 attr
->values
[0].string
.text
);
10610 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
10611 "compression", NULL
, attr
->values
[0].string
.text
);
10616 * Is it a format we support?
10619 if ((format
= ippFindAttribute(con
->request
, "document-format",
10620 IPP_TAG_MIMETYPE
)) != NULL
)
10622 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
10625 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"!"),
10626 format
->values
[0].string
.text
);
10630 if ((strcmp(super
, "application") || strcmp(type
, "octet-stream")) &&
10631 !mimeType(MimeDatabase
, super
, type
))
10633 cupsdLogMessage(CUPSD_LOG_INFO
,
10634 "Hint: Do you have the raw file printing rules enabled?");
10635 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
10636 _("Unsupported format \"%s\"!"),
10637 format
->values
[0].string
.text
);
10638 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
10639 "document-format", NULL
, format
->values
[0].string
.text
);
10645 * Is the destination valid?
10648 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10654 send_ipp_status(con
, IPP_NOT_FOUND
,
10655 _("The printer or class was not found."));
10663 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10665 send_http_error(con
, status
, printer
);
10670 * Everything was ok, so return OK status...
10673 con
->response
->request
.status
.status_code
= IPP_OK
;
10678 * 'validate_name()' - Make sure the printer name only contains valid chars.
10681 static int /* O - 0 if name is no good, 1 if good */
10682 validate_name(const char *name
) /* I - Name to check */
10684 const char *ptr
; /* Pointer into name */
10688 * Scan the whole name...
10691 for (ptr
= name
; *ptr
; ptr
++)
10692 if ((*ptr
> 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
10696 * All the characters are good; validate the length, too...
10699 return ((ptr
- name
) < 128);
10704 * 'validate_user()' - Validate the user for the request.
10707 static int /* O - 1 if permitted, 0 otherwise */
10708 validate_user(cupsd_job_t
*job
, /* I - Job */
10709 cupsd_client_t
*con
, /* I - Client connection */
10710 const char *owner
, /* I - Owner of job/resource */
10711 char *username
, /* O - Authenticated username */
10712 int userlen
) /* I - Length of username */
10714 cupsd_printer_t
*printer
; /* Printer for job */
10717 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
10718 "validate_user(job=%d, con=%d, owner=\"%s\", username=%p, "
10720 job
->id
, con
? con
->http
.fd
: 0,
10721 owner
? owner
: "(null)", username
, userlen
);
10724 * Validate input...
10727 if (!con
|| !owner
|| !username
|| userlen
<= 0)
10731 * Get the best authenticated username that is available.
10734 strlcpy(username
, get_username(con
), userlen
);
10737 * Check the username against the owner...
10740 printer
= cupsdFindDest(job
->dest
);
10742 return (cupsdCheckPolicy(printer
? printer
->op_policy_ptr
: DefaultPolicyPtr
,
10743 con
, owner
) == HTTP_OK
);
10748 * End of "$Id: ipp.c 7014 2007-10-10 21:57:43Z mike $".