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 *timeout
, /* timeout attribute */
6163 *requested
, /* requested-attributes attribute */
6164 *exclude
; /* exclude-schemes attribute */
6165 char command
[1024], /* cups-deviced command */
6166 options
[1024], /* Options to pass to command */
6168 /* String for requested attributes */
6170 /* String for excluded attributes */
6173 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_devices(%p[%d])", con
, con
->http
.fd
);
6179 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6181 send_http_error(con
, status
, NULL
);
6186 * Run cups-deviced command with the given options...
6189 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
6190 timeout
= ippFindAttribute(con
->request
, "timeout", IPP_TAG_INTEGER
);
6191 requested
= ippFindAttribute(con
->request
, "requested-attributes",
6193 exclude
= ippFindAttribute(con
->request
, "exclude-schemes", IPP_TAG_NAME
);
6196 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
6198 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
6201 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
6203 exclude_str
[0] = '\0';
6205 snprintf(command
, sizeof(command
), "%s/daemon/cups-deviced", ServerBin
);
6206 snprintf(options
, sizeof(options
),
6207 "%d+%d+%d+%d+%s%s%s",
6208 con
->request
->request
.op
.request_id
,
6209 limit
? limit
->values
[0].integer
: 0,
6210 timeout
? timeout
->values
[0].integer
: 10,
6213 exclude_str
[0] ? "%20" : "", exclude_str
);
6215 if (cupsdSendCommand(con
, command
, options
, 1))
6218 * Command started successfully, don't send an IPP response here...
6221 ippDelete(con
->response
);
6222 con
->response
= NULL
;
6227 * Command failed, return "internal error" so the user knows something
6231 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
6232 _("cups-deviced failed to execute."));
6238 * 'get_document()' - Get a copy of a job file.
6242 get_document(cupsd_client_t
*con
, /* I - Client connection */
6243 ipp_attribute_t
*uri
) /* I - Job URI */
6245 http_status_t status
; /* Policy status */
6246 ipp_attribute_t
*attr
; /* Current attribute */
6247 int jobid
; /* Job ID */
6248 int docnum
; /* Document number */
6249 cupsd_job_t
*job
; /* Current job */
6250 char method
[HTTP_MAX_URI
], /* Method portion of URI */
6251 username
[HTTP_MAX_URI
], /* Username portion of URI */
6252 host
[HTTP_MAX_URI
], /* Host portion of URI */
6253 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6254 int port
; /* Port portion of URI */
6255 char filename
[1024], /* Filename for document */
6256 format
[1024]; /* Format for document */
6259 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_document(%p[%d], %s)", con
,
6260 con
->http
.fd
, uri
->values
[0].string
.text
);
6263 * See if we have a job URI or a printer URI...
6266 if (!strcmp(uri
->name
, "printer-uri"))
6269 * Got a printer URI; see if we also have a job-id attribute...
6272 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6273 IPP_TAG_INTEGER
)) == NULL
)
6275 send_ipp_status(con
, IPP_BAD_REQUEST
,
6276 _("Got a printer-uri attribute but no job-id!"));
6280 jobid
= attr
->values
[0].integer
;
6285 * Got a job URI; parse it to get the job ID...
6288 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
6289 sizeof(method
), username
, sizeof(username
), host
,
6290 sizeof(host
), &port
, resource
, sizeof(resource
));
6292 if (strncmp(resource
, "/jobs/", 6))
6298 send_ipp_status(con
, IPP_BAD_REQUEST
,
6299 _("Bad job-uri attribute \"%s\"!"),
6300 uri
->values
[0].string
.text
);
6304 jobid
= atoi(resource
+ 6);
6308 * See if the job exists...
6311 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6314 * Nope - return a "not found" error...
6317 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
6325 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6327 send_http_error(con
, status
, NULL
);
6332 * Get the document number...
6335 if ((attr
= ippFindAttribute(con
->request
, "document-number",
6336 IPP_TAG_INTEGER
)) == NULL
)
6338 send_ipp_status(con
, IPP_BAD_REQUEST
,
6339 _("Missing document-number attribute!"));
6343 if ((docnum
= attr
->values
[0].integer
) < 1 || docnum
> job
->num_files
||
6344 attr
->num_values
> 1)
6346 send_ipp_status(con
, IPP_NOT_FOUND
, _("Document %d not found in job %d."),
6351 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, jobid
,
6353 if ((con
->file
= open(filename
, O_RDONLY
)) == -1)
6355 cupsdLogMessage(CUPSD_LOG_ERROR
,
6356 "Unable to open document %d in job %d - %s", docnum
, jobid
,
6358 send_ipp_status(con
, IPP_NOT_FOUND
,
6359 _("Unable to open document %d in job %d!"), docnum
, jobid
);
6363 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
6367 snprintf(format
, sizeof(format
), "%s/%s", job
->filetypes
[docnum
- 1]->super
,
6368 job
->filetypes
[docnum
- 1]->type
);
6370 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format",
6372 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "document-number",
6374 if ((attr
= ippFindAttribute(job
->attrs
, "document-name",
6375 IPP_TAG_NAME
)) != NULL
)
6376 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name",
6377 NULL
, attr
->values
[0].string
.text
);
6382 * 'get_job_attrs()' - Get job attributes.
6386 get_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
6387 ipp_attribute_t
*uri
) /* I - Job URI */
6389 http_status_t status
; /* Policy status */
6390 ipp_attribute_t
*attr
; /* Current attribute */
6391 int jobid
; /* Job ID */
6392 cupsd_job_t
*job
; /* Current job */
6393 char method
[HTTP_MAX_URI
], /* Method portion of URI */
6394 username
[HTTP_MAX_URI
], /* Username portion of URI */
6395 host
[HTTP_MAX_URI
], /* Host portion of URI */
6396 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6397 int port
; /* Port portion of URI */
6398 cups_array_t
*ra
; /* Requested attributes array */
6401 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_job_attrs(%p[%d], %s)", con
,
6402 con
->http
.fd
, uri
->values
[0].string
.text
);
6405 * See if we have a job URI or a printer URI...
6408 if (!strcmp(uri
->name
, "printer-uri"))
6411 * Got a printer URI; see if we also have a job-id attribute...
6414 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6415 IPP_TAG_INTEGER
)) == NULL
)
6417 send_ipp_status(con
, IPP_BAD_REQUEST
,
6418 _("Got a printer-uri attribute but no job-id!"));
6422 jobid
= attr
->values
[0].integer
;
6427 * Got a job URI; parse it to get the job ID...
6430 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
6431 sizeof(method
), username
, sizeof(username
), host
,
6432 sizeof(host
), &port
, resource
, sizeof(resource
));
6434 if (strncmp(resource
, "/jobs/", 6))
6440 send_ipp_status(con
, IPP_BAD_REQUEST
,
6441 _("Bad job-uri attribute \"%s\"!"),
6442 uri
->values
[0].string
.text
);
6446 jobid
= atoi(resource
+ 6);
6450 * See if the job exists...
6453 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6456 * Nope - return a "not found" error...
6459 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
6467 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6469 send_http_error(con
, status
, NULL
);
6474 * Copy attributes...
6479 ra
= create_requested_array(con
->request
);
6480 copy_job_attrs(con
, job
, ra
);
6481 cupsArrayDelete(ra
);
6483 con
->response
->request
.status
.status_code
= IPP_OK
;
6488 * 'get_jobs()' - Get a list of jobs for the specified printer.
6492 get_jobs(cupsd_client_t
*con
, /* I - Client connection */
6493 ipp_attribute_t
*uri
) /* I - Printer URI */
6495 http_status_t status
; /* Policy status */
6496 ipp_attribute_t
*attr
; /* Current attribute */
6497 const char *dest
; /* Destination */
6498 cups_ptype_t dtype
; /* Destination type (printer/class) */
6499 cups_ptype_t dmask
; /* Destination type mask */
6500 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6501 username
[HTTP_MAX_URI
], /* Username portion of URI */
6502 host
[HTTP_MAX_URI
], /* Host portion of URI */
6503 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6504 int port
; /* Port portion of URI */
6505 int completed
; /* Completed jobs? */
6506 int first_job_id
; /* First job ID */
6507 int limit
; /* Maximum number of jobs to return */
6508 int count
; /* Number of jobs that match */
6509 cupsd_job_t
*job
; /* Current job pointer */
6510 cupsd_printer_t
*printer
; /* Printer */
6511 cups_array_t
*list
; /* Which job list... */
6512 cups_array_t
*ra
; /* Requested attributes array */
6515 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs(%p[%d], %s)", con
, con
->http
.fd
,
6516 uri
->values
[0].string
.text
);
6519 * Is the destination valid?
6522 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6523 sizeof(scheme
), username
, sizeof(username
), host
,
6524 sizeof(host
), &port
, resource
, sizeof(resource
));
6526 if (!strcmp(resource
, "/") ||
6527 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6))
6530 dtype
= (cups_ptype_t
)0;
6531 dmask
= (cups_ptype_t
)0;
6534 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6537 dtype
= (cups_ptype_t
)0;
6538 dmask
= CUPS_PRINTER_CLASS
;
6541 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6544 dtype
= CUPS_PRINTER_CLASS
;
6545 dmask
= CUPS_PRINTER_CLASS
;
6548 else if ((dest
= cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
,
6555 send_ipp_status(con
, IPP_NOT_FOUND
,
6556 _("The printer or class was not found."));
6561 dtype
&= CUPS_PRINTER_CLASS
;
6562 dmask
= CUPS_PRINTER_CLASS
;
6571 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
6574 send_http_error(con
, status
, printer
);
6578 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6580 send_http_error(con
, status
, NULL
);
6585 * See if the "which-jobs" attribute have been specified...
6588 if ((attr
= ippFindAttribute(con
->request
, "which-jobs",
6589 IPP_TAG_KEYWORD
)) != NULL
&&
6590 !strcmp(attr
->values
[0].string
.text
, "completed"))
6595 else if (attr
&& !strcmp(attr
->values
[0].string
.text
, "all"))
6607 * See if they want to limit the number of jobs reported...
6610 if ((attr
= ippFindAttribute(con
->request
, "limit",
6611 IPP_TAG_INTEGER
)) != NULL
)
6612 limit
= attr
->values
[0].integer
;
6616 if ((attr
= ippFindAttribute(con
->request
, "first-job-id",
6617 IPP_TAG_INTEGER
)) != NULL
)
6618 first_job_id
= attr
->values
[0].integer
;
6623 * See if we only want to see jobs for a specific user...
6626 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
6627 IPP_TAG_BOOLEAN
)) != NULL
&&
6628 attr
->values
[0].boolean
)
6629 strlcpy(username
, get_username(con
), sizeof(username
));
6633 ra
= create_requested_array(con
->request
);
6636 * OK, build a list of jobs for this printer...
6639 for (count
= 0, job
= (cupsd_job_t
*)cupsArrayFirst(list
);
6640 count
< limit
&& job
;
6641 job
= (cupsd_job_t
*)cupsArrayNext(list
))
6644 * Filter out jobs that don't match...
6647 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: job->id = %d", job
->id
);
6649 if (!job
->dest
|| !job
->username
)
6652 if (!job
->dest
|| !job
->username
)
6655 if ((dest
&& strcmp(job
->dest
, dest
)) &&
6656 (!job
->printer
|| !dest
|| strcmp(job
->printer
->name
, dest
)))
6658 if ((job
->dtype
& dmask
) != dtype
&&
6659 (!job
->printer
|| (job
->printer
->type
& dmask
) != dtype
))
6661 if (completed
&& job
->state_value
<= IPP_JOB_STOPPED
)
6664 if (job
->id
< first_job_id
)
6672 if (username
[0] && strcasecmp(username
, job
->username
))
6676 ippAddSeparator(con
->response
);
6680 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: count = %d", count
);
6682 copy_job_attrs(con
, job
, ra
);
6685 cupsArrayDelete(ra
);
6687 con
->response
->request
.status
.status_code
= IPP_OK
;
6692 * 'get_notifications()' - Get events for a subscription.
6696 get_notifications(cupsd_client_t
*con
) /* I - Client connection */
6698 int i
, j
; /* Looping vars */
6699 http_status_t status
; /* Policy status */
6700 cupsd_subscription_t
*sub
; /* Subscription */
6701 ipp_attribute_t
*ids
, /* notify-subscription-ids */
6702 *sequences
; /* notify-sequence-numbers */
6703 int min_seq
; /* Minimum sequence number */
6704 int interval
; /* Poll interval */
6707 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_notifications(con=%p[%d])",
6711 * Get subscription attributes...
6714 ids
= ippFindAttribute(con
->request
, "notify-subscription-ids",
6716 sequences
= ippFindAttribute(con
->request
, "notify-sequence-numbers",
6721 send_ipp_status(con
, IPP_BAD_REQUEST
,
6722 _("Missing notify-subscription-ids attribute!"));
6727 * Are the subscription IDs valid?
6730 for (i
= 0, interval
= 60; i
< ids
->num_values
; i
++)
6732 if ((sub
= cupsdFindSubscription(ids
->values
[i
].integer
)) == NULL
)
6735 * Bad subscription ID...
6738 send_ipp_status(con
, IPP_NOT_FOUND
,
6739 _("notify-subscription-id %d no good!"),
6740 ids
->values
[i
].integer
);
6748 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
6750 con
, sub
->owner
)) != HTTP_OK
)
6752 send_http_error(con
, status
, sub
->dest
);
6757 * Check the subscription type and update the interval accordingly.
6760 if (sub
->job
&& sub
->job
->state_value
== IPP_JOB_PROCESSING
&&
6763 else if (sub
->job
&& sub
->job
->state_value
>= IPP_JOB_STOPPED
)
6765 else if (sub
->dest
&& sub
->dest
->state
== IPP_PRINTER_PROCESSING
&&
6771 * Tell the client to poll again in N seconds...
6775 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
6776 "notify-get-interval", interval
);
6778 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
6779 "printer-up-time", time(NULL
));
6782 * Copy the subscription event attributes to the response.
6785 con
->response
->request
.status
.status_code
=
6786 interval
? IPP_OK
: IPP_OK_EVENTS_COMPLETE
;
6788 for (i
= 0; i
< ids
->num_values
; i
++)
6791 * Get the subscription and sequence number...
6794 sub
= cupsdFindSubscription(ids
->values
[i
].integer
);
6796 if (sequences
&& i
< sequences
->num_values
)
6797 min_seq
= sequences
->values
[i
].integer
;
6802 * If we don't have any new events, nothing to do here...
6805 if (min_seq
> (sub
->first_event_id
+ sub
->num_events
))
6809 * Otherwise copy all of the new events...
6812 if (sub
->first_event_id
> min_seq
)
6815 j
= min_seq
- sub
->first_event_id
;
6817 for (; j
< sub
->num_events
; j
++)
6819 ippAddSeparator(con
->response
);
6821 copy_attrs(con
->response
, sub
->events
[j
]->attrs
, NULL
,
6822 IPP_TAG_EVENT_NOTIFICATION
, 0);
6829 * 'get_ppd()' - Get a named PPD from the local system.
6833 get_ppd(cupsd_client_t
*con
, /* I - Client connection */
6834 ipp_attribute_t
*uri
) /* I - Printer URI or PPD name */
6836 http_status_t status
; /* Policy status */
6837 cupsd_printer_t
*dest
; /* Destination */
6838 cups_ptype_t dtype
; /* Destination type */
6841 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppd(%p[%d], %p[%s=%s])", con
,
6842 con
->http
.fd
, uri
, uri
->name
, uri
->values
[0].string
.text
);
6844 if (!strcmp(uri
->name
, "ppd-name"))
6847 * Return a PPD file from cups-driverd...
6850 char command
[1024], /* cups-driverd command */
6851 options
[1024], /* Options to pass to command */
6852 ppd_name
[1024]; /* ppd-name */
6859 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6861 send_http_error(con
, status
, NULL
);
6866 * Run cups-driverd command with the given options...
6869 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
6870 url_encode_string(uri
->values
[0].string
.text
, ppd_name
, sizeof(ppd_name
));
6871 snprintf(options
, sizeof(options
), "get+%d+%s",
6872 con
->request
->request
.op
.request_id
, ppd_name
);
6874 if (cupsdSendCommand(con
, command
, options
, 0))
6877 * Command started successfully, don't send an IPP response here...
6880 ippDelete(con
->response
);
6881 con
->response
= NULL
;
6886 * Command failed, return "internal error" so the user knows something
6890 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
6891 _("cups-driverd failed to execute."));
6894 else if (!strcmp(uri
->name
, "printer-uri") &&
6895 cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &dest
))
6897 int i
; /* Looping var */
6898 char filename
[1024]; /* PPD filename */
6905 if ((status
= cupsdCheckPolicy(dest
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
6907 send_http_error(con
, status
, dest
);
6912 * See if we need the PPD for a class or remote printer...
6915 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
6918 if ((dtype
& CUPS_PRINTER_REMOTE
) && access(filename
, 0))
6920 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
6921 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
6922 "printer-uri", NULL
, dest
->uri
);
6925 else if (dtype
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
6927 for (i
= 0; i
< dest
->num_printers
; i
++)
6928 if (!(dest
->printers
[i
]->type
&
6929 (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
)))
6931 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
6932 dest
->printers
[i
]->name
);
6934 if (!access(filename
, 0))
6938 if (i
< dest
->num_printers
)
6939 dest
= dest
->printers
[i
];
6942 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
6943 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
6944 "printer-uri", NULL
, dest
->printers
[0]->uri
);
6950 * Found the printer with the PPD file, now see if there is one...
6953 if ((con
->file
= open(filename
, O_RDONLY
)) < 0)
6955 send_ipp_status(con
, IPP_NOT_FOUND
,
6956 _("The PPD file \"%s\" could not be opened: %s"),
6957 uri
->values
[0].string
.text
, strerror(errno
));
6961 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
6965 con
->response
->request
.status
.status_code
= IPP_OK
;
6968 send_ipp_status(con
, IPP_NOT_FOUND
,
6969 _("The PPD file \"%s\" could not be found."),
6970 uri
->values
[0].string
.text
);
6975 * 'get_ppds()' - Get the list of PPD files on the local system.
6979 get_ppds(cupsd_client_t
*con
) /* I - Client connection */
6981 http_status_t status
; /* Policy status */
6982 ipp_attribute_t
*limit
, /* Limit attribute */
6983 *device
, /* ppd-device-id attribute */
6984 *language
, /* ppd-natural-language attribute */
6985 *make
, /* ppd-make attribute */
6986 *model
, /* ppd-make-and-model attribute */
6987 *model_number
, /* ppd-model-number attribute */
6988 *product
, /* ppd-product attribute */
6989 *psversion
, /* ppd-psverion attribute */
6990 *type
, /* ppd-type attribute */
6991 *requested
; /* requested-attributes attribute */
6992 char command
[1024], /* cups-driverd command */
6993 options
[1024], /* Options to pass to command */
6994 device_str
[256],/* Escaped ppd-device-id string */
6996 /* Escaped ppd-natural-language */
6997 make_str
[256], /* Escaped ppd-make string */
6998 model_str
[256], /* Escaped ppd-make-and-model string */
6999 model_number_str
[256],
7000 /* ppd-model-number string */
7002 /* Escaped ppd-product string */
7004 /* Escaped ppd-psversion string */
7005 type_str
[256], /* Escaped ppd-type string */
7007 /* String for requested attributes */
7010 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppds(%p[%d])", con
, con
->http
.fd
);
7016 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7018 send_http_error(con
, status
, NULL
);
7023 * Run cups-driverd command with the given options...
7026 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
7027 device
= ippFindAttribute(con
->request
, "ppd-device-id", IPP_TAG_TEXT
);
7028 language
= ippFindAttribute(con
->request
, "ppd-natural-language",
7030 make
= ippFindAttribute(con
->request
, "ppd-make", IPP_TAG_TEXT
);
7031 model
= ippFindAttribute(con
->request
, "ppd-make-and-model",
7033 model_number
= ippFindAttribute(con
->request
, "ppd-model-number",
7035 product
= ippFindAttribute(con
->request
, "ppd-product", IPP_TAG_TEXT
);
7036 psversion
= ippFindAttribute(con
->request
, "ppd-psversion", IPP_TAG_TEXT
);
7037 type
= ippFindAttribute(con
->request
, "ppd-type", IPP_TAG_KEYWORD
);
7038 requested
= ippFindAttribute(con
->request
, "requested-attributes",
7042 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
7044 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
7047 url_encode_attr(device
, device_str
, sizeof(device_str
));
7049 device_str
[0] = '\0';
7052 url_encode_attr(language
, language_str
, sizeof(language_str
));
7054 language_str
[0] = '\0';
7057 url_encode_attr(make
, make_str
, sizeof(make_str
));
7062 url_encode_attr(model
, model_str
, sizeof(model_str
));
7064 model_str
[0] = '\0';
7067 snprintf(model_number_str
, sizeof(model_number_str
), "ppd-model-number=%d",
7068 model_number
->values
[0].integer
);
7070 model_number_str
[0] = '\0';
7073 url_encode_attr(product
, product_str
, sizeof(product_str
));
7075 product_str
[0] = '\0';
7078 url_encode_attr(psversion
, psversion_str
, sizeof(psversion_str
));
7080 psversion_str
[0] = '\0';
7083 url_encode_attr(type
, type_str
, sizeof(type_str
));
7087 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7088 snprintf(options
, sizeof(options
),
7089 "list+%d+%d+%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
7090 con
->request
->request
.op
.request_id
,
7091 limit
? limit
->values
[0].integer
: 0,
7093 device
? "%20" : "", device_str
,
7094 language
? "%20" : "", language_str
,
7095 make
? "%20" : "", make_str
,
7096 model
? "%20" : "", model_str
,
7097 model_number
? "%20" : "", model_number_str
,
7098 product
? "%20" : "", product_str
,
7099 psversion
? "%20" : "", psversion_str
,
7100 type
? "%20" : "", type_str
);
7102 if (cupsdSendCommand(con
, command
, options
, 0))
7105 * Command started successfully, don't send an IPP response here...
7108 ippDelete(con
->response
);
7109 con
->response
= NULL
;
7114 * Command failed, return "internal error" so the user knows something
7118 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7119 _("cups-driverd failed to execute."));
7125 * 'get_printer_attrs()' - Get printer attributes.
7129 get_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
7130 ipp_attribute_t
*uri
) /* I - Printer URI */
7132 http_status_t status
; /* Policy status */
7133 cups_ptype_t dtype
; /* Destination type (printer/class) */
7134 cupsd_printer_t
*printer
; /* Printer/class */
7135 cups_array_t
*ra
; /* Requested attributes array */
7138 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_attrs(%p[%d], %s)", con
,
7139 con
->http
.fd
, uri
->values
[0].string
.text
);
7142 * Is the destination valid?
7145 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7151 send_ipp_status(con
, IPP_NOT_FOUND
,
7152 _("The printer or class was not found."));
7160 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7162 send_http_error(con
, status
, printer
);
7167 * Send the attributes...
7170 ra
= create_requested_array(con
->request
);
7172 copy_printer_attrs(con
, printer
, ra
);
7174 cupsArrayDelete(ra
);
7176 con
->response
->request
.status
.status_code
= IPP_OK
;
7181 * 'get_printers()' - Get a list of printers or classes.
7185 get_printers(cupsd_client_t
*con
, /* I - Client connection */
7186 int type
) /* I - 0 or CUPS_PRINTER_CLASS */
7188 http_status_t status
; /* Policy status */
7189 ipp_attribute_t
*attr
; /* Current attribute */
7190 int limit
; /* Max number of printers to return */
7191 int count
; /* Number of printers that match */
7192 cupsd_printer_t
*printer
; /* Current printer pointer */
7193 int printer_type
, /* printer-type attribute */
7194 printer_mask
; /* printer-type-mask attribute */
7195 char *location
; /* Location string */
7196 const char *username
; /* Current user */
7197 char *first_printer_name
; /* first-printer-name attribute */
7198 cups_array_t
*ra
; /* Requested attributes array */
7201 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printers(%p[%d], %x)", con
,
7202 con
->http
.fd
, type
);
7208 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7210 send_http_error(con
, status
, NULL
);
7215 * Check for printers...
7218 if (!Printers
|| !cupsArrayCount(Printers
))
7220 send_ipp_status(con
, IPP_NOT_FOUND
, _("No destinations added."));
7225 * See if they want to limit the number of printers reported...
7228 if ((attr
= ippFindAttribute(con
->request
, "limit",
7229 IPP_TAG_INTEGER
)) != NULL
)
7230 limit
= attr
->values
[0].integer
;
7234 if ((attr
= ippFindAttribute(con
->request
, "first-printer-name",
7235 IPP_TAG_NAME
)) != NULL
)
7236 first_printer_name
= attr
->values
[0].string
.text
;
7238 first_printer_name
= NULL
;
7241 * Support filtering...
7244 if ((attr
= ippFindAttribute(con
->request
, "printer-type",
7245 IPP_TAG_ENUM
)) != NULL
)
7246 printer_type
= attr
->values
[0].integer
;
7250 if ((attr
= ippFindAttribute(con
->request
, "printer-type-mask",
7251 IPP_TAG_ENUM
)) != NULL
)
7252 printer_mask
= attr
->values
[0].integer
;
7256 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
7257 IPP_TAG_TEXT
)) != NULL
)
7258 location
= attr
->values
[0].string
.text
;
7262 if (con
->username
[0])
7263 username
= con
->username
;
7264 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7265 IPP_TAG_NAME
)) != NULL
)
7266 username
= attr
->values
[0].string
.text
;
7270 ra
= create_requested_array(con
->request
);
7273 * OK, build a list of printers for this printer...
7276 if (first_printer_name
)
7278 if ((printer
= cupsdFindDest(first_printer_name
)) == NULL
)
7279 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7282 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7285 count
< limit
&& printer
;
7286 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
7288 if ((!type
|| (printer
->type
& CUPS_PRINTER_CLASS
) == type
) &&
7289 (printer
->type
& printer_mask
) == printer_type
&&
7290 (!location
|| !printer
->location
||
7291 !strcasecmp(printer
->location
, location
)))
7294 * If HideImplicitMembers is enabled, see if this printer or class
7295 * is a member of an implicit class...
7298 if (ImplicitClasses
&& HideImplicitMembers
&&
7299 printer
->in_implicit_class
)
7303 * If a username is specified, see if it is allowed or denied
7307 if (printer
->num_users
&& username
&& !user_allowed(printer
, username
))
7311 * Add the group separator as needed...
7315 ippAddSeparator(con
->response
);
7320 * Send the attributes...
7323 copy_printer_attrs(con
, printer
, ra
);
7327 cupsArrayDelete(ra
);
7329 con
->response
->request
.status
.status_code
= IPP_OK
;
7334 * 'get_subscription_attrs()' - Get subscription attributes.
7338 get_subscription_attrs(
7339 cupsd_client_t
*con
, /* I - Client connection */
7340 int sub_id
) /* I - Subscription ID */
7342 http_status_t status
; /* Policy status */
7343 cupsd_subscription_t
*sub
; /* Subscription */
7344 cups_array_t
*ra
; /* Requested attributes array */
7347 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7348 "get_subscription_attrs(con=%p[%d], sub_id=%d)",
7349 con
, con
->http
.fd
, sub_id
);
7352 * Is the subscription ID valid?
7355 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
7358 * Bad subscription ID...
7361 send_ipp_status(con
, IPP_NOT_FOUND
,
7362 _("notify-subscription-id %d no good!"), sub_id
);
7370 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
7372 con
, sub
->owner
)) != HTTP_OK
)
7374 send_http_error(con
, status
, sub
->dest
);
7379 * Copy the subscription attributes to the response using the
7380 * requested-attributes attribute that may be provided by the client.
7383 ra
= create_requested_array(con
->request
);
7385 copy_subscription_attrs(con
, sub
, ra
);
7387 cupsArrayDelete(ra
);
7389 con
->response
->request
.status
.status_code
= IPP_OK
;
7394 * 'get_subscriptions()' - Get subscriptions.
7398 get_subscriptions(cupsd_client_t
*con
, /* I - Client connection */
7399 ipp_attribute_t
*uri
) /* I - Printer/job URI */
7401 http_status_t status
; /* Policy status */
7402 int count
; /* Number of subscriptions */
7403 int limit
; /* Limit */
7404 cupsd_subscription_t
*sub
; /* Subscription */
7405 cups_array_t
*ra
; /* Requested attributes array */
7406 ipp_attribute_t
*attr
; /* Attribute */
7407 cups_ptype_t dtype
; /* Destination type (printer/class) */
7408 char scheme
[HTTP_MAX_URI
],
7409 /* Scheme portion of URI */
7410 username
[HTTP_MAX_URI
],
7411 /* Username portion of URI */
7413 /* Host portion of URI */
7414 resource
[HTTP_MAX_URI
];
7415 /* Resource portion of URI */
7416 int port
; /* Port portion of URI */
7417 cupsd_job_t
*job
; /* Job pointer */
7418 cupsd_printer_t
*printer
; /* Printer */
7421 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7422 "get_subscriptions(con=%p[%d], uri=%s)",
7423 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
7426 * Is the destination valid?
7429 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7430 sizeof(scheme
), username
, sizeof(username
), host
,
7431 sizeof(host
), &port
, resource
, sizeof(resource
));
7433 if (!strcmp(resource
, "/") ||
7434 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6) ||
7435 (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10) ||
7436 (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9))
7441 else if (!strncmp(resource
, "/jobs/", 6) && resource
[6])
7444 job
= cupsdFindJob(atoi(resource
+ 6));
7448 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%s does not exist!"),
7453 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7459 send_ipp_status(con
, IPP_NOT_FOUND
,
7460 _("The printer or class was not found."));
7463 else if ((attr
= ippFindAttribute(con
->request
, "notify-job-id",
7464 IPP_TAG_INTEGER
)) != NULL
)
7466 job
= cupsdFindJob(attr
->values
[0].integer
);
7470 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"),
7471 attr
->values
[0].integer
);
7482 if ((status
= cupsdCheckPolicy(printer
? printer
->op_policy_ptr
:
7484 con
, NULL
)) != HTTP_OK
)
7486 send_http_error(con
, status
, printer
);
7491 * Copy the subscription attributes to the response using the
7492 * requested-attributes attribute that may be provided by the client.
7495 ra
= create_requested_array(con
->request
);
7497 if ((attr
= ippFindAttribute(con
->request
, "limit",
7498 IPP_TAG_INTEGER
)) != NULL
)
7499 limit
= attr
->values
[0].integer
;
7504 * See if we only want to see subscriptions for a specific user...
7507 if ((attr
= ippFindAttribute(con
->request
, "my-subscriptions",
7508 IPP_TAG_BOOLEAN
)) != NULL
&&
7509 attr
->values
[0].boolean
)
7510 strlcpy(username
, get_username(con
), sizeof(username
));
7514 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
), count
= 0;
7516 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
7517 if ((!printer
|| sub
->dest
== printer
) && (!job
|| sub
->job
== job
) &&
7518 (!username
[0] || !strcasecmp(username
, sub
->owner
)))
7520 ippAddSeparator(con
->response
);
7521 copy_subscription_attrs(con
, sub
, ra
);
7524 if (limit
&& count
>= limit
)
7528 cupsArrayDelete(ra
);
7531 con
->response
->request
.status
.status_code
= IPP_OK
;
7533 send_ipp_status(con
, IPP_NOT_FOUND
, _("No subscriptions found."));
7538 * 'get_username()' - Get the username associated with a request.
7541 static const char * /* O - Username */
7542 get_username(cupsd_client_t
*con
) /* I - Connection */
7544 ipp_attribute_t
*attr
; /* Attribute */
7547 if (con
->username
[0])
7548 return (con
->username
);
7549 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7550 IPP_TAG_NAME
)) != NULL
)
7551 return (attr
->values
[0].string
.text
);
7553 return ("anonymous");
7558 * 'hold_job()' - Hold a print job.
7562 hold_job(cupsd_client_t
*con
, /* I - Client connection */
7563 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
7565 ipp_attribute_t
*attr
, /* Current job-hold-until */
7566 *newattr
; /* New job-hold-until */
7567 int jobid
; /* Job ID */
7568 char method
[HTTP_MAX_URI
], /* Method portion of URI */
7569 username
[HTTP_MAX_URI
], /* Username portion of URI */
7570 host
[HTTP_MAX_URI
], /* Host portion of URI */
7571 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7572 int port
; /* Port portion of URI */
7573 cupsd_job_t
*job
; /* Job information */
7576 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_job(%p[%d], %s)", con
, con
->http
.fd
,
7577 uri
->values
[0].string
.text
);
7580 * See if we have a job URI or a printer URI...
7583 if (!strcmp(uri
->name
, "printer-uri"))
7586 * Got a printer URI; see if we also have a job-id attribute...
7589 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7590 IPP_TAG_INTEGER
)) == NULL
)
7592 send_ipp_status(con
, IPP_BAD_REQUEST
,
7593 _("Got a printer-uri attribute but no job-id!"));
7597 jobid
= attr
->values
[0].integer
;
7602 * Got a job URI; parse it to get the job ID...
7605 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
7606 sizeof(method
), username
, sizeof(username
), host
,
7607 sizeof(host
), &port
, resource
, sizeof(resource
));
7609 if (strncmp(resource
, "/jobs/", 6))
7615 send_ipp_status(con
, IPP_BAD_REQUEST
,
7616 _("Bad job-uri attribute \"%s\"!"),
7617 uri
->values
[0].string
.text
);
7621 jobid
= atoi(resource
+ 6);
7625 * See if the job exists...
7628 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7631 * Nope - return a "not found" error...
7634 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
7639 * See if the job is owned by the requesting user...
7642 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7644 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
7649 * Hold the job and return...
7654 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, job
->printer
, job
,
7655 "Job held by user.");
7657 if ((newattr
= ippFindAttribute(con
->request
, "job-hold-until",
7658 IPP_TAG_KEYWORD
)) == NULL
)
7659 newattr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
7661 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
7662 IPP_TAG_KEYWORD
)) == NULL
)
7663 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
7668 * Free the old hold value and copy the new one over...
7671 _cupsStrFree(attr
->values
[0].string
.text
);
7675 attr
->value_tag
= newattr
->value_tag
;
7676 attr
->values
[0].string
.text
=
7677 _cupsStrAlloc(newattr
->values
[0].string
.text
);
7681 attr
->value_tag
= IPP_TAG_KEYWORD
;
7682 attr
->values
[0].string
.text
= _cupsStrAlloc("indefinite");
7686 * Hold job until specified time...
7689 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
);
7691 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, job
->printer
, job
,
7692 "Job job-hold-until value changed by user.");
7695 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Held by \"%s\".", jobid
,
7698 con
->response
->request
.status
.status_code
= IPP_OK
;
7703 * 'move_job()' - Move a job to a new destination.
7707 move_job(cupsd_client_t
*con
, /* I - Client connection */
7708 ipp_attribute_t
*uri
) /* I - Job URI */
7710 http_status_t status
; /* Policy status */
7711 ipp_attribute_t
*attr
; /* Current attribute */
7712 int jobid
; /* Job ID */
7713 cupsd_job_t
*job
; /* Current job */
7714 const char *src
; /* Source printer/class */
7715 cups_ptype_t stype
, /* Source type (printer or class) */
7716 dtype
; /* Destination type (printer/class) */
7717 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
7718 username
[HTTP_MAX_URI
], /* Username portion of URI */
7719 host
[HTTP_MAX_URI
], /* Host portion of URI */
7720 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7721 int port
; /* Port portion of URI */
7722 cupsd_printer_t
*sprinter
, /* Source printer */
7723 *dprinter
; /* Destination printer */
7726 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "move_job(%p[%d], %s)", con
, con
->http
.fd
,
7727 uri
->values
[0].string
.text
);
7730 * Get the new printer or class...
7733 if ((attr
= ippFindAttribute(con
->request
, "job-printer-uri",
7734 IPP_TAG_URI
)) == NULL
)
7737 * Need job-printer-uri...
7740 send_ipp_status(con
, IPP_BAD_REQUEST
,
7741 _("job-printer-uri attribute missing!"));
7745 if (!cupsdValidateDest(attr
->values
[0].string
.text
, &dtype
, &dprinter
))
7751 send_ipp_status(con
, IPP_NOT_FOUND
,
7752 _("The printer or class was not found."));
7757 * See if we have a job URI or a printer URI...
7760 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7761 sizeof(scheme
), username
, sizeof(username
), host
,
7762 sizeof(host
), &port
, resource
, sizeof(resource
));
7764 if (!strcmp(uri
->name
, "printer-uri"))
7767 * Got a printer URI; see if we also have a job-id attribute...
7770 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7771 IPP_TAG_INTEGER
)) == NULL
)
7777 if ((src
= cupsdValidateDest(uri
->values
[0].string
.text
, &stype
,
7778 &sprinter
)) == NULL
)
7784 send_ipp_status(con
, IPP_NOT_FOUND
,
7785 _("The printer or class was not found."));
7794 * Otherwise, just move a single job...
7797 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
7800 * Nope - return a "not found" error...
7803 send_ipp_status(con
, IPP_NOT_FOUND
,
7804 _("Job #%d does not exist!"), attr
->values
[0].integer
);
7810 * Job found, initialize source pointers...
7821 * Got a job URI; parse it to get the job ID...
7824 if (strncmp(resource
, "/jobs/", 6))
7830 send_ipp_status(con
, IPP_BAD_REQUEST
,
7831 _("Bad job-uri attribute \"%s\"!"),
7832 uri
->values
[0].string
.text
);
7837 * See if the job exists...
7840 jobid
= atoi(resource
+ 6);
7842 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7845 * Nope - return a "not found" error...
7848 send_ipp_status(con
, IPP_NOT_FOUND
,
7849 _("Job #%d does not exist!"), jobid
);
7855 * Job found, initialize source pointers...
7864 * Check the policy of the destination printer...
7867 if ((status
= cupsdCheckPolicy(dprinter
->op_policy_ptr
, con
,
7868 job
? job
->username
: NULL
)) != HTTP_OK
)
7870 send_http_error(con
, status
, dprinter
);
7875 * Now move the job or jobs...
7881 * See if the job has been completed...
7884 if (job
->state_value
> IPP_JOB_STOPPED
)
7887 * Return a "not-possible" error...
7890 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
7891 _("Job #%d is finished and cannot be altered!"),
7897 * See if the job is owned by the requesting user...
7900 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7902 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
7907 * Move the job to a different printer or class...
7910 cupsdMoveJob(job
, dprinter
);
7915 * Got the source printer, now look through the jobs...
7918 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
7920 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
7923 * See if the job is pointing at the source printer or has not been
7927 if (strcasecmp(job
->dest
, src
) ||
7928 job
->state_value
> IPP_JOB_STOPPED
)
7932 * See if the job can be moved by the requesting user...
7935 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7939 * Move the job to a different printer or class...
7942 cupsdMoveJob(job
, dprinter
);
7947 * Start jobs if possible...
7953 * Return with "everything is OK" status...
7956 con
->response
->request
.status
.status_code
= IPP_OK
;
7961 * 'ppd_parse_line()' - Parse a PPD default line.
7964 static int /* O - 0 on success, -1 on failure */
7965 ppd_parse_line(const char *line
, /* I - Line */
7966 char *option
, /* O - Option name */
7967 int olen
, /* I - Size of option name */
7968 char *choice
, /* O - Choice name */
7969 int clen
) /* I - Size of choice name */
7972 * Verify this is a default option line...
7975 if (strncmp(line
, "*Default", 8))
7979 * Read the option name...
7982 for (line
+= 8, olen
--; isalnum(*line
& 255); line
++)
7992 * Skip everything else up to the colon (:)...
7995 while (*line
&& *line
!= ':')
8004 * Now grab the option choice, skipping leading whitespace...
8007 while (isspace(*line
& 255))
8010 for (clen
--; isalnum(*line
& 255); line
++)
8020 * Return with no errors...
8028 * 'print_job()' - Print a file to a printer or class.
8032 print_job(cupsd_client_t
*con
, /* I - Client connection */
8033 ipp_attribute_t
*uri
) /* I - Printer URI */
8035 ipp_attribute_t
*attr
; /* Current attribute */
8036 ipp_attribute_t
*format
; /* Document-format attribute */
8037 const char *default_format
; /* document-format-default value */
8038 cupsd_job_t
*job
; /* New job */
8039 char filename
[1024]; /* Job filename */
8040 mime_type_t
*filetype
; /* Type of file */
8041 char super
[MIME_MAX_SUPER
], /* Supertype of file */
8042 type
[MIME_MAX_TYPE
], /* Subtype of file */
8043 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
8044 /* Textual name of mime type */
8045 cupsd_printer_t
*printer
; /* Printer data */
8046 struct stat fileinfo
; /* File information */
8047 int kbytes
; /* Size of file */
8048 int compression
; /* Document compression */
8051 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "print_job(%p[%d], %s)", con
, con
->http
.fd
,
8052 uri
->values
[0].string
.text
);
8055 * Validate print file attributes, for now just document-format and
8056 * compression (CUPS only supports "none" and "gzip")...
8059 compression
= CUPS_FILE_NONE
;
8061 if ((attr
= ippFindAttribute(con
->request
, "compression",
8062 IPP_TAG_KEYWORD
)) != NULL
)
8064 if (strcmp(attr
->values
[0].string
.text
, "none")
8066 && strcmp(attr
->values
[0].string
.text
, "gzip")
8067 #endif /* HAVE_LIBZ */
8070 send_ipp_status(con
, IPP_ATTRIBUTES
,
8071 _("Unsupported compression \"%s\"!"),
8072 attr
->values
[0].string
.text
);
8073 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
8074 "compression", NULL
, attr
->values
[0].string
.text
);
8079 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
8080 compression
= CUPS_FILE_GZIP
;
8081 #endif /* HAVE_LIBZ */
8085 * Do we have a file to print?
8090 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file!?!"));
8095 * Is the destination valid?
8098 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
8104 send_ipp_status(con
, IPP_NOT_FOUND
,
8105 _("The printer or class was not found."));
8110 * Is it a format we support?
8113 if ((format
= ippFindAttribute(con
->request
, "document-format",
8114 IPP_TAG_MIMETYPE
)) != NULL
)
8117 * Grab format from client...
8120 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]", super
,
8123 send_ipp_status(con
, IPP_BAD_REQUEST
,
8124 _("Could not scan type \"%s\"!"),
8125 format
->values
[0].string
.text
);
8129 else if ((default_format
= cupsGetOption("document-format",
8130 printer
->num_options
,
8131 printer
->options
)) != NULL
)
8134 * Use default document format...
8137 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
8139 send_ipp_status(con
, IPP_BAD_REQUEST
,
8140 _("Could not scan type \"%s\"!"),
8151 strcpy(super
, "application");
8152 strcpy(type
, "octet-stream");
8155 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
8158 * Auto-type the file...
8161 ipp_attribute_t
*doc_name
; /* document-name attribute */
8164 cupsdLogMessage(CUPSD_LOG_DEBUG
, "print_job: auto-typing file...");
8166 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
8167 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
8168 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
8172 filetype
= mimeType(MimeDatabase
, super
, type
);
8175 filetype
= mimeType(MimeDatabase
, super
, type
);
8179 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
8182 * Replace the document-format attribute value with the auto-typed or
8186 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
8191 _cupsStrFree(format
->values
[0].string
.text
);
8193 format
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
8196 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
8197 "document-format", NULL
, mimetype
);
8201 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
8202 _("Unsupported format \'%s/%s\'!"), super
, type
);
8203 cupsdLogMessage(CUPSD_LOG_INFO
,
8204 "Hint: Do you have the raw file printing rules enabled?");
8207 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
8208 "document-format", NULL
, format
->values
[0].string
.text
);
8214 * Read any embedded job ticket info from PS files...
8217 if (!strcasecmp(filetype
->super
, "application") &&
8218 !strcasecmp(filetype
->type
, "postscript"))
8219 read_ps_job_ticket(con
);
8222 * Create the job object...
8225 if ((job
= add_job(con
, printer
, filetype
)) == NULL
)
8228 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Adding job file of type %s/%s.",
8229 job
->id
, filetype
->super
, filetype
->type
);
8232 * Update quota data...
8235 if (stat(con
->filename
, &fileinfo
))
8238 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
8240 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
8242 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
8243 IPP_TAG_INTEGER
)) != NULL
)
8244 attr
->values
[0].integer
+= kbytes
;
8247 * Add the job file...
8250 if (add_file(con
, job
, filetype
, compression
))
8253 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
8255 rename(con
->filename
, filename
);
8256 cupsdClearString(&con
->filename
);
8259 * See if we need to add the ending sheet...
8262 if (cupsdTimeoutJob(job
))
8266 * Log and save the job...
8269 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Queued on \"%s\" by \"%s\".",
8270 job
->id
, job
->dest
, job
->username
);
8271 cupsdLogMessage(CUPSD_LOG_DEBUG
, "[Job %d] hold_until = %d", job
->id
,
8272 (int)job
->hold_until
);
8277 * Start the job if possible...
8285 * 'read_ps_job_ticket()' - Reads a job ticket embedded in a PS file.
8287 * This function only gets called when printing a single PostScript
8288 * file using the Print-Job operation. It doesn't work for Create-Job +
8289 * Send-File, since the job attributes need to be set at job creation
8290 * time for banners to work. The embedded PS job ticket stuff is here
8291 * only to allow the Windows printer driver for CUPS to pass in JCL
8292 * options and IPP attributes which otherwise would be lost.
8294 * The format of a PS job ticket is simple:
8296 * %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
8298 * %cupsJobTicket: attr1=value1
8299 * %cupsJobTicket: attr2=value2
8301 * %cupsJobTicket: attrN=valueN
8303 * Job ticket lines must appear immediately after the first line that
8304 * specifies PostScript format (%!PS-Adobe-3.0), and CUPS will stop
8305 * looking for job ticket info when it finds a line that does not begin
8306 * with "%cupsJobTicket:".
8308 * The maximum length of a job ticket line, including the prefix, is
8309 * 255 characters to conform with the Adobe DSC.
8311 * Read-only attributes are rejected with a notice to the error log in
8312 * case a malicious user tries anything. Since the job ticket is read
8313 * prior to attribute validation in print_job(), job ticket attributes
8314 * will go through the same validation as IPP attributes...
8318 read_ps_job_ticket(cupsd_client_t
*con
) /* I - Client connection */
8320 cups_file_t
*fp
; /* File to read from */
8321 char line
[256]; /* Line data */
8322 int num_options
; /* Number of options */
8323 cups_option_t
*options
; /* Options */
8324 ipp_t
*ticket
; /* New attributes */
8325 ipp_attribute_t
*attr
, /* Current attribute */
8326 *attr2
, /* Job attribute */
8327 *prev2
; /* Previous job attribute */
8331 * First open the print file...
8334 if ((fp
= cupsFileOpen(con
->filename
, "rb")) == NULL
)
8336 cupsdLogMessage(CUPSD_LOG_ERROR
,
8337 "read_ps_job_ticket: Unable to open PostScript print file "
8344 * Skip the first line...
8347 if (cupsFileGets(fp
, line
, sizeof(line
)) == NULL
)
8349 cupsdLogMessage(CUPSD_LOG_ERROR
,
8350 "read_ps_job_ticket: Unable to read from PostScript print "
8357 if (strncmp(line
, "%!PS-Adobe-", 11))
8360 * Not a DSC-compliant file, so no job ticket info will be available...
8368 * Read job ticket info from the file...
8374 while (cupsFileGets(fp
, line
, sizeof(line
)))
8377 * Stop at the first non-ticket line...
8380 if (strncmp(line
, "%cupsJobTicket:", 15))
8384 * Add the options to the option array...
8387 num_options
= cupsParseOptions(line
+ 15, num_options
, &options
);
8391 * Done with the file; see if we have any options...
8396 if (num_options
== 0)
8400 * OK, convert the options to an attribute list, and apply them to
8405 cupsEncodeOptions(ticket
, num_options
, options
);
8408 * See what the user wants to change.
8411 for (attr
= ticket
->attrs
; attr
; attr
= attr
->next
)
8413 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
8416 if (!strcmp(attr
->name
, "job-originating-host-name") ||
8417 !strcmp(attr
->name
, "job-originating-user-name") ||
8418 !strcmp(attr
->name
, "job-media-sheets-completed") ||
8419 !strcmp(attr
->name
, "job-k-octets") ||
8420 !strcmp(attr
->name
, "job-id") ||
8421 !strncmp(attr
->name
, "job-state", 9) ||
8422 !strncmp(attr
->name
, "time-at-", 8))
8423 continue; /* Read-only attrs */
8425 if ((attr2
= ippFindAttribute(con
->request
, attr
->name
,
8426 IPP_TAG_ZERO
)) != NULL
)
8429 * Some other value; first free the old value...
8432 if (con
->request
->attrs
== attr2
)
8434 con
->request
->attrs
= attr2
->next
;
8439 for (prev2
= con
->request
->attrs
; prev2
; prev2
= prev2
->next
)
8440 if (prev2
->next
== attr2
)
8442 prev2
->next
= attr2
->next
;
8447 if (con
->request
->last
== attr2
)
8448 con
->request
->last
= prev2
;
8450 _ippFreeAttr(attr2
);
8454 * Add new option by copying it...
8457 copy_attribute(con
->request
, attr
, 0);
8461 * Then free the attribute list and option array...
8465 cupsFreeOptions(num_options
, options
);
8470 * 'reject_jobs()' - Reject print jobs to a printer.
8474 reject_jobs(cupsd_client_t
*con
, /* I - Client connection */
8475 ipp_attribute_t
*uri
) /* I - Printer or class URI */
8477 http_status_t status
; /* Policy status */
8478 cups_ptype_t dtype
; /* Destination type (printer/class) */
8479 cupsd_printer_t
*printer
; /* Printer data */
8480 ipp_attribute_t
*attr
; /* printer-state-message text */
8483 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "reject_jobs(%p[%d], %s)", con
,
8484 con
->http
.fd
, uri
->values
[0].string
.text
);
8487 * Is the destination valid?
8490 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8496 send_ipp_status(con
, IPP_NOT_FOUND
,
8497 _("The printer or class was not found."));
8505 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8507 send_http_error(con
, status
, printer
);
8512 * Reject jobs sent to the printer...
8515 printer
->accepting
= 0;
8517 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
8518 IPP_TAG_TEXT
)) == NULL
)
8519 strcpy(printer
->state_message
, "Rejecting Jobs");
8521 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
8522 sizeof(printer
->state_message
));
8524 cupsdAddPrinterHistory(printer
);
8526 if (dtype
& CUPS_PRINTER_CLASS
)
8528 cupsdSaveAllClasses();
8530 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" rejecting jobs (\"%s\").",
8531 printer
->name
, get_username(con
));
8535 cupsdSaveAllPrinters();
8537 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" rejecting jobs (\"%s\").",
8538 printer
->name
, get_username(con
));
8542 * Everything was ok, so return OK status...
8545 con
->response
->request
.status
.status_code
= IPP_OK
;
8550 * 'release_job()' - Release a held print job.
8554 release_job(cupsd_client_t
*con
, /* I - Client connection */
8555 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
8557 ipp_attribute_t
*attr
; /* Current attribute */
8558 int jobid
; /* Job ID */
8559 char method
[HTTP_MAX_URI
], /* Method portion of URI */
8560 username
[HTTP_MAX_URI
], /* Username portion of URI */
8561 host
[HTTP_MAX_URI
], /* Host portion of URI */
8562 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8563 int port
; /* Port portion of URI */
8564 cupsd_job_t
*job
; /* Job information */
8567 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_job(%p[%d], %s)", con
,
8568 con
->http
.fd
, uri
->values
[0].string
.text
);
8571 * See if we have a job URI or a printer URI...
8574 if (!strcmp(uri
->name
, "printer-uri"))
8577 * Got a printer URI; see if we also have a job-id attribute...
8580 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8581 IPP_TAG_INTEGER
)) == NULL
)
8583 send_ipp_status(con
, IPP_BAD_REQUEST
,
8584 _("Got a printer-uri attribute but no job-id!"));
8588 jobid
= attr
->values
[0].integer
;
8593 * Got a job URI; parse it to get the job ID...
8596 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
8597 sizeof(method
), username
, sizeof(username
), host
,
8598 sizeof(host
), &port
, resource
, sizeof(resource
));
8600 if (strncmp(resource
, "/jobs/", 6))
8606 send_ipp_status(con
, IPP_BAD_REQUEST
,
8607 _("Bad job-uri attribute \"%s\"!"),
8608 uri
->values
[0].string
.text
);
8612 jobid
= atoi(resource
+ 6);
8616 * See if the job exists...
8619 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8622 * Nope - return a "not found" error...
8625 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
8630 * See if job is "held"...
8633 if (job
->state_value
!= IPP_JOB_HELD
)
8636 * Nope - return a "not possible" error...
8639 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not held!"), jobid
);
8644 * See if the job is owned by the requesting user...
8647 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8649 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
8654 * Reset the job-hold-until value to "no-hold"...
8657 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
8658 IPP_TAG_KEYWORD
)) == NULL
)
8659 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
8663 _cupsStrFree(attr
->values
[0].string
.text
);
8665 attr
->value_tag
= IPP_TAG_KEYWORD
;
8666 attr
->values
[0].string
.text
= _cupsStrAlloc("no-hold");
8668 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, job
->printer
, job
,
8669 "Job job-hold-until value changed by user.");
8673 * Release the job and return...
8676 cupsdReleaseJob(job
);
8678 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, job
->printer
, job
,
8679 "Job released by user.");
8681 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Released by \"%s\".", jobid
,
8684 con
->response
->request
.status
.status_code
= IPP_OK
;
8689 * 'renew_subscription()' - Renew an existing subscription...
8694 cupsd_client_t
*con
, /* I - Client connection */
8695 int sub_id
) /* I - Subscription ID */
8697 http_status_t status
; /* Policy status */
8698 cupsd_subscription_t
*sub
; /* Subscription */
8699 ipp_attribute_t
*lease
; /* notify-lease-duration */
8702 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
8703 "renew_subscription(con=%p[%d], sub_id=%d)",
8704 con
, con
->http
.fd
, sub_id
);
8707 * Is the subscription ID valid?
8710 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
8713 * Bad subscription ID...
8716 send_ipp_status(con
, IPP_NOT_FOUND
,
8717 _("notify-subscription-id %d no good!"), sub_id
);
8724 * Job subscriptions cannot be renewed...
8727 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8728 _("Job subscriptions cannot be renewed!"));
8736 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
8738 con
, sub
->owner
)) != HTTP_OK
)
8740 send_http_error(con
, status
, sub
->dest
);
8745 * Renew the subscription...
8748 lease
= ippFindAttribute(con
->request
, "notify-lease-duration",
8751 sub
->lease
= lease
? lease
->values
[0].integer
: DefaultLeaseDuration
;
8753 if (MaxLeaseDuration
&& (sub
->lease
== 0 || sub
->lease
> MaxLeaseDuration
))
8755 cupsdLogMessage(CUPSD_LOG_INFO
,
8756 "renew_subscription: Limiting notify-lease-duration to "
8759 sub
->lease
= MaxLeaseDuration
;
8762 sub
->expire
= sub
->lease
? time(NULL
) + sub
->lease
: 0;
8764 cupsdSaveAllSubscriptions();
8766 con
->response
->request
.status
.status_code
= IPP_OK
;
8768 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
8769 "notify-lease-duration", sub
->lease
);
8774 * 'restart_job()' - Restart an old print job.
8778 restart_job(cupsd_client_t
*con
, /* I - Client connection */
8779 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
8781 ipp_attribute_t
*attr
; /* Current attribute */
8782 int jobid
; /* Job ID */
8783 char method
[HTTP_MAX_URI
], /* Method portion of URI */
8784 username
[HTTP_MAX_URI
], /* Username portion of URI */
8785 host
[HTTP_MAX_URI
], /* Host portion of URI */
8786 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8787 int port
; /* Port portion of URI */
8788 cupsd_job_t
*job
; /* Job information */
8791 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "restart_job(%p[%d], %s)", con
,
8792 con
->http
.fd
, uri
->values
[0].string
.text
);
8795 * See if we have a job URI or a printer URI...
8798 if (!strcmp(uri
->name
, "printer-uri"))
8801 * Got a printer URI; see if we also have a job-id attribute...
8804 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8805 IPP_TAG_INTEGER
)) == NULL
)
8807 send_ipp_status(con
, IPP_BAD_REQUEST
,
8808 _("Got a printer-uri attribute but no job-id!"));
8812 jobid
= attr
->values
[0].integer
;
8817 * Got a job URI; parse it to get the job ID...
8820 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
8821 sizeof(method
), username
, sizeof(username
), host
,
8822 sizeof(host
), &port
, resource
, sizeof(resource
));
8824 if (strncmp(resource
, "/jobs/", 6))
8830 send_ipp_status(con
, IPP_BAD_REQUEST
,
8831 _("Bad job-uri attribute \"%s\"!"),
8832 uri
->values
[0].string
.text
);
8836 jobid
= atoi(resource
+ 6);
8840 * See if the job exists...
8843 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8846 * Nope - return a "not found" error...
8849 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
8854 * See if job is in any of the "completed" states...
8857 if (job
->state_value
<= IPP_JOB_PROCESSING
)
8860 * Nope - return a "not possible" error...
8863 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not complete!"),
8869 * See if we have retained the job files...
8874 if (!job
->attrs
|| job
->num_files
== 0)
8877 * Nope - return a "not possible" error...
8880 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8881 _("Job #%d cannot be restarted - no files!"), jobid
);
8886 * See if the job is owned by the requesting user...
8889 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8891 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
8896 * Restart the job and return...
8899 cupsdRestartJob(job
);
8901 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Restarted by \"%s\".", jobid
,
8904 con
->response
->request
.status
.status_code
= IPP_OK
;
8909 * 'save_auth_info()' - Save authentication information for a job.
8914 cupsd_client_t
*con
, /* I - Client connection */
8915 cupsd_job_t
*job
, /* I - Job */
8916 ipp_attribute_t
*auth_info
) /* I - auth-info attribute, if any */
8918 int i
; /* Looping var */
8919 char filename
[1024]; /* Job authentication filename */
8920 cups_file_t
*fp
; /* Job authentication file */
8921 char line
[2048]; /* Line for file */
8922 cupsd_printer_t
*dest
; /* Destination printer/class */
8926 * This function saves the in-memory authentication information for
8927 * a job so that it can be used to authenticate with a remote host.
8928 * The information is stored in a file that is readable only by the
8929 * root user. The fields are Base-64 encoded, each on a separate line,
8930 * followed by random number (up to 1024) of newlines to limit the
8931 * amount of information that is exposed.
8933 * Because of the potential for exposing of authentication information,
8934 * this functionality is only enabled when running cupsd as root.
8936 * This caching only works for the Basic and BasicDigest authentication
8937 * types. Digest authentication cannot be cached this way, and in
8938 * the future Kerberos authentication may make all of this obsolete.
8940 * Authentication information is saved whenever an authenticated
8941 * Print-Job, Create-Job, or CUPS-Authenticate-Job operation is
8944 * This information is deleted after a job is completed or canceled,
8945 * so reprints may require subsequent re-authentication.
8951 if ((dest
= cupsdFindDest(job
->dest
)) == NULL
)
8955 * Create the authentication file and change permissions...
8958 snprintf(filename
, sizeof(filename
), "%s/a%05d", RequestRoot
, job
->id
);
8959 if ((fp
= cupsFileOpen(filename
, "w")) == NULL
)
8961 cupsdLogMessage(CUPSD_LOG_ERROR
,
8962 "Unable to save authentication info to \"%s\" - %s",
8963 filename
, strerror(errno
));
8967 fchown(cupsFileNumber(fp
), 0, 0);
8968 fchmod(cupsFileNumber(fp
), 0400);
8970 if (auth_info
&& auth_info
->num_values
== dest
->num_auth_info_required
)
8973 * Write 1 to 3 auth values...
8976 cupsdClearString(&job
->auth_username
);
8977 cupsdClearString(&job
->auth_domain
);
8978 cupsdClearString(&job
->auth_password
);
8980 for (i
= 0; i
< auth_info
->num_values
; i
++)
8982 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[i
].string
.text
,
8983 strlen(auth_info
->values
[i
].string
.text
));
8984 cupsFilePrintf(fp
, "%s\n", line
);
8986 if (!strcmp(dest
->auth_info_required
[i
], "username"))
8987 cupsdSetStringf(&job
->auth_username
, "AUTH_USERNAME=%s",
8988 auth_info
->values
[i
].string
.text
);
8989 else if (!strcmp(dest
->auth_info_required
[i
], "domain"))
8990 cupsdSetStringf(&job
->auth_domain
, "AUTH_DOMAIN=%s",
8991 auth_info
->values
[i
].string
.text
);
8992 else if (!strcmp(dest
->auth_info_required
[i
], "password"))
8993 cupsdSetStringf(&job
->auth_password
, "AUTH_PASSWORD=%s",
8994 auth_info
->values
[i
].string
.text
);
8997 else if (con
->username
[0])
9000 * Write the authenticated username...
9003 httpEncode64_2(line
, sizeof(line
), con
->username
, strlen(con
->username
));
9004 cupsFilePrintf(fp
, "%s\n", line
);
9006 cupsdSetStringf(&job
->auth_username
, "AUTH_USERNAME=%s", con
->username
);
9007 cupsdClearString(&job
->auth_domain
);
9010 * Write the authenticated password...
9013 httpEncode64_2(line
, sizeof(line
), con
->password
, strlen(con
->password
));
9014 cupsFilePrintf(fp
, "%s\n", line
);
9016 cupsdSetStringf(&job
->auth_password
, "AUTH_PASSWORD=%s", con
->password
);
9020 * Write a random number of newlines to the end of the file...
9023 for (i
= (rand() % 1024); i
>= 0; i
--)
9024 cupsFilePutChar(fp
, '\n');
9027 * Close the file and return...
9032 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
9033 if (con
->gss_have_creds
)
9034 save_krb5_creds(con
, job
);
9035 else if (job
->ccname
)
9036 cupsdClearString(&(job
->ccname
));
9037 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
9041 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
9043 * 'save_krb5_creds()' - Save Kerberos credentials for the job.
9047 save_krb5_creds(cupsd_client_t
*con
, /* I - Client connection */
9048 cupsd_job_t
*job
) /* I - Job */
9050 # if !defined(HAVE_KRB5_CC_NEW_UNIQUE) && !defined(HAVE_HEIMDAL)
9051 cupsdLogMessage(CUPSD_LOG_INFO
,
9052 "Sorry, your version of Kerberos does not support delegated "
9057 krb5_error_code error
; /* Kerberos error code */
9058 OM_uint32 major_status
, /* Major status code */
9059 minor_status
; /* Minor status code */
9060 krb5_principal principal
; /* Kerberos principal */
9065 * If the weak-linked GSSAPI/Kerberos library is not present, don't try
9069 if (krb5_init_context
== NULL
)
9071 # endif /* __APPLE__ */
9074 * We MUST create a file-based cache because memory-based caches are
9075 * only valid for the current process/address space.
9077 * Due to various bugs/features in different versions of Kerberos, we
9078 * need either the krb5_cc_new_unique() function or Heimdal's version
9079 * of krb5_cc_gen_new() to create a new FILE: credential cache that
9080 * can be passed to the backend. These functions create a temporary
9081 * file (typically in /tmp) containing the cached credentials, which
9082 * are removed when we have successfully printed a job.
9085 # ifdef HAVE_KRB5_CC_NEW_UNIQUE
9086 if ((error
= krb5_cc_new_unique(KerberosContext
, "FILE", NULL
,
9087 &(job
->ccache
))) != 0)
9088 # else /* HAVE_HEIMDAL */
9089 if ((error
= krb5_cc_gen_new(KerberosContext
, &krb5_fcc_ops
,
9090 &(job
->ccache
))) != 0)
9091 # endif /* HAVE_KRB5_CC_NEW_UNIQUE */
9093 cupsdLogMessage(CUPSD_LOG_ERROR
,
9094 "Unable to create new credentials cache (%d/%s)",
9095 error
, strerror(errno
));
9100 if ((error
= krb5_parse_name(KerberosContext
, con
->username
, &principal
)) != 0)
9102 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to parse kerberos username (%d/%s)",
9103 error
, strerror(errno
));
9104 krb5_cc_destroy(KerberosContext
, job
->ccache
);
9109 if ((error
= krb5_cc_initialize(KerberosContext
, job
->ccache
, principal
)))
9111 cupsdLogMessage(CUPSD_LOG_ERROR
,
9112 "Unable to initialize credentials cache (%d/%s)", error
,
9114 krb5_cc_destroy(KerberosContext
, job
->ccache
);
9115 krb5_free_principal(KerberosContext
, principal
);
9120 krb5_free_principal(KerberosContext
, principal
);
9123 * Copy the user's credentials to the new cache file...
9126 major_status
= gss_krb5_copy_ccache(&minor_status
, con
->gss_delegated_cred
,
9129 if (GSS_ERROR(major_status
))
9131 cupsdLogGSSMessage(CUPSD_LOG_ERROR
, major_status
, minor_status
,
9132 "Unable to import client credentials cache");
9133 krb5_cc_destroy(KerberosContext
, job
->ccache
);
9139 * Add the KRB5CCNAME environment variable to the job so that the
9140 * backend can use the credentials when printing.
9143 cupsdSetStringf(&(job
->ccname
), "KRB5CCNAME=FILE:%s",
9144 krb5_cc_get_name(KerberosContext
, job
->ccache
));
9146 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "[Job %d] save_krb5_creds: %s", job
->id
,
9148 # endif /* HAVE_KRB5_CC_NEW_UNIQUE || HAVE_HEIMDAL */
9150 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
9154 * 'send_document()' - Send a file to a printer or class.
9158 send_document(cupsd_client_t
*con
, /* I - Client connection */
9159 ipp_attribute_t
*uri
) /* I - Printer URI */
9161 ipp_attribute_t
*attr
; /* Current attribute */
9162 ipp_attribute_t
*format
; /* Document-format attribute */
9163 const char *default_format
;/* document-format-default value */
9164 int jobid
; /* Job ID number */
9165 cupsd_job_t
*job
; /* Current job */
9166 char job_uri
[HTTP_MAX_URI
],
9168 method
[HTTP_MAX_URI
],
9169 /* Method portion of URI */
9170 username
[HTTP_MAX_URI
],
9171 /* Username portion of URI */
9173 /* Host portion of URI */
9174 resource
[HTTP_MAX_URI
];
9175 /* Resource portion of URI */
9176 int port
; /* Port portion of URI */
9177 mime_type_t
*filetype
; /* Type of file */
9178 char super
[MIME_MAX_SUPER
],
9179 /* Supertype of file */
9180 type
[MIME_MAX_TYPE
],
9181 /* Subtype of file */
9182 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
9183 /* Textual name of mime type */
9184 char filename
[1024]; /* Job filename */
9185 cupsd_printer_t
*printer
; /* Current printer */
9186 struct stat fileinfo
; /* File information */
9187 int kbytes
; /* Size of file */
9188 int compression
; /* Type of compression */
9191 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "send_document(%p[%d], %s)", con
,
9192 con
->http
.fd
, uri
->values
[0].string
.text
);
9195 * See if we have a job URI or a printer URI...
9198 if (!strcmp(uri
->name
, "printer-uri"))
9201 * Got a printer URI; see if we also have a job-id attribute...
9204 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9205 IPP_TAG_INTEGER
)) == NULL
)
9207 send_ipp_status(con
, IPP_BAD_REQUEST
,
9208 _("Got a printer-uri attribute but no job-id!"));
9212 jobid
= attr
->values
[0].integer
;
9217 * Got a job URI; parse it to get the job ID...
9220 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
9221 sizeof(method
), username
, sizeof(username
), host
,
9222 sizeof(host
), &port
, resource
, sizeof(resource
));
9224 if (strncmp(resource
, "/jobs/", 6))
9230 send_ipp_status(con
, IPP_BAD_REQUEST
,
9231 _("Bad job-uri attribute \"%s\"!"),
9232 uri
->values
[0].string
.text
);
9236 jobid
= atoi(resource
+ 6);
9240 * See if the job exists...
9243 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9246 * Nope - return a "not found" error...
9249 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
9253 printer
= cupsdFindDest(job
->dest
);
9256 * See if the job is owned by the requesting user...
9259 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9261 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
9266 * OK, see if the client is sending the document compressed - CUPS
9267 * only supports "none" and "gzip".
9270 compression
= CUPS_FILE_NONE
;
9272 if ((attr
= ippFindAttribute(con
->request
, "compression",
9273 IPP_TAG_KEYWORD
)) != NULL
)
9275 if (strcmp(attr
->values
[0].string
.text
, "none")
9277 && strcmp(attr
->values
[0].string
.text
, "gzip")
9278 #endif /* HAVE_LIBZ */
9281 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Unsupported compression \"%s\"!"),
9282 attr
->values
[0].string
.text
);
9283 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
9284 "compression", NULL
, attr
->values
[0].string
.text
);
9289 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
9290 compression
= CUPS_FILE_GZIP
;
9291 #endif /* HAVE_LIBZ */
9295 * Do we have a file to print?
9300 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file!?!"));
9305 * Is it a format we support?
9308 if ((format
= ippFindAttribute(con
->request
, "document-format",
9309 IPP_TAG_MIMETYPE
)) != NULL
)
9312 * Grab format from client...
9315 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
9318 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"!"),
9319 format
->values
[0].string
.text
);
9323 else if ((default_format
= cupsGetOption("document-format",
9324 printer
->num_options
,
9325 printer
->options
)) != NULL
)
9328 * Use default document format...
9331 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
9333 send_ipp_status(con
, IPP_BAD_REQUEST
,
9334 _("Could not scan type \"%s\"!"),
9342 * No document format attribute? Auto-type it!
9345 strcpy(super
, "application");
9346 strcpy(type
, "octet-stream");
9349 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
9352 * Auto-type the file...
9355 ipp_attribute_t
*doc_name
; /* document-name attribute */
9358 cupsdLogMessage(CUPSD_LOG_DEBUG
, "send_document: auto-typing file...");
9360 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
9361 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
9362 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
9366 filetype
= mimeType(MimeDatabase
, super
, type
);
9369 filetype
= mimeType(MimeDatabase
, super
, type
);
9373 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
9376 * Replace the document-format attribute value with the auto-typed or
9380 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9385 _cupsStrFree(format
->values
[0].string
.text
);
9387 format
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
9390 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
9391 "document-format", NULL
, mimetype
);
9395 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9396 _("Unsupported format \'%s/%s\'!"), super
, type
);
9397 cupsdLogMessage(CUPSD_LOG_INFO
,
9398 "Hint: Do you have the raw file printing rules enabled?");
9401 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9402 "document-format", NULL
, format
->values
[0].string
.text
);
9407 if (printer
->filetypes
&& !cupsArrayFind(printer
->filetypes
, filetype
))
9409 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9412 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9413 _("Unsupported format \'%s\'!"), mimetype
);
9415 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9416 "document-format", NULL
, mimetype
);
9421 cupsdLogMessage(CUPSD_LOG_DEBUG
,
9422 "send_document: request file type is %s/%s.",
9423 filetype
->super
, filetype
->type
);
9426 * Add the file to the job...
9431 if (add_file(con
, job
, filetype
, compression
))
9434 if (stat(con
->filename
, &fileinfo
))
9437 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
9439 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
9441 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
9442 IPP_TAG_INTEGER
)) != NULL
)
9443 attr
->values
[0].integer
+= kbytes
;
9445 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
9447 rename(con
->filename
, filename
);
9449 cupsdClearString(&con
->filename
);
9451 cupsdLogMessage(CUPSD_LOG_INFO
,
9452 "File of type %s/%s queued in job #%d by \"%s\".",
9453 filetype
->super
, filetype
->type
, job
->id
, job
->username
);
9456 * Start the job if this is the last document...
9459 if ((attr
= ippFindAttribute(con
->request
, "last-document",
9460 IPP_TAG_BOOLEAN
)) != NULL
&&
9461 attr
->values
[0].boolean
)
9464 * See if we need to add the ending sheet...
9467 if (cupsdTimeoutJob(job
))
9470 if (job
->state_value
== IPP_JOB_STOPPED
)
9472 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9473 job
->state_value
= IPP_JOB_PENDING
;
9475 else if (job
->state_value
== IPP_JOB_HELD
)
9477 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9478 IPP_TAG_KEYWORD
)) == NULL
)
9479 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9481 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9483 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9484 job
->state_value
= IPP_JOB_PENDING
;
9491 * Start the job if possible... Since cupsdCheckJobs() can cancel a
9492 * job if it doesn't print, we need to re-find the job afterwards...
9499 job
= cupsdFindJob(jobid
);
9503 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9504 IPP_TAG_KEYWORD
)) == NULL
)
9505 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9507 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9509 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
9510 job
->state_value
= IPP_JOB_HELD
;
9511 job
->hold_until
= time(NULL
) + 60;
9517 * Fill in the response info...
9520 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
9523 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
9526 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", jobid
);
9528 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
9529 job
? job
->state_value
: IPP_JOB_CANCELED
);
9530 add_job_state_reasons(con
, job
);
9532 con
->response
->request
.status
.status_code
= IPP_OK
;
9537 * 'send_http_error()' - Send a HTTP error back to the IPP client.
9542 cupsd_client_t
*con
, /* I - Client connection */
9543 http_status_t status
, /* I - HTTP status code */
9544 cupsd_printer_t
*printer
) /* I - Printer, if any */
9546 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: %s",
9547 ippOpString(con
->request
->request
.op
.operation_id
),
9548 httpStatus(status
));
9550 if (status
== HTTP_UNAUTHORIZED
&&
9551 printer
&& printer
->num_auth_info_required
> 0 &&
9552 !strcmp(printer
->auth_info_required
[0], "negotiate"))
9553 cupsdSendError(con
, status
, CUPSD_AUTH_NEGOTIATE
);
9556 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9557 cupsd_location_t
*auth
; /* Pointer to authentication element */
9558 int auth_type
; /* Type of authentication required */
9561 if (printer
->type
& CUPS_PRINTER_CLASS
)
9562 snprintf(resource
, sizeof(resource
), "/classes/%s", printer
->name
);
9564 snprintf(resource
, sizeof(resource
), "/printers/%s", printer
->name
);
9566 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
9567 auth
->type
== CUPSD_AUTH_NONE
)
9568 auth
= cupsdFindPolicyOp(printer
->op_policy_ptr
,
9570 con
->request
->request
.op
.operation_id
:
9574 auth_type
= CUPSD_AUTH_NONE
;
9575 else if (auth
->type
== CUPSD_AUTH_DEFAULT
)
9576 auth_type
= DefaultAuthType
;
9578 auth_type
= auth
->type
;
9580 cupsdSendError(con
, status
, auth_type
);
9583 cupsdSendError(con
, status
, CUPSD_AUTH_NONE
);
9585 ippDelete(con
->response
);
9586 con
->response
= NULL
;
9593 * 'send_ipp_status()' - Send a status back to the IPP client.
9597 send_ipp_status(cupsd_client_t
*con
, /* I - Client connection */
9598 ipp_status_t status
, /* I - IPP status code */
9599 const char *message
, /* I - Status message */
9600 ...) /* I - Additional args as needed */
9602 va_list ap
; /* Pointer to additional args */
9603 char formatted
[1024]; /* Formatted errror message */
9606 va_start(ap
, message
);
9607 vsnprintf(formatted
, sizeof(formatted
),
9608 _cupsLangString(con
->language
, message
), ap
);
9611 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s: %s",
9612 ippOpString(con
->request
->request
.op
.operation_id
),
9613 ippErrorString(status
), formatted
);
9615 con
->response
->request
.status
.status_code
= status
;
9617 if (ippFindAttribute(con
->response
, "attributes-charset",
9618 IPP_TAG_ZERO
) == NULL
)
9619 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
9620 "attributes-charset", NULL
, DefaultCharset
);
9622 if (ippFindAttribute(con
->response
, "attributes-natural-language",
9623 IPP_TAG_ZERO
) == NULL
)
9624 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
9625 "attributes-natural-language", NULL
, DefaultLanguage
);
9627 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
9628 "status-message", NULL
, formatted
);
9633 * 'set_default()' - Set the default destination...
9637 set_default(cupsd_client_t
*con
, /* I - Client connection */
9638 ipp_attribute_t
*uri
) /* I - Printer URI */
9640 http_status_t status
; /* Policy status */
9641 cups_ptype_t dtype
; /* Destination type (printer/class) */
9642 cupsd_printer_t
*printer
; /* Printer */
9645 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_default(%p[%d], %s)", con
,
9646 con
->http
.fd
, uri
->values
[0].string
.text
);
9649 * Is the destination valid?
9652 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9658 send_ipp_status(con
, IPP_NOT_FOUND
,
9659 _("The printer or class was not found."));
9667 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
9669 send_http_error(con
, status
, NULL
);
9674 * Set it as the default...
9677 DefaultPrinter
= printer
;
9679 cupsdSaveAllPrinters();
9680 cupsdSaveAllClasses();
9682 cupsdWritePrintcap();
9684 cupsdLogMessage(CUPSD_LOG_INFO
,
9685 "Default destination set to \"%s\" by \"%s\".",
9686 printer
->name
, get_username(con
));
9689 * Everything was ok, so return OK status...
9692 con
->response
->request
.status
.status_code
= IPP_OK
;
9697 * 'set_job_attrs()' - Set job attributes.
9701 set_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
9702 ipp_attribute_t
*uri
) /* I - Job URI */
9704 ipp_attribute_t
*attr
, /* Current attribute */
9705 *attr2
; /* Job attribute */
9706 int jobid
; /* Job ID */
9707 cupsd_job_t
*job
; /* Current job */
9708 char method
[HTTP_MAX_URI
],
9709 /* Method portion of URI */
9710 username
[HTTP_MAX_URI
],
9711 /* Username portion of URI */
9713 /* Host portion of URI */
9714 resource
[HTTP_MAX_URI
];
9715 /* Resource portion of URI */
9716 int port
; /* Port portion of URI */
9717 int event
; /* Events? */
9720 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_job_attrs(%p[%d], %s)", con
,
9721 con
->http
.fd
, uri
->values
[0].string
.text
);
9724 * Start with "everything is OK" status...
9727 con
->response
->request
.status
.status_code
= IPP_OK
;
9730 * See if we have a job URI or a printer URI...
9733 if (!strcmp(uri
->name
, "printer-uri"))
9736 * Got a printer URI; see if we also have a job-id attribute...
9739 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9740 IPP_TAG_INTEGER
)) == NULL
)
9742 send_ipp_status(con
, IPP_BAD_REQUEST
,
9743 _("Got a printer-uri attribute but no job-id!"));
9747 jobid
= attr
->values
[0].integer
;
9752 * Got a job URI; parse it to get the job ID...
9755 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
9756 sizeof(method
), username
, sizeof(username
), host
,
9757 sizeof(host
), &port
, resource
, sizeof(resource
));
9759 if (strncmp(resource
, "/jobs/", 6))
9765 send_ipp_status(con
, IPP_BAD_REQUEST
,
9766 _("Bad job-uri attribute \"%s\"!"),
9767 uri
->values
[0].string
.text
);
9771 jobid
= atoi(resource
+ 6);
9775 * See if the job exists...
9778 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9781 * Nope - return a "not found" error...
9784 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
9789 * See if the job has been completed...
9792 if (job
->state_value
> IPP_JOB_STOPPED
)
9795 * Return a "not-possible" error...
9798 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9799 _("Job #%d is finished and cannot be altered!"), jobid
);
9804 * See if the job is owned by the requesting user...
9807 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9809 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
9814 * See what the user wants to change.
9821 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
9823 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
9826 if (!strcmp(attr
->name
, "attributes-charset") ||
9827 !strcmp(attr
->name
, "attributes-natural-language") ||
9828 !strcmp(attr
->name
, "document-compression") ||
9829 !strcmp(attr
->name
, "document-format") ||
9830 !strcmp(attr
->name
, "job-detailed-status-messages") ||
9831 !strcmp(attr
->name
, "job-document-access-errors") ||
9832 !strcmp(attr
->name
, "job-id") ||
9833 !strcmp(attr
->name
, "job-k-octets") ||
9834 !strcmp(attr
->name
, "job-originating-host-name") ||
9835 !strcmp(attr
->name
, "job-originating-user-name") ||
9836 !strcmp(attr
->name
, "job-printer-up-time") ||
9837 !strcmp(attr
->name
, "job-printer-uri") ||
9838 !strcmp(attr
->name
, "job-sheets") ||
9839 !strcmp(attr
->name
, "job-state-message") ||
9840 !strcmp(attr
->name
, "job-state-reasons") ||
9841 !strcmp(attr
->name
, "job-uri") ||
9842 !strcmp(attr
->name
, "number-of-documents") ||
9843 !strcmp(attr
->name
, "number-of-intervening-jobs") ||
9844 !strcmp(attr
->name
, "output-device-assigned") ||
9845 !strncmp(attr
->name
, "date-time-at-", 13) ||
9846 !strncmp(attr
->name
, "job-impressions", 15) ||
9847 !strncmp(attr
->name
, "job-k-octets", 12) ||
9848 !strncmp(attr
->name
, "job-media-sheets", 16) ||
9849 !strncmp(attr
->name
, "time-at-", 8))
9855 send_ipp_status(con
, IPP_ATTRIBUTES_NOT_SETTABLE
,
9856 _("%s cannot be changed."), attr
->name
);
9858 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
9859 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
9864 if (!strcmp(attr
->name
, "job-priority"))
9867 * Change the job priority...
9870 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
9872 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-priority value!"));
9874 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
9875 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
9877 else if (job
->state_value
>= IPP_JOB_PROCESSING
)
9879 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9880 _("Job is completed and cannot be changed."));
9883 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
9885 cupsdSetJobPriority(job
, attr
->values
[0].integer
);
9886 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
|
9887 CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
;
9890 else if (!strcmp(attr
->name
, "job-state"))
9893 * Change the job state...
9896 if (attr
->value_tag
!= IPP_TAG_ENUM
)
9898 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-state value!"));
9900 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
9901 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
9905 switch (attr
->values
[0].integer
)
9907 case IPP_JOB_PENDING
:
9909 if (job
->state_value
> IPP_JOB_HELD
)
9911 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9912 _("Job state cannot be changed."));
9915 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
9917 job
->state
->values
[0].integer
= attr
->values
[0].integer
;
9918 job
->state_value
= (ipp_jstate_t
)attr
->values
[0].integer
;
9920 event
|= CUPSD_EVENT_JOB_STATE
;
9924 case IPP_JOB_PROCESSING
:
9925 case IPP_JOB_STOPPED
:
9926 if (job
->state_value
!= attr
->values
[0].integer
)
9928 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9929 _("Job state cannot be changed."));
9934 case IPP_JOB_CANCELED
:
9935 case IPP_JOB_ABORTED
:
9936 case IPP_JOB_COMPLETED
:
9937 if (job
->state_value
> IPP_JOB_PROCESSING
)
9939 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9940 _("Job state cannot be changed."));
9943 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
9944 cupsdCancelJob(job
, 0, (ipp_jstate_t
)attr
->values
[0].integer
);
9949 else if (con
->response
->request
.status
.status_code
!= IPP_OK
)
9951 else if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
9952 IPP_TAG_ZERO
)) != NULL
)
9955 * Some other value; first free the old value...
9958 if (job
->attrs
->prev
)
9959 job
->attrs
->prev
->next
= attr2
->next
;
9961 job
->attrs
->attrs
= attr2
->next
;
9963 if (job
->attrs
->last
== attr2
)
9964 job
->attrs
->last
= job
->attrs
->prev
;
9966 _ippFreeAttr(attr2
);
9969 * Then copy the attribute...
9972 copy_attribute(job
->attrs
, attr
, 0);
9975 * See if the job-name or job-hold-until is being changed.
9978 if (!strcmp(attr
->name
, "job-hold-until"))
9980 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
);
9982 if (!strcmp(attr
->values
[0].string
.text
, "no-hold"))
9983 cupsdReleaseJob(job
);
9987 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
;
9990 else if (attr
->value_tag
== IPP_TAG_DELETEATTR
)
9993 * Delete the attribute...
9996 if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
9997 IPP_TAG_ZERO
)) != NULL
)
9999 if (job
->attrs
->prev
)
10000 job
->attrs
->prev
->next
= attr2
->next
;
10002 job
->attrs
->attrs
= attr2
->next
;
10004 if (attr2
== job
->attrs
->last
)
10005 job
->attrs
->last
= job
->attrs
->prev
;
10007 _ippFreeAttr(attr2
);
10009 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10015 * Add new option by copying it...
10018 copy_attribute(job
->attrs
, attr
, 0);
10020 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10031 * Send events as needed...
10034 if (event
& CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
)
10035 cupsdAddEvent(CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
, job
->printer
, job
,
10036 "Job priority changed by user.");
10038 if (event
& CUPSD_EVENT_JOB_STATE
)
10039 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, job
->printer
, job
,
10040 job
->state_value
== IPP_JOB_HELD
?
10041 "Job held by user." : "Job restarted by user.");
10043 if (event
& CUPSD_EVENT_JOB_CONFIG_CHANGED
)
10044 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, job
->printer
, job
,
10045 "Job options changed by user.");
10048 * Start jobs if possible...
10056 * 'set_printer_defaults()' - Set printer default options from a request.
10060 set_printer_defaults(
10061 cupsd_client_t
*con
, /* I - Client connection */
10062 cupsd_printer_t
*printer
) /* I - Printer */
10064 int i
; /* Looping var */
10065 ipp_attribute_t
*attr
; /* Current attribute */
10066 int namelen
; /* Length of attribute name */
10067 char name
[256], /* New attribute name */
10068 value
[256]; /* String version of integer attrs */
10071 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10074 * Skip non-printer attributes...
10077 if (attr
->group_tag
!= IPP_TAG_PRINTER
|| !attr
->name
)
10080 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_defaults: %s", attr
->name
);
10082 if (!strcmp(attr
->name
, "job-sheets-default"))
10085 * Only allow keywords and names...
10088 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10092 * Only allow job-sheets-default to be set when running without a
10093 * system high classification level...
10096 if (Classification
)
10099 cupsdSetString(&printer
->job_sheets
[0], attr
->values
[0].string
.text
);
10101 if (attr
->num_values
> 1)
10102 cupsdSetString(&printer
->job_sheets
[1], attr
->values
[1].string
.text
);
10104 cupsdSetString(&printer
->job_sheets
[1], "none");
10106 else if (!strcmp(attr
->name
, "requesting-user-name-allowed"))
10108 cupsdFreePrinterUsers(printer
);
10110 printer
->deny_users
= 0;
10112 if (attr
->value_tag
== IPP_TAG_NAME
&&
10113 (attr
->num_values
> 1 ||
10114 strcmp(attr
->values
[0].string
.text
, "all")))
10116 for (i
= 0; i
< attr
->num_values
; i
++)
10117 cupsdAddPrinterUser(printer
, attr
->values
[i
].string
.text
);
10120 else if (!strcmp(attr
->name
, "requesting-user-name-denied"))
10122 cupsdFreePrinterUsers(printer
);
10124 printer
->deny_users
= 1;
10126 if (attr
->value_tag
== IPP_TAG_NAME
&&
10127 (attr
->num_values
> 1 ||
10128 strcmp(attr
->values
[0].string
.text
, "none")))
10130 for (i
= 0; i
< attr
->num_values
; i
++)
10131 cupsdAddPrinterUser(printer
, attr
->values
[i
].string
.text
);
10134 else if (!strcmp(attr
->name
, "job-quota-period"))
10136 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10139 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-quota-period to %d...",
10140 attr
->values
[0].integer
);
10141 cupsdFreeQuotas(printer
);
10143 printer
->quota_period
= attr
->values
[0].integer
;
10145 else if (!strcmp(attr
->name
, "job-k-limit"))
10147 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10150 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-k-limit to %d...",
10151 attr
->values
[0].integer
);
10152 cupsdFreeQuotas(printer
);
10154 printer
->k_limit
= attr
->values
[0].integer
;
10156 else if (!strcmp(attr
->name
, "job-page-limit"))
10158 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10161 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-page-limit to %d...",
10162 attr
->values
[0].integer
);
10163 cupsdFreeQuotas(printer
);
10165 printer
->page_limit
= attr
->values
[0].integer
;
10167 else if (!strcmp(attr
->name
, "printer-op-policy"))
10169 cupsd_policy_t
*p
; /* Policy */
10172 if (attr
->value_tag
!= IPP_TAG_NAME
)
10175 if ((p
= cupsdFindPolicy(attr
->values
[0].string
.text
)) != NULL
)
10177 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10178 "Setting printer-op-policy to \"%s\"...",
10179 attr
->values
[0].string
.text
);
10180 cupsdSetString(&printer
->op_policy
, attr
->values
[0].string
.text
);
10181 printer
->op_policy_ptr
= p
;
10185 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10186 _("Unknown printer-op-policy \"%s\"."),
10187 attr
->values
[0].string
.text
);
10191 else if (!strcmp(attr
->name
, "printer-error-policy"))
10193 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10196 if (strcmp(attr
->values
[0].string
.text
, "abort-job") &&
10197 strcmp(attr
->values
[0].string
.text
, "retry-job") &&
10198 strcmp(attr
->values
[0].string
.text
, "stop-printer"))
10200 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10201 _("Unknown printer-error-policy \"%s\"."),
10202 attr
->values
[0].string
.text
);
10206 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10207 "Setting printer-error-policy to \"%s\"...",
10208 attr
->values
[0].string
.text
);
10209 cupsdSetString(&printer
->error_policy
, attr
->values
[0].string
.text
);
10213 * Skip any other non-default attributes...
10216 namelen
= strlen(attr
->name
);
10217 if (namelen
< 9 || strcmp(attr
->name
+ namelen
- 8, "-default") ||
10218 namelen
> (sizeof(name
) - 1) || attr
->num_values
!= 1)
10222 * OK, anything else must be a user-defined default...
10225 strlcpy(name
, attr
->name
, sizeof(name
));
10226 name
[namelen
- 8] = '\0'; /* Strip "-default" */
10228 switch (attr
->value_tag
)
10230 case IPP_TAG_DELETEATTR
:
10231 printer
->num_options
= cupsRemoveOption(name
,
10232 printer
->num_options
,
10233 &(printer
->options
));
10234 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10235 "Deleting %s", attr
->name
);
10238 case IPP_TAG_NAME
:
10239 case IPP_TAG_KEYWORD
:
10241 printer
->num_options
= cupsAddOption(name
,
10242 attr
->values
[0].string
.text
,
10243 printer
->num_options
,
10244 &(printer
->options
));
10245 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10246 "Setting %s to \"%s\"...", attr
->name
,
10247 attr
->values
[0].string
.text
);
10250 case IPP_TAG_BOOLEAN
:
10251 printer
->num_options
= cupsAddOption(name
,
10252 attr
->values
[0].boolean
?
10254 printer
->num_options
,
10255 &(printer
->options
));
10256 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10257 "Setting %s to %s...", attr
->name
,
10258 attr
->values
[0].boolean
? "true" : "false");
10261 case IPP_TAG_INTEGER
:
10262 case IPP_TAG_ENUM
:
10263 sprintf(value
, "%d", attr
->values
[0].integer
);
10264 printer
->num_options
= cupsAddOption(name
, value
,
10265 printer
->num_options
,
10266 &(printer
->options
));
10267 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10268 "Setting %s to %s...", attr
->name
, value
);
10271 case IPP_TAG_RANGE
:
10272 sprintf(value
, "%d-%d", attr
->values
[0].range
.lower
,
10273 attr
->values
[0].range
.upper
);
10274 printer
->num_options
= cupsAddOption(name
, value
,
10275 printer
->num_options
,
10276 &(printer
->options
));
10277 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10278 "Setting %s to %s...", attr
->name
, value
);
10281 case IPP_TAG_RESOLUTION
:
10282 sprintf(value
, "%dx%d%s", attr
->values
[0].resolution
.xres
,
10283 attr
->values
[0].resolution
.yres
,
10284 attr
->values
[0].resolution
.units
== IPP_RES_PER_INCH
?
10286 printer
->num_options
= cupsAddOption(name
, value
,
10287 printer
->num_options
,
10288 &(printer
->options
));
10289 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10290 "Setting %s to %s...", attr
->name
, value
);
10294 /* Do nothing for other values */
10302 * 'start_printer()' - Start a printer.
10306 start_printer(cupsd_client_t
*con
, /* I - Client connection */
10307 ipp_attribute_t
*uri
) /* I - Printer URI */
10309 http_status_t status
; /* Policy status */
10310 cups_ptype_t dtype
; /* Destination type (printer/class) */
10311 cupsd_printer_t
*printer
; /* Printer data */
10314 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_printer(%p[%d], %s)", con
,
10315 con
->http
.fd
, uri
->values
[0].string
.text
);
10318 * Is the destination valid?
10321 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10327 send_ipp_status(con
, IPP_NOT_FOUND
,
10328 _("The printer or class was not found."));
10336 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10338 send_http_error(con
, status
, printer
);
10343 * Start the printer...
10346 printer
->state_message
[0] = '\0';
10348 cupsdStartPrinter(printer
, 1);
10350 if (dtype
& CUPS_PRINTER_CLASS
)
10351 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" started by \"%s\".",
10352 printer
->name
, get_username(con
));
10354 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" started by \"%s\".",
10355 printer
->name
, get_username(con
));
10360 * Everything was ok, so return OK status...
10363 con
->response
->request
.status
.status_code
= IPP_OK
;
10368 * 'stop_printer()' - Stop a printer.
10372 stop_printer(cupsd_client_t
*con
, /* I - Client connection */
10373 ipp_attribute_t
*uri
) /* I - Printer URI */
10375 http_status_t status
; /* Policy status */
10376 cups_ptype_t dtype
; /* Destination type (printer/class) */
10377 cupsd_printer_t
*printer
; /* Printer data */
10378 ipp_attribute_t
*attr
; /* printer-state-message attribute */
10381 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "stop_printer(%p[%d], %s)", con
,
10382 con
->http
.fd
, uri
->values
[0].string
.text
);
10385 * Is the destination valid?
10388 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10394 send_ipp_status(con
, IPP_NOT_FOUND
,
10395 _("The printer or class was not found."));
10403 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10405 send_http_error(con
, status
, printer
);
10410 * Stop the printer...
10413 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
10414 IPP_TAG_TEXT
)) == NULL
)
10415 strcpy(printer
->state_message
, "Paused");
10418 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
10419 sizeof(printer
->state_message
));
10422 cupsdStopPrinter(printer
, 1);
10424 if (dtype
& CUPS_PRINTER_CLASS
)
10425 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" stopped by \"%s\".",
10426 printer
->name
, get_username(con
));
10428 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" stopped by \"%s\".",
10429 printer
->name
, get_username(con
));
10432 * Everything was ok, so return OK status...
10435 con
->response
->request
.status
.status_code
= IPP_OK
;
10440 * 'url_encode_attr()' - URL-encode a string attribute.
10444 url_encode_attr(ipp_attribute_t
*attr
, /* I - Attribute */
10445 char *buffer
,/* I - String buffer */
10446 int bufsize
)/* I - Size of buffer */
10448 int i
; /* Looping var */
10449 char *bufptr
, /* Pointer into buffer */
10450 *bufend
; /* End of buffer */
10453 strlcpy(buffer
, attr
->name
, bufsize
);
10454 bufptr
= buffer
+ strlen(buffer
);
10455 bufend
= buffer
+ bufsize
- 1;
10457 for (i
= 0; i
< attr
->num_values
; i
++)
10459 if (bufptr
>= bufend
)
10467 if (bufptr
>= bufend
)
10472 bufptr
= url_encode_string(attr
->values
[i
].string
.text
,
10473 bufptr
, bufend
- bufptr
+ 1);
10475 if (bufptr
>= bufend
)
10486 * 'url_encode_string()' - URL-encode a string.
10489 static char * /* O - End of string */
10490 url_encode_string(const char *s
, /* I - String */
10491 char *buffer
, /* I - String buffer */
10492 int bufsize
) /* I - Size of buffer */
10494 char *bufptr
, /* Pointer into buffer */
10495 *bufend
; /* End of buffer */
10496 static const char *hex
= "0123456789ABCDEF";
10501 bufend
= buffer
+ bufsize
- 1;
10503 while (*s
&& bufptr
< bufend
)
10505 if (*s
== ' ' || *s
== '%')
10507 if (bufptr
>= (bufend
- 2))
10511 *bufptr
++ = hex
[(*s
>> 4) & 15];
10512 *bufptr
++ = hex
[*s
& 15];
10516 else if (*s
== '\'' || *s
== '\\')
10518 if (bufptr
>= (bufend
- 1))
10535 * 'user_allowed()' - See if a user is allowed to print to a queue.
10538 static int /* O - 0 if not allowed, 1 if allowed */
10539 user_allowed(cupsd_printer_t
*p
, /* I - Printer or class */
10540 const char *username
) /* I - Username */
10542 int i
; /* Looping var */
10543 struct passwd
*pw
; /* User password data */
10544 char baseuser
[256], /* Base username */
10545 *baseptr
; /* Pointer to "@" in base username */
10548 if (p
->num_users
== 0)
10551 if (!strcmp(username
, "root"))
10554 if (strchr(username
, '@'))
10557 * Strip @REALM for username check...
10560 strlcpy(baseuser
, username
, sizeof(baseuser
));
10562 if ((baseptr
= strchr(baseuser
, '@')) != NULL
)
10565 username
= baseuser
;
10568 pw
= getpwnam(username
);
10571 for (i
= 0; i
< p
->num_users
; i
++)
10573 if (p
->users
[i
][0] == '@')
10576 * Check group membership...
10579 if (cupsdCheckGroup(username
, pw
, p
->users
[i
] + 1))
10582 else if (!strcasecmp(username
, p
->users
[i
]))
10586 return ((i
< p
->num_users
) != p
->deny_users
);
10591 * 'validate_job()' - Validate printer options and destination.
10595 validate_job(cupsd_client_t
*con
, /* I - Client connection */
10596 ipp_attribute_t
*uri
) /* I - Printer URI */
10598 http_status_t status
; /* Policy status */
10599 ipp_attribute_t
*attr
; /* Current attribute */
10600 ipp_attribute_t
*format
; /* Document-format attribute */
10601 cups_ptype_t dtype
; /* Destination type (printer/class) */
10602 char super
[MIME_MAX_SUPER
],
10603 /* Supertype of file */
10604 type
[MIME_MAX_TYPE
];
10605 /* Subtype of file */
10606 cupsd_printer_t
*printer
; /* Printer */
10609 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_job(%p[%d], %s)", con
,
10610 con
->http
.fd
, uri
->values
[0].string
.text
);
10613 * OK, see if the client is sending the document compressed - CUPS
10614 * doesn't support compression yet...
10617 if ((attr
= ippFindAttribute(con
->request
, "compression",
10618 IPP_TAG_KEYWORD
)) != NULL
&&
10619 !strcmp(attr
->values
[0].string
.text
, "none"))
10621 send_ipp_status(con
, IPP_ATTRIBUTES
,
10622 _("Unsupported compression attribute %s!"),
10623 attr
->values
[0].string
.text
);
10624 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
10625 "compression", NULL
, attr
->values
[0].string
.text
);
10630 * Is it a format we support?
10633 if ((format
= ippFindAttribute(con
->request
, "document-format",
10634 IPP_TAG_MIMETYPE
)) != NULL
)
10636 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
10639 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"!"),
10640 format
->values
[0].string
.text
);
10644 if ((strcmp(super
, "application") || strcmp(type
, "octet-stream")) &&
10645 !mimeType(MimeDatabase
, super
, type
))
10647 cupsdLogMessage(CUPSD_LOG_INFO
,
10648 "Hint: Do you have the raw file printing rules enabled?");
10649 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
10650 _("Unsupported format \"%s\"!"),
10651 format
->values
[0].string
.text
);
10652 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
10653 "document-format", NULL
, format
->values
[0].string
.text
);
10659 * Is the destination valid?
10662 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10668 send_ipp_status(con
, IPP_NOT_FOUND
,
10669 _("The printer or class was not found."));
10677 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10679 send_http_error(con
, status
, printer
);
10684 * Everything was ok, so return OK status...
10687 con
->response
->request
.status
.status_code
= IPP_OK
;
10692 * 'validate_name()' - Make sure the printer name only contains valid chars.
10695 static int /* O - 0 if name is no good, 1 if good */
10696 validate_name(const char *name
) /* I - Name to check */
10698 const char *ptr
; /* Pointer into name */
10702 * Scan the whole name...
10705 for (ptr
= name
; *ptr
; ptr
++)
10706 if ((*ptr
> 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
10710 * All the characters are good; validate the length, too...
10713 return ((ptr
- name
) < 128);
10718 * 'validate_user()' - Validate the user for the request.
10721 static int /* O - 1 if permitted, 0 otherwise */
10722 validate_user(cupsd_job_t
*job
, /* I - Job */
10723 cupsd_client_t
*con
, /* I - Client connection */
10724 const char *owner
, /* I - Owner of job/resource */
10725 char *username
, /* O - Authenticated username */
10726 int userlen
) /* I - Length of username */
10728 cupsd_printer_t
*printer
; /* Printer for job */
10731 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
10732 "validate_user(job=%d, con=%d, owner=\"%s\", username=%p, "
10734 job
->id
, con
? con
->http
.fd
: 0,
10735 owner
? owner
: "(null)", username
, userlen
);
10738 * Validate input...
10741 if (!con
|| !owner
|| !username
|| userlen
<= 0)
10745 * Get the best authenticated username that is available.
10748 strlcpy(username
, get_username(con
), userlen
);
10751 * Check the username against the owner...
10754 printer
= cupsdFindDest(job
->dest
);
10756 return (cupsdCheckPolicy(printer
? printer
->op_policy_ptr
: DefaultPolicyPtr
,
10757 con
, owner
) == HTTP_OK
);
10762 * End of "$Id: ipp.c 7014 2007-10-10 21:57:43Z mike $".