2 * "$Id: ipp.c 6370 2007-03-20 14:36:12Z mike $"
4 * IPP routines for the Common UNIX Printing System (CUPS) scheduler.
6 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
8 * This file contains Kerberos support code, copyright 2006 by
11 * These coded instructions, statements, and computer programs are the
12 * property of Easy Software Products and are protected by Federal
13 * copyright law. Distribution and use rights are outlined in the file
14 * "LICENSE.txt" which should have been included with this file. If this
15 * file is missing or damaged please contact Easy Software Products
18 * Attn: CUPS Licensing Information
19 * Easy Software Products
20 * 44141 Airport View Drive, Suite 204
21 * Hollywood, Maryland 20636 USA
23 * Voice: (301) 373-9600
24 * EMail: cups-info@cups.org
25 * WWW: http://www.cups.org
29 * cupsdProcessIPPRequest() - Process an incoming IPP request...
30 * accept_jobs() - Accept print jobs to a printer.
31 * add_class() - Add a class to the system.
32 * add_file() - Add a file to a job.
33 * add_job() - Add a job to a print queue.
34 * add_job_state_reasons() - Add the "job-state-reasons" attribute based
35 * upon the job and printer state...
36 * add_job_subscriptions() - Add any subcriptions for a job.
37 * add_job_uuid() - Add job-uuid attribute to a job.
38 * add_printer() - Add a printer to the system.
39 * add_printer_state_reasons() - Add the "printer-state-reasons" attribute
40 * based upon the printer state...
41 * add_queued_job_count() - Add the "queued-job-count" attribute for
42 * apply_printer_defaults() - Apply printer default options to a job.
43 * authenticate_job() - Set job authentication info.
44 * cancel_all_jobs() - Cancel all print jobs.
45 * cancel_job() - Cancel a print job.
46 * cancel_subscription() - Cancel a subscription.
47 * check_quotas() - Check quotas for a printer and user.
48 * copy_attribute() - Copy a single attribute.
49 * copy_attrs() - Copy attributes from one request to another.
50 * copy_banner() - Copy a banner file to the requests directory
51 * for the specified job.
52 * copy_file() - Copy a PPD file or interface script...
53 * copy_model() - Copy a PPD model file, substituting default
55 * copy_job_attrs() - Copy job attributes.
56 * copy_printer_attrs() - Copy printer attributes.
57 * copy_subscription_attrs() - Copy subscription attributes.
58 * create_job() - Print a file to a printer or class.
59 * create_requested_array() - Create an array for the requested-attributes.
60 * create_subscription() - Create a notification subscription.
61 * delete_printer() - Remove a printer or class from the system.
62 * get_default() - Get the default destination.
63 * get_devices() - Get the list of available devices on the
65 * get_job_attrs() - Get job attributes.
66 * get_jobs() - Get a list of jobs for the specified printer.
67 * get_notifications() - Get events for a subscription.
68 * get_ppds() - Get the list of PPD files on the local
70 * get_printer_attrs() - Get printer attributes.
71 * get_printers() - Get a list of printers.
72 * get_subscription_attrs() - Get subscription attributes.
73 * get_subscriptions() - Get subscriptions.
74 * get_username() - Get the username associated with a request.
75 * hold_job() - Hold a print job.
76 * move_job() - Move a job to a new destination.
77 * ppd_parse_line() - Parse a PPD default line.
78 * print_job() - Print a file to a printer or class.
79 * read_ps_line() - Read a line from a PS file...
80 * read_ps_job_ticket() - Reads a job ticket embedded in a PS file.
81 * reject_jobs() - Reject print jobs to a printer.
82 * release_job() - Release a held print job.
83 * restart_job() - Restart an old print job.
84 * save_auth_info() - Save authentication information for a job.
85 * save_krb5_creds() - Save Kerberos credentials for a job.
86 * send_document() - Send a file to a printer or class.
87 * send_http_error() - Send a HTTP error back to the IPP client.
88 * send_ipp_status() - Send a status back to the IPP client.
89 * set_default() - Set the default destination...
90 * set_job_attrs() - Set job attributes.
91 * set_printer_defaults() - Set printer default options from a request.
92 * start_printer() - Start a printer.
93 * stop_printer() - Stop a printer.
94 * url_encode_attr() - URL-encode a string attribute.
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...
110 #endif /* HAVE_KRB5_H */
114 #endif /* HAVE_LIBPAPER */
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 */
132 static void accept_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
133 static void add_class(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
134 static int add_file(cupsd_client_t
*con
, cupsd_job_t
*job
,
135 mime_type_t
*filetype
, int compression
);
136 static cupsd_job_t
*add_job(cupsd_client_t
*con
, cupsd_printer_t
*printer
,
137 mime_type_t
*filetype
);
138 static void add_job_state_reasons(cupsd_client_t
*con
, cupsd_job_t
*job
);
139 static void add_job_subscriptions(cupsd_client_t
*con
, cupsd_job_t
*job
);
140 static void add_job_uuid(cupsd_client_t
*con
, cupsd_job_t
*job
);
141 static void add_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
142 static void add_printer_state_reasons(cupsd_client_t
*con
,
144 static void add_queued_job_count(cupsd_client_t
*con
, cupsd_printer_t
*p
);
145 static void apply_printer_defaults(cupsd_printer_t
*printer
,
147 static void authenticate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
148 static void cancel_all_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
149 static void cancel_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
150 static void cancel_subscription(cupsd_client_t
*con
, int id
);
151 static int check_quotas(cupsd_client_t
*con
, cupsd_printer_t
*p
);
152 static ipp_attribute_t
*copy_attribute(ipp_t
*to
, ipp_attribute_t
*attr
,
154 static void copy_attrs(ipp_t
*to
, ipp_t
*from
, cups_array_t
*ra
,
155 ipp_tag_t group
, int quickcopy
);
156 static int copy_banner(cupsd_client_t
*con
, cupsd_job_t
*job
,
158 static int copy_file(const char *from
, const char *to
);
159 static int copy_model(cupsd_client_t
*con
, const char *from
,
161 static void copy_job_attrs(cupsd_client_t
*con
,
164 static void copy_printer_attrs(cupsd_client_t
*con
,
165 cupsd_printer_t
*printer
,
167 static void copy_subscription_attrs(cupsd_client_t
*con
,
168 cupsd_subscription_t
*sub
,
170 static void create_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
171 static cups_array_t
*create_requested_array(ipp_t
*request
);
172 static void create_subscription(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
173 static void delete_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
174 static void get_default(cupsd_client_t
*con
);
175 static void get_devices(cupsd_client_t
*con
);
176 static void get_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
177 static void get_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
178 static void get_notifications(cupsd_client_t
*con
);
179 static void get_ppds(cupsd_client_t
*con
);
180 static void get_printers(cupsd_client_t
*con
, int type
);
181 static void get_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
182 static void get_subscription_attrs(cupsd_client_t
*con
, int sub_id
);
183 static void get_subscriptions(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
184 static const char *get_username(cupsd_client_t
*con
);
185 static void hold_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
186 static void move_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
187 static int ppd_parse_line(const char *line
, char *option
, int olen
,
188 char *choice
, int clen
);
189 static void print_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
190 static void read_ps_job_ticket(cupsd_client_t
*con
);
191 static void reject_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
192 static void release_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
193 static void renew_subscription(cupsd_client_t
*con
, int sub_id
);
194 static void restart_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
195 static void save_auth_info(cupsd_client_t
*con
, cupsd_job_t
*job
,
196 ipp_attribute_t
*auth_info
);
197 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
198 static void save_krb5_creds(cupsd_client_t
*con
, cupsd_job_t
*job
);
199 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
200 static void send_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
201 static void send_http_error(cupsd_client_t
*con
, http_status_t status
);
202 static void send_ipp_status(cupsd_client_t
*con
, ipp_status_t status
,
203 const char *message
, ...)
205 __attribute__ ((__format__ (__printf__
, 3, 4)))
206 # endif /* __GNUC__ */
208 static void set_default(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
209 static void set_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
210 static void set_printer_defaults(cupsd_client_t
*con
,
211 cupsd_printer_t
*printer
);
212 static void start_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
213 static void stop_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
214 static void url_encode_attr(ipp_attribute_t
*attr
, char *buffer
,
216 static int user_allowed(cupsd_printer_t
*p
, const char *username
);
217 static void validate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
218 static int validate_name(const char *name
);
219 static int validate_user(cupsd_job_t
*job
, cupsd_client_t
*con
,
220 const char *owner
, char *username
,
225 * 'cupsdProcessIPPRequest()' - Process an incoming IPP request...
228 int /* O - 1 on success, 0 on failure */
229 cupsdProcessIPPRequest(
230 cupsd_client_t
*con
) /* I - Client connection */
232 ipp_tag_t group
; /* Current group tag */
233 ipp_attribute_t
*attr
; /* Current attribute */
234 ipp_attribute_t
*charset
; /* Character set attribute */
235 ipp_attribute_t
*language
; /* Language attribute */
236 ipp_attribute_t
*uri
; /* Printer URI attribute */
237 ipp_attribute_t
*username
; /* requesting-user-name attr */
238 int sub_id
; /* Subscription ID */
241 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
242 "cupsdProcessIPPRequest(%p[%d]): operation_id = %04x",
243 con
, con
->http
.fd
, con
->request
->request
.op
.operation_id
);
246 * First build an empty response message for this request...
249 con
->response
= ippNew();
251 con
->response
->request
.status
.version
[0] = con
->request
->request
.op
.version
[0];
252 con
->response
->request
.status
.version
[1] = con
->request
->request
.op
.version
[1];
253 con
->response
->request
.status
.request_id
= con
->request
->request
.op
.request_id
;
256 * Then validate the request header and required attributes...
259 if (con
->request
->request
.any
.version
[0] != 1)
262 * Return an error, since we only support IPP 1.x.
265 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
266 "%04X %s Bad request version number %d.%d",
267 IPP_VERSION_NOT_SUPPORTED
, con
->http
.hostname
,
268 con
->request
->request
.any
.version
[0],
269 con
->request
->request
.any
.version
[1]);
271 send_ipp_status(con
, IPP_VERSION_NOT_SUPPORTED
,
272 _("Bad request version number %d.%d!"),
273 con
->request
->request
.any
.version
[0],
274 con
->request
->request
.any
.version
[1]);
276 else if (!con
->request
->attrs
)
278 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
279 "%04X %s No attributes in request",
280 IPP_BAD_REQUEST
, con
->http
.hostname
);
282 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No attributes in request!"));
287 * Make sure that the attributes are provided in the correct order and
288 * don't repeat groups...
291 for (attr
= con
->request
->attrs
, group
= attr
->group_tag
;
294 if (attr
->group_tag
< group
&& attr
->group_tag
!= IPP_TAG_ZERO
)
297 * Out of order; return an error...
300 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
301 "%04X %s Attribute groups are out of order",
302 IPP_BAD_REQUEST
, con
->http
.hostname
);
304 send_ipp_status(con
, IPP_BAD_REQUEST
,
305 _("Attribute groups are out of order (%x < %x)!"),
306 attr
->group_tag
, group
);
310 group
= attr
->group_tag
;
315 * Then make sure that the first three attributes are:
318 * attributes-natural-language
319 * printer-uri/job-uri
322 attr
= con
->request
->attrs
;
323 if (attr
&& !strcmp(attr
->name
, "attributes-charset") &&
324 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_CHARSET
)
332 if (attr
&& !strcmp(attr
->name
, "attributes-natural-language") &&
333 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_LANGUAGE
)
338 if ((attr
= ippFindAttribute(con
->request
, "printer-uri",
339 IPP_TAG_URI
)) != NULL
)
341 else if ((attr
= ippFindAttribute(con
->request
, "job-uri",
342 IPP_TAG_URI
)) != NULL
)
348 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
349 "attributes-charset", NULL
, charset
->values
[0].string
.text
);
351 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
352 "attributes-charset", NULL
, DefaultCharset
);
355 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
356 "attributes-natural-language", NULL
,
357 language
->values
[0].string
.text
);
359 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
360 "attributes-natural-language", NULL
, DefaultLanguage
);
362 if (!charset
|| !language
||
364 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEFAULT
&&
365 con
->request
->request
.op
.operation_id
!= CUPS_GET_PRINTERS
&&
366 con
->request
->request
.op
.operation_id
!= CUPS_GET_CLASSES
&&
367 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEVICES
&&
368 con
->request
->request
.op
.operation_id
!= CUPS_GET_PPDS
))
371 * Return an error, since attributes-charset,
372 * attributes-natural-language, and printer-uri/job-uri are required
373 * for all operations.
378 cupsdLogMessage(CUPSD_LOG_ERROR
,
379 "Missing attributes-charset attribute!");
381 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
382 "%04X %s Missing attributes-charset attribute",
383 IPP_BAD_REQUEST
, con
->http
.hostname
);
388 cupsdLogMessage(CUPSD_LOG_ERROR
,
389 "Missing attributes-natural-language attribute!");
391 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
392 "%04X %s Missing attributes-natural-language attribute",
393 IPP_BAD_REQUEST
, con
->http
.hostname
);
398 cupsdLogMessage(CUPSD_LOG_ERROR
,
399 "Missing printer-uri or job-uri attribute!");
401 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
402 "%04X %s Missing printer-uri or job-uri attribute",
403 IPP_BAD_REQUEST
, con
->http
.hostname
);
406 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Request attributes follow...");
408 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
409 cupsdLogMessage(CUPSD_LOG_DEBUG
,
410 "attr \"%s\": group_tag = %x, value_tag = %x",
411 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
414 cupsdLogMessage(CUPSD_LOG_DEBUG
, "End of attributes...");
416 send_ipp_status(con
, IPP_BAD_REQUEST
,
417 _("Missing required attributes!"));
422 * OK, all the checks pass so far; make sure requesting-user-name is
423 * not "root" from a remote host...
426 if ((username
= ippFindAttribute(con
->request
, "requesting-user-name",
427 IPP_TAG_NAME
)) != NULL
)
430 * Check for root user...
433 if (!strcmp(username
->values
[0].string
.text
, "root") &&
434 strcasecmp(con
->http
.hostname
, "localhost") &&
435 strcmp(con
->username
, "root"))
438 * Remote unauthenticated user masquerading as local root...
441 _cupsStrFree(username
->values
[0].string
.text
);
442 username
->values
[0].string
.text
= _cupsStrAlloc(RemoteRoot
);
446 if ((attr
= ippFindAttribute(con
->request
, "notify-subscription-id",
447 IPP_TAG_INTEGER
)) != NULL
)
448 sub_id
= attr
->values
[0].integer
;
453 * Then try processing the operation...
457 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s",
458 ippOpString(con
->request
->request
.op
.operation_id
),
459 uri
->values
[0].string
.text
);
461 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s",
462 ippOpString(con
->request
->request
.op
.operation_id
));
464 switch (con
->request
->request
.op
.operation_id
)
470 case IPP_VALIDATE_JOB
:
471 validate_job(con
, uri
);
474 case IPP_CREATE_JOB
:
475 create_job(con
, uri
);
478 case IPP_SEND_DOCUMENT
:
479 send_document(con
, uri
);
482 case IPP_CANCEL_JOB
:
483 cancel_job(con
, uri
);
486 case IPP_GET_JOB_ATTRIBUTES
:
487 get_job_attrs(con
, uri
);
494 case IPP_GET_PRINTER_ATTRIBUTES
:
495 get_printer_attrs(con
, uri
);
502 case IPP_RELEASE_JOB
:
503 release_job(con
, uri
);
506 case IPP_RESTART_JOB
:
507 restart_job(con
, uri
);
510 case IPP_PAUSE_PRINTER
:
511 stop_printer(con
, uri
);
514 case IPP_RESUME_PRINTER
:
515 start_printer(con
, uri
);
518 case IPP_PURGE_JOBS
:
519 cancel_all_jobs(con
, uri
);
522 case IPP_SET_JOB_ATTRIBUTES
:
523 set_job_attrs(con
, uri
);
526 case CUPS_GET_DEFAULT
:
530 case CUPS_GET_PRINTERS
:
531 get_printers(con
, 0);
534 case CUPS_GET_CLASSES
:
535 get_printers(con
, CUPS_PRINTER_CLASS
);
538 case CUPS_ADD_PRINTER
:
539 add_printer(con
, uri
);
542 case CUPS_DELETE_PRINTER
:
543 delete_printer(con
, uri
);
546 case CUPS_ADD_CLASS
:
550 case CUPS_DELETE_CLASS
:
551 delete_printer(con
, uri
);
554 case CUPS_ACCEPT_JOBS
:
555 case IPP_ENABLE_PRINTER
:
556 accept_jobs(con
, uri
);
559 case CUPS_REJECT_JOBS
:
560 case IPP_DISABLE_PRINTER
:
561 reject_jobs(con
, uri
);
564 case CUPS_SET_DEFAULT
:
565 set_default(con
, uri
);
568 case CUPS_GET_DEVICES
:
580 case CUPS_AUTHENTICATE_JOB
:
581 authenticate_job(con
, uri
);
584 case IPP_CREATE_PRINTER_SUBSCRIPTION
:
585 case IPP_CREATE_JOB_SUBSCRIPTION
:
586 create_subscription(con
, uri
);
589 case IPP_GET_SUBSCRIPTION_ATTRIBUTES
:
590 get_subscription_attrs(con
, sub_id
);
593 case IPP_GET_SUBSCRIPTIONS
:
594 get_subscriptions(con
, uri
);
597 case IPP_RENEW_SUBSCRIPTION
:
598 renew_subscription(con
, sub_id
);
601 case IPP_CANCEL_SUBSCRIPTION
:
602 cancel_subscription(con
, sub_id
);
605 case IPP_GET_NOTIFICATIONS
:
606 get_notifications(con
);
610 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
611 "%04X %s Operation %04X (%s) not supported",
612 IPP_OPERATION_NOT_SUPPORTED
, con
->http
.hostname
,
613 con
->request
->request
.op
.operation_id
,
614 ippOpString(con
->request
->request
.op
.operation_id
));
616 send_ipp_status(con
, IPP_OPERATION_NOT_SUPPORTED
,
617 _("%s not supported!"),
618 ippOpString(con
->request
->request
.op
.operation_id
));
628 * Sending data from the scheduler...
631 cupsdLogMessage(CUPSD_LOG_DEBUG
,
632 "cupsdProcessIPPRequest: %d status_code=%x (%s)",
633 con
->http
.fd
, con
->response
->request
.status
.status_code
,
634 ippErrorString(con
->response
->request
.status
.status_code
));
636 if (cupsdSendHeader(con
, HTTP_OK
, "application/ipp"))
638 #ifdef CUPSD_USE_CHUNKING
640 * Because older versions of CUPS (1.1.17 and older) and some IPP
641 * clients do not implement chunking properly, we cannot use
642 * chunking by default. This may become the default in future
643 * CUPS releases, or we might add a configuration directive for
647 if (con
->http
.version
== HTTP_1_1
)
649 if (httpPrintf(HTTP(con
), "Transfer-Encoding: chunked\r\n\r\n") < 0)
652 if (cupsdFlushHeader(con
) < 0)
655 con
->http
.data_encoding
= HTTP_ENCODE_CHUNKED
;
658 #endif /* CUPSD_USE_CHUNKING */
660 size_t length
; /* Length of response */
663 length
= ippLength(con
->response
);
665 if (httpPrintf(HTTP(con
), "Content-Length: " CUPS_LLFMT
"\r\n\r\n",
666 CUPS_LLCAST length
) < 0)
669 if (cupsdFlushHeader(con
) < 0)
672 con
->http
.data_encoding
= HTTP_ENCODE_LENGTH
;
673 con
->http
.data_remaining
= length
;
676 cupsdAddSelect(con
->http
.fd
, (cupsd_selfunc_t
)cupsdReadClient
,
677 (cupsd_selfunc_t
)cupsdWriteClient
, con
);
680 * Tell the caller the response header was sent successfully...
688 * Tell the caller the response header could not be sent...
697 * Sending data from a subprocess like cups-deviced; tell the caller
698 * everything is A-OK so far...
707 * 'accept_jobs()' - Accept print jobs to a printer.
711 accept_jobs(cupsd_client_t
*con
, /* I - Client connection */
712 ipp_attribute_t
*uri
) /* I - Printer or class URI */
714 http_status_t status
; /* Policy status */
715 cups_ptype_t dtype
; /* Destination type (printer or class) */
716 cupsd_printer_t
*printer
; /* Printer data */
719 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "accept_jobs(%p[%d], %s)", con
,
720 con
->http
.fd
, uri
->values
[0].string
.text
);
723 * Is the destination valid?
726 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
732 send_ipp_status(con
, IPP_NOT_FOUND
,
733 _("The printer or class was not found."));
741 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
743 send_http_error(con
, status
);
748 * Accept jobs sent to the printer...
751 printer
->accepting
= 1;
752 printer
->state_message
[0] = '\0';
754 cupsdAddPrinterHistory(printer
);
756 if (dtype
& CUPS_PRINTER_CLASS
)
758 cupsdSaveAllClasses();
760 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" now accepting jobs (\"%s\").",
761 printer
->name
, get_username(con
));
765 cupsdSaveAllPrinters();
767 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" now accepting jobs (\"%s\").",
768 printer
->name
, get_username(con
));
772 * Everything was ok, so return OK status...
775 con
->response
->request
.status
.status_code
= IPP_OK
;
780 * 'add_class()' - Add a class to the system.
784 add_class(cupsd_client_t
*con
, /* I - Client connection */
785 ipp_attribute_t
*uri
) /* I - URI of class */
787 http_status_t status
; /* Policy status */
788 int i
; /* Looping var */
789 char method
[HTTP_MAX_URI
], /* Method portion of URI */
790 username
[HTTP_MAX_URI
], /* Username portion of URI */
791 host
[HTTP_MAX_URI
], /* Host portion of URI */
792 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
793 int port
; /* Port portion of URI */
794 cupsd_printer_t
*pclass
, /* Class */
795 *member
; /* Member printer/class */
796 cups_ptype_t dtype
; /* Destination type */
797 ipp_attribute_t
*attr
; /* Printer attribute */
798 int modify
; /* Non-zero if we just modified */
799 char newname
[IPP_MAX_NAME
]; /* New class name */
800 int need_restart_job
; /* Need to restart job? */
803 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_class(%p[%d], %s)", con
,
804 con
->http
.fd
, uri
->values
[0].string
.text
);
807 * Do we have a valid URI?
810 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
811 sizeof(method
), username
, sizeof(username
), host
,
812 sizeof(host
), &port
, resource
, sizeof(resource
));
815 if (strncmp(resource
, "/classes/", 9) || strlen(resource
) == 9)
818 * No, return an error...
821 send_ipp_status(con
, IPP_BAD_REQUEST
,
822 _("The printer-uri must be of the form "
823 "\"ipp://HOSTNAME/classes/CLASSNAME\"."));
828 * Do we have a valid printer name?
831 if (!validate_name(resource
+ 9))
834 * No, return an error...
837 send_ipp_status(con
, IPP_BAD_REQUEST
,
838 _("The printer-uri \"%s\" contains invalid characters."),
839 uri
->values
[0].string
.text
);
847 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
849 send_http_error(con
, status
);
854 * See if the class already exists; if not, create a new class...
857 if ((pclass
= cupsdFindClass(resource
+ 9)) == NULL
)
860 * Class doesn't exist; see if we have a printer of the same name...
863 if ((pclass
= cupsdFindPrinter(resource
+ 9)) != NULL
&&
864 !(pclass
->type
& CUPS_PRINTER_REMOTE
))
867 * Yes, return an error...
870 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
871 _("A printer named \"%s\" already exists!"),
877 * No, add the pclass...
880 pclass
= cupsdAddClass(resource
+ 9);
883 else if (pclass
->type
& CUPS_PRINTER_IMPLICIT
)
886 * Rename the implicit class to "AnyClass" or remove it...
889 if (ImplicitAnyClasses
)
891 snprintf(newname
, sizeof(newname
), "Any%s", resource
+ 9);
892 cupsdRenamePrinter(pclass
, newname
);
895 cupsdDeletePrinter(pclass
, 1);
898 * Add the class as a new local class...
901 pclass
= cupsdAddClass(resource
+ 9);
904 else if (pclass
->type
& CUPS_PRINTER_REMOTE
)
907 * Rename the remote class to "Class"...
910 snprintf(newname
, sizeof(newname
), "%s@%s", resource
+ 9, pclass
->hostname
);
911 cupsdRenamePrinter(pclass
, newname
);
914 * Add the class as a new local class...
917 pclass
= cupsdAddClass(resource
+ 9);
924 * Look for attributes and copy them over as needed...
927 need_restart_job
= 0;
929 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
930 IPP_TAG_TEXT
)) != NULL
)
931 cupsdSetString(&pclass
->location
, attr
->values
[0].string
.text
);
933 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
934 IPP_TAG_TEXT
)) != NULL
)
935 cupsdSetString(&pclass
->info
, attr
->values
[0].string
.text
);
937 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
938 IPP_TAG_BOOLEAN
)) != NULL
)
940 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-is-accepting-jobs to %d (was %d.)",
941 pclass
->name
, attr
->values
[0].boolean
, pclass
->accepting
);
943 pclass
->accepting
= attr
->values
[0].boolean
;
944 cupsdAddPrinterHistory(pclass
);
947 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
948 IPP_TAG_BOOLEAN
)) != NULL
)
950 if (pclass
->shared
&& !attr
->values
[0].boolean
)
951 cupsdDeregisterPrinter(pclass
, 1);
953 cupsdLogMessage(CUPSD_LOG_INFO
,
954 "Setting %s printer-is-shared to %d (was %d.)",
955 pclass
->name
, attr
->values
[0].boolean
, pclass
->shared
);
957 pclass
->shared
= attr
->values
[0].boolean
;
960 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
961 IPP_TAG_ENUM
)) != NULL
)
963 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
964 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
966 send_ipp_status(con
, IPP_BAD_REQUEST
,
967 _("Attempt to set %s printer-state to bad value %d!"),
968 pclass
->name
, attr
->values
[0].integer
);
972 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)", pclass
->name
,
973 attr
->values
[0].integer
, pclass
->state
);
975 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
976 cupsdStopPrinter(pclass
, 0);
979 cupsdSetPrinterState(pclass
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
980 need_restart_job
= 1;
983 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
984 IPP_TAG_TEXT
)) != NULL
)
986 strlcpy(pclass
->state_message
, attr
->values
[0].string
.text
,
987 sizeof(pclass
->state_message
));
988 cupsdAddPrinterHistory(pclass
);
990 if ((attr
= ippFindAttribute(con
->request
, "member-uris",
991 IPP_TAG_URI
)) != NULL
)
994 * Clear the printer array as needed...
997 need_restart_job
= 1;
999 if (pclass
->num_printers
> 0)
1001 free(pclass
->printers
);
1002 pclass
->num_printers
= 0;
1006 * Add each printer or class that is listed...
1009 for (i
= 0; i
< attr
->num_values
; i
++)
1012 * Search for the printer or class URI...
1015 if (!cupsdValidateDest(attr
->values
[i
].string
.text
, &dtype
, &member
))
1021 send_ipp_status(con
, IPP_NOT_FOUND
,
1022 _("The printer or class was not found."));
1027 * Add it to the class...
1030 cupsdAddPrinterToClass(pclass
, member
);
1034 set_printer_defaults(con
, pclass
);
1037 * Update the printer class attributes and return...
1040 cupsdSetPrinterAttrs(pclass
);
1041 cupsdSaveAllClasses();
1043 if (need_restart_job
&& pclass
->job
)
1048 * Stop the current job and then restart it below...
1051 job
= (cupsd_job_t
*)pclass
->job
;
1053 cupsdStopJob(job
, 1);
1055 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1056 job
->state_value
= IPP_JOB_PENDING
;
1059 if (need_restart_job
)
1062 cupsdWritePrintcap();
1066 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
, pclass
, NULL
,
1067 "Class \"%s\" modified by \"%s\".", pclass
->name
,
1070 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" modified by \"%s\".",
1071 pclass
->name
, get_username(con
));
1075 cupsdAddPrinterHistory(pclass
);
1077 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
, pclass
, NULL
,
1078 "New class \"%s\" added by \"%s\".", pclass
->name
,
1081 cupsdLogMessage(CUPSD_LOG_INFO
, "New class \"%s\" added by \"%s\".",
1082 pclass
->name
, get_username(con
));
1085 con
->response
->request
.status
.status_code
= IPP_OK
;
1090 * 'add_file()' - Add a file to a job.
1093 static int /* O - 0 on success, -1 on error */
1094 add_file(cupsd_client_t
*con
, /* I - Connection to client */
1095 cupsd_job_t
*job
, /* I - Job to add to */
1096 mime_type_t
*filetype
, /* I - Type of file */
1097 int compression
) /* I - Compression */
1099 mime_type_t
**filetypes
; /* New filetypes array... */
1100 int *compressions
; /* New compressions array... */
1103 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1104 "add_file(con=%p[%d], job=%d, filetype=%s/%s, compression=%d)",
1105 con
, con
->http
.fd
, job
->id
, filetype
->super
, filetype
->type
,
1109 * Add the file to the job...
1112 if (job
->num_files
== 0)
1114 compressions
= (int *)malloc(sizeof(int));
1115 filetypes
= (mime_type_t
**)malloc(sizeof(mime_type_t
*));
1119 compressions
= (int *)realloc(job
->compressions
,
1120 (job
->num_files
+ 1) * sizeof(int));
1121 filetypes
= (mime_type_t
**)realloc(job
->filetypes
,
1122 (job
->num_files
+ 1) *
1123 sizeof(mime_type_t
*));
1126 if (!compressions
|| !filetypes
)
1128 cupsdCancelJob(job
, 1, IPP_JOB_ABORTED
);
1130 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1131 _("Unable to allocate memory for file types!"));
1135 job
->compressions
= compressions
;
1136 job
->compressions
[job
->num_files
] = compression
;
1137 job
->filetypes
= filetypes
;
1138 job
->filetypes
[job
->num_files
] = filetype
;
1147 * 'add_job()' - Add a job to a print queue.
1150 static cupsd_job_t
* /* O - Job object */
1151 add_job(cupsd_client_t
*con
, /* I - Client connection */
1152 cupsd_printer_t
*printer
, /* I - Destination printer */
1153 mime_type_t
*filetype
) /* I - First print file type, if any */
1155 http_status_t status
; /* Policy status */
1156 ipp_attribute_t
*attr
, /* Current attribute */
1157 *auth_info
; /* auth-info attribute */
1158 const char *val
; /* Default option value */
1159 int priority
; /* Job priority */
1160 char *title
; /* Job name/title */
1161 cupsd_job_t
*job
; /* Current job */
1162 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
1163 int kbytes
; /* Size of print file */
1164 int i
; /* Looping var */
1165 int lowerpagerange
; /* Page range bound */
1168 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job(%p[%d], %p(%s), %p(%s/%s))",
1169 con
, con
->http
.fd
, printer
, printer
->name
,
1170 filetype
, filetype
->super
, filetype
->type
);
1173 * Check remote printing to non-shared printer...
1176 if (!printer
->shared
&&
1177 strcasecmp(con
->http
.hostname
, "localhost") &&
1178 strcasecmp(con
->http
.hostname
, ServerName
))
1180 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
1181 _("The printer or class is not shared!"));
1189 auth_info
= ippFindAttribute(job
->attrs
, "auth-info", IPP_TAG_TEXT
);
1191 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
1193 send_http_error(con
, status
);
1196 else if ((printer
->type
& CUPS_PRINTER_AUTHENTICATED
) &&
1197 !con
->username
[0] && !auth_info
)
1199 send_http_error(con
, HTTP_UNAUTHORIZED
);
1203 else if (auth_info
&& !con
->http
.tls
&&
1204 !httpAddrLocalhost(con
->http
.hostaddr
))
1207 * Require encryption of auth-info over non-local connections...
1210 send_http_error(con
, HTTP_UPGRADE_REQUIRED
);
1213 #endif /* HAVE_SSL */
1216 * See if the printer is accepting jobs...
1219 if (!printer
->accepting
)
1221 send_ipp_status(con
, IPP_NOT_ACCEPTING
,
1222 _("Destination \"%s\" is not accepting jobs."),
1228 * Validate job template attributes; for now just document-format,
1229 * copies, number-up, and page-ranges...
1232 if (filetype
&& printer
->filetypes
&&
1233 !cupsArrayFind(printer
->filetypes
, filetype
))
1235 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
1236 /* MIME media type string */
1239 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
1242 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
1243 _("Unsupported format \'%s\'!"), mimetype
);
1245 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
1246 "document-format", NULL
, mimetype
);
1251 if ((attr
= ippFindAttribute(con
->request
, "copies",
1252 IPP_TAG_INTEGER
)) != NULL
)
1254 if (attr
->values
[0].integer
< 1 || attr
->values
[0].integer
> MaxCopies
)
1256 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad copies value %d."),
1257 attr
->values
[0].integer
);
1258 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1259 "copies", attr
->values
[0].integer
);
1264 if ((attr
= ippFindAttribute(con
->request
, "number-up",
1265 IPP_TAG_INTEGER
)) != NULL
)
1267 if (attr
->values
[0].integer
!= 1 &&
1268 attr
->values
[0].integer
!= 2 &&
1269 attr
->values
[0].integer
!= 4 &&
1270 attr
->values
[0].integer
!= 6 &&
1271 attr
->values
[0].integer
!= 9 &&
1272 attr
->values
[0].integer
!= 16)
1274 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad number-up value %d."),
1275 attr
->values
[0].integer
);
1276 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1277 "number-up", attr
->values
[0].integer
);
1282 if ((attr
= ippFindAttribute(con
->request
, "page-ranges",
1283 IPP_TAG_RANGE
)) != NULL
)
1285 for (i
= 0, lowerpagerange
= 1; i
< attr
->num_values
; i
++)
1287 if (attr
->values
[i
].range
.lower
< lowerpagerange
||
1288 attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
1290 send_ipp_status(con
, IPP_BAD_REQUEST
,
1291 _("Bad page-ranges values %d-%d."),
1292 attr
->values
[i
].range
.lower
,
1293 attr
->values
[i
].range
.upper
);
1297 lowerpagerange
= attr
->values
[i
].range
.upper
+ 1;
1302 * Make sure we aren't over our limit...
1305 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1308 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1310 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
1311 _("Too many active jobs."));
1315 if (!check_quotas(con
, printer
))
1317 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
1322 * Create the job and set things up...
1325 if ((attr
= ippFindAttribute(con
->request
, "job-priority",
1326 IPP_TAG_INTEGER
)) != NULL
)
1327 priority
= attr
->values
[0].integer
;
1330 if ((val
= cupsGetOption("job-priority", printer
->num_options
,
1331 printer
->options
)) != NULL
)
1332 priority
= atoi(val
);
1336 ippAddInteger(con
->request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-priority",
1340 if ((attr
= ippFindAttribute(con
->request
, "job-name",
1341 IPP_TAG_NAME
)) != NULL
)
1342 title
= attr
->values
[0].string
.text
;
1344 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
,
1345 title
= "Untitled");
1347 if ((job
= cupsdAddJob(priority
, printer
->name
)) == NULL
)
1349 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1350 _("Unable to add job for destination \"%s\"!"),
1355 job
->dtype
= printer
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
1356 CUPS_PRINTER_REMOTE
);
1357 job
->attrs
= con
->request
;
1358 con
->request
= ippNewRequest(job
->attrs
->request
.op
.operation_id
);
1360 add_job_uuid(con
, job
);
1361 apply_printer_defaults(printer
, job
);
1363 attr
= ippFindAttribute(job
->attrs
, "requesting-user-name", IPP_TAG_NAME
);
1365 if (con
->username
[0])
1367 cupsdSetString(&job
->username
, con
->username
);
1370 cupsdSetString(&attr
->values
[0].string
.text
, con
->username
);
1374 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1375 "add_job: requesting-user-name=\"%s\"",
1376 attr
->values
[0].string
.text
);
1378 cupsdSetString(&job
->username
, attr
->values
[0].string
.text
);
1381 cupsdSetString(&job
->username
, "anonymous");
1384 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1385 "job-originating-user-name", NULL
, job
->username
);
1388 attr
->group_tag
= IPP_TAG_JOB
;
1389 _cupsStrFree(attr
->name
);
1390 attr
->name
= _cupsStrAlloc("job-originating-user-name");
1393 if (con
->username
[0] || auth_info
)
1395 save_auth_info(con
, job
, auth_info
);
1398 * Remove the auth-info attribute from the attribute data...
1403 if (job
->attrs
->prev
)
1404 job
->attrs
->prev
->next
= auth_info
->next
;
1406 job
->attrs
->attrs
= auth_info
->next
;
1408 if (job
->attrs
->last
== auth_info
)
1409 job
->attrs
->last
= job
->attrs
->prev
;
1411 _ippFreeAttr(auth_info
);
1415 if ((attr
= ippFindAttribute(job
->attrs
, "job-originating-host-name",
1416 IPP_TAG_ZERO
)) != NULL
)
1419 * Request contains a job-originating-host-name attribute; validate it...
1422 if (attr
->value_tag
!= IPP_TAG_NAME
||
1423 attr
->num_values
!= 1 ||
1424 strcmp(con
->http
.hostname
, "localhost"))
1427 * Can't override the value if we aren't connected via localhost.
1428 * Also, we can only have 1 value and it must be a name value.
1431 switch (attr
->value_tag
)
1433 case IPP_TAG_STRING
:
1434 case IPP_TAG_TEXTLANG
:
1435 case IPP_TAG_NAMELANG
:
1438 case IPP_TAG_KEYWORD
:
1440 case IPP_TAG_URISCHEME
:
1441 case IPP_TAG_CHARSET
:
1442 case IPP_TAG_LANGUAGE
:
1443 case IPP_TAG_MIMETYPE
:
1445 * Free old strings...
1448 for (i
= 0; i
< attr
->num_values
; i
++)
1450 _cupsStrFree(attr
->values
[i
].string
.text
);
1451 attr
->values
[i
].string
.text
= NULL
;
1452 if (attr
->values
[i
].string
.charset
)
1454 _cupsStrFree(attr
->values
[i
].string
.charset
);
1455 attr
->values
[i
].string
.charset
= NULL
;
1464 * Use the default connection hostname instead...
1467 attr
->value_tag
= IPP_TAG_NAME
;
1468 attr
->num_values
= 1;
1469 attr
->values
[0].string
.text
= _cupsStrAlloc(con
->http
.hostname
);
1472 attr
->group_tag
= IPP_TAG_JOB
;
1477 * No job-originating-host-name attribute, so use the hostname from
1481 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1482 "job-originating-host-name", NULL
, con
->http
.hostname
);
1485 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation",
1487 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1488 "time-at-processing", 0);
1489 attr
->value_tag
= IPP_TAG_NOVALUE
;
1490 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1491 "time-at-completed", 0);
1492 attr
->value_tag
= IPP_TAG_NOVALUE
;
1495 * Add remaining job attributes...
1498 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1499 job
->state
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_ENUM
,
1500 "job-state", IPP_JOB_STOPPED
);
1501 job
->state_value
= (ipp_jstate_t
)job
->state
->values
[0].integer
;
1502 job
->sheets
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1503 "job-media-sheets-completed", 0);
1504 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-printer-uri", NULL
,
1506 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
,
1509 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
1510 IPP_TAG_INTEGER
)) != NULL
)
1511 attr
->values
[0].integer
= 0;
1513 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1516 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
1517 IPP_TAG_KEYWORD
)) == NULL
)
1518 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
1521 if ((val
= cupsGetOption("job-hold-until", printer
->num_options
,
1522 printer
->options
)) == NULL
)
1525 attr
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1526 "job-hold-until", NULL
, val
);
1528 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold") &&
1529 !(printer
->type
& CUPS_PRINTER_REMOTE
))
1532 * Hold job until specified time...
1535 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
);
1537 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1538 job
->state_value
= IPP_JOB_HELD
;
1540 else if (job
->attrs
->request
.op
.operation_id
== IPP_CREATE_JOB
)
1542 job
->hold_until
= time(NULL
) + 60;
1543 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1544 job
->state_value
= IPP_JOB_HELD
;
1548 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1549 job
->state_value
= IPP_JOB_PENDING
;
1552 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)) ||
1556 * Add job sheets options...
1559 if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1560 IPP_TAG_ZERO
)) == NULL
)
1562 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1563 "Adding default job-sheets values \"%s,%s\"...",
1564 printer
->job_sheets
[0], printer
->job_sheets
[1]);
1566 attr
= ippAddStrings(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-sheets",
1568 attr
->values
[0].string
.text
= _cupsStrAlloc(printer
->job_sheets
[0]);
1569 attr
->values
[1].string
.text
= _cupsStrAlloc(printer
->job_sheets
[1]);
1572 job
->job_sheets
= attr
;
1575 * Enforce classification level if set...
1580 cupsdLogMessage(CUPSD_LOG_INFO
,
1581 "Classification=\"%s\", ClassifyOverride=%d",
1582 Classification
? Classification
: "(null)",
1585 if (ClassifyOverride
)
1587 if (!strcmp(attr
->values
[0].string
.text
, "none") &&
1588 (attr
->num_values
== 1 ||
1589 !strcmp(attr
->values
[1].string
.text
, "none")))
1592 * Force the leading banner to have the classification on it...
1595 cupsdSetString(&attr
->values
[0].string
.text
, Classification
);
1597 cupsdLogMessage(CUPSD_LOG_NOTICE
, "[Job %d] CLASSIFICATION FORCED "
1598 "job-sheets=\"%s,none\", "
1599 "job-originating-user-name=\"%s\"",
1600 job
->id
, Classification
, job
->username
);
1602 else if (attr
->num_values
== 2 &&
1603 strcmp(attr
->values
[0].string
.text
,
1604 attr
->values
[1].string
.text
) &&
1605 strcmp(attr
->values
[0].string
.text
, "none") &&
1606 strcmp(attr
->values
[1].string
.text
, "none"))
1609 * Can't put two different security markings on the same document!
1612 cupsdSetString(&attr
->values
[1].string
.text
, attr
->values
[0].string
.text
);
1614 cupsdLogMessage(CUPSD_LOG_NOTICE
, "[Job %d] CLASSIFICATION FORCED "
1615 "job-sheets=\"%s,%s\", "
1616 "job-originating-user-name=\"%s\"",
1617 job
->id
, attr
->values
[0].string
.text
,
1618 attr
->values
[1].string
.text
, job
->username
);
1620 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1621 strcmp(attr
->values
[0].string
.text
, "none") &&
1622 (attr
->num_values
== 1 ||
1623 (strcmp(attr
->values
[1].string
.text
, Classification
) &&
1624 strcmp(attr
->values
[1].string
.text
, "none"))))
1626 if (attr
->num_values
== 1)
1627 cupsdLogMessage(CUPSD_LOG_NOTICE
,
1628 "[Job %d] CLASSIFICATION OVERRIDDEN "
1629 "job-sheets=\"%s\", "
1630 "job-originating-user-name=\"%s\"",
1631 job
->id
, attr
->values
[0].string
.text
, job
->username
);
1633 cupsdLogMessage(CUPSD_LOG_NOTICE
,
1634 "[Job %d] CLASSIFICATION OVERRIDDEN "
1635 "job-sheets=\"%s,%s\",fffff "
1636 "job-originating-user-name=\"%s\"",
1637 job
->id
, attr
->values
[0].string
.text
,
1638 attr
->values
[1].string
.text
, job
->username
);
1641 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1642 (attr
->num_values
== 1 ||
1643 strcmp(attr
->values
[1].string
.text
, Classification
)))
1646 * Force the banner to have the classification on it...
1649 if (attr
->num_values
> 1 &&
1650 !strcmp(attr
->values
[0].string
.text
, attr
->values
[1].string
.text
))
1652 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1653 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1657 if (attr
->num_values
== 1 ||
1658 strcmp(attr
->values
[0].string
.text
, "none"))
1659 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1661 if (attr
->num_values
> 1 &&
1662 strcmp(attr
->values
[1].string
.text
, "none"))
1663 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1666 if (attr
->num_values
> 1)
1667 cupsdLogMessage(CUPSD_LOG_NOTICE
,
1668 "[Job %d] CLASSIFICATION FORCED "
1669 "job-sheets=\"%s,%s\", "
1670 "job-originating-user-name=\"%s\"",
1671 job
->id
, attr
->values
[0].string
.text
,
1672 attr
->values
[1].string
.text
, job
->username
);
1674 cupsdLogMessage(CUPSD_LOG_NOTICE
,
1675 "[Job %d] CLASSIFICATION FORCED "
1676 "job-sheets=\"%s\", "
1677 "job-originating-user-name=\"%s\"",
1678 job
->id
, Classification
, job
->username
);
1683 * See if we need to add the starting sheet...
1686 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)))
1688 cupsdLogMessage(CUPSD_LOG_INFO
,
1689 "Adding start banner page \"%s\" to job %d.",
1690 attr
->values
[0].string
.text
, job
->id
);
1692 kbytes
= copy_banner(con
, job
, attr
->values
[0].string
.text
);
1694 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
1697 else if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1698 IPP_TAG_ZERO
)) != NULL
)
1702 * Fill in the response info...
1705 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
1706 LocalPort
, job
->id
);
1708 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
1711 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1713 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
1715 add_job_state_reasons(con
, job
);
1717 con
->response
->request
.status
.status_code
= IPP_OK
;
1720 * Add any job subscriptions...
1723 add_job_subscriptions(con
, job
);
1726 * Set all but the first two attributes to the job attributes group...
1729 for (attr
= job
->attrs
->attrs
->next
->next
; attr
; attr
= attr
->next
)
1730 attr
->group_tag
= IPP_TAG_JOB
;
1733 * Fire the "job created" event...
1736 cupsdAddEvent(CUPSD_EVENT_JOB_CREATED
, printer
, job
, "Job created.");
1739 * Return the new job...
1747 * 'add_job_state_reasons()' - Add the "job-state-reasons" attribute based
1748 * upon the job and printer state...
1752 add_job_state_reasons(
1753 cupsd_client_t
*con
, /* I - Client connection */
1754 cupsd_job_t
*job
) /* I - Job info */
1756 cupsd_printer_t
*dest
; /* Destination printer */
1759 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job_state_reasons(%p[%d], %d)",
1760 con
, con
->http
.fd
, job
? job
->id
: 0);
1762 switch (job
? job
->state_value
: IPP_JOB_CANCELED
)
1764 case IPP_JOB_PENDING
:
1765 dest
= cupsdFindDest(job
->dest
);
1767 if (dest
&& dest
->state
== IPP_PRINTER_STOPPED
)
1768 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1769 "job-state-reasons", NULL
, "printer-stopped");
1771 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1772 "job-state-reasons", NULL
, "none");
1776 if (ippFindAttribute(job
->attrs
, "job-hold-until",
1777 IPP_TAG_KEYWORD
) != NULL
||
1778 ippFindAttribute(job
->attrs
, "job-hold-until",
1779 IPP_TAG_NAME
) != NULL
)
1780 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1781 "job-state-reasons", NULL
, "job-hold-until-specified");
1783 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1784 "job-state-reasons", NULL
, "job-incoming");
1787 case IPP_JOB_PROCESSING
:
1788 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1789 "job-state-reasons", NULL
, "job-printing");
1792 case IPP_JOB_STOPPED
:
1793 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1794 "job-state-reasons", NULL
, "job-stopped");
1797 case IPP_JOB_CANCELED
:
1798 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1799 "job-state-reasons", NULL
, "job-canceled-by-user");
1802 case IPP_JOB_ABORTED
:
1803 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1804 "job-state-reasons", NULL
, "aborted-by-system");
1807 case IPP_JOB_COMPLETED
:
1808 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1809 "job-state-reasons", NULL
, "job-completed-successfully");
1816 * 'add_job_subscriptions()' - Add any subcriptions for a job.
1820 add_job_subscriptions(
1821 cupsd_client_t
*con
, /* I - Client connection */
1822 cupsd_job_t
*job
) /* I - Newly created job */
1824 int i
; /* Looping var */
1825 ipp_attribute_t
*prev
, /* Previous attribute */
1826 *next
, /* Next attribute */
1827 *attr
; /* Current attribute */
1828 cupsd_subscription_t
*sub
; /* Subscription object */
1829 const char *recipient
, /* notify-recipient-uri */
1830 *pullmethod
; /* notify-pull-method */
1831 ipp_attribute_t
*user_data
; /* notify-user-data */
1832 int interval
; /* notify-time-interval */
1833 unsigned mask
; /* notify-events */
1837 * Find the first subscription group attribute; return if we have
1841 for (attr
= job
->attrs
->attrs
, prev
= NULL
;
1843 prev
= attr
, attr
= attr
->next
)
1844 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
1851 * Process the subscription attributes in the request...
1860 mask
= CUPSD_EVENT_NONE
;
1862 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
1864 if (!strcmp(attr
->name
, "notify-recipient") &&
1865 attr
->value_tag
== IPP_TAG_URI
)
1866 recipient
= attr
->values
[0].string
.text
;
1867 else if (!strcmp(attr
->name
, "notify-pull-method") &&
1868 attr
->value_tag
== IPP_TAG_KEYWORD
)
1869 pullmethod
= attr
->values
[0].string
.text
;
1870 else if (!strcmp(attr
->name
, "notify-charset") &&
1871 attr
->value_tag
== IPP_TAG_CHARSET
&&
1872 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
1873 strcmp(attr
->values
[0].string
.text
, "utf-8"))
1875 send_ipp_status(con
, IPP_CHARSET
,
1876 _("Character set \"%s\" not supported!"),
1877 attr
->values
[0].string
.text
);
1880 else if (!strcmp(attr
->name
, "notify-natural-language") &&
1881 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
1882 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
1884 send_ipp_status(con
, IPP_CHARSET
,
1885 _("Language \"%s\" not supported!"),
1886 attr
->values
[0].string
.text
);
1889 else if (!strcmp(attr
->name
, "notify-user-data") &&
1890 attr
->value_tag
== IPP_TAG_STRING
)
1892 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
1894 send_ipp_status(con
, IPP_REQUEST_VALUE
,
1895 _("The notify-user-data value is too large "
1896 "(%d > 63 octets)!"),
1897 attr
->values
[0].unknown
.length
);
1903 else if (!strcmp(attr
->name
, "notify-events") &&
1904 attr
->value_tag
== IPP_TAG_KEYWORD
)
1906 for (i
= 0; i
< attr
->num_values
; i
++)
1907 mask
|= cupsdEventValue(attr
->values
[i
].string
.text
);
1909 else if (!strcmp(attr
->name
, "notify-lease-duration"))
1911 send_ipp_status(con
, IPP_BAD_REQUEST
,
1912 _("The notify-lease-duration attribute cannot be "
1913 "used with job subscriptions."));
1916 else if (!strcmp(attr
->name
, "notify-time-interval") &&
1917 attr
->value_tag
== IPP_TAG_INTEGER
)
1918 interval
= attr
->values
[0].integer
;
1923 if (!recipient
&& !pullmethod
)
1926 if (mask
== CUPSD_EVENT_NONE
)
1927 mask
= CUPSD_EVENT_JOB_COMPLETED
;
1929 sub
= cupsdAddSubscription(mask
, cupsdFindDest(job
->dest
), job
, recipient
,
1932 sub
->interval
= interval
;
1934 cupsdSetString(&sub
->owner
, job
->username
);
1938 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
1939 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
1940 sub
->user_data_len
);
1943 ippAddSeparator(con
->response
);
1944 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
1945 "notify-subscription-id", sub
->id
);
1951 cupsdSaveAllSubscriptions();
1954 * Remove all of the subscription attributes from the job request...
1957 for (attr
= job
->attrs
->attrs
, prev
= NULL
; attr
; attr
= next
)
1961 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
||
1962 attr
->group_tag
== IPP_TAG_ZERO
)
1965 * Free and remove this attribute...
1973 job
->attrs
->attrs
= next
;
1979 job
->attrs
->last
= prev
;
1980 job
->attrs
->current
= prev
;
1985 * 'add_job_uuid()' - Add job-uuid attribute to a job.
1987 * See RFC 4122 for the definition of UUIDs and the format.
1991 add_job_uuid(cupsd_client_t
*con
, /* I - Client connection */
1992 cupsd_job_t
*job
) /* I - Job */
1994 char uuid
[1024]; /* job-uuid string */
1995 _cups_md5_state_t md5state
; /* MD5 state */
1996 unsigned char md5sum
[16]; /* MD5 digest/sum */
2000 * First see if the job already has a job-uuid attribute; if so, return...
2003 if (ippFindAttribute(job
->attrs
, "job-uuid", IPP_TAG_URI
))
2007 * No job-uuid attribute, so build a version 3 UUID with the local job
2008 * ID at the end; see RFC 4122 for details. Start with the MD5 sum of
2009 * the ServerName, server name and port that the client connected to,
2010 * and local job ID...
2013 snprintf(uuid
, sizeof(uuid
), "%s:%s:%d:%d", ServerName
, con
->servername
,
2014 con
->serverport
, job
->id
);
2016 _cupsMD5Init(&md5state
);
2017 _cupsMD5Append(&md5state
, (unsigned char *)uuid
, strlen(uuid
));
2018 _cupsMD5Finish(&md5state
, md5sum
);
2021 * Format the UUID URI using the MD5 sum and job ID.
2024 snprintf(uuid
, sizeof(uuid
),
2025 "urn:uuid:%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-"
2026 "%02x%02x%02x%02x%02x%02x",
2027 md5sum
[0], md5sum
[1], md5sum
[2], md5sum
[3], md5sum
[4], md5sum
[5],
2028 (md5sum
[6] & 15) | 0x30, md5sum
[7], (md5sum
[8] & 0x3f) | 0x40,
2029 md5sum
[9], md5sum
[10], md5sum
[11], md5sum
[12], md5sum
[13],
2030 md5sum
[14], md5sum
[15]);
2032 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uuid", NULL
, uuid
);
2037 * 'add_printer()' - Add a printer to the system.
2041 add_printer(cupsd_client_t
*con
, /* I - Client connection */
2042 ipp_attribute_t
*uri
) /* I - URI of printer */
2044 http_status_t status
; /* Policy status */
2045 int i
; /* Looping var */
2046 char method
[HTTP_MAX_URI
], /* Method portion of URI */
2047 username
[HTTP_MAX_URI
], /* Username portion of URI */
2048 host
[HTTP_MAX_URI
], /* Host portion of URI */
2049 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2050 int port
; /* Port portion of URI */
2051 cupsd_printer_t
*printer
; /* Printer/class */
2052 ipp_attribute_t
*attr
; /* Printer attribute */
2053 cups_file_t
*fp
; /* Script/PPD file */
2054 char line
[1024]; /* Line from file... */
2055 char srcfile
[1024], /* Source Script/PPD file */
2056 dstfile
[1024]; /* Destination Script/PPD file */
2057 int modify
; /* Non-zero if we are modifying */
2058 char newname
[IPP_MAX_NAME
]; /* New printer name */
2059 int need_restart_job
; /* Need to restart job? */
2062 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer(%p[%d], %s)", con
,
2063 con
->http
.fd
, uri
->values
[0].string
.text
);
2066 * Do we have a valid URI?
2069 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
2070 sizeof(method
), username
, sizeof(username
), host
,
2071 sizeof(host
), &port
, resource
, sizeof(resource
));
2073 if (strncmp(resource
, "/printers/", 10) || strlen(resource
) == 10)
2076 * No, return an error...
2079 send_ipp_status(con
, IPP_BAD_REQUEST
,
2080 _("The printer-uri must be of the form "
2081 "\"ipp://HOSTNAME/printers/PRINTERNAME\"."));
2086 * Do we have a valid printer name?
2089 if (!validate_name(resource
+ 10))
2092 * No, return an error...
2095 send_ipp_status(con
, IPP_BAD_REQUEST
,
2096 _("The printer-uri \"%s\" contains invalid characters."),
2097 uri
->values
[0].string
.text
);
2105 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2107 send_http_error(con
, status
);
2112 * See if the printer already exists; if not, create a new printer...
2115 if ((printer
= cupsdFindPrinter(resource
+ 10)) == NULL
)
2118 * Printer doesn't exist; see if we have a class of the same name...
2121 if ((printer
= cupsdFindClass(resource
+ 10)) != NULL
&&
2122 !(printer
->type
& CUPS_PRINTER_REMOTE
))
2125 * Yes, return an error...
2128 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2129 _("A class named \"%s\" already exists!"),
2135 * No, add the printer...
2138 printer
= cupsdAddPrinter(resource
+ 10);
2141 else if (printer
->type
& CUPS_PRINTER_IMPLICIT
)
2144 * Rename the implicit printer to "AnyPrinter" or delete it...
2147 if (ImplicitAnyClasses
)
2149 snprintf(newname
, sizeof(newname
), "Any%s", resource
+ 10);
2150 cupsdRenamePrinter(printer
, newname
);
2153 cupsdDeletePrinter(printer
, 1);
2156 * Add the printer as a new local printer...
2159 printer
= cupsdAddPrinter(resource
+ 10);
2162 else if (printer
->type
& CUPS_PRINTER_REMOTE
)
2165 * Rename the remote printer to "Printer@server"...
2168 snprintf(newname
, sizeof(newname
), "%s@%s", resource
+ 10,
2170 cupsdRenamePrinter(printer
, newname
);
2173 * Add the printer as a new local printer...
2176 printer
= cupsdAddPrinter(resource
+ 10);
2183 * Look for attributes and copy them over as needed...
2186 need_restart_job
= 0;
2188 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
2189 IPP_TAG_TEXT
)) != NULL
)
2190 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
2192 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
2193 IPP_TAG_TEXT
)) != NULL
)
2194 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
2196 if ((attr
= ippFindAttribute(con
->request
, "device-uri",
2197 IPP_TAG_URI
)) != NULL
)
2200 * Do we have a valid device URI?
2203 need_restart_job
= 1;
2205 httpSeparateURI(HTTP_URI_CODING_ALL
, attr
->values
[0].string
.text
, method
,
2206 sizeof(method
), username
, sizeof(username
), host
,
2207 sizeof(host
), &port
, resource
, sizeof(resource
));
2209 if (!strcmp(method
, "file"))
2212 * See if the administrator has enabled file devices...
2215 if (!FileDevice
&& strcmp(resource
, "/dev/null"))
2218 * File devices are disabled and the URL is not file:/dev/null...
2221 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2222 _("File device URIs have been disabled! "
2223 "To enable, see the FileDevice directive in "
2224 "\"%s/cupsd.conf\"."),
2232 * See if the backend exists and is executable...
2235 snprintf(srcfile
, sizeof(srcfile
), "%s/backend/%s", ServerBin
, method
);
2236 if (access(srcfile
, X_OK
))
2239 * Could not find device in list!
2242 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri \"%s\"!"),
2243 attr
->values
[0].string
.text
);
2248 cupsdLogMessage(CUPSD_LOG_INFO
,
2249 "Setting %s device-uri to \"%s\" (was \"%s\".)",
2251 cupsdSanitizeURI(attr
->values
[0].string
.text
, line
,
2253 cupsdSanitizeURI(printer
->device_uri
, resource
,
2256 cupsdSetString(&printer
->device_uri
, attr
->values
[0].string
.text
);
2259 if ((attr
= ippFindAttribute(con
->request
, "port-monitor",
2260 IPP_TAG_KEYWORD
)) != NULL
)
2262 ipp_attribute_t
*supported
; /* port-monitor-supported attribute */
2265 need_restart_job
= 1;
2267 supported
= ippFindAttribute(printer
->attrs
, "port-monitor-supported",
2269 for (i
= 0; i
< supported
->num_values
; i
++)
2270 if (!strcmp(supported
->values
[i
].string
.text
,
2271 attr
->values
[0].string
.text
))
2274 if (i
>= supported
->num_values
)
2276 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad port-monitor \"%s\"!"),
2277 attr
->values
[0].string
.text
);
2281 cupsdLogMessage(CUPSD_LOG_INFO
,
2282 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2283 printer
->name
, attr
->values
[0].string
.text
,
2284 printer
->port_monitor
);
2286 if (strcmp(attr
->values
[0].string
.text
, "none"))
2287 cupsdSetString(&printer
->port_monitor
, attr
->values
[0].string
.text
);
2289 cupsdClearString(&printer
->port_monitor
);
2292 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
2293 IPP_TAG_BOOLEAN
)) != NULL
)
2295 cupsdLogMessage(CUPSD_LOG_INFO
,
2296 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
2297 printer
->name
, attr
->values
[0].boolean
, printer
->accepting
);
2299 printer
->accepting
= attr
->values
[0].boolean
;
2300 cupsdAddPrinterHistory(printer
);
2303 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
2304 IPP_TAG_BOOLEAN
)) != NULL
)
2306 if (printer
->shared
&& !attr
->values
[0].boolean
)
2307 cupsdDeregisterPrinter(printer
, 1);
2309 cupsdLogMessage(CUPSD_LOG_INFO
,
2310 "Setting %s printer-is-shared to %d (was %d.)",
2311 printer
->name
, attr
->values
[0].boolean
, printer
->shared
);
2313 printer
->shared
= attr
->values
[0].boolean
;
2316 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
2317 IPP_TAG_ENUM
)) != NULL
)
2319 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
2320 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
2322 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad printer-state value %d!"),
2323 attr
->values
[0].integer
);
2327 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)", printer
->name
,
2328 attr
->values
[0].integer
, printer
->state
);
2330 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
2331 cupsdStopPrinter(printer
, 0);
2334 need_restart_job
= 1;
2335 cupsdSetPrinterState(printer
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
2338 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
2339 IPP_TAG_TEXT
)) != NULL
)
2341 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
2342 sizeof(printer
->state_message
));
2343 cupsdAddPrinterHistory(printer
);
2346 set_printer_defaults(con
, printer
);
2349 * See if we have all required attributes...
2352 if (!printer
->device_uri
)
2353 cupsdSetString(&printer
->device_uri
, "file:///dev/null");
2356 * See if we have an interface script or PPD file attached to the request...
2361 need_restart_job
= 1;
2363 strlcpy(srcfile
, con
->filename
, sizeof(srcfile
));
2365 if ((fp
= cupsFileOpen(srcfile
, "rb")))
2368 * Yes; get the first line from it...
2372 cupsFileGets(fp
, line
, sizeof(line
));
2376 * Then see what kind of file it is...
2379 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2382 if (!strncmp(line
, "*PPD-Adobe", 10))
2385 * The new file is a PPD file, so remove any old interface script
2386 * that might be lying around...
2394 * This must be an interface script, so move the file over to the
2395 * interfaces directory and make it executable...
2398 if (copy_file(srcfile
, dstfile
))
2400 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2401 _("Unable to copy interface script - %s!"),
2407 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2408 "Copied interface script successfully!");
2409 chmod(dstfile
, 0755);
2413 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2416 if (!strncmp(line
, "*PPD-Adobe", 10))
2419 * The new file is a PPD file, so move the file over to the
2420 * ppd directory and make it readable by all...
2423 if (copy_file(srcfile
, dstfile
))
2425 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2426 _("Unable to copy PPD file - %s!"),
2432 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2433 "Copied PPD file successfully!");
2434 chmod(dstfile
, 0644);
2440 * This must be an interface script, so remove any old PPD file that
2441 * may be lying around...
2448 else if ((attr
= ippFindAttribute(con
->request
, "ppd-name",
2449 IPP_TAG_NAME
)) != NULL
)
2451 need_restart_job
= 1;
2453 if (!strcmp(attr
->values
[0].string
.text
, "raw"))
2456 * Raw driver, remove any existing PPD or interface script files.
2459 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2463 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2473 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2477 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2480 if (copy_model(con
, attr
->values
[0].string
.text
, dstfile
))
2482 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file!"));
2487 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2488 "Copied PPD file successfully!");
2489 chmod(dstfile
, 0644);
2495 * Update the printer attributes and return...
2498 cupsdSetPrinterAttrs(printer
);
2499 cupsdSaveAllPrinters();
2501 if (need_restart_job
&& printer
->job
)
2506 * Stop the current job and then restart it below...
2509 job
= (cupsd_job_t
*)printer
->job
;
2511 cupsdStopJob(job
, 1);
2513 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
2514 job
->state_value
= IPP_JOB_PENDING
;
2517 if (need_restart_job
)
2520 cupsdWritePrintcap();
2524 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
, printer
, NULL
,
2525 "Printer \"%s\" modified by \"%s\".", printer
->name
,
2528 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" modified by \"%s\".",
2529 printer
->name
, get_username(con
));
2533 cupsdAddPrinterHistory(printer
);
2535 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
, printer
, NULL
,
2536 "New printer \"%s\" added by \"%s\".", printer
->name
,
2539 cupsdLogMessage(CUPSD_LOG_INFO
, "New printer \"%s\" added by \"%s\".",
2540 printer
->name
, get_username(con
));
2543 con
->response
->request
.status
.status_code
= IPP_OK
;
2548 * 'add_printer_state_reasons()' - Add the "printer-state-reasons" attribute
2549 * based upon the printer state...
2553 add_printer_state_reasons(
2554 cupsd_client_t
*con
, /* I - Client connection */
2555 cupsd_printer_t
*p
) /* I - Printer info */
2557 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2558 "add_printer_state_reasons(%p[%d], %p[%s])",
2559 con
, con
->http
.fd
, p
, p
->name
);
2561 if (p
->num_reasons
== 0)
2562 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2563 "printer-state-reasons", NULL
,
2564 p
->state
== IPP_PRINTER_STOPPED
? "paused" : "none");
2566 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2567 "printer-state-reasons", p
->num_reasons
, NULL
,
2568 (const char * const *)p
->reasons
);
2573 * 'add_queued_job_count()' - Add the "queued-job-count" attribute for
2574 * the specified printer or class.
2578 add_queued_job_count(
2579 cupsd_client_t
*con
, /* I - Client connection */
2580 cupsd_printer_t
*p
) /* I - Printer or class */
2582 int count
; /* Number of jobs on destination */
2585 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_queued_job_count(%p[%d], %p[%s])",
2586 con
, con
->http
.fd
, p
, p
->name
);
2588 count
= cupsdGetPrinterJobCount(p
->name
);
2590 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2591 "queued-job-count", count
);
2596 * 'apply_printer_defaults()' - Apply printer default options to a job.
2600 apply_printer_defaults(
2601 cupsd_printer_t
*printer
, /* I - Printer */
2602 cupsd_job_t
*job
) /* I - Job */
2604 int i
, /* Looping var */
2605 num_options
; /* Number of default options */
2606 cups_option_t
*options
, /* Default options */
2607 *option
; /* Current option */
2611 * Collect all of the default options and add the missing ones to the
2615 for (i
= printer
->num_options
, num_options
= 0, option
= printer
->options
;
2618 if (!ippFindAttribute(job
->attrs
, option
->name
, IPP_TAG_ZERO
))
2620 num_options
= cupsAddOption(option
->name
, option
->value
, num_options
,
2625 * Encode these options as attributes in the job object...
2628 cupsEncodeOptions2(job
->attrs
, num_options
, options
, IPP_TAG_JOB
);
2629 cupsFreeOptions(num_options
, options
);
2634 * 'authenticate_job()' - Set job authentication info.
2638 authenticate_job(cupsd_client_t
*con
, /* I - Client connection */
2639 ipp_attribute_t
*uri
) /* I - Job URI */
2641 ipp_attribute_t
*attr
, /* job-id attribute */
2642 *auth_info
; /* auth-info attribute */
2643 int jobid
; /* Job ID */
2644 cupsd_job_t
*job
; /* Current job */
2645 char method
[HTTP_MAX_URI
],
2646 /* Method portion of URI */
2647 username
[HTTP_MAX_URI
],
2648 /* Username portion of URI */
2650 /* Host portion of URI */
2651 resource
[HTTP_MAX_URI
];
2652 /* Resource portion of URI */
2653 int port
; /* Port portion of URI */
2656 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "authenticate_job(%p[%d], %s)",
2657 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
2660 * Start with "everything is OK" status...
2663 con
->response
->request
.status
.status_code
= IPP_OK
;
2666 * See if we have a job URI or a printer URI...
2669 if (!strcmp(uri
->name
, "printer-uri"))
2672 * Got a printer URI; see if we also have a job-id attribute...
2675 if ((attr
= ippFindAttribute(con
->request
, "job-id",
2676 IPP_TAG_INTEGER
)) == NULL
)
2678 send_ipp_status(con
, IPP_BAD_REQUEST
,
2679 _("Got a printer-uri attribute but no job-id!"));
2683 jobid
= attr
->values
[0].integer
;
2688 * Got a job URI; parse it to get the job ID...
2691 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
2692 sizeof(method
), username
, sizeof(username
), host
,
2693 sizeof(host
), &port
, resource
, sizeof(resource
));
2695 if (strncmp(resource
, "/jobs/", 6))
2701 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri attribute \"%s\"!"),
2702 uri
->values
[0].string
.text
);
2706 jobid
= atoi(resource
+ 6);
2710 * See if the job exists...
2713 if ((job
= cupsdFindJob(jobid
)) == NULL
)
2716 * Nope - return a "not found" error...
2719 send_ipp_status(con
, IPP_NOT_FOUND
,
2720 _("Job #%d does not exist!"), jobid
);
2725 * See if the job has been completed...
2728 if (job
->state_value
!= IPP_JOB_HELD
)
2731 * Return a "not-possible" error...
2734 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2735 _("Job #%d is not held for authentication!"),
2741 * See if we have already authenticated...
2744 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
2746 if (!con
->username
[0] && !auth_info
)
2748 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
2749 _("No authentication information provided!"));
2754 * See if the job is owned by the requesting user...
2757 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
2759 send_http_error(con
, HTTP_UNAUTHORIZED
);
2764 * Save the authentication information for this job...
2767 save_auth_info(con
, job
, auth_info
);
2770 * Reset the job-hold-until value to "no-hold"...
2773 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
2774 IPP_TAG_KEYWORD
)) == NULL
)
2775 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
2779 attr
->value_tag
= IPP_TAG_KEYWORD
;
2780 cupsdSetString(&(attr
->values
[0].string
.text
), "no-hold");
2784 * Release the job and return...
2787 cupsdReleaseJob(job
);
2789 cupsdLogMessage(CUPSD_LOG_INFO
, "Job %d was authenticated by \"%s\".", jobid
,
2795 * 'cancel_all_jobs()' - Cancel all print jobs.
2799 cancel_all_jobs(cupsd_client_t
*con
, /* I - Client connection */
2800 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
2802 http_status_t status
; /* Policy status */
2803 cups_ptype_t dtype
; /* Destination type */
2804 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
2805 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
2806 hostname
[HTTP_MAX_URI
], /* Host portion of URI */
2807 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2808 int port
; /* Port portion of URI */
2809 ipp_attribute_t
*attr
; /* Attribute in request */
2810 const char *username
; /* Username */
2811 int purge
; /* Purge? */
2812 cupsd_printer_t
*printer
; /* Printer */
2815 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_all_jobs(%p[%d], %s)", con
,
2816 con
->http
.fd
, uri
->values
[0].string
.text
);
2819 * See if we have a printer URI...
2822 if (strcmp(uri
->name
, "printer-uri"))
2824 send_ipp_status(con
, IPP_BAD_REQUEST
,
2825 _("The printer-uri attribute is required!"));
2830 * Get the username (if any) for the jobs we want to cancel (only if
2831 * "my-jobs" is specified...
2834 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
2835 IPP_TAG_BOOLEAN
)) != NULL
&&
2836 attr
->values
[0].boolean
)
2838 if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
2839 IPP_TAG_NAME
)) != NULL
)
2840 username
= attr
->values
[0].string
.text
;
2843 send_ipp_status(con
, IPP_BAD_REQUEST
,
2844 _("Missing requesting-user-name attribute!"));
2852 * Look for the "purge-jobs" attribute...
2855 if ((attr
= ippFindAttribute(con
->request
, "purge-jobs",
2856 IPP_TAG_BOOLEAN
)) != NULL
)
2857 purge
= attr
->values
[0].boolean
;
2862 * And if the destination is valid...
2865 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
2871 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
,
2872 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
2873 hostname
, sizeof(hostname
), &port
,
2874 resource
, sizeof(resource
));
2876 if ((!strncmp(resource
, "/printers/", 10) && resource
[10]) ||
2877 (!strncmp(resource
, "/classes/", 9) && resource
[9]))
2879 send_ipp_status(con
, IPP_NOT_FOUND
,
2880 _("The printer or class was not found."));
2888 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2890 send_http_error(con
, status
);
2895 * Cancel all jobs on all printers...
2898 cupsdCancelJobs(NULL
, username
, purge
);
2900 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs were %s by \"%s\".",
2901 purge
? "purged" : "canceled", get_username(con
));
2909 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
2912 send_http_error(con
, status
);
2917 * Cancel all of the jobs on the named printer...
2920 cupsdCancelJobs(printer
->name
, username
, purge
);
2922 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs on \"%s\" were %s by \"%s\".",
2923 printer
->name
, purge
? "purged" : "canceled",
2927 con
->response
->request
.status
.status_code
= IPP_OK
;
2932 * 'cancel_job()' - Cancel a print job.
2936 cancel_job(cupsd_client_t
*con
, /* I - Client connection */
2937 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
2939 ipp_attribute_t
*attr
; /* Current attribute */
2940 int jobid
; /* Job ID */
2941 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
2942 username
[HTTP_MAX_URI
], /* Username portion of URI */
2943 host
[HTTP_MAX_URI
], /* Host portion of URI */
2944 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2945 int port
; /* Port portion of URI */
2946 cupsd_job_t
*job
; /* Job information */
2947 cups_ptype_t dtype
; /* Destination type (printer or class) */
2948 cupsd_printer_t
*printer
; /* Printer data */
2951 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_job(%p[%d], %s)", con
,
2952 con
->http
.fd
, uri
->values
[0].string
.text
);
2955 * See if we have a job URI or a printer URI...
2958 if (!strcmp(uri
->name
, "printer-uri"))
2961 * Got a printer URI; see if we also have a job-id attribute...
2964 if ((attr
= ippFindAttribute(con
->request
, "job-id",
2965 IPP_TAG_INTEGER
)) == NULL
)
2967 send_ipp_status(con
, IPP_BAD_REQUEST
,
2968 _("Got a printer-uri attribute but no job-id!"));
2972 if ((jobid
= attr
->values
[0].integer
) == 0)
2975 * Find the current job on the specified printer...
2978 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
2984 send_ipp_status(con
, IPP_NOT_FOUND
,
2985 _("The printer or class was not found."));
2990 * See if the printer is currently printing a job...
2994 jobid
= ((cupsd_job_t
*)printer
->job
)->id
;
2998 * No, see if there are any pending jobs...
3001 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3003 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3004 if (job
->state_value
<= IPP_JOB_PROCESSING
&&
3005 !strcasecmp(job
->dest
, printer
->name
))
3012 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("No active jobs on %s!"),
3022 * Got a job URI; parse it to get the job ID...
3025 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
3026 sizeof(scheme
), username
, sizeof(username
), host
,
3027 sizeof(host
), &port
, resource
, sizeof(resource
));
3029 if (strncmp(resource
, "/jobs/", 6))
3035 send_ipp_status(con
, IPP_BAD_REQUEST
,
3036 _("Bad job-uri attribute \"%s\"!"),
3037 uri
->values
[0].string
.text
);
3041 jobid
= atoi(resource
+ 6);
3045 * See if the job exists...
3048 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3051 * Nope - return a "not found" error...
3054 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
3059 * See if the job is owned by the requesting user...
3062 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3064 send_http_error(con
, HTTP_UNAUTHORIZED
);
3069 * See if the job is already completed, canceled, or aborted; if so,
3070 * we can't cancel...
3073 if (job
->state_value
>= IPP_JOB_CANCELED
)
3075 switch (job
->state_value
)
3077 case IPP_JOB_CANCELED
:
3078 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3079 _("Job #%d is already canceled - can\'t cancel."),
3083 case IPP_JOB_ABORTED
:
3084 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3085 _("Job #%d is already aborted - can\'t cancel."),
3090 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3091 _("Job #%d is already completed - can\'t cancel."),
3100 * Cancel the job and return...
3103 cupsdCancelJob(job
, 0, IPP_JOB_CANCELED
);
3106 cupsdLogMessage(CUPSD_LOG_INFO
, "Job %d was canceled by \"%s\".", jobid
,
3109 con
->response
->request
.status
.status_code
= IPP_OK
;
3114 * 'cancel_subscription()' - Cancel a subscription.
3118 cancel_subscription(
3119 cupsd_client_t
*con
, /* I - Client connection */
3120 int sub_id
) /* I - Subscription ID */
3122 http_status_t status
; /* Policy status */
3123 cupsd_subscription_t
*sub
; /* Subscription */
3126 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3127 "cancel_subscription(con=%p[%d], sub_id=%d)",
3128 con
, con
->http
.fd
, sub_id
);
3131 * Is the subscription ID valid?
3134 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
3137 * Bad subscription ID...
3140 send_ipp_status(con
, IPP_NOT_FOUND
,
3141 _("notify-subscription-id %d no good!"), sub_id
);
3149 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
3151 con
, sub
->owner
)) != HTTP_OK
)
3153 send_http_error(con
, status
);
3158 * Cancel the subscription...
3161 cupsdDeleteSubscription(sub
, 1);
3163 con
->response
->request
.status
.status_code
= IPP_OK
;
3168 * 'check_quotas()' - Check quotas for a printer and user.
3171 static int /* O - 1 if OK, 0 if not */
3172 check_quotas(cupsd_client_t
*con
, /* I - Client connection */
3173 cupsd_printer_t
*p
) /* I - Printer or class */
3175 int i
; /* Looping var */
3176 char username
[33]; /* Username */
3177 cupsd_quota_t
*q
; /* Quota data */
3178 #ifdef HAVE_MBR_UID_TO_UUID
3180 * Use Apple membership APIs which require that all names represent
3181 * valid user account or group records accessible by the server.
3184 uuid_t usr_uuid
; /* UUID for job requesting user */
3185 uuid_t usr2_uuid
; /* UUID for ACL user name entry */
3186 uuid_t grp_uuid
; /* UUID for ACL group name entry */
3187 int mbr_err
; /* Error from membership function */
3188 int is_member
; /* Is this user a member? */
3191 * Use standard POSIX APIs for checking users and groups...
3194 struct passwd
*pw
; /* User password data */
3195 #endif /* HAVE_MBR_UID_TO_UUID */
3198 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "check_quotas(%p[%d], %p[%s])",
3199 con
, con
->http
.fd
, p
, p
->name
);
3209 * Figure out who is printing...
3212 strlcpy(username
, get_username(con
), sizeof(username
));
3215 * Check global active job limits for printers and users...
3218 if (MaxJobsPerPrinter
)
3221 * Check if there are too many pending jobs on this printer...
3224 if (cupsdGetPrinterJobCount(p
->name
) >= MaxJobsPerPrinter
)
3226 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for printer \"%s\"...",
3235 * Check if there are too many pending jobs for this user...
3238 if (cupsdGetUserJobCount(username
) >= MaxJobsPerUser
)
3240 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for user \"%s\"...",
3247 * Check against users...
3250 if (p
->num_users
== 0 && p
->k_limit
== 0 && p
->page_limit
== 0)
3255 #ifdef HAVE_MBR_UID_TO_UUID
3257 * Get UUID for job requesting user...
3260 if (mbr_user_name_to_uuid((char *)username
, usr_uuid
))
3266 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3267 "check_quotas: UUID lookup failed for user \"%s\"",
3269 cupsdLogMessage(CUPSD_LOG_INFO
,
3270 "Denying user \"%s\" access to printer \"%s\" "
3271 "(unknown user)...",
3277 * Get UID and GID of requesting user...
3280 pw
= getpwnam(username
);
3282 #endif /* HAVE_MBR_UID_TO_UUID */
3284 for (i
= 0; i
< p
->num_users
; i
++)
3285 if (p
->users
[i
][0] == '@')
3288 * Check group membership...
3291 #ifdef HAVE_MBR_UID_TO_UUID
3292 if ((mbr_err
= mbr_group_name_to_uuid((char *)p
->users
[i
] + 1,
3296 * Invalid ACL entries are ignored for matching; just record a
3297 * warning in the log...
3300 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3301 "check_quotas: UUID lookup failed for ACL entry "
3302 "\"%s\" (err=%d)", p
->users
[i
], mbr_err
);
3303 cupsdLogMessage(CUPSD_LOG_WARN
,
3304 "Access control entry \"%s\" not a valid group name; "
3305 "entry ignored", p
->users
[i
]);
3309 if ((mbr_err
= mbr_check_membership(usr_uuid
, grp_uuid
,
3313 * At this point, there should be no errors, but check anyways...
3316 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3317 "check_quotas: group \"%s\" membership check "
3318 "failed (err=%d)", p
->users
[i
] + 1, mbr_err
);
3323 * Stop if we found a match...
3330 if (cupsdCheckGroup(username
, pw
, p
->users
[i
] + 1))
3332 #endif /* HAVE_MBR_UID_TO_UUID */
3334 #ifdef HAVE_MBR_UID_TO_UUID
3337 if ((mbr_err
= mbr_user_name_to_uuid((char *)p
->users
[i
],
3341 * Invalid ACL entries are ignored for matching; just record a
3342 * warning in the log...
3345 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3346 "check_quotas: UUID lookup failed for ACL entry "
3347 "\"%s\" (err=%d)", p
->users
[i
], mbr_err
);
3348 cupsdLogMessage(CUPSD_LOG_WARN
,
3349 "Access control entry \"%s\" not a valid user name; "
3350 "entry ignored", p
->users
[i
]);
3354 if ((mbr_err
= mbr_check_membership(usr_uuid
, usr2_uuid
,
3357 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3358 "check_quotas: User \"%s\" identity check failed "
3359 "(err=%d)", p
->users
[i
], mbr_err
);
3368 else if (!strcasecmp(username
, p
->users
[i
]))
3370 #endif /* HAVE_MBR_UID_TO_UUID */
3372 if ((i
< p
->num_users
) == p
->deny_users
)
3374 cupsdLogMessage(CUPSD_LOG_INFO
,
3375 "Denying user \"%s\" access to printer \"%s\"...",
3389 * TODO: Define these special page count values as constants!
3392 if (q
->page_count
== -4) /* special case: unlimited user */
3394 cupsdLogMessage(CUPSD_LOG_INFO
,
3395 "User \"%s\" request approved for printer %s (%s): "
3397 username
, p
->name
, p
->info
);
3398 q
->page_count
= 0; /* allow user to print */
3401 else if (q
->page_count
== -3) /* quota exceeded */
3403 cupsdLogMessage(CUPSD_LOG_INFO
,
3404 "User \"%s\" request denied for printer %s (%s): "
3405 "quota limit exceeded.",
3406 username
, p
->name
, p
->info
);
3407 q
->page_count
= 2; /* force quota exceeded failure */
3410 else if (q
->page_count
== -2) /* quota disabled for user */
3412 cupsdLogMessage(CUPSD_LOG_INFO
,
3413 "User \"%s\" request denied for printer %s (%s): "
3414 "printing disabled for user.",
3415 username
, p
->name
, p
->info
);
3416 q
->page_count
= 2; /* force quota exceeded failure */
3419 else if (q
->page_count
== -1) /* quota access error */
3421 cupsdLogMessage(CUPSD_LOG_INFO
,
3422 "User \"%s\" request denied for printer %s (%s): "
3423 "unable to determine quota limit.",
3424 username
, p
->name
, p
->info
);
3425 q
->page_count
= 2; /* force quota exceeded failure */
3428 else if (q
->page_count
< 0) /* user not found or other error */
3430 cupsdLogMessage(CUPSD_LOG_INFO
,
3431 "User \"%s\" request denied for printer %s (%s): "
3432 "user disabled / missing quota.",
3433 username
, p
->name
, p
->info
);
3434 q
->page_count
= 2; /* force quota exceeded failure */
3437 else /* page within user limits */
3439 q
->page_count
= 0; /* allow user to print */
3444 #endif /* __APPLE__ */
3445 if (p
->k_limit
|| p
->page_limit
)
3447 if ((q
= cupsdUpdateQuota(p
, username
, 0, 0)) == NULL
)
3449 cupsdLogMessage(CUPSD_LOG_ERROR
,
3450 "Unable to allocate quota data for user \"%s\"!",
3455 if ((q
->k_count
>= p
->k_limit
&& p
->k_limit
) ||
3456 (q
->page_count
>= p
->page_limit
&& p
->page_limit
))
3458 cupsdLogMessage(CUPSD_LOG_INFO
, "User \"%s\" is over the quota limit...",
3465 * If we have gotten this far, we're done!
3473 * 'copy_attribute()' - Copy a single attribute.
3476 static ipp_attribute_t
* /* O - New attribute */
3478 ipp_t
*to
, /* O - Destination request/response */
3479 ipp_attribute_t
*attr
, /* I - Attribute to copy */
3480 int quickcopy
) /* I - Do a quick copy? */
3482 int i
; /* Looping var */
3483 ipp_attribute_t
*toattr
; /* Destination attribute */
3486 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3487 "copy_attribute(%p, %p[%s,%x,%x])", to
, attr
,
3488 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
3491 switch (attr
->value_tag
& ~IPP_TAG_COPY
)
3494 toattr
= ippAddSeparator(to
);
3497 case IPP_TAG_INTEGER
:
3499 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
3500 attr
->name
, attr
->num_values
, NULL
);
3502 for (i
= 0; i
< attr
->num_values
; i
++)
3503 toattr
->values
[i
].integer
= attr
->values
[i
].integer
;
3506 case IPP_TAG_BOOLEAN
:
3507 toattr
= ippAddBooleans(to
, attr
->group_tag
, attr
->name
,
3508 attr
->num_values
, NULL
);
3510 for (i
= 0; i
< attr
->num_values
; i
++)
3511 toattr
->values
[i
].boolean
= attr
->values
[i
].boolean
;
3514 case IPP_TAG_STRING
:
3517 case IPP_TAG_KEYWORD
:
3519 case IPP_TAG_URISCHEME
:
3520 case IPP_TAG_CHARSET
:
3521 case IPP_TAG_LANGUAGE
:
3522 case IPP_TAG_MIMETYPE
:
3523 toattr
= ippAddStrings(to
, attr
->group_tag
,
3524 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
3525 attr
->name
, attr
->num_values
, NULL
, NULL
);
3529 for (i
= 0; i
< attr
->num_values
; i
++)
3530 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
3534 for (i
= 0; i
< attr
->num_values
; i
++)
3535 toattr
->values
[i
].string
.text
= _cupsStrAlloc(attr
->values
[i
].string
.text
);
3540 toattr
= ippAddDate(to
, attr
->group_tag
, attr
->name
,
3541 attr
->values
[0].date
);
3544 case IPP_TAG_RESOLUTION
:
3545 toattr
= ippAddResolutions(to
, attr
->group_tag
, attr
->name
,
3546 attr
->num_values
, IPP_RES_PER_INCH
,
3549 for (i
= 0; i
< attr
->num_values
; i
++)
3551 toattr
->values
[i
].resolution
.xres
= attr
->values
[i
].resolution
.xres
;
3552 toattr
->values
[i
].resolution
.yres
= attr
->values
[i
].resolution
.yres
;
3553 toattr
->values
[i
].resolution
.units
= attr
->values
[i
].resolution
.units
;
3557 case IPP_TAG_RANGE
:
3558 toattr
= ippAddRanges(to
, attr
->group_tag
, attr
->name
,
3559 attr
->num_values
, NULL
, NULL
);
3561 for (i
= 0; i
< attr
->num_values
; i
++)
3563 toattr
->values
[i
].range
.lower
= attr
->values
[i
].range
.lower
;
3564 toattr
->values
[i
].range
.upper
= attr
->values
[i
].range
.upper
;
3568 case IPP_TAG_TEXTLANG
:
3569 case IPP_TAG_NAMELANG
:
3570 toattr
= ippAddStrings(to
, attr
->group_tag
,
3571 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
3572 attr
->name
, attr
->num_values
, NULL
, NULL
);
3576 for (i
= 0; i
< attr
->num_values
; i
++)
3578 toattr
->values
[i
].string
.charset
= attr
->values
[i
].string
.charset
;
3579 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
3584 for (i
= 0; i
< attr
->num_values
; i
++)
3587 toattr
->values
[i
].string
.charset
=
3588 _cupsStrAlloc(attr
->values
[i
].string
.charset
);
3590 toattr
->values
[i
].string
.charset
=
3591 toattr
->values
[0].string
.charset
;
3593 toattr
->values
[i
].string
.text
= _cupsStrAlloc(attr
->values
[i
].string
.text
);
3598 case IPP_TAG_BEGIN_COLLECTION
:
3599 toattr
= ippAddCollections(to
, attr
->group_tag
, attr
->name
,
3600 attr
->num_values
, NULL
);
3602 for (i
= 0; i
< attr
->num_values
; i
++)
3604 toattr
->values
[i
].collection
= ippNew();
3605 copy_attrs(toattr
->values
[i
].collection
, attr
->values
[i
].collection
,
3606 NULL
, IPP_TAG_ZERO
, 0);
3611 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
3612 attr
->name
, attr
->num_values
, NULL
);
3614 for (i
= 0; i
< attr
->num_values
; i
++)
3616 toattr
->values
[i
].unknown
.length
= attr
->values
[i
].unknown
.length
;
3618 if (toattr
->values
[i
].unknown
.length
> 0)
3620 if ((toattr
->values
[i
].unknown
.data
=
3621 malloc(toattr
->values
[i
].unknown
.length
)) == NULL
)
3622 toattr
->values
[i
].unknown
.length
= 0;
3624 memcpy(toattr
->values
[i
].unknown
.data
,
3625 attr
->values
[i
].unknown
.data
,
3626 toattr
->values
[i
].unknown
.length
);
3629 break; /* anti-compiler-warning-code */
3637 * 'copy_attrs()' - Copy attributes from one request to another.
3641 copy_attrs(ipp_t
*to
, /* I - Destination request */
3642 ipp_t
*from
, /* I - Source request */
3643 cups_array_t
*ra
, /* I - Requested attributes */
3644 ipp_tag_t group
, /* I - Group to copy */
3645 int quickcopy
) /* I - Do a quick copy? */
3647 ipp_attribute_t
*fromattr
; /* Source attribute */
3650 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3651 "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)",
3652 to
, from
, ra
, group
, quickcopy
);
3657 for (fromattr
= from
->attrs
; fromattr
; fromattr
= fromattr
->next
)
3660 * Filter attributes as needed...
3663 if ((group
!= IPP_TAG_ZERO
&& fromattr
->group_tag
!= group
&&
3664 fromattr
->group_tag
!= IPP_TAG_ZERO
) || !fromattr
->name
)
3667 if (!ra
|| cupsArrayFind(ra
, fromattr
->name
))
3668 copy_attribute(to
, fromattr
, quickcopy
);
3674 * 'copy_banner()' - Copy a banner file to the requests directory for the
3678 static int /* O - Size of banner file in kbytes */
3679 copy_banner(cupsd_client_t
*con
, /* I - Client connection */
3680 cupsd_job_t
*job
, /* I - Job information */
3681 const char *name
) /* I - Name of banner */
3683 int i
; /* Looping var */
3684 int kbytes
; /* Size of banner file in kbytes */
3685 char filename
[1024]; /* Job filename */
3686 cupsd_banner_t
*banner
; /* Pointer to banner */
3687 cups_file_t
*in
; /* Input file */
3688 cups_file_t
*out
; /* Output file */
3689 int ch
; /* Character from file */
3690 char attrname
[255], /* Name of attribute */
3691 *s
; /* Pointer into name */
3692 ipp_attribute_t
*attr
; /* Attribute */
3695 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_banner(%p[%d], %p[%d], %s)",
3696 con
, con
->http
.fd
, job
, job
->id
, name
? name
: "(null)");
3699 * Find the banner; return if not found or "none"...
3702 if (!name
|| !strcmp(name
, "none") ||
3703 (banner
= cupsdFindBanner(name
)) == NULL
)
3707 * Open the banner and job files...
3710 if (add_file(con
, job
, banner
->filetype
, 0))
3713 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
3715 if ((out
= cupsFileOpen(filename
, "w")) == NULL
)
3717 cupsdLogMessage(CUPSD_LOG_ERROR
,
3718 "copy_banner: Unable to create banner job file %s - %s",
3719 filename
, strerror(errno
));
3724 fchmod(cupsFileNumber(out
), 0640);
3725 fchown(cupsFileNumber(out
), RunUser
, Group
);
3728 * Try the localized banner file under the subdirectory...
3731 strlcpy(attrname
, job
->attrs
->attrs
->next
->values
[0].string
.text
,
3733 if (strlen(attrname
) > 2 && attrname
[2] == '-')
3736 * Convert ll-cc to ll_CC...
3740 attrname
[3] = toupper(attrname
[3] & 255);
3741 attrname
[4] = toupper(attrname
[4] & 255);
3744 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
3747 if (access(filename
, 0) && strlen(attrname
) > 2)
3750 * Wasn't able to find "ll_CC" locale file; try the non-national
3751 * localization banner directory.
3756 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
3760 if (access(filename
, 0))
3763 * Use the non-localized banner file.
3766 snprintf(filename
, sizeof(filename
), "%s/banners/%s", DataDir
, name
);
3769 if ((in
= cupsFileOpen(filename
, "r")) == NULL
)
3773 cupsdLogMessage(CUPSD_LOG_ERROR
,
3774 "copy_banner: Unable to open banner template file %s - %s",
3775 filename
, strerror(errno
));
3781 * Parse the file to the end...
3784 while ((ch
= cupsFileGetChar(in
)) != EOF
)
3788 * Get an attribute name...
3791 for (s
= attrname
; (ch
= cupsFileGetChar(in
)) != EOF
;)
3792 if (!isalpha(ch
& 255) && ch
!= '-' && ch
!= '?')
3794 else if (s
< (attrname
+ sizeof(attrname
) - 1))
3804 * Ignore { followed by stuff that is not an attribute name...
3807 cupsFilePrintf(out
, "{%s%c", attrname
, ch
);
3812 * See if it is defined...
3815 if (attrname
[0] == '?')
3820 if (!strcmp(s
, "printer-name"))
3822 cupsFilePuts(out
, job
->dest
);
3825 else if ((attr
= ippFindAttribute(job
->attrs
, s
, IPP_TAG_ZERO
)) == NULL
)
3828 * See if we have a leading question mark...
3831 if (attrname
[0] != '?')
3834 * Nope, write to file as-is; probably a PostScript procedure...
3837 cupsFilePrintf(out
, "{%s}", attrname
);
3844 * Output value(s)...
3847 for (i
= 0; i
< attr
->num_values
; i
++)
3850 cupsFilePutChar(out
, ',');
3852 switch (attr
->value_tag
)
3854 case IPP_TAG_INTEGER
:
3856 if (!strncmp(s
, "time-at-", 8))
3857 cupsFilePuts(out
, cupsdGetDateTime(attr
->values
[i
].integer
));
3859 cupsFilePrintf(out
, "%d", attr
->values
[i
].integer
);
3862 case IPP_TAG_BOOLEAN
:
3863 cupsFilePrintf(out
, "%d", attr
->values
[i
].boolean
);
3866 case IPP_TAG_NOVALUE
:
3867 cupsFilePuts(out
, "novalue");
3870 case IPP_TAG_RANGE
:
3871 cupsFilePrintf(out
, "%d-%d", attr
->values
[i
].range
.lower
,
3872 attr
->values
[i
].range
.upper
);
3875 case IPP_TAG_RESOLUTION
:
3876 cupsFilePrintf(out
, "%dx%d%s", attr
->values
[i
].resolution
.xres
,
3877 attr
->values
[i
].resolution
.yres
,
3878 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
3883 case IPP_TAG_STRING
:
3886 case IPP_TAG_KEYWORD
:
3887 case IPP_TAG_CHARSET
:
3888 case IPP_TAG_LANGUAGE
:
3889 if (!strcasecmp(banner
->filetype
->type
, "postscript"))
3892 * Need to quote strings for PS banners...
3897 for (p
= attr
->values
[i
].string
.text
; *p
; p
++)
3899 if (*p
== '(' || *p
== ')' || *p
== '\\')
3901 cupsFilePutChar(out
, '\\');
3902 cupsFilePutChar(out
, *p
);
3904 else if (*p
< 32 || *p
> 126)
3905 cupsFilePrintf(out
, "\\%03o", *p
& 255);
3907 cupsFilePutChar(out
, *p
);
3911 cupsFilePuts(out
, attr
->values
[i
].string
.text
);
3915 break; /* anti-compiler-warning-code */
3919 else if (ch
== '\\') /* Quoted char */
3921 ch
= cupsFileGetChar(in
);
3923 if (ch
!= '{') /* Only do special handling for \{ */
3924 cupsFilePutChar(out
, '\\');
3926 cupsFilePutChar(out
, ch
);
3929 cupsFilePutChar(out
, ch
);
3933 kbytes
= (cupsFileTell(out
) + 1023) / 1024;
3935 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
3936 IPP_TAG_INTEGER
)) != NULL
)
3937 attr
->values
[0].integer
+= kbytes
;
3946 * 'copy_file()' - Copy a PPD file or interface script...
3949 static int /* O - 0 = success, -1 = error */
3950 copy_file(const char *from
, /* I - Source file */
3951 const char *to
) /* I - Destination file */
3953 cups_file_t
*src
, /* Source file */
3954 *dst
; /* Destination file */
3955 int bytes
; /* Bytes to read/write */
3956 char buffer
[2048]; /* Copy buffer */
3959 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_file(\"%s\", \"%s\")", from
, to
);
3962 * Open the source and destination file for a copy...
3965 if ((src
= cupsFileOpen(from
, "rb")) == NULL
)
3968 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
3975 * Copy the source file to the destination...
3978 while ((bytes
= cupsFileRead(src
, buffer
, sizeof(buffer
))) > 0)
3979 if (cupsFileWrite(dst
, buffer
, bytes
) < bytes
)
3987 * Close both files and return...
3992 return (cupsFileClose(dst
));
3997 * 'copy_model()' - Copy a PPD model file, substituting default values
4001 static int /* O - 0 = success, -1 = error */
4002 copy_model(cupsd_client_t
*con
, /* I - Client connection */
4003 const char *from
, /* I - Source file */
4004 const char *to
) /* I - Destination file */
4006 fd_set input
; /* select() input set */
4007 struct timeval timeout
; /* select() timeout */
4008 int maxfd
; /* Maximum file descriptor for select() */
4009 char tempfile
[1024]; /* Temporary PPD file */
4010 int tempfd
; /* Temporary PPD file descriptor */
4011 int temppid
; /* Process ID of cups-driverd */
4012 int temppipe
[2]; /* Temporary pipes */
4013 char *argv
[4], /* Command-line arguments */
4014 *envp
[MAX_ENV
]; /* Environment */
4015 cups_file_t
*src
, /* Source file */
4016 *dst
; /* Destination file */
4017 ppd_file_t
*ppd
; /* PPD file */
4018 int bytes
, /* Bytes from pipe */
4019 total
; /* Total bytes from pipe */
4020 char buffer
[2048]; /* Copy buffer */
4021 int i
; /* Looping var */
4022 char option
[PPD_MAX_NAME
], /* Option name */
4023 choice
[PPD_MAX_NAME
]; /* Choice name */
4024 int num_defaults
; /* Number of default options */
4025 cups_option_t
*defaults
; /* Default options */
4026 char cups_protocol
[PPD_MAX_LINE
];
4027 /* cupsProtocol attribute */
4028 int have_letter
, /* Have Letter size */
4029 have_a4
; /* Have A4 size */
4030 #ifdef HAVE_LIBPAPER
4031 char *paper_result
; /* Paper size name from libpaper */
4032 char system_paper
[64]; /* Paper size name buffer */
4033 #endif /* HAVE_LIBPAPER */
4036 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4037 "copy_model(con=%p, from=\"%s\", to=\"%s\")",
4041 * Run cups-driverd to get the PPD file...
4044 argv
[0] = "cups-driverd";
4046 argv
[2] = (char *)from
;
4049 cupsdLoadEnv(envp
, (int)(sizeof(envp
) / sizeof(envp
[0])));
4051 snprintf(buffer
, sizeof(buffer
), "%s/daemon/cups-driverd", ServerBin
);
4052 snprintf(tempfile
, sizeof(tempfile
), "%s/%d.ppd", TempDir
, con
->http
.fd
);
4053 tempfd
= open(tempfile
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
4057 cupsdOpenPipe(temppipe
);
4059 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4060 "copy_model: Running \"cups-driverd cat %s\"...", from
);
4062 if (!cupsdStartProcess(buffer
, argv
, envp
, -1, temppipe
[1], CGIPipes
[1],
4063 -1, -1, 0, &temppid
))
4073 * Wait up to 30 seconds for the PPD file to be copied...
4078 if (temppipe
[0] > CGIPipes
[0])
4079 maxfd
= temppipe
[0] + 1;
4081 maxfd
= CGIPipes
[0] + 1;
4086 * See if we have data ready...
4092 FD_SET(temppipe
[0], &input
);
4093 FD_SET(CGIPipes
[0], &input
);
4095 timeout
.tv_sec
= 30;
4096 timeout
.tv_usec
= 0;
4098 if ((i
= select(maxfd
, &input
, NULL
, NULL
, &timeout
)) < 0)
4108 * We have timed out...
4114 if (FD_ISSET(temppipe
[0], &input
))
4117 * Read the PPD file from the pipe, and write it to the PPD file.
4120 if ((bytes
= read(temppipe
[0], buffer
, sizeof(buffer
))) > 0)
4122 if (write(tempfd
, buffer
, bytes
) < bytes
)
4131 if (FD_ISSET(CGIPipes
[0], &input
))
4141 * No data from cups-deviced...
4144 cupsdLogMessage(CUPSD_LOG_ERROR
, "copy_model: empty PPD file!");
4150 * Read the source file and see what page sizes are supported...
4153 if ((ppd
= ppdOpenFile(tempfile
)) == NULL
)
4159 have_letter
= ppdPageSize(ppd
, "Letter") != NULL
;
4160 have_a4
= ppdPageSize(ppd
, "A4") != NULL
;
4163 * Open the destination (if possible) and set the default options...
4168 cups_protocol
[0] = '\0';
4170 if ((dst
= cupsFileOpen(to
, "rb")) != NULL
)
4173 * Read all of the default lines from the old PPD...
4176 while (cupsFileGets(dst
, buffer
, sizeof(buffer
)))
4177 if (!strncmp(buffer
, "*Default", 8))
4180 * Add the default option...
4183 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
4184 choice
, sizeof(choice
)))
4186 ppd_option_t
*ppdo
; /* PPD option */
4190 * Only add the default if the default hasn't already been
4191 * set and the choice exists in the new PPD...
4194 if (!cupsGetOption(option
, num_defaults
, defaults
) &&
4195 (ppdo
= ppdFindOption(ppd
, option
)) != NULL
&&
4196 ppdFindChoice(ppdo
, choice
))
4197 num_defaults
= cupsAddOption(option
, choice
, num_defaults
,
4201 else if (!strncmp(buffer
, "*cupsProtocol:", 14))
4202 strlcpy(cups_protocol
, buffer
, sizeof(cups_protocol
));
4206 #ifdef HAVE_LIBPAPER
4207 else if ((paper_result
= systempapername()) != NULL
)
4210 * Set the default media sizes from the systemwide default...
4213 strlcpy(system_paper
, paper_result
, sizeof(system_paper
));
4214 system_paper
[0] = toupper(system_paper
[0] & 255);
4216 if ((!strcmp(system_paper
, "Letter") && have_letter
) ||
4217 (!strcmp(system_paper
, "A4") && have_a4
))
4219 num_defaults
= cupsAddOption("PageSize", system_paper
,
4220 num_defaults
, &defaults
);
4221 num_defaults
= cupsAddOption("PageRegion", system_paper
,
4222 num_defaults
, &defaults
);
4223 num_defaults
= cupsAddOption("PaperDimension", system_paper
,
4224 num_defaults
, &defaults
);
4225 num_defaults
= cupsAddOption("ImageableArea", system_paper
,
4226 num_defaults
, &defaults
);
4229 #endif /* HAVE_LIBPAPER */
4233 * Add the default media sizes...
4235 * Note: These values are generally not valid for large-format devices
4236 * like plotters, however it is probably safe to say that those
4237 * users will configure the media size after initially adding
4238 * the device anyways...
4241 if (!DefaultLanguage
||
4242 !strcasecmp(DefaultLanguage
, "C") ||
4243 !strcasecmp(DefaultLanguage
, "POSIX") ||
4244 !strcasecmp(DefaultLanguage
, "en") ||
4245 !strncasecmp(DefaultLanguage
, "en.", 3) ||
4246 !strncasecmp(DefaultLanguage
, "en_US", 5) ||
4247 !strncasecmp(DefaultLanguage
, "en_CA", 5) ||
4248 !strncasecmp(DefaultLanguage
, "fr_CA", 5))
4251 * These are the only locales that will default to "letter" size...
4256 num_defaults
= cupsAddOption("PageSize", "Letter", num_defaults
,
4258 num_defaults
= cupsAddOption("PageRegion", "Letter", num_defaults
,
4260 num_defaults
= cupsAddOption("PaperDimension", "Letter", num_defaults
,
4262 num_defaults
= cupsAddOption("ImageableArea", "Letter", num_defaults
,
4269 * The rest default to "a4" size...
4272 num_defaults
= cupsAddOption("PageSize", "A4", num_defaults
,
4274 num_defaults
= cupsAddOption("PageRegion", "A4", num_defaults
,
4276 num_defaults
= cupsAddOption("PaperDimension", "A4", num_defaults
,
4278 num_defaults
= cupsAddOption("ImageableArea", "A4", num_defaults
,
4286 * Open the source file for a copy...
4289 if ((src
= cupsFileOpen(tempfile
, "rb")) == NULL
)
4291 cupsFreeOptions(num_defaults
, defaults
);
4297 * Open the destination file for a copy...
4300 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
4302 cupsFreeOptions(num_defaults
, defaults
);
4309 * Copy the source file to the destination...
4312 while (cupsFileGets(src
, buffer
, sizeof(buffer
)))
4314 if (!strncmp(buffer
, "*Default", 8))
4317 * Check for an previous default option choice...
4320 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
4321 choice
, sizeof(choice
)))
4323 const char *val
; /* Default option value */
4326 if ((val
= cupsGetOption(option
, num_defaults
, defaults
)) != NULL
)
4329 * Substitute the previous choice...
4332 snprintf(buffer
, sizeof(buffer
), "*Default%s: %s", option
, val
);
4337 cupsFilePrintf(dst
, "%s\n", buffer
);
4340 if (cups_protocol
[0])
4341 cupsFilePrintf(dst
, "%s\n", cups_protocol
);
4343 cupsFreeOptions(num_defaults
, defaults
);
4346 * Close both files and return...
4353 return (cupsFileClose(dst
));
4358 * 'copy_job_attrs()' - Copy job attributes.
4362 copy_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
4363 cupsd_job_t
*job
, /* I - Job */
4364 cups_array_t
*ra
) /* I - Requested attributes array */
4366 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
4370 * Send the requested attributes for each job...
4373 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
4374 con
->servername
, con
->serverport
, "/jobs/%d",
4377 if (!ra
|| cupsArrayFind(ra
, "job-more-info"))
4378 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4379 "job-more-info", NULL
, job_uri
);
4381 if (job
->state_value
> IPP_JOB_PROCESSING
&&
4382 (!ra
|| cupsArrayFind(ra
, "job-preserved")))
4383 ippAddBoolean(con
->response
, IPP_TAG_JOB
, "job-preserved",
4384 job
->num_files
> 0);
4386 if (!ra
|| cupsArrayFind(ra
, "job-printer-up-time"))
4387 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4388 "job-printer-up-time", time(NULL
));
4390 if (!ra
|| cupsArrayFind(ra
, "job-state-reasons"))
4391 add_job_state_reasons(con
, job
);
4393 if (!ra
|| cupsArrayFind(ra
, "job-uri"))
4394 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4395 "job-uri", NULL
, job_uri
);
4397 copy_attrs(con
->response
, job
->attrs
, ra
, IPP_TAG_JOB
, 0);
4402 * 'copy_printer_attrs()' - Copy printer attributes.
4407 cupsd_client_t
*con
, /* I - Client connection */
4408 cupsd_printer_t
*printer
, /* I - Printer */
4409 cups_array_t
*ra
) /* I - Requested attributes array */
4411 char printer_uri
[HTTP_MAX_URI
];
4413 time_t curtime
; /* Current time */
4414 int i
; /* Looping var */
4415 ipp_attribute_t
*history
; /* History collection */
4419 * Copy the printer attributes to the response using requested-attributes
4420 * and document-format attributes that may be provided by the client.
4423 curtime
= time(NULL
);
4426 if ((!ra
|| cupsArrayFind(ra
, "com.apple.print.recoverable-message")) &&
4427 printer
->recoverable
)
4428 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4429 "com.apple.print.recoverable-message", NULL
,
4430 printer
->recoverable
);
4431 #endif /* __APPLE__ */
4433 if (!ra
|| cupsArrayFind(ra
, "printer-current-time"))
4434 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-current-time",
4435 ippTimeToDate(curtime
));
4437 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy"))
4438 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4439 "printer-error-policy", NULL
, printer
->error_policy
);
4441 if (!ra
|| cupsArrayFind(ra
, "printer-is-accepting-jobs"))
4442 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
4443 printer
->accepting
);
4445 if (!ra
|| cupsArrayFind(ra
, "printer-is-shared"))
4446 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-shared",
4449 if (!ra
|| cupsArrayFind(ra
, "printer-op-policy"))
4450 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4451 "printer-op-policy", NULL
, printer
->op_policy
);
4453 if (!ra
|| cupsArrayFind(ra
, "printer-state"))
4454 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
4457 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-time"))
4458 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4459 "printer-state-change-time", printer
->state_time
);
4461 if (MaxPrinterHistory
> 0 && printer
->num_history
> 0 &&
4462 cupsArrayFind(ra
, "printer-state-history"))
4465 * Printer history is only sent if specifically requested, so that
4466 * older CUPS/IPP clients won't barf on the collection attributes.
4469 history
= ippAddCollections(con
->response
, IPP_TAG_PRINTER
,
4470 "printer-state-history",
4471 printer
->num_history
, NULL
);
4473 for (i
= 0; i
< printer
->num_history
; i
++)
4474 copy_attrs(history
->values
[i
].collection
= ippNew(), printer
->history
[i
],
4475 NULL
, IPP_TAG_ZERO
, 0);
4478 if (!ra
|| cupsArrayFind(ra
, "printer-state-message"))
4479 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4480 "printer-state-message", NULL
, printer
->state_message
);
4482 if (!ra
|| cupsArrayFind(ra
, "printer-state-reasons"))
4483 add_printer_state_reasons(con
, printer
);
4485 if (!ra
|| cupsArrayFind(ra
, "printer-type"))
4487 int type
; /* printer-type value */
4491 * Add the CUPS-specific printer-type attribute...
4494 type
= printer
->type
;
4496 if (printer
== DefaultPrinter
)
4497 type
|= CUPS_PRINTER_DEFAULT
;
4499 if (!printer
->accepting
)
4500 type
|= CUPS_PRINTER_REJECTING
;
4502 if (!printer
->shared
)
4503 type
|= CUPS_PRINTER_NOT_SHARED
;
4505 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-type",
4509 if (!ra
|| cupsArrayFind(ra
, "printer-up-time"))
4510 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4511 "printer-up-time", curtime
);
4513 if ((!ra
|| cupsArrayFind(ra
, "printer-uri-supported")) &&
4514 !ippFindAttribute(printer
->attrs
, "printer-uri-supported",
4517 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
4518 "ipp", NULL
, con
->servername
, con
->serverport
,
4519 (printer
->type
& CUPS_PRINTER_CLASS
) ?
4520 "/classes/%s" : "/printers/%s", printer
->name
);
4521 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
4522 "printer-uri-supported", NULL
, printer_uri
);
4523 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-uri-supported=\"%s\"",
4527 if (!ra
|| cupsArrayFind(ra
, "queued-job-count"))
4528 add_queued_job_count(con
, printer
);
4530 copy_attrs(con
->response
, printer
->attrs
, ra
, IPP_TAG_ZERO
, 0);
4531 copy_attrs(con
->response
, CommonData
, ra
, IPP_TAG_ZERO
, IPP_TAG_COPY
);
4536 * 'copy_subscription_attrs()' - Copy subscription attributes.
4540 copy_subscription_attrs(
4541 cupsd_client_t
*con
, /* I - Client connection */
4542 cupsd_subscription_t
*sub
, /* I - Subscription */
4543 cups_array_t
*ra
) /* I - Requested attributes array */
4545 ipp_attribute_t
*attr
; /* Current attribute */
4546 char printer_uri
[HTTP_MAX_URI
];
4548 int count
; /* Number of events */
4549 unsigned mask
; /* Current event mask */
4550 const char *name
; /* Current event name */
4554 * Copy the subscription attributes to the response using the
4555 * requested-attributes attribute that may be provided by the client.
4558 if (!ra
|| cupsArrayFind(ra
, "notify-events"))
4560 if ((name
= cupsdEventName((cupsd_eventmask_t
)sub
->mask
)) != NULL
)
4563 * Simple event list...
4566 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
,
4567 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
4568 "notify-events", NULL
, name
);
4573 * Complex event list...
4576 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
4577 if (sub
->mask
& mask
)
4580 attr
= ippAddStrings(con
->response
, IPP_TAG_SUBSCRIPTION
,
4581 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
4582 "notify-events", count
, NULL
, NULL
);
4584 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
4585 if (sub
->mask
& mask
)
4587 attr
->values
[count
].string
.text
=
4588 (char *)cupsdEventName((cupsd_eventmask_t
)mask
);
4595 if (sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-job-id")))
4596 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
4597 "notify-job-id", sub
->job
->id
);
4599 if (!sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-lease-duration")))
4600 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
4601 "notify-lease-duration", sub
->lease
);
4603 if (sub
->dest
&& (!ra
|| cupsArrayFind(ra
, "notify-printer-uri")))
4605 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
4606 "ipp", NULL
, con
->servername
, con
->serverport
,
4607 "/printers/%s", sub
->dest
->name
);
4608 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
4609 "notify-printer-uri", NULL
, printer_uri
);
4612 if (sub
->recipient
&& (!ra
|| cupsArrayFind(ra
, "notify-recipient-uri")))
4613 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
4614 "notify-recipient-uri", NULL
, sub
->recipient
);
4615 else if (!ra
|| cupsArrayFind(ra
, "notify-pull-method"))
4616 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_KEYWORD
,
4617 "notify-pull-method", NULL
, "ippget");
4619 if (!ra
|| cupsArrayFind(ra
, "notify-subscriber-user-name"))
4620 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_NAME
,
4621 "notify-subscriber-user-name", NULL
, sub
->owner
);
4623 if (!ra
|| cupsArrayFind(ra
, "notify-subscription-id"))
4624 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
4625 "notify-subscription-id", sub
->id
);
4627 if (!ra
|| cupsArrayFind(ra
, "notify-time-interval"))
4628 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
4629 "notify-time-interval", sub
->interval
);
4631 if (sub
->user_data_len
> 0 && (!ra
|| cupsArrayFind(ra
, "notify-user-data")))
4632 ippAddOctetString(con
->response
, IPP_TAG_SUBSCRIPTION
, "notify-user-data",
4633 sub
->user_data
, sub
->user_data_len
);
4638 * 'create_job()' - Print a file to a printer or class.
4642 create_job(cupsd_client_t
*con
, /* I - Client connection */
4643 ipp_attribute_t
*uri
) /* I - Printer URI */
4645 cupsd_printer_t
*printer
; /* Printer */
4646 cupsd_job_t
*job
; /* New job */
4649 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "create_job(%p[%d], %s)", con
,
4650 con
->http
.fd
, uri
->values
[0].string
.text
);
4653 * Is the destination valid?
4656 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
4662 send_ipp_status(con
, IPP_NOT_FOUND
,
4663 _("The printer or class was not found."));
4668 * Create the job object...
4671 if ((job
= add_job(con
, printer
, NULL
)) == NULL
)
4675 * Save and log the job...
4680 cupsdLogMessage(CUPSD_LOG_INFO
, "Job %d created on \"%s\" by \"%s\".",
4681 job
->id
, job
->dest
, job
->username
);
4686 * 'create_requested_array()' - Create an array for the requested-attributes.
4689 static cups_array_t
* /* O - Array of attributes or NULL */
4690 create_requested_array(ipp_t
*request
) /* I - IPP request */
4692 int i
; /* Looping var */
4693 ipp_attribute_t
*requested
; /* requested-attributes attribute */
4694 cups_array_t
*ra
; /* Requested attributes array */
4695 char *value
; /* Current value */
4699 * Get the requested-attributes attribute, and return NULL if we don't
4703 if ((requested
= ippFindAttribute(request
, "requested-attributes",
4704 IPP_TAG_KEYWORD
)) == NULL
)
4708 * If the attribute contains a single "all" keyword, return NULL...
4711 if (requested
->num_values
== 1 &&
4712 !strcmp(requested
->values
[0].string
.text
, "all"))
4716 * Create an array using "strcmp" as the comparison function...
4719 ra
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
4721 for (i
= 0; i
< requested
->num_values
; i
++)
4723 value
= requested
->values
[i
].string
.text
;
4725 if (!strcmp(value
, "job-template"))
4727 cupsArrayAdd(ra
, "copies");
4728 cupsArrayAdd(ra
, "copies-default");
4729 cupsArrayAdd(ra
, "copies-supported");
4730 cupsArrayAdd(ra
, "finishings");
4731 cupsArrayAdd(ra
, "finishings-default");
4732 cupsArrayAdd(ra
, "finishings-supported");
4733 cupsArrayAdd(ra
, "job-hold-until");
4734 cupsArrayAdd(ra
, "job-hold-until-default");
4735 cupsArrayAdd(ra
, "job-hold-until-supported");
4736 cupsArrayAdd(ra
, "job-priority");
4737 cupsArrayAdd(ra
, "job-priority-default");
4738 cupsArrayAdd(ra
, "job-priority-supported");
4739 cupsArrayAdd(ra
, "job-sheets");
4740 cupsArrayAdd(ra
, "job-sheets-default");
4741 cupsArrayAdd(ra
, "job-sheets-supported");
4742 cupsArrayAdd(ra
, "media");
4743 cupsArrayAdd(ra
, "media-default");
4744 cupsArrayAdd(ra
, "media-supported");
4745 cupsArrayAdd(ra
, "multiple-document-handling");
4746 cupsArrayAdd(ra
, "multiple-document-handling-default");
4747 cupsArrayAdd(ra
, "multiple-document-handling-supported");
4748 cupsArrayAdd(ra
, "number-up");
4749 cupsArrayAdd(ra
, "number-up-default");
4750 cupsArrayAdd(ra
, "number-up-supported");
4751 cupsArrayAdd(ra
, "orientation-requested");
4752 cupsArrayAdd(ra
, "orientation-requested-default");
4753 cupsArrayAdd(ra
, "orientation-requested-supported");
4754 cupsArrayAdd(ra
, "page-ranges");
4755 cupsArrayAdd(ra
, "page-ranges-supported");
4756 cupsArrayAdd(ra
, "printer-resolution");
4757 cupsArrayAdd(ra
, "printer-resolution-default");
4758 cupsArrayAdd(ra
, "printer-resolution-supported");
4759 cupsArrayAdd(ra
, "print-quality");
4760 cupsArrayAdd(ra
, "print-quality-default");
4761 cupsArrayAdd(ra
, "print-quality-supported");
4762 cupsArrayAdd(ra
, "sides");
4763 cupsArrayAdd(ra
, "sides-default");
4764 cupsArrayAdd(ra
, "sides-supported");
4766 else if (!strcmp(value
, "job-description"))
4768 cupsArrayAdd(ra
, "date-time-at-completed");
4769 cupsArrayAdd(ra
, "date-time-at-creation");
4770 cupsArrayAdd(ra
, "date-time-at-processing");
4771 cupsArrayAdd(ra
, "job-detailed-status-message");
4772 cupsArrayAdd(ra
, "job-document-access-errors");
4773 cupsArrayAdd(ra
, "job-id");
4774 cupsArrayAdd(ra
, "job-impressions");
4775 cupsArrayAdd(ra
, "job-impressions-completed");
4776 cupsArrayAdd(ra
, "job-k-octets");
4777 cupsArrayAdd(ra
, "job-k-octets-processed");
4778 cupsArrayAdd(ra
, "job-media-sheets");
4779 cupsArrayAdd(ra
, "job-media-sheets-completed");
4780 cupsArrayAdd(ra
, "job-message-from-operator");
4781 cupsArrayAdd(ra
, "job-more-info");
4782 cupsArrayAdd(ra
, "job-name");
4783 cupsArrayAdd(ra
, "job-originating-user-name");
4784 cupsArrayAdd(ra
, "job-printer-up-time");
4785 cupsArrayAdd(ra
, "job-printer-uri");
4786 cupsArrayAdd(ra
, "job-state");
4787 cupsArrayAdd(ra
, "job-state-message");
4788 cupsArrayAdd(ra
, "job-state-reasons");
4789 cupsArrayAdd(ra
, "job-uri");
4790 cupsArrayAdd(ra
, "number-of-documents");
4791 cupsArrayAdd(ra
, "number-of-intervening-jobs");
4792 cupsArrayAdd(ra
, "output-device-assigned");
4793 cupsArrayAdd(ra
, "time-at-completed");
4794 cupsArrayAdd(ra
, "time-at-creation");
4795 cupsArrayAdd(ra
, "time-at-processing");
4797 else if (!strcmp(value
, "printer-description"))
4799 cupsArrayAdd(ra
, "charset-configured");
4800 cupsArrayAdd(ra
, "charset-supported");
4801 cupsArrayAdd(ra
, "color-supported");
4802 cupsArrayAdd(ra
, "compression-supported");
4803 cupsArrayAdd(ra
, "document-format-default");
4804 cupsArrayAdd(ra
, "document-format-supported");
4805 cupsArrayAdd(ra
, "generated-natural-language-supported");
4806 cupsArrayAdd(ra
, "ipp-versions-supported");
4807 cupsArrayAdd(ra
, "job-impressions-supported");
4808 cupsArrayAdd(ra
, "job-k-octets-supported");
4809 cupsArrayAdd(ra
, "job-media-sheets-supported");
4810 cupsArrayAdd(ra
, "multiple-document-jobs-supported");
4811 cupsArrayAdd(ra
, "multiple-operation-time-out");
4812 cupsArrayAdd(ra
, "natural-language-configured");
4813 cupsArrayAdd(ra
, "notify-attributes-supported");
4814 cupsArrayAdd(ra
, "notify-lease-duration-default");
4815 cupsArrayAdd(ra
, "notify-lease-duration-supported");
4816 cupsArrayAdd(ra
, "notify-max-events-supported");
4817 cupsArrayAdd(ra
, "notify-events-default");
4818 cupsArrayAdd(ra
, "notify-events-supported");
4819 cupsArrayAdd(ra
, "notify-pull-method-supported");
4820 cupsArrayAdd(ra
, "notify-schemes-supported");
4821 cupsArrayAdd(ra
, "operations-supported");
4822 cupsArrayAdd(ra
, "pages-per-minute");
4823 cupsArrayAdd(ra
, "pages-per-minute-color");
4824 cupsArrayAdd(ra
, "pdl-override-supported");
4825 cupsArrayAdd(ra
, "printer-current-time");
4826 cupsArrayAdd(ra
, "printer-driver-installer");
4827 cupsArrayAdd(ra
, "printer-info");
4828 cupsArrayAdd(ra
, "printer-is-accepting-jobs");
4829 cupsArrayAdd(ra
, "printer-location");
4830 cupsArrayAdd(ra
, "printer-make-and-model");
4831 cupsArrayAdd(ra
, "printer-message-from-operator");
4832 cupsArrayAdd(ra
, "printer-more-info");
4833 cupsArrayAdd(ra
, "printer-more-info-manufacturer");
4834 cupsArrayAdd(ra
, "printer-name");
4835 cupsArrayAdd(ra
, "printer-state");
4836 cupsArrayAdd(ra
, "printer-state-message");
4837 cupsArrayAdd(ra
, "printer-state-reasons");
4838 cupsArrayAdd(ra
, "printer-up-time");
4839 cupsArrayAdd(ra
, "printer-uri-supported");
4840 cupsArrayAdd(ra
, "queued-job-count");
4841 cupsArrayAdd(ra
, "reference-uri-schemes-supported");
4842 cupsArrayAdd(ra
, "uri-authentication-supported");
4843 cupsArrayAdd(ra
, "uri-security-supported");
4845 else if (!strcmp(value
, "printer-defaults"))
4847 char *name
; /* Option name */
4850 for (name
= (char *)cupsArrayFirst(CommonDefaults
);
4852 name
= (char *)cupsArrayNext(CommonDefaults
))
4853 cupsArrayAdd(ra
, name
);
4855 else if (!strcmp(value
, "subscription-template"))
4857 cupsArrayAdd(ra
, "notify-attributes");
4858 cupsArrayAdd(ra
, "notify-charset");
4859 cupsArrayAdd(ra
, "notify-events");
4860 cupsArrayAdd(ra
, "notify-lease-duration");
4861 cupsArrayAdd(ra
, "notify-natural-language");
4862 cupsArrayAdd(ra
, "notify-pull-method");
4863 cupsArrayAdd(ra
, "notify-recipient-uri");
4864 cupsArrayAdd(ra
, "notify-time-interval");
4865 cupsArrayAdd(ra
, "notify-user-data");
4868 cupsArrayAdd(ra
, value
);
4876 * 'create_subscription()' - Create a notification subscription.
4880 create_subscription(
4881 cupsd_client_t
*con
, /* I - Client connection */
4882 ipp_attribute_t
*uri
) /* I - Printer URI */
4884 http_status_t status
; /* Policy status */
4885 int i
; /* Looping var */
4886 ipp_attribute_t
*attr
; /* Current attribute */
4887 cups_ptype_t dtype
; /* Destination type (printer or class) */
4888 char scheme
[HTTP_MAX_URI
],
4889 /* Scheme portion of URI */
4890 userpass
[HTTP_MAX_URI
],
4891 /* Username portion of URI */
4893 /* Host portion of URI */
4894 resource
[HTTP_MAX_URI
];
4895 /* Resource portion of URI */
4896 int port
; /* Port portion of URI */
4897 cupsd_printer_t
*printer
; /* Printer/class */
4898 cupsd_job_t
*job
; /* Job */
4899 int jobid
; /* Job ID */
4900 cupsd_subscription_t
*sub
; /* Subscription object */
4901 const char *username
, /* requesting-user-name or authenticated username */
4902 *recipient
, /* notify-recipient-uri */
4903 *pullmethod
; /* notify-pull-method */
4904 ipp_attribute_t
*user_data
; /* notify-user-data */
4905 int interval
, /* notify-time-interval */
4906 lease
; /* notify-lease-duration */
4907 unsigned mask
; /* notify-events */
4908 ipp_attribute_t
*notify_events
,/* notify-events(-default) */
4909 *notify_lease
; /* notify-lease-duration(-default) */
4913 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
4915 if (attr
->group_tag
!= IPP_TAG_ZERO
)
4916 cupsdLogMessage(CUPSD_LOG_DEBUG
, "g%04x v%04x %s", attr
->group_tag
,
4917 attr
->value_tag
, attr
->name
);
4919 cupsdLogMessage(CUPSD_LOG_DEBUG
, "----SEP----");
4924 * Is the destination valid?
4927 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4928 "cupsdCreateSubscription(con=%p(%d), uri=\"%s\")",
4929 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
4931 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
4932 sizeof(scheme
), userpass
, sizeof(userpass
), host
,
4933 sizeof(host
), &port
, resource
, sizeof(resource
));
4935 if (!strcmp(resource
, "/"))
4937 dtype
= (cups_ptype_t
)0;
4940 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
4942 dtype
= (cups_ptype_t
)0;
4945 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
4947 dtype
= CUPS_PRINTER_CLASS
;
4950 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
4956 send_ipp_status(con
, IPP_NOT_FOUND
,
4957 _("The printer or class was not found."));
4967 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
4970 send_http_error(con
, status
);
4974 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
4976 send_http_error(con
, status
);
4981 * Get the user that is requesting the subscription...
4984 username
= get_username(con
);
4987 * Find the first subscription group attribute; return if we have
4991 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
4992 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
4997 send_ipp_status(con
, IPP_BAD_REQUEST
,
4998 _("No subscription attributes in request!"));
5003 * Process the subscription attributes in the request...
5006 con
->response
->request
.status
.status_code
= IPP_BAD_REQUEST
;
5014 lease
= DefaultLeaseDuration
;
5016 mask
= CUPSD_EVENT_NONE
;
5020 notify_events
= ippFindAttribute(printer
->attrs
, "notify-events-default",
5022 notify_lease
= ippFindAttribute(printer
->attrs
,
5023 "notify-lease-duration-default",
5027 lease
= notify_lease
->values
[0].integer
;
5031 notify_events
= NULL
;
5032 notify_lease
= NULL
;
5035 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
5037 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
5038 attr
->value_tag
== IPP_TAG_URI
)
5041 * Validate the recipient scheme against the ServerBin/notifier
5045 char notifier
[1024]; /* Notifier filename */
5048 recipient
= attr
->values
[0].string
.text
;
5050 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
5051 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
5052 host
, sizeof(host
), &port
,
5053 resource
, sizeof(resource
)) < HTTP_URI_OK
)
5055 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5056 _("Bad notify-recipient-uri URI \"%s\"!"), recipient
);
5057 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5058 "notify-status-code", IPP_URI_SCHEME
);
5062 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
5064 if (access(notifier
, X_OK
))
5066 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5067 _("notify-recipient-uri URI \"%s\" uses unknown scheme!"),
5069 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5070 "notify-status-code", IPP_URI_SCHEME
);
5074 else if (!strcmp(attr
->name
, "notify-pull-method") &&
5075 attr
->value_tag
== IPP_TAG_KEYWORD
)
5077 pullmethod
= attr
->values
[0].string
.text
;
5079 if (strcmp(pullmethod
, "ippget"))
5081 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5082 _("Bad notify-pull-method \"%s\"!"), pullmethod
);
5083 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5084 "notify-status-code", IPP_ATTRIBUTES
);
5088 else if (!strcmp(attr
->name
, "notify-charset") &&
5089 attr
->value_tag
== IPP_TAG_CHARSET
&&
5090 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
5091 strcmp(attr
->values
[0].string
.text
, "utf-8"))
5093 send_ipp_status(con
, IPP_CHARSET
,
5094 _("Character set \"%s\" not supported!"),
5095 attr
->values
[0].string
.text
);
5098 else if (!strcmp(attr
->name
, "notify-natural-language") &&
5099 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
5100 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
5102 send_ipp_status(con
, IPP_CHARSET
,
5103 _("Language \"%s\" not supported!"),
5104 attr
->values
[0].string
.text
);
5107 else if (!strcmp(attr
->name
, "notify-user-data") &&
5108 attr
->value_tag
== IPP_TAG_STRING
)
5110 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
5112 send_ipp_status(con
, IPP_REQUEST_VALUE
,
5113 _("The notify-user-data value is too large "
5114 "(%d > 63 octets)!"),
5115 attr
->values
[0].unknown
.length
);
5121 else if (!strcmp(attr
->name
, "notify-events") &&
5122 attr
->value_tag
== IPP_TAG_KEYWORD
)
5123 notify_events
= attr
;
5124 else if (!strcmp(attr
->name
, "notify-lease-duration") &&
5125 attr
->value_tag
== IPP_TAG_INTEGER
)
5126 lease
= attr
->values
[0].integer
;
5127 else if (!strcmp(attr
->name
, "notify-time-interval") &&
5128 attr
->value_tag
== IPP_TAG_INTEGER
)
5129 interval
= attr
->values
[0].integer
;
5130 else if (!strcmp(attr
->name
, "notify-job-id") &&
5131 attr
->value_tag
== IPP_TAG_INTEGER
)
5132 jobid
= attr
->values
[0].integer
;
5139 for (i
= 0; i
< notify_events
->num_values
; i
++)
5140 mask
|= cupsdEventValue(notify_events
->values
[i
].string
.text
);
5144 cupsdLogMessage(CUPSD_LOG_DEBUG
, "recipient=\"%s\"", recipient
);
5146 cupsdLogMessage(CUPSD_LOG_DEBUG
, "pullmethod=\"%s\"", pullmethod
);
5147 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-lease-duration=%d", lease
);
5148 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-time-interval=%d", interval
);
5150 if (!recipient
&& !pullmethod
)
5153 if (mask
== CUPSD_EVENT_NONE
)
5156 mask
= CUPSD_EVENT_JOB_COMPLETED
;
5158 mask
= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
5161 send_ipp_status(con
, IPP_BAD_REQUEST
,
5162 _("notify-events not specified!"));
5167 if (MaxLeaseDuration
&& (lease
== 0 || lease
> MaxLeaseDuration
))
5169 cupsdLogMessage(CUPSD_LOG_INFO
,
5170 "create_subscription: Limiting notify-lease-duration to "
5173 lease
= MaxLeaseDuration
;
5178 if ((job
= cupsdFindJob(jobid
)) == NULL
)
5180 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job %d not found!"), jobid
);
5187 sub
= cupsdAddSubscription(mask
, printer
, job
, recipient
, 0);
5190 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
5193 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5194 "Added subscription %d for printer \"%s\"",
5195 sub
->id
, printer
->name
);
5197 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for server",
5200 sub
->interval
= interval
;
5202 sub
->expire
= lease
? time(NULL
) + lease
: 0;
5204 cupsdSetString(&sub
->owner
, username
);
5208 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
5209 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
5210 sub
->user_data_len
);
5213 ippAddSeparator(con
->response
);
5214 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5215 "notify-subscription-id", sub
->id
);
5217 con
->response
->request
.status
.status_code
= IPP_OK
;
5223 cupsdSaveAllSubscriptions();
5229 * 'delete_printer()' - Remove a printer or class from the system.
5233 delete_printer(cupsd_client_t
*con
, /* I - Client connection */
5234 ipp_attribute_t
*uri
) /* I - URI of printer or class */
5236 http_status_t status
; /* Policy status */
5237 cups_ptype_t dtype
; /* Destination type (printer or class) */
5238 cupsd_printer_t
*printer
; /* Printer/class */
5239 char filename
[1024]; /* Script/PPD filename */
5242 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "delete_printer(%p[%d], %s)", con
,
5243 con
->http
.fd
, uri
->values
[0].string
.text
);
5246 * Do we have a valid URI?
5249 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
5255 send_ipp_status(con
, IPP_NOT_FOUND
,
5256 _("The printer or class was not found."));
5264 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5266 send_http_error(con
, status
);
5271 * Remove old jobs...
5274 cupsdCancelJobs(printer
->name
, NULL
, 1);
5277 * Remove old subscriptions and send a "deleted printer" event...
5280 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED
, printer
, NULL
,
5281 "%s \"%s\" deleted by \"%s\".",
5282 (dtype
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
5283 printer
->name
, get_username(con
));
5285 cupsdExpireSubscriptions(printer
, NULL
);
5288 * Remove any old PPD or script files...
5291 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
,
5295 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
5299 if (dtype
& CUPS_PRINTER_CLASS
)
5301 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" deleted by \"%s\".",
5302 printer
->name
, get_username(con
));
5304 cupsdDeletePrinter(printer
, 0);
5305 cupsdSaveAllClasses();
5309 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" deleted by \"%s\".",
5310 printer
->name
, get_username(con
));
5312 cupsdDeletePrinter(printer
, 0);
5313 cupsdSaveAllPrinters();
5316 cupsdWritePrintcap();
5319 * Return with no errors...
5322 con
->response
->request
.status
.status_code
= IPP_OK
;
5327 * 'get_default()' - Get the default destination.
5331 get_default(cupsd_client_t
*con
) /* I - Client connection */
5333 http_status_t status
; /* Policy status */
5334 cups_array_t
*ra
; /* Requested attributes array */
5337 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_default(%p[%d])", con
, con
->http
.fd
);
5343 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5345 send_http_error(con
, status
);
5351 ra
= create_requested_array(con
->request
);
5353 copy_printer_attrs(con
, DefaultPrinter
, ra
);
5355 cupsArrayDelete(ra
);
5357 con
->response
->request
.status
.status_code
= IPP_OK
;
5360 send_ipp_status(con
, IPP_NOT_FOUND
, _("No default printer"));
5365 * 'get_devices()' - Get the list of available devices on the local system.
5369 get_devices(cupsd_client_t
*con
) /* I - Client connection */
5371 http_status_t status
; /* Policy status */
5372 ipp_attribute_t
*limit
, /* Limit attribute */
5373 *requested
; /* requested-attributes attribute */
5374 char command
[1024], /* cups-deviced command */
5375 options
[1024], /* Options to pass to command */
5377 /* String for requested attributes */
5380 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_devices(%p[%d])", con
, con
->http
.fd
);
5386 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5388 send_http_error(con
, status
);
5393 * Run cups-deviced command with the given options...
5396 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
5397 requested
= ippFindAttribute(con
->request
, "requested-attributes",
5401 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
5403 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
5405 snprintf(command
, sizeof(command
), "%s/daemon/cups-deviced", ServerBin
);
5406 snprintf(options
, sizeof(options
),
5408 con
->request
->request
.op
.request_id
,
5409 limit
? limit
->values
[0].integer
: 0, (int)User
,
5412 if (cupsdSendCommand(con
, command
, options
, 1))
5415 * Command started successfully, don't send an IPP response here...
5418 ippDelete(con
->response
);
5419 con
->response
= NULL
;
5424 * Command failed, return "internal error" so the user knows something
5428 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
5429 _("cups-deviced failed to execute."));
5435 * 'get_job_attrs()' - Get job attributes.
5439 get_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
5440 ipp_attribute_t
*uri
) /* I - Job URI */
5442 http_status_t status
; /* Policy status */
5443 ipp_attribute_t
*attr
; /* Current attribute */
5444 int jobid
; /* Job ID */
5445 cupsd_job_t
*job
; /* Current job */
5446 char method
[HTTP_MAX_URI
], /* Method portion of URI */
5447 username
[HTTP_MAX_URI
], /* Username portion of URI */
5448 host
[HTTP_MAX_URI
], /* Host portion of URI */
5449 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
5450 int port
; /* Port portion of URI */
5451 cups_array_t
*ra
; /* Requested attributes array */
5454 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_job_attrs(%p[%d], %s)", con
,
5455 con
->http
.fd
, uri
->values
[0].string
.text
);
5458 * See if we have a job URI or a printer URI...
5461 if (!strcmp(uri
->name
, "printer-uri"))
5464 * Got a printer URI; see if we also have a job-id attribute...
5467 if ((attr
= ippFindAttribute(con
->request
, "job-id",
5468 IPP_TAG_INTEGER
)) == NULL
)
5470 send_ipp_status(con
, IPP_BAD_REQUEST
,
5471 _("Got a printer-uri attribute but no job-id!"));
5475 jobid
= attr
->values
[0].integer
;
5480 * Got a job URI; parse it to get the job ID...
5483 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
5484 sizeof(method
), username
, sizeof(username
), host
,
5485 sizeof(host
), &port
, resource
, sizeof(resource
));
5487 if (strncmp(resource
, "/jobs/", 6))
5493 send_ipp_status(con
, IPP_BAD_REQUEST
,
5494 _("Bad job-uri attribute \"%s\"!"),
5495 uri
->values
[0].string
.text
);
5499 jobid
= atoi(resource
+ 6);
5503 * See if the job exists...
5506 if ((job
= cupsdFindJob(jobid
)) == NULL
)
5509 * Nope - return a "not found" error...
5512 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
5520 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5522 send_http_error(con
, status
);
5527 * Copy attributes...
5532 ra
= create_requested_array(con
->request
);
5533 copy_job_attrs(con
, job
, ra
);
5534 cupsArrayDelete(ra
);
5536 con
->response
->request
.status
.status_code
= IPP_OK
;
5541 * 'get_jobs()' - Get a list of jobs for the specified printer.
5545 get_jobs(cupsd_client_t
*con
, /* I - Client connection */
5546 ipp_attribute_t
*uri
) /* I - Printer URI */
5548 http_status_t status
; /* Policy status */
5549 ipp_attribute_t
*attr
; /* Current attribute */
5550 const char *dest
; /* Destination */
5551 cups_ptype_t dtype
; /* Destination type (printer or class) */
5552 cups_ptype_t dmask
; /* Destination type mask */
5553 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
5554 username
[HTTP_MAX_URI
], /* Username portion of URI */
5555 host
[HTTP_MAX_URI
], /* Host portion of URI */
5556 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
5557 int port
; /* Port portion of URI */
5558 int completed
; /* Completed jobs? */
5559 int first_job_id
; /* First job ID */
5560 int limit
; /* Maximum number of jobs to return */
5561 int count
; /* Number of jobs that match */
5562 cupsd_job_t
*job
; /* Current job pointer */
5563 cupsd_printer_t
*printer
; /* Printer */
5564 cups_array_t
*list
; /* Which job list... */
5565 cups_array_t
*ra
; /* Requested attributes array */
5568 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs(%p[%d], %s)", con
, con
->http
.fd
,
5569 uri
->values
[0].string
.text
);
5572 * Is the destination valid?
5575 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
5576 sizeof(scheme
), username
, sizeof(username
), host
,
5577 sizeof(host
), &port
, resource
, sizeof(resource
));
5579 if (!strcmp(resource
, "/") ||
5580 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6))
5583 dtype
= (cups_ptype_t
)0;
5584 dmask
= (cups_ptype_t
)0;
5587 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
5590 dtype
= (cups_ptype_t
)0;
5591 dmask
= CUPS_PRINTER_CLASS
;
5594 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
5597 dtype
= CUPS_PRINTER_CLASS
;
5598 dmask
= CUPS_PRINTER_CLASS
;
5601 else if ((dest
= cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
,
5608 send_ipp_status(con
, IPP_NOT_FOUND
,
5609 _("The printer or class was not found."));
5614 dtype
&= CUPS_PRINTER_CLASS
;
5615 dmask
= CUPS_PRINTER_CLASS
;
5624 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
5627 send_http_error(con
, status
);
5631 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5633 send_http_error(con
, status
);
5638 * See if the "which-jobs" attribute have been specified...
5641 if ((attr
= ippFindAttribute(con
->request
, "which-jobs",
5642 IPP_TAG_KEYWORD
)) != NULL
&&
5643 !strcmp(attr
->values
[0].string
.text
, "completed"))
5648 else if (attr
&& !strcmp(attr
->values
[0].string
.text
, "all"))
5660 * See if they want to limit the number of jobs reported...
5663 if ((attr
= ippFindAttribute(con
->request
, "limit",
5664 IPP_TAG_INTEGER
)) != NULL
)
5665 limit
= attr
->values
[0].integer
;
5669 if ((attr
= ippFindAttribute(con
->request
, "first-job-id",
5670 IPP_TAG_INTEGER
)) != NULL
)
5671 first_job_id
= attr
->values
[0].integer
;
5676 * See if we only want to see jobs for a specific user...
5679 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
5680 IPP_TAG_BOOLEAN
)) != NULL
&&
5681 attr
->values
[0].boolean
)
5682 strlcpy(username
, get_username(con
), sizeof(username
));
5686 ra
= create_requested_array(con
->request
);
5689 * OK, build a list of jobs for this printer...
5692 for (count
= 0, job
= (cupsd_job_t
*)cupsArrayFirst(list
);
5693 count
< limit
&& job
;
5694 job
= (cupsd_job_t
*)cupsArrayNext(list
))
5697 * Filter out jobs that don't match...
5700 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: job->id = %d", job
->id
);
5702 if ((dest
&& strcmp(job
->dest
, dest
)) &&
5703 (!job
->printer
|| !dest
|| strcmp(job
->printer
->name
, dest
)))
5705 if ((job
->dtype
& dmask
) != dtype
&&
5706 (!job
->printer
|| (job
->printer
->type
& dmask
) != dtype
))
5708 if (completed
&& job
->state_value
<= IPP_JOB_STOPPED
)
5711 if (job
->id
< first_job_id
)
5719 if (username
[0] && strcasecmp(username
, job
->username
))
5723 ippAddSeparator(con
->response
);
5727 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: count = %d", count
);
5729 copy_job_attrs(con
, job
, ra
);
5732 cupsArrayDelete(ra
);
5734 con
->response
->request
.status
.status_code
= IPP_OK
;
5739 * 'get_notifications()' - Get events for a subscription.
5743 get_notifications(cupsd_client_t
*con
) /* I - Client connection */
5745 int i
, j
; /* Looping vars */
5746 http_status_t status
; /* Policy status */
5747 cupsd_subscription_t
*sub
; /* Subscription */
5748 ipp_attribute_t
*ids
, /* notify-subscription-ids */
5749 *sequences
; /* notify-sequence-numbers */
5750 int min_seq
; /* Minimum sequence number */
5751 int interval
; /* Poll interval */
5754 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_notifications(con=%p[%d])",
5758 * Get subscription attributes...
5761 ids
= ippFindAttribute(con
->request
, "notify-subscription-ids",
5763 sequences
= ippFindAttribute(con
->request
, "notify-sequence-numbers",
5768 send_ipp_status(con
, IPP_BAD_REQUEST
,
5769 _("Missing notify-subscription-ids attribute!"));
5774 * Are the subscription IDs valid?
5777 for (i
= 0, interval
= 60; i
< ids
->num_values
; i
++)
5779 if ((sub
= cupsdFindSubscription(ids
->values
[i
].integer
)) == NULL
)
5782 * Bad subscription ID...
5785 send_ipp_status(con
, IPP_NOT_FOUND
,
5786 _("notify-subscription-id %d no good!"),
5787 ids
->values
[i
].integer
);
5795 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
5797 con
, sub
->owner
)) != HTTP_OK
)
5799 send_http_error(con
, status
);
5804 * Check the subscription type and update the interval accordingly.
5807 if (sub
->job
&& sub
->job
->state_value
== IPP_JOB_PROCESSING
&&
5810 else if (sub
->job
&& sub
->job
->state_value
>= IPP_JOB_STOPPED
)
5812 else if (sub
->dest
&& sub
->dest
->state
== IPP_PRINTER_PROCESSING
&&
5818 * Tell the client to poll again in N seconds...
5822 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
5823 "notify-get-interval", interval
);
5825 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
5826 "printer-up-time", time(NULL
));
5829 * Copy the subscription event attributes to the response.
5832 con
->response
->request
.status
.status_code
=
5833 interval
? IPP_OK
: IPP_OK_EVENTS_COMPLETE
;
5835 for (i
= 0; i
< ids
->num_values
; i
++)
5838 * Get the subscription and sequence number...
5841 sub
= cupsdFindSubscription(ids
->values
[i
].integer
);
5843 if (sequences
&& i
< sequences
->num_values
)
5844 min_seq
= sequences
->values
[i
].integer
;
5849 * If we don't have any new events, nothing to do here...
5852 if (min_seq
> (sub
->first_event_id
+ sub
->num_events
))
5856 * Otherwise copy all of the new events...
5859 if (sub
->first_event_id
> min_seq
)
5862 j
= min_seq
- sub
->first_event_id
;
5864 for (; j
< sub
->num_events
; j
++)
5866 ippAddSeparator(con
->response
);
5868 copy_attrs(con
->response
, sub
->events
[j
]->attrs
, NULL
,
5869 IPP_TAG_EVENT_NOTIFICATION
, 0);
5876 * 'get_ppds()' - Get the list of PPD files on the local system.
5880 get_ppds(cupsd_client_t
*con
) /* I - Client connection */
5882 http_status_t status
; /* Policy status */
5883 ipp_attribute_t
*limit
, /* Limit attribute */
5884 *make
, /* ppd-make attribute */
5885 *requested
; /* requested-attributes attribute */
5886 char command
[1024], /* cups-deviced command */
5887 options
[1024], /* Options to pass to command */
5889 /* String for requested attributes */
5890 make_str
[256]; /* Escaped ppd-make string */
5893 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppds(%p[%d])", con
, con
->http
.fd
);
5899 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5901 send_http_error(con
, status
);
5906 * Run cups-driverd command with the given options...
5909 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
5910 make
= ippFindAttribute(con
->request
, "ppd-make", IPP_TAG_TEXT
);
5911 requested
= ippFindAttribute(con
->request
, "requested-attributes",
5915 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
5917 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
5920 url_encode_attr(make
, make_str
, sizeof(make_str
));
5924 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
5925 snprintf(options
, sizeof(options
), "list+%d+%d+%s%s%s",
5926 con
->request
->request
.op
.request_id
,
5927 limit
? limit
->values
[0].integer
: 0,
5928 requested_str
, make
? "%20" : "", make_str
);
5930 if (cupsdSendCommand(con
, command
, options
, 0))
5933 * Command started successfully, don't send an IPP response here...
5936 ippDelete(con
->response
);
5937 con
->response
= NULL
;
5942 * Command failed, return "internal error" so the user knows something
5946 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
5947 _("cups-driverd failed to execute."));
5953 * 'get_printer_attrs()' - Get printer attributes.
5957 get_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
5958 ipp_attribute_t
*uri
) /* I - Printer URI */
5960 http_status_t status
; /* Policy status */
5961 cups_ptype_t dtype
; /* Destination type (printer or class) */
5962 cupsd_printer_t
*printer
; /* Printer/class */
5963 cups_array_t
*ra
; /* Requested attributes array */
5966 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_attrs(%p[%d], %s)", con
,
5967 con
->http
.fd
, uri
->values
[0].string
.text
);
5970 * Is the destination valid?
5973 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
5979 send_ipp_status(con
, IPP_NOT_FOUND
,
5980 _("The printer or class was not found."));
5988 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
5990 send_http_error(con
, status
);
5995 * Send the attributes...
5998 ra
= create_requested_array(con
->request
);
6000 copy_printer_attrs(con
, printer
, ra
);
6002 cupsArrayDelete(ra
);
6004 con
->response
->request
.status
.status_code
= IPP_OK
;
6009 * 'get_printers()' - Get a list of printers or classes.
6013 get_printers(cupsd_client_t
*con
, /* I - Client connection */
6014 int type
) /* I - 0 or CUPS_PRINTER_CLASS */
6016 http_status_t status
; /* Policy status */
6017 ipp_attribute_t
*attr
; /* Current attribute */
6018 int limit
; /* Maximum number of printers to return */
6019 int count
; /* Number of printers that match */
6020 cupsd_printer_t
*printer
; /* Current printer pointer */
6021 int printer_type
, /* printer-type attribute */
6022 printer_mask
; /* printer-type-mask attribute */
6023 char *location
; /* Location string */
6024 const char *username
; /* Current user */
6025 char *first_printer_name
; /* first-printer-name attribute */
6026 cups_array_t
*ra
; /* Requested attributes array */
6029 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printers(%p[%d], %x)", con
,
6030 con
->http
.fd
, type
);
6036 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6038 send_http_error(con
, status
);
6043 * Check for printers...
6046 if (!Printers
|| !cupsArrayCount(Printers
))
6048 send_ipp_status(con
, IPP_NOT_FOUND
, _("No destinations added."));
6053 * See if they want to limit the number of printers reported...
6056 if ((attr
= ippFindAttribute(con
->request
, "limit",
6057 IPP_TAG_INTEGER
)) != NULL
)
6058 limit
= attr
->values
[0].integer
;
6062 if ((attr
= ippFindAttribute(con
->request
, "first-printer-name",
6063 IPP_TAG_NAME
)) != NULL
)
6064 first_printer_name
= attr
->values
[0].string
.text
;
6066 first_printer_name
= NULL
;
6069 * Support filtering...
6072 if ((attr
= ippFindAttribute(con
->request
, "printer-type",
6073 IPP_TAG_ENUM
)) != NULL
)
6074 printer_type
= attr
->values
[0].integer
;
6078 if ((attr
= ippFindAttribute(con
->request
, "printer-type-mask",
6079 IPP_TAG_ENUM
)) != NULL
)
6080 printer_mask
= attr
->values
[0].integer
;
6084 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
6085 IPP_TAG_TEXT
)) != NULL
)
6086 location
= attr
->values
[0].string
.text
;
6090 if (con
->username
[0])
6091 username
= con
->username
;
6092 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
6093 IPP_TAG_NAME
)) != NULL
)
6094 username
= attr
->values
[0].string
.text
;
6098 ra
= create_requested_array(con
->request
);
6101 * OK, build a list of printers for this printer...
6104 if (first_printer_name
)
6106 if ((printer
= cupsdFindDest(first_printer_name
)) == NULL
)
6107 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
6110 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
6113 count
< limit
&& printer
;
6114 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
6116 if ((!type
|| (printer
->type
& CUPS_PRINTER_CLASS
) == type
) &&
6117 (printer
->type
& printer_mask
) == printer_type
&&
6118 (!location
|| !printer
->location
||
6119 !strcasecmp(printer
->location
, location
)))
6122 * If HideImplicitMembers is enabled, see if this printer or class
6123 * is a member of an implicit class...
6126 if (ImplicitClasses
&& HideImplicitMembers
&&
6127 printer
->in_implicit_class
)
6131 * If a username is specified, see if it is allowed or denied
6135 if (printer
->num_users
&& username
&& !user_allowed(printer
, username
))
6139 * Add the group separator as needed...
6143 ippAddSeparator(con
->response
);
6148 * Send the attributes...
6151 copy_printer_attrs(con
, printer
, ra
);
6155 cupsArrayDelete(ra
);
6157 con
->response
->request
.status
.status_code
= IPP_OK
;
6162 * 'get_subscription_attrs()' - Get subscription attributes.
6166 get_subscription_attrs(
6167 cupsd_client_t
*con
, /* I - Client connection */
6168 int sub_id
) /* I - Subscription ID */
6170 http_status_t status
; /* Policy status */
6171 cupsd_subscription_t
*sub
; /* Subscription */
6172 cups_array_t
*ra
; /* Requested attributes array */
6175 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
6176 "get_subscription_attrs(con=%p[%d], sub_id=%d)",
6177 con
, con
->http
.fd
, sub_id
);
6180 * Is the subscription ID valid?
6183 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
6186 * Bad subscription ID...
6189 send_ipp_status(con
, IPP_NOT_FOUND
,
6190 _("notify-subscription-id %d no good!"), sub_id
);
6198 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
6200 con
, sub
->owner
)) != HTTP_OK
)
6202 send_http_error(con
, status
);
6207 * Copy the subscription attributes to the response using the
6208 * requested-attributes attribute that may be provided by the client.
6211 ra
= create_requested_array(con
->request
);
6213 copy_subscription_attrs(con
, sub
, ra
);
6215 cupsArrayDelete(ra
);
6217 con
->response
->request
.status
.status_code
= IPP_OK
;
6222 * 'get_subscriptions()' - Get subscriptions.
6226 get_subscriptions(cupsd_client_t
*con
, /* I - Client connection */
6227 ipp_attribute_t
*uri
) /* I - Printer/job URI */
6229 http_status_t status
; /* Policy status */
6230 int count
; /* Number of subscriptions */
6231 int limit
; /* Limit */
6232 cupsd_subscription_t
*sub
; /* Subscription */
6233 cups_array_t
*ra
; /* Requested attributes array */
6234 ipp_attribute_t
*attr
; /* Attribute */
6235 cups_ptype_t dtype
; /* Destination type (printer or class) */
6236 char scheme
[HTTP_MAX_URI
],
6237 /* Scheme portion of URI */
6238 username
[HTTP_MAX_URI
],
6239 /* Username portion of URI */
6241 /* Host portion of URI */
6242 resource
[HTTP_MAX_URI
];
6243 /* Resource portion of URI */
6244 int port
; /* Port portion of URI */
6245 cupsd_job_t
*job
; /* Job pointer */
6246 cupsd_printer_t
*printer
; /* Printer */
6249 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
6250 "get_subscriptions(con=%p[%d], uri=%s)",
6251 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
6254 * Is the destination valid?
6257 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6258 sizeof(scheme
), username
, sizeof(username
), host
,
6259 sizeof(host
), &port
, resource
, sizeof(resource
));
6261 if (!strcmp(resource
, "/") ||
6262 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6) ||
6263 (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10) ||
6264 (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9))
6269 else if (!strncmp(resource
, "/jobs/", 6) && resource
[6])
6272 job
= cupsdFindJob(atoi(resource
+ 6));
6276 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%s does not exist!"),
6281 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6287 send_ipp_status(con
, IPP_NOT_FOUND
,
6288 _("The printer or class was not found."));
6291 else if ((attr
= ippFindAttribute(con
->request
, "notify-job-id",
6292 IPP_TAG_INTEGER
)) != NULL
)
6294 job
= cupsdFindJob(attr
->values
[0].integer
);
6298 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"),
6299 attr
->values
[0].integer
);
6310 if ((status
= cupsdCheckPolicy(printer
? printer
->op_policy_ptr
:
6312 con
, NULL
)) != HTTP_OK
)
6314 send_http_error(con
, status
);
6319 * Copy the subscription attributes to the response using the
6320 * requested-attributes attribute that may be provided by the client.
6323 ra
= create_requested_array(con
->request
);
6325 if ((attr
= ippFindAttribute(con
->request
, "limit",
6326 IPP_TAG_INTEGER
)) != NULL
)
6327 limit
= attr
->values
[0].integer
;
6332 * See if we only want to see subscriptions for a specific user...
6335 if ((attr
= ippFindAttribute(con
->request
, "my-subscriptions",
6336 IPP_TAG_BOOLEAN
)) != NULL
&&
6337 attr
->values
[0].boolean
)
6338 strlcpy(username
, get_username(con
), sizeof(username
));
6342 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
), count
= 0;
6344 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
6345 if ((!printer
|| sub
->dest
== printer
) && (!job
|| sub
->job
== job
) &&
6346 (!username
[0] || !strcasecmp(username
, sub
->owner
)))
6348 ippAddSeparator(con
->response
);
6349 copy_subscription_attrs(con
, sub
, ra
);
6352 if (limit
&& count
>= limit
)
6356 cupsArrayDelete(ra
);
6359 con
->response
->request
.status
.status_code
= IPP_OK
;
6361 send_ipp_status(con
, IPP_NOT_FOUND
, _("No subscriptions found."));
6366 * 'get_username()' - Get the username associated with a request.
6369 static const char * /* O - Username */
6370 get_username(cupsd_client_t
*con
) /* I - Connection */
6372 ipp_attribute_t
*attr
; /* Attribute */
6375 if (con
->username
[0])
6376 return (con
->username
);
6377 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
6378 IPP_TAG_NAME
)) != NULL
)
6379 return (attr
->values
[0].string
.text
);
6381 return ("anonymous");
6386 * 'hold_job()' - Hold a print job.
6390 hold_job(cupsd_client_t
*con
, /* I - Client connection */
6391 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
6393 ipp_attribute_t
*attr
, /* Current job-hold-until */
6394 *newattr
; /* New job-hold-until */
6395 int jobid
; /* Job ID */
6396 char method
[HTTP_MAX_URI
], /* Method portion of URI */
6397 username
[HTTP_MAX_URI
], /* Username portion of URI */
6398 host
[HTTP_MAX_URI
], /* Host portion of URI */
6399 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6400 int port
; /* Port portion of URI */
6401 cupsd_job_t
*job
; /* Job information */
6404 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_job(%p[%d], %s)", con
, con
->http
.fd
,
6405 uri
->values
[0].string
.text
);
6408 * See if we have a job URI or a printer URI...
6411 if (!strcmp(uri
->name
, "printer-uri"))
6414 * Got a printer URI; see if we also have a job-id attribute...
6417 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6418 IPP_TAG_INTEGER
)) == NULL
)
6420 send_ipp_status(con
, IPP_BAD_REQUEST
,
6421 _("Got a printer-uri attribute but no job-id!"));
6425 jobid
= attr
->values
[0].integer
;
6430 * Got a job URI; parse it to get the job ID...
6433 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
6434 sizeof(method
), username
, sizeof(username
), host
,
6435 sizeof(host
), &port
, resource
, sizeof(resource
));
6437 if (strncmp(resource
, "/jobs/", 6))
6443 send_ipp_status(con
, IPP_BAD_REQUEST
,
6444 _("Bad job-uri attribute \"%s\"!"),
6445 uri
->values
[0].string
.text
);
6449 jobid
= atoi(resource
+ 6);
6453 * See if the job exists...
6456 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6459 * Nope - return a "not found" error...
6462 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
6467 * See if the job is owned by the requesting user...
6470 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
6472 send_http_error(con
, HTTP_UNAUTHORIZED
);
6477 * Hold the job and return...
6482 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, job
->printer
, job
,
6483 "Job held by user.");
6485 if ((newattr
= ippFindAttribute(con
->request
, "job-hold-until",
6486 IPP_TAG_KEYWORD
)) == NULL
)
6487 newattr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
6489 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
6490 IPP_TAG_KEYWORD
)) == NULL
)
6491 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
6496 * Free the old hold value and copy the new one over...
6499 _cupsStrFree(attr
->values
[0].string
.text
);
6503 attr
->value_tag
= newattr
->value_tag
;
6504 attr
->values
[0].string
.text
=
6505 _cupsStrAlloc(newattr
->values
[0].string
.text
);
6509 attr
->value_tag
= IPP_TAG_KEYWORD
;
6510 attr
->values
[0].string
.text
= _cupsStrAlloc("indefinite");
6514 * Hold job until specified time...
6517 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
);
6519 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, job
->printer
, job
,
6520 "Job job-hold-until value changed by user.");
6523 cupsdLogMessage(CUPSD_LOG_INFO
, "Job %d was held by \"%s\".", jobid
,
6526 con
->response
->request
.status
.status_code
= IPP_OK
;
6531 * 'move_job()' - Move a job to a new destination.
6535 move_job(cupsd_client_t
*con
, /* I - Client connection */
6536 ipp_attribute_t
*uri
) /* I - Job URI */
6538 http_status_t status
; /* Policy status */
6539 ipp_attribute_t
*attr
; /* Current attribute */
6540 int jobid
; /* Job ID */
6541 cupsd_job_t
*job
; /* Current job */
6542 const char *src
; /* Source printer/class */
6543 cups_ptype_t stype
, /* Source type (printer or class) */
6544 dtype
; /* Destination type (printer or class) */
6545 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6546 username
[HTTP_MAX_URI
], /* Username portion of URI */
6547 host
[HTTP_MAX_URI
], /* Host portion of URI */
6548 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6549 int port
; /* Port portion of URI */
6550 cupsd_printer_t
*sprinter
, /* Source printer */
6551 *dprinter
; /* Destination printer */
6554 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "move_job(%p[%d], %s)", con
, con
->http
.fd
,
6555 uri
->values
[0].string
.text
);
6558 * Get the new printer or class...
6561 if ((attr
= ippFindAttribute(con
->request
, "job-printer-uri",
6562 IPP_TAG_URI
)) == NULL
)
6565 * Need job-printer-uri...
6568 send_ipp_status(con
, IPP_BAD_REQUEST
,
6569 _("job-printer-uri attribute missing!"));
6573 if (!cupsdValidateDest(attr
->values
[0].string
.text
, &dtype
, &dprinter
))
6579 send_ipp_status(con
, IPP_NOT_FOUND
,
6580 _("The printer or class was not found."));
6588 if ((status
= cupsdCheckPolicy(dprinter
->op_policy_ptr
, con
,
6591 send_http_error(con
, status
);
6596 * See if we have a job URI or a printer URI...
6599 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6600 sizeof(scheme
), username
, sizeof(username
), host
,
6601 sizeof(host
), &port
, resource
, sizeof(resource
));
6603 if (!strcmp(uri
->name
, "printer-uri"))
6606 * Got a printer URI; see if we also have a job-id attribute...
6609 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6610 IPP_TAG_INTEGER
)) == NULL
)
6616 if ((src
= cupsdValidateDest(uri
->values
[0].string
.text
, &stype
,
6617 &sprinter
)) == NULL
)
6623 send_ipp_status(con
, IPP_NOT_FOUND
,
6624 _("The printer or class was not found."));
6633 * Otherwise, just move a single job...
6636 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
6639 * Nope - return a "not found" error...
6642 send_ipp_status(con
, IPP_NOT_FOUND
,
6643 _("Job #%d does not exist!"), attr
->values
[0].integer
);
6649 * Job found, initialize source pointers...
6660 * Got a job URI; parse it to get the job ID...
6663 if (strncmp(resource
, "/jobs/", 6))
6669 send_ipp_status(con
, IPP_BAD_REQUEST
,
6670 _("Bad job-uri attribute \"%s\"!"),
6671 uri
->values
[0].string
.text
);
6676 * See if the job exists...
6679 jobid
= atoi(resource
+ 6);
6681 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6684 * Nope - return a "not found" error...
6687 send_ipp_status(con
, IPP_NOT_FOUND
,
6688 _("Job #%d does not exist!"), jobid
);
6694 * Job found, initialize source pointers...
6703 * Now move the job or jobs...
6709 * See if the job has been completed...
6712 if (job
->state_value
> IPP_JOB_STOPPED
)
6715 * Return a "not-possible" error...
6718 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6719 _("Job #%d is finished and cannot be altered!"),
6725 * See if the job is owned by the requesting user...
6728 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
6730 send_http_error(con
, HTTP_UNAUTHORIZED
);
6735 * Move the job to a different printer or class...
6738 cupsdMoveJob(job
, dprinter
);
6743 * Got the source printer, now look through the jobs...
6746 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
6748 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
6751 * See if the job is pointing at the source printer or has not been
6755 if (strcasecmp(job
->dest
, src
) ||
6756 job
->state_value
> IPP_JOB_STOPPED
)
6760 * See if the job can be moved by the requesting user...
6763 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
6767 * Move the job to a different printer or class...
6770 cupsdMoveJob(job
, dprinter
);
6775 * Start jobs if possible...
6781 * Return with "everything is OK" status...
6784 con
->response
->request
.status
.status_code
= IPP_OK
;
6789 * 'ppd_parse_line()' - Parse a PPD default line.
6792 static int /* O - 0 on success, -1 on failure */
6793 ppd_parse_line(const char *line
, /* I - Line */
6794 char *option
, /* O - Option name */
6795 int olen
, /* I - Size of option name */
6796 char *choice
, /* O - Choice name */
6797 int clen
) /* I - Size of choice name */
6800 * Verify this is a default option line...
6803 if (strncmp(line
, "*Default", 8))
6807 * Read the option name...
6810 for (line
+= 8, olen
--; isalnum(*line
& 255); line
++)
6820 * Skip everything else up to the colon (:)...
6823 while (*line
&& *line
!= ':')
6832 * Now grab the option choice, skipping leading whitespace...
6835 while (isspace(*line
& 255))
6838 for (clen
--; isalnum(*line
& 255); line
++)
6848 * Return with no errors...
6856 * 'print_job()' - Print a file to a printer or class.
6860 print_job(cupsd_client_t
*con
, /* I - Client connection */
6861 ipp_attribute_t
*uri
) /* I - Printer URI */
6863 ipp_attribute_t
*attr
; /* Current attribute */
6864 ipp_attribute_t
*format
; /* Document-format attribute */
6865 const char *default_format
; /* document-format-default value */
6866 cupsd_job_t
*job
; /* New job */
6867 char filename
[1024]; /* Job filename */
6868 mime_type_t
*filetype
; /* Type of file */
6869 char super
[MIME_MAX_SUPER
], /* Supertype of file */
6870 type
[MIME_MAX_TYPE
], /* Subtype of file */
6871 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
6872 /* Textual name of mime type */
6873 cupsd_printer_t
*printer
; /* Printer data */
6874 struct stat fileinfo
; /* File information */
6875 int kbytes
; /* Size of file */
6876 int compression
; /* Document compression */
6879 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "print_job(%p[%d], %s)", con
, con
->http
.fd
,
6880 uri
->values
[0].string
.text
);
6883 * Validate print file attributes, for now just document-format and
6884 * compression (CUPS only supports "none" and "gzip")...
6887 compression
= CUPS_FILE_NONE
;
6889 if ((attr
= ippFindAttribute(con
->request
, "compression",
6890 IPP_TAG_KEYWORD
)) != NULL
)
6892 if (strcmp(attr
->values
[0].string
.text
, "none")
6894 && strcmp(attr
->values
[0].string
.text
, "gzip")
6895 #endif /* HAVE_LIBZ */
6898 send_ipp_status(con
, IPP_ATTRIBUTES
,
6899 _("Unsupported compression \"%s\"!"),
6900 attr
->values
[0].string
.text
);
6901 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
6902 "compression", NULL
, attr
->values
[0].string
.text
);
6907 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
6908 compression
= CUPS_FILE_GZIP
;
6909 #endif /* HAVE_LIBZ */
6913 * Do we have a file to print?
6918 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file!?!"));
6923 * Is the destination valid?
6926 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
6932 send_ipp_status(con
, IPP_NOT_FOUND
,
6933 _("The printer or class was not found."));
6938 * Is it a format we support?
6941 if ((format
= ippFindAttribute(con
->request
, "document-format",
6942 IPP_TAG_MIMETYPE
)) != NULL
)
6945 * Grab format from client...
6948 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]", super
,
6951 send_ipp_status(con
, IPP_BAD_REQUEST
,
6952 _("Could not scan type \"%s\"!"),
6953 format
->values
[0].string
.text
);
6957 else if ((default_format
= cupsGetOption("document-format",
6958 printer
->num_options
,
6959 printer
->options
)) != NULL
)
6962 * Use default document format...
6965 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
6967 send_ipp_status(con
, IPP_BAD_REQUEST
,
6968 _("Could not scan type \"%s\"!"),
6979 strcpy(super
, "application");
6980 strcpy(type
, "octet-stream");
6983 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
6986 * Auto-type the file...
6989 ipp_attribute_t
*doc_name
; /* document-name attribute */
6992 cupsdLogMessage(CUPSD_LOG_DEBUG
, "print_job: auto-typing file...");
6994 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
6995 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
6996 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
7000 filetype
= mimeType(MimeDatabase
, super
, type
);
7003 filetype
= mimeType(MimeDatabase
, super
, type
);
7007 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
7010 * Replace the document-format attribute value with the auto-typed or
7014 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
7019 _cupsStrFree(format
->values
[0].string
.text
);
7021 format
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
7024 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
7025 "document-format", NULL
, mimetype
);
7029 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
7030 _("Unsupported format \'%s/%s\'!"), super
, type
);
7031 cupsdLogMessage(CUPSD_LOG_INFO
,
7032 "Hint: Do you have the raw file printing rules enabled?");
7035 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
7036 "document-format", NULL
, format
->values
[0].string
.text
);
7041 cupsdLogMessage(CUPSD_LOG_DEBUG
, "print_job: request file type is %s/%s.",
7042 filetype
->super
, filetype
->type
);
7045 * Read any embedded job ticket info from PS files...
7048 if (!strcasecmp(filetype
->super
, "application") &&
7049 !strcasecmp(filetype
->type
, "postscript"))
7050 read_ps_job_ticket(con
);
7053 * Create the job object...
7056 if ((job
= add_job(con
, printer
, filetype
)) == NULL
)
7060 * Update quota data...
7063 if (stat(con
->filename
, &fileinfo
))
7066 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
7068 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
7070 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
7071 IPP_TAG_INTEGER
)) != NULL
)
7072 attr
->values
[0].integer
+= kbytes
;
7075 * Add the job file...
7078 if (add_file(con
, job
, filetype
, compression
))
7081 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
7083 rename(con
->filename
, filename
);
7084 cupsdClearString(&con
->filename
);
7087 * See if we need to add the ending sheet...
7090 attr
= ippFindAttribute(job
->attrs
, "job-sheets", IPP_TAG_NAME
);
7092 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)) &&
7093 attr
&& attr
->num_values
> 1)
7099 cupsdLogMessage(CUPSD_LOG_INFO
, "Adding end banner page \"%s\" to job %d.",
7100 attr
->values
[1].string
.text
, job
->id
);
7102 kbytes
= copy_banner(con
, job
, attr
->values
[1].string
.text
);
7104 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
7108 * Log and save the job...
7111 cupsdLogMessage(CUPSD_LOG_INFO
, "Job %d queued on \"%s\" by \"%s\".", job
->id
,
7112 job
->dest
, job
->username
);
7113 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Job %d hold_until = %d", job
->id
,
7114 (int)job
->hold_until
);
7119 * Start the job if possible...
7127 * 'read_ps_job_ticket()' - Reads a job ticket embedded in a PS file.
7129 * This function only gets called when printing a single PostScript
7130 * file using the Print-Job operation. It doesn't work for Create-Job +
7131 * Send-File, since the job attributes need to be set at job creation
7132 * time for banners to work. The embedded PS job ticket stuff is here
7133 * only to allow the Windows printer driver for CUPS to pass in JCL
7134 * options and IPP attributes which otherwise would be lost.
7136 * The format of a PS job ticket is simple:
7138 * %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
7140 * %cupsJobTicket: attr1=value1
7141 * %cupsJobTicket: attr2=value2
7143 * %cupsJobTicket: attrN=valueN
7145 * Job ticket lines must appear immediately after the first line that
7146 * specifies PostScript format (%!PS-Adobe-3.0), and CUPS will stop
7147 * looking for job ticket info when it finds a line that does not begin
7148 * with "%cupsJobTicket:".
7150 * The maximum length of a job ticket line, including the prefix, is
7151 * 255 characters to conform with the Adobe DSC.
7153 * Read-only attributes are rejected with a notice to the error log in
7154 * case a malicious user tries anything. Since the job ticket is read
7155 * prior to attribute validation in print_job(), job ticket attributes
7156 * will go through the same validation as IPP attributes...
7160 read_ps_job_ticket(cupsd_client_t
*con
) /* I - Client connection */
7162 cups_file_t
*fp
; /* File to read from */
7163 char line
[256]; /* Line data */
7164 int num_options
; /* Number of options */
7165 cups_option_t
*options
; /* Options */
7166 ipp_t
*ticket
; /* New attributes */
7167 ipp_attribute_t
*attr
, /* Current attribute */
7168 *attr2
, /* Job attribute */
7169 *prev2
; /* Previous job attribute */
7173 * First open the print file...
7176 if ((fp
= cupsFileOpen(con
->filename
, "rb")) == NULL
)
7178 cupsdLogMessage(CUPSD_LOG_ERROR
,
7179 "read_ps_job_ticket: Unable to open PostScript print file "
7186 * Skip the first line...
7189 if (cupsFileGets(fp
, line
, sizeof(line
)) == NULL
)
7191 cupsdLogMessage(CUPSD_LOG_ERROR
,
7192 "read_ps_job_ticket: Unable to read from PostScript print "
7199 if (strncmp(line
, "%!PS-Adobe-", 11))
7202 * Not a DSC-compliant file, so no job ticket info will be available...
7210 * Read job ticket info from the file...
7216 while (cupsFileGets(fp
, line
, sizeof(line
)))
7219 * Stop at the first non-ticket line...
7222 if (strncmp(line
, "%cupsJobTicket:", 15))
7226 * Add the options to the option array...
7229 num_options
= cupsParseOptions(line
+ 15, num_options
, &options
);
7233 * Done with the file; see if we have any options...
7238 if (num_options
== 0)
7242 * OK, convert the options to an attribute list, and apply them to
7247 cupsEncodeOptions(ticket
, num_options
, options
);
7250 * See what the user wants to change.
7253 for (attr
= ticket
->attrs
; attr
; attr
= attr
->next
)
7255 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
7258 if (!strcmp(attr
->name
, "job-originating-host-name") ||
7259 !strcmp(attr
->name
, "job-originating-user-name") ||
7260 !strcmp(attr
->name
, "job-media-sheets-completed") ||
7261 !strcmp(attr
->name
, "job-k-octets") ||
7262 !strcmp(attr
->name
, "job-id") ||
7263 !strncmp(attr
->name
, "job-state", 9) ||
7264 !strncmp(attr
->name
, "time-at-", 8))
7265 continue; /* Read-only attrs */
7267 if ((attr2
= ippFindAttribute(con
->request
, attr
->name
,
7268 IPP_TAG_ZERO
)) != NULL
)
7271 * Some other value; first free the old value...
7274 if (con
->request
->attrs
== attr2
)
7276 con
->request
->attrs
= attr2
->next
;
7281 for (prev2
= con
->request
->attrs
; prev2
; prev2
= prev2
->next
)
7282 if (prev2
->next
== attr2
)
7284 prev2
->next
= attr2
->next
;
7289 if (con
->request
->last
== attr2
)
7290 con
->request
->last
= prev2
;
7292 _ippFreeAttr(attr2
);
7296 * Add new option by copying it...
7299 copy_attribute(con
->request
, attr
, 0);
7303 * Then free the attribute list and option array...
7307 cupsFreeOptions(num_options
, options
);
7312 * 'reject_jobs()' - Reject print jobs to a printer.
7316 reject_jobs(cupsd_client_t
*con
, /* I - Client connection */
7317 ipp_attribute_t
*uri
) /* I - Printer or class URI */
7319 http_status_t status
; /* Policy status */
7320 cups_ptype_t dtype
; /* Destination type (printer or class) */
7321 cupsd_printer_t
*printer
; /* Printer data */
7322 ipp_attribute_t
*attr
; /* printer-state-message text */
7325 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "reject_jobs(%p[%d], %s)", con
,
7326 con
->http
.fd
, uri
->values
[0].string
.text
);
7329 * Is the destination valid?
7332 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7338 send_ipp_status(con
, IPP_NOT_FOUND
,
7339 _("The printer or class was not found."));
7347 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7349 send_http_error(con
, status
);
7354 * Reject jobs sent to the printer...
7357 printer
->accepting
= 0;
7359 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
7360 IPP_TAG_TEXT
)) == NULL
)
7361 strcpy(printer
->state_message
, "Rejecting Jobs");
7363 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
7364 sizeof(printer
->state_message
));
7366 cupsdAddPrinterHistory(printer
);
7368 if (dtype
& CUPS_PRINTER_CLASS
)
7370 cupsdSaveAllClasses();
7372 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" rejecting jobs (\"%s\").",
7373 printer
->name
, get_username(con
));
7377 cupsdSaveAllPrinters();
7379 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" rejecting jobs (\"%s\").",
7380 printer
->name
, get_username(con
));
7384 * Everything was ok, so return OK status...
7387 con
->response
->request
.status
.status_code
= IPP_OK
;
7392 * 'release_job()' - Release a held print job.
7396 release_job(cupsd_client_t
*con
, /* I - Client connection */
7397 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
7399 ipp_attribute_t
*attr
; /* Current attribute */
7400 int jobid
; /* Job ID */
7401 char method
[HTTP_MAX_URI
], /* Method portion of URI */
7402 username
[HTTP_MAX_URI
], /* Username portion of URI */
7403 host
[HTTP_MAX_URI
], /* Host portion of URI */
7404 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7405 int port
; /* Port portion of URI */
7406 cupsd_job_t
*job
; /* Job information */
7409 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_job(%p[%d], %s)", con
,
7410 con
->http
.fd
, uri
->values
[0].string
.text
);
7413 * See if we have a job URI or a printer URI...
7416 if (!strcmp(uri
->name
, "printer-uri"))
7419 * Got a printer URI; see if we also have a job-id attribute...
7422 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7423 IPP_TAG_INTEGER
)) == NULL
)
7425 send_ipp_status(con
, IPP_BAD_REQUEST
,
7426 _("Got a printer-uri attribute but no job-id!"));
7430 jobid
= attr
->values
[0].integer
;
7435 * Got a job URI; parse it to get the job ID...
7438 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
7439 sizeof(method
), username
, sizeof(username
), host
,
7440 sizeof(host
), &port
, resource
, sizeof(resource
));
7442 if (strncmp(resource
, "/jobs/", 6))
7448 send_ipp_status(con
, IPP_BAD_REQUEST
,
7449 _("Bad job-uri attribute \"%s\"!"),
7450 uri
->values
[0].string
.text
);
7454 jobid
= atoi(resource
+ 6);
7458 * See if the job exists...
7461 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7464 * Nope - return a "not found" error...
7467 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
7472 * See if job is "held"...
7475 if (job
->state_value
!= IPP_JOB_HELD
)
7478 * Nope - return a "not possible" error...
7481 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not held!"), jobid
);
7486 * See if the job is owned by the requesting user...
7489 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7491 send_http_error(con
, HTTP_UNAUTHORIZED
);
7496 * Reset the job-hold-until value to "no-hold"...
7499 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
7500 IPP_TAG_KEYWORD
)) == NULL
)
7501 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
7505 _cupsStrFree(attr
->values
[0].string
.text
);
7507 attr
->value_tag
= IPP_TAG_KEYWORD
;
7508 attr
->values
[0].string
.text
= _cupsStrAlloc("no-hold");
7510 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, job
->printer
, job
,
7511 "Job job-hold-until value changed by user.");
7515 * Release the job and return...
7518 cupsdReleaseJob(job
);
7520 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, job
->printer
, job
,
7521 "Job released by user.");
7523 cupsdLogMessage(CUPSD_LOG_INFO
, "Job %d was released by \"%s\".", jobid
,
7526 con
->response
->request
.status
.status_code
= IPP_OK
;
7531 * 'renew_subscription()' - Renew an existing subscription...
7536 cupsd_client_t
*con
, /* I - Client connection */
7537 int sub_id
) /* I - Subscription ID */
7539 http_status_t status
; /* Policy status */
7540 cupsd_subscription_t
*sub
; /* Subscription */
7541 ipp_attribute_t
*lease
; /* notify-lease-duration */
7544 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7545 "renew_subscription(con=%p[%d], sub_id=%d)",
7546 con
, con
->http
.fd
, sub_id
);
7549 * Is the subscription ID valid?
7552 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
7555 * Bad subscription ID...
7558 send_ipp_status(con
, IPP_NOT_FOUND
,
7559 _("notify-subscription-id %d no good!"), sub_id
);
7566 * Job subscriptions cannot be renewed...
7569 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
7570 _("Job subscriptions cannot be renewed!"));
7578 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
7580 con
, sub
->owner
)) != HTTP_OK
)
7582 send_http_error(con
, status
);
7587 * Renew the subscription...
7590 lease
= ippFindAttribute(con
->request
, "notify-lease-duration",
7593 sub
->lease
= lease
? lease
->values
[0].integer
: DefaultLeaseDuration
;
7595 if (MaxLeaseDuration
&& (sub
->lease
== 0 || sub
->lease
> MaxLeaseDuration
))
7597 cupsdLogMessage(CUPSD_LOG_INFO
,
7598 "renew_subscription: Limiting notify-lease-duration to "
7601 sub
->lease
= MaxLeaseDuration
;
7604 sub
->expire
= sub
->lease
? time(NULL
) + sub
->lease
: 0;
7606 cupsdSaveAllSubscriptions();
7608 con
->response
->request
.status
.status_code
= IPP_OK
;
7613 * 'restart_job()' - Restart an old print job.
7617 restart_job(cupsd_client_t
*con
, /* I - Client connection */
7618 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
7620 ipp_attribute_t
*attr
; /* Current attribute */
7621 int jobid
; /* Job ID */
7622 char method
[HTTP_MAX_URI
], /* Method portion of URI */
7623 username
[HTTP_MAX_URI
], /* Username portion of URI */
7624 host
[HTTP_MAX_URI
], /* Host portion of URI */
7625 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7626 int port
; /* Port portion of URI */
7627 cupsd_job_t
*job
; /* Job information */
7630 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "restart_job(%p[%d], %s)", con
,
7631 con
->http
.fd
, uri
->values
[0].string
.text
);
7634 * See if we have a job URI or a printer URI...
7637 if (!strcmp(uri
->name
, "printer-uri"))
7640 * Got a printer URI; see if we also have a job-id attribute...
7643 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7644 IPP_TAG_INTEGER
)) == NULL
)
7646 send_ipp_status(con
, IPP_BAD_REQUEST
,
7647 _("Got a printer-uri attribute but no job-id!"));
7651 jobid
= attr
->values
[0].integer
;
7656 * Got a job URI; parse it to get the job ID...
7659 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
7660 sizeof(method
), username
, sizeof(username
), host
,
7661 sizeof(host
), &port
, resource
, sizeof(resource
));
7663 if (strncmp(resource
, "/jobs/", 6))
7669 send_ipp_status(con
, IPP_BAD_REQUEST
,
7670 _("Bad job-uri attribute \"%s\"!"),
7671 uri
->values
[0].string
.text
);
7675 jobid
= atoi(resource
+ 6);
7679 * See if the job exists...
7682 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7685 * Nope - return a "not found" error...
7688 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
7693 * See if job is in any of the "completed" states...
7696 if (job
->state_value
<= IPP_JOB_PROCESSING
)
7699 * Nope - return a "not possible" error...
7702 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not complete!"),
7708 * See if we have retained the job files...
7713 if (!job
->attrs
|| job
->num_files
== 0)
7716 * Nope - return a "not possible" error...
7719 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
7720 _("Job #%d cannot be restarted - no files!"), jobid
);
7725 * See if the job is owned by the requesting user...
7728 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7730 send_http_error(con
, HTTP_UNAUTHORIZED
);
7735 * Restart the job and return...
7738 cupsdRestartJob(job
);
7740 cupsdLogMessage(CUPSD_LOG_INFO
, "Job %d was restarted by \"%s\".", jobid
,
7743 con
->response
->request
.status
.status_code
= IPP_OK
;
7748 * 'save_auth_info()' - Save authentication information for a job.
7753 cupsd_client_t
*con
, /* I - Client connection */
7754 cupsd_job_t
*job
, /* I - Job */
7755 ipp_attribute_t
*auth_info
) /* I - auth-info attribute, if any */
7757 int i
; /* Looping var */
7758 char filename
[1024]; /* Job authentication filename */
7759 cups_file_t
*fp
; /* Job authentication file */
7760 char line
[2048]; /* Line for file */
7764 * This function saves the in-memory authentication information for
7765 * a job so that it can be used to authenticate with a remote host.
7766 * The information is stored in a file that is readable only by the
7767 * root user. The fields are Base-64 encoded, each on a separate line,
7768 * followed by random number (up to 1024) of newlines to limit the
7769 * amount of information that is exposed.
7771 * Because of the potential for exposing of authentication information,
7772 * this functionality is only enabled when running cupsd as root.
7774 * This caching only works for the Basic and BasicDigest authentication
7775 * types. Digest authentication cannot be cached this way, and in
7776 * the future Kerberos authentication may make all of this obsolete.
7778 * Authentication information is saved whenever an authenticated
7779 * Print-Job, Create-Job, or CUPS-Authenticate-Job operation is
7782 * This information is deleted after a job is completed or canceled,
7783 * so reprints may require subsequent re-authentication.
7790 * Create the authentication file and change permissions...
7793 snprintf(filename
, sizeof(filename
), "%s/a%05d", RequestRoot
, job
->id
);
7794 if ((fp
= cupsFileOpen(filename
, "w")) == NULL
)
7796 cupsdLogMessage(CUPSD_LOG_ERROR
,
7797 "Unable to save authentication info to \"%s\" - %s",
7798 filename
, strerror(errno
));
7802 fchown(cupsFileNumber(fp
), 0, 0);
7803 fchmod(cupsFileNumber(fp
), 0400);
7808 * Write 1 to 4 auth values...
7811 for (i
= 0; i
< auth_info
->num_values
; i
++)
7813 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[i
].string
.text
,
7814 strlen(auth_info
->values
[i
].string
.text
));
7815 cupsFilePrintf(fp
, "%s\n", line
);
7821 * Write the authenticated username...
7824 httpEncode64_2(line
, sizeof(line
), con
->username
, strlen(con
->username
));
7825 cupsFilePrintf(fp
, "%s\n", line
);
7828 * Write the authenticated password...
7831 httpEncode64_2(line
, sizeof(line
), con
->password
, strlen(con
->password
));
7832 cupsFilePrintf(fp
, "%s\n", line
);
7836 * Write a random number of newlines to the end of the file...
7839 for (i
= (rand() % 1024); i
>= 0; i
--)
7840 cupsFilePutChar(fp
, '\n');
7843 * Close the file and return...
7848 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
7849 save_krb5_creds(con
, job
);
7850 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
7854 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
7856 * 'save_krb5_creds()' - Save Kerberos credentials for the job.
7860 save_krb5_creds(cupsd_client_t
*con
, /* I - Client connection */
7861 cupsd_job_t
*job
) /* I - Job */
7863 krb5_context krb_context
; /* Kerberos context */
7864 krb5_ccache ccache
; /* Credentials cache */
7865 OM_uint32 major_status
, /* Major status code */
7866 minor_status
; /* Minor status code */
7870 * Setup a cached context for the job filters to use...
7873 if (krb5_init_context(&krb_context
))
7875 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to initialize Kerberos context");
7879 # ifdef HAVE_HEIMDAL
7880 if (krb5_cc_gen_new(krb_context
, &krb5_fcc_ops
, &ccache
))
7882 if (krb5_cc_gen_new(krb_context
, &ccache
))
7883 # endif /* HAVE_HEIMDAL */
7885 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to create new credentials");
7889 major_status
= gss_krb5_copy_ccache(&minor_status
, con
->gss_delegated_cred
,
7892 if (GSS_ERROR(major_status
))
7894 cupsdLogGSSMessage(CUPSD_LOG_ERROR
, major_status
, minor_status
,
7895 "Unable to import client credentials cache");
7896 krb5_cc_destroy(krb_context
, ccache
);
7900 cupsdSetStringf(&(job
->ccname
), "KRB5CCNAME=FILE:%s",
7901 krb5_cc_get_name(krb_context
, ccache
));
7902 krb5_cc_close(krb_context
, ccache
);
7904 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
7908 * 'send_document()' - Send a file to a printer or class.
7912 send_document(cupsd_client_t
*con
, /* I - Client connection */
7913 ipp_attribute_t
*uri
) /* I - Printer URI */
7915 ipp_attribute_t
*attr
; /* Current attribute */
7916 ipp_attribute_t
*format
; /* Document-format attribute */
7917 const char *default_format
;/* document-format-default value */
7918 int jobid
; /* Job ID number */
7919 cupsd_job_t
*job
; /* Current job */
7920 char job_uri
[HTTP_MAX_URI
],
7922 method
[HTTP_MAX_URI
],
7923 /* Method portion of URI */
7924 username
[HTTP_MAX_URI
],
7925 /* Username portion of URI */
7927 /* Host portion of URI */
7928 resource
[HTTP_MAX_URI
];
7929 /* Resource portion of URI */
7930 int port
; /* Port portion of URI */
7931 mime_type_t
*filetype
; /* Type of file */
7932 char super
[MIME_MAX_SUPER
],
7933 /* Supertype of file */
7934 type
[MIME_MAX_TYPE
],
7935 /* Subtype of file */
7936 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
7937 /* Textual name of mime type */
7938 char filename
[1024]; /* Job filename */
7939 cupsd_printer_t
*printer
; /* Current printer */
7940 struct stat fileinfo
; /* File information */
7941 int kbytes
; /* Size of file */
7942 int compression
; /* Type of compression */
7945 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "send_document(%p[%d], %s)", con
,
7946 con
->http
.fd
, uri
->values
[0].string
.text
);
7949 * See if we have a job URI or a printer URI...
7952 if (!strcmp(uri
->name
, "printer-uri"))
7955 * Got a printer URI; see if we also have a job-id attribute...
7958 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7959 IPP_TAG_INTEGER
)) == NULL
)
7961 send_ipp_status(con
, IPP_BAD_REQUEST
,
7962 _("Got a printer-uri attribute but no job-id!"));
7966 jobid
= attr
->values
[0].integer
;
7971 * Got a job URI; parse it to get the job ID...
7974 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
7975 sizeof(method
), username
, sizeof(username
), host
,
7976 sizeof(host
), &port
, resource
, sizeof(resource
));
7978 if (strncmp(resource
, "/jobs/", 6))
7984 send_ipp_status(con
, IPP_BAD_REQUEST
,
7985 _("Bad job-uri attribute \"%s\"!"),
7986 uri
->values
[0].string
.text
);
7990 jobid
= atoi(resource
+ 6);
7994 * See if the job exists...
7997 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8000 * Nope - return a "not found" error...
8003 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
8007 printer
= cupsdFindDest(job
->dest
);
8010 * See if the job is owned by the requesting user...
8013 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8015 send_http_error(con
, HTTP_UNAUTHORIZED
);
8020 * OK, see if the client is sending the document compressed - CUPS
8021 * only supports "none" and "gzip".
8024 compression
= CUPS_FILE_NONE
;
8026 if ((attr
= ippFindAttribute(con
->request
, "compression",
8027 IPP_TAG_KEYWORD
)) != NULL
)
8029 if (strcmp(attr
->values
[0].string
.text
, "none")
8031 && strcmp(attr
->values
[0].string
.text
, "gzip")
8032 #endif /* HAVE_LIBZ */
8035 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Unsupported compression \"%s\"!"),
8036 attr
->values
[0].string
.text
);
8037 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
8038 "compression", NULL
, attr
->values
[0].string
.text
);
8043 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
8044 compression
= CUPS_FILE_GZIP
;
8045 #endif /* HAVE_LIBZ */
8049 * Do we have a file to print?
8054 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file!?!"));
8059 * Is it a format we support?
8062 if ((format
= ippFindAttribute(con
->request
, "document-format",
8063 IPP_TAG_MIMETYPE
)) != NULL
)
8066 * Grab format from client...
8069 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]", super
, type
) != 2)
8071 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"!"),
8072 format
->values
[0].string
.text
);
8076 else if ((default_format
= cupsGetOption("document-format",
8077 printer
->num_options
,
8078 printer
->options
)) != NULL
)
8081 * Use default document format...
8084 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
8086 send_ipp_status(con
, IPP_BAD_REQUEST
,
8087 _("Could not scan type \"%s\"!"),
8095 * No document format attribute? Auto-type it!
8098 strcpy(super
, "application");
8099 strcpy(type
, "octet-stream");
8102 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
8105 * Auto-type the file...
8108 ipp_attribute_t
*doc_name
; /* document-name attribute */
8111 cupsdLogMessage(CUPSD_LOG_DEBUG
, "send_document: auto-typing file...");
8113 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
8114 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
8115 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
8119 filetype
= mimeType(MimeDatabase
, super
, type
);
8122 filetype
= mimeType(MimeDatabase
, super
, type
);
8126 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
8129 * Replace the document-format attribute value with the auto-typed or
8133 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
8138 _cupsStrFree(format
->values
[0].string
.text
);
8140 format
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
8143 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
8144 "document-format", NULL
, mimetype
);
8148 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
8149 _("Unsupported format \'%s/%s\'!"), super
, type
);
8150 cupsdLogMessage(CUPSD_LOG_INFO
,
8151 "Hint: Do you have the raw file printing rules enabled?");
8154 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
8155 "document-format", NULL
, format
->values
[0].string
.text
);
8160 if (printer
->filetypes
&& !cupsArrayFind(printer
->filetypes
, filetype
))
8162 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
8165 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
8166 _("Unsupported format \'%s\'!"), mimetype
);
8168 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
8169 "document-format", NULL
, mimetype
);
8174 cupsdLogMessage(CUPSD_LOG_DEBUG
,
8175 "send_document: request file type is %s/%s.",
8176 filetype
->super
, filetype
->type
);
8179 * Add the file to the job...
8184 if (add_file(con
, job
, filetype
, compression
))
8187 if (stat(con
->filename
, &fileinfo
))
8190 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
8192 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
8194 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
8195 IPP_TAG_INTEGER
)) != NULL
)
8196 attr
->values
[0].integer
+= kbytes
;
8198 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
8200 rename(con
->filename
, filename
);
8202 cupsdClearString(&con
->filename
);
8204 cupsdLogMessage(CUPSD_LOG_INFO
,
8205 "File of type %s/%s queued in job #%d by \"%s\".",
8206 filetype
->super
, filetype
->type
, job
->id
, job
->username
);
8209 * Start the job if this is the last document...
8212 if ((attr
= ippFindAttribute(con
->request
, "last-document",
8213 IPP_TAG_BOOLEAN
)) != NULL
&&
8214 attr
->values
[0].boolean
)
8217 * See if we need to add the ending sheet...
8221 !(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)) &&
8222 (attr
= ippFindAttribute(job
->attrs
, "job-sheets",
8223 IPP_TAG_ZERO
)) != NULL
&&
8224 attr
->num_values
> 1)
8230 cupsdLogMessage(CUPSD_LOG_INFO
,
8231 "Adding end banner page \"%s\" to job %d.",
8232 attr
->values
[1].string
.text
, job
->id
);
8234 kbytes
= copy_banner(con
, job
, attr
->values
[1].string
.text
);
8236 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
8239 if (job
->state_value
== IPP_JOB_STOPPED
)
8241 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
8242 job
->state_value
= IPP_JOB_PENDING
;
8244 else if (job
->state_value
== IPP_JOB_HELD
)
8246 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
8247 IPP_TAG_KEYWORD
)) == NULL
)
8248 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
8250 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
8252 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
8253 job
->state_value
= IPP_JOB_PENDING
;
8260 * Start the job if possible... Since cupsdCheckJobs() can cancel a
8261 * job if it doesn't print, we need to re-find the job afterwards...
8268 job
= cupsdFindJob(jobid
);
8272 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
8273 IPP_TAG_KEYWORD
)) == NULL
)
8274 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
8276 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
8278 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
8279 job
->state_value
= IPP_JOB_HELD
;
8280 job
->hold_until
= time(NULL
) + 60;
8286 * Fill in the response info...
8289 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
8292 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
8295 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", jobid
);
8297 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
8298 job
? job
->state_value
: IPP_JOB_CANCELED
);
8299 add_job_state_reasons(con
, job
);
8301 con
->response
->request
.status
.status_code
= IPP_OK
;
8306 * 'send_http_error()' - Send a HTTP error back to the IPP client.
8310 send_http_error(cupsd_client_t
*con
, /* I - Client connection */
8311 http_status_t status
) /* I - HTTP status code */
8313 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: %s",
8314 ippOpString(con
->request
->request
.op
.operation_id
),
8315 httpStatus(status
));
8317 cupsdSendError(con
, status
);
8319 ippDelete(con
->response
);
8320 con
->response
= NULL
;
8327 * 'send_ipp_status()' - Send a status back to the IPP client.
8331 send_ipp_status(cupsd_client_t
*con
, /* I - Client connection */
8332 ipp_status_t status
, /* I - IPP status code */
8333 const char *message
, /* I - Status message */
8334 ...) /* I - Additional args as needed */
8336 va_list ap
; /* Pointer to additional args */
8337 char formatted
[1024]; /* Formatted errror message */
8342 va_start(ap
, message
);
8343 vsnprintf(formatted
, sizeof(formatted
),
8344 _cupsLangString(con
->language
, message
), ap
);
8347 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s: %s",
8348 ippOpString(con
->request
->request
.op
.operation_id
),
8349 ippErrorString(status
), formatted
);
8352 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s",
8353 ippOpString(con
->request
->request
.op
.operation_id
),
8354 ippErrorString(status
));
8356 con
->response
->request
.status
.status_code
= status
;
8358 if (ippFindAttribute(con
->response
, "attributes-charset",
8359 IPP_TAG_ZERO
) == NULL
)
8360 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
8361 "attributes-charset", NULL
, DefaultCharset
);
8363 if (ippFindAttribute(con
->response
, "attributes-natural-language",
8364 IPP_TAG_ZERO
) == NULL
)
8365 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
8366 "attributes-natural-language", NULL
, DefaultLanguage
);
8369 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
8370 "status-message", NULL
, formatted
);
8375 * 'set_default()' - Set the default destination...
8379 set_default(cupsd_client_t
*con
, /* I - Client connection */
8380 ipp_attribute_t
*uri
) /* I - Printer URI */
8382 http_status_t status
; /* Policy status */
8383 cups_ptype_t dtype
; /* Destination type (printer or class) */
8384 cupsd_printer_t
*printer
; /* Printer */
8387 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_default(%p[%d], %s)", con
,
8388 con
->http
.fd
, uri
->values
[0].string
.text
);
8391 * Is the destination valid?
8394 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8400 send_ipp_status(con
, IPP_NOT_FOUND
,
8401 _("The printer or class was not found."));
8409 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
8411 send_http_error(con
, status
);
8416 * Set it as the default...
8419 DefaultPrinter
= printer
;
8421 cupsdSaveAllPrinters();
8422 cupsdSaveAllClasses();
8424 cupsdWritePrintcap();
8426 cupsdLogMessage(CUPSD_LOG_INFO
,
8427 "Default destination set to \"%s\" by \"%s\".",
8428 printer
->name
, get_username(con
));
8431 * Everything was ok, so return OK status...
8434 con
->response
->request
.status
.status_code
= IPP_OK
;
8439 * 'set_job_attrs()' - Set job attributes.
8443 set_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
8444 ipp_attribute_t
*uri
) /* I - Job URI */
8446 ipp_attribute_t
*attr
, /* Current attribute */
8447 *attr2
; /* Job attribute */
8448 int jobid
; /* Job ID */
8449 cupsd_job_t
*job
; /* Current job */
8450 char method
[HTTP_MAX_URI
],
8451 /* Method portion of URI */
8452 username
[HTTP_MAX_URI
],
8453 /* Username portion of URI */
8455 /* Host portion of URI */
8456 resource
[HTTP_MAX_URI
];
8457 /* Resource portion of URI */
8458 int port
; /* Port portion of URI */
8459 int event
; /* Events? */
8462 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_job_attrs(%p[%d], %s)", con
,
8463 con
->http
.fd
, uri
->values
[0].string
.text
);
8466 * Start with "everything is OK" status...
8469 con
->response
->request
.status
.status_code
= IPP_OK
;
8472 * See if we have a job URI or a printer URI...
8475 if (!strcmp(uri
->name
, "printer-uri"))
8478 * Got a printer URI; see if we also have a job-id attribute...
8481 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8482 IPP_TAG_INTEGER
)) == NULL
)
8484 send_ipp_status(con
, IPP_BAD_REQUEST
,
8485 _("Got a printer-uri attribute but no job-id!"));
8489 jobid
= attr
->values
[0].integer
;
8494 * Got a job URI; parse it to get the job ID...
8497 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
8498 sizeof(method
), username
, sizeof(username
), host
,
8499 sizeof(host
), &port
, resource
, sizeof(resource
));
8501 if (strncmp(resource
, "/jobs/", 6))
8507 send_ipp_status(con
, IPP_BAD_REQUEST
,
8508 _("Bad job-uri attribute \"%s\"!"),
8509 uri
->values
[0].string
.text
);
8513 jobid
= atoi(resource
+ 6);
8517 * See if the job exists...
8520 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8523 * Nope - return a "not found" error...
8526 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
8531 * See if the job has been completed...
8534 if (job
->state_value
> IPP_JOB_STOPPED
)
8537 * Return a "not-possible" error...
8540 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8541 _("Job #%d is finished and cannot be altered!"), jobid
);
8546 * See if the job is owned by the requesting user...
8549 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8551 send_http_error(con
, HTTP_UNAUTHORIZED
);
8556 * See what the user wants to change.
8563 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
8565 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
8568 if (!strcmp(attr
->name
, "attributes-charset") ||
8569 !strcmp(attr
->name
, "attributes-natural-language") ||
8570 !strcmp(attr
->name
, "document-compression") ||
8571 !strcmp(attr
->name
, "document-format") ||
8572 !strcmp(attr
->name
, "job-detailed-status-messages") ||
8573 !strcmp(attr
->name
, "job-document-access-errors") ||
8574 !strcmp(attr
->name
, "job-id") ||
8575 !strcmp(attr
->name
, "job-k-octets") ||
8576 !strcmp(attr
->name
, "job-originating-host-name") ||
8577 !strcmp(attr
->name
, "job-originating-user-name") ||
8578 !strcmp(attr
->name
, "job-printer-up-time") ||
8579 !strcmp(attr
->name
, "job-printer-uri") ||
8580 !strcmp(attr
->name
, "job-sheets") ||
8581 !strcmp(attr
->name
, "job-state-message") ||
8582 !strcmp(attr
->name
, "job-state-reasons") ||
8583 !strcmp(attr
->name
, "job-uri") ||
8584 !strcmp(attr
->name
, "number-of-documents") ||
8585 !strcmp(attr
->name
, "number-of-intervening-jobs") ||
8586 !strcmp(attr
->name
, "output-device-assigned") ||
8587 !strncmp(attr
->name
, "date-time-at-", 13) ||
8588 !strncmp(attr
->name
, "job-impressions", 15) ||
8589 !strncmp(attr
->name
, "job-k-octets", 12) ||
8590 !strncmp(attr
->name
, "job-media-sheets", 16) ||
8591 !strncmp(attr
->name
, "time-at-", 8))
8597 send_ipp_status(con
, IPP_ATTRIBUTES_NOT_SETTABLE
,
8598 _("%s cannot be changed."), attr
->name
);
8600 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
8601 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
8606 if (!strcmp(attr
->name
, "job-priority"))
8609 * Change the job priority...
8612 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
8614 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-priority value!"));
8616 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
8617 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
8619 else if (job
->state_value
>= IPP_JOB_PROCESSING
)
8621 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8622 _("Job is completed and cannot be changed."));
8625 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
8627 cupsdSetJobPriority(job
, attr
->values
[0].integer
);
8628 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
8631 else if (!strcmp(attr
->name
, "job-state"))
8634 * Change the job state...
8637 if (attr
->value_tag
!= IPP_TAG_ENUM
)
8639 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-state value!"));
8641 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
8642 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
8646 switch (attr
->values
[0].integer
)
8648 case IPP_JOB_PENDING
:
8650 if (job
->state_value
> IPP_JOB_HELD
)
8652 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8653 _("Job state cannot be changed."));
8656 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
8658 job
->state
->values
[0].integer
= attr
->values
[0].integer
;
8659 job
->state_value
= (ipp_jstate_t
)attr
->values
[0].integer
;
8661 event
|= CUPSD_EVENT_JOB_STATE
;
8665 case IPP_JOB_PROCESSING
:
8666 case IPP_JOB_STOPPED
:
8667 if (job
->state_value
!= attr
->values
[0].integer
)
8669 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8670 _("Job state cannot be changed."));
8675 case IPP_JOB_CANCELED
:
8676 case IPP_JOB_ABORTED
:
8677 case IPP_JOB_COMPLETED
:
8678 if (job
->state_value
> IPP_JOB_PROCESSING
)
8680 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8681 _("Job state cannot be changed."));
8684 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
8685 cupsdCancelJob(job
, 0, (ipp_jstate_t
)attr
->values
[0].integer
);
8690 else if (con
->response
->request
.status
.status_code
!= IPP_OK
)
8692 else if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
8693 IPP_TAG_ZERO
)) != NULL
)
8696 * Some other value; first free the old value...
8699 if (job
->attrs
->prev
)
8700 job
->attrs
->prev
->next
= attr2
->next
;
8702 job
->attrs
->attrs
= attr2
->next
;
8704 if (job
->attrs
->last
== attr2
)
8705 job
->attrs
->last
= job
->attrs
->prev
;
8707 _ippFreeAttr(attr2
);
8710 * Then copy the attribute...
8713 copy_attribute(job
->attrs
, attr
, 0);
8716 * See if the job-name or job-hold-until is being changed.
8719 if (!strcmp(attr
->name
, "job-hold-until"))
8721 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
);
8723 if (!strcmp(attr
->values
[0].string
.text
, "no-hold"))
8724 cupsdReleaseJob(job
);
8728 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
;
8731 else if (attr
->value_tag
== IPP_TAG_DELETEATTR
)
8734 * Delete the attribute...
8737 if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
8738 IPP_TAG_ZERO
)) != NULL
)
8740 if (job
->attrs
->prev
)
8741 job
->attrs
->prev
->next
= attr2
->next
;
8743 job
->attrs
->attrs
= attr2
->next
;
8745 if (attr2
== job
->attrs
->last
)
8746 job
->attrs
->last
= job
->attrs
->prev
;
8748 _ippFreeAttr(attr2
);
8750 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
8756 * Add new option by copying it...
8759 copy_attribute(job
->attrs
, attr
, 0);
8761 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
8772 * Send events as needed...
8775 if (event
& CUPSD_EVENT_JOB_STATE
)
8776 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, job
->printer
, job
,
8777 job
->state_value
== IPP_JOB_HELD
?
8778 "Job held by user." : "Job restarted by user.");
8780 if (event
& CUPSD_EVENT_JOB_CONFIG_CHANGED
)
8781 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, job
->printer
, job
,
8782 "Job options changed by user.");
8785 * Start jobs if possible...
8793 * 'set_printer_defaults()' - Set printer default options from a request.
8797 set_printer_defaults(
8798 cupsd_client_t
*con
, /* I - Client connection */
8799 cupsd_printer_t
*printer
) /* I - Printer */
8801 int i
; /* Looping var */
8802 ipp_attribute_t
*attr
; /* Current attribute */
8803 int namelen
; /* Length of attribute name */
8804 char name
[256], /* New attribute name */
8805 value
[256]; /* String version of integer attrs */
8808 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
8811 * Skip non-printer attributes...
8814 if (attr
->group_tag
!= IPP_TAG_PRINTER
|| !attr
->name
)
8817 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_defaults: %s", attr
->name
);
8819 if (!strcmp(attr
->name
, "job-sheets-default"))
8822 * Only allow keywords and names...
8825 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
8829 * Only allow job-sheets-default to be set when running without a
8830 * system high classification level...
8836 cupsdSetString(&printer
->job_sheets
[0], attr
->values
[0].string
.text
);
8838 if (attr
->num_values
> 1)
8839 cupsdSetString(&printer
->job_sheets
[1], attr
->values
[1].string
.text
);
8841 cupsdSetString(&printer
->job_sheets
[1], "none");
8843 else if (!strcmp(attr
->name
, "requesting-user-name-allowed"))
8845 cupsdFreePrinterUsers(printer
);
8847 printer
->deny_users
= 0;
8849 if (attr
->value_tag
== IPP_TAG_NAME
&&
8850 (attr
->num_values
> 1 ||
8851 strcmp(attr
->values
[0].string
.text
, "all")))
8853 for (i
= 0; i
< attr
->num_values
; i
++)
8854 cupsdAddPrinterUser(printer
, attr
->values
[i
].string
.text
);
8857 else if (!strcmp(attr
->name
, "requesting-user-name-denied"))
8859 cupsdFreePrinterUsers(printer
);
8861 printer
->deny_users
= 1;
8863 if (attr
->value_tag
== IPP_TAG_NAME
&&
8864 (attr
->num_values
> 1 ||
8865 strcmp(attr
->values
[0].string
.text
, "none")))
8867 for (i
= 0; i
< attr
->num_values
; i
++)
8868 cupsdAddPrinterUser(printer
, attr
->values
[i
].string
.text
);
8871 else if (!strcmp(attr
->name
, "job-quota-period"))
8873 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
8876 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-quota-period to %d...",
8877 attr
->values
[0].integer
);
8878 cupsdFreeQuotas(printer
);
8880 printer
->quota_period
= attr
->values
[0].integer
;
8882 else if (!strcmp(attr
->name
, "job-k-limit"))
8884 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
8887 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-k-limit to %d...",
8888 attr
->values
[0].integer
);
8889 cupsdFreeQuotas(printer
);
8891 printer
->k_limit
= attr
->values
[0].integer
;
8893 else if (!strcmp(attr
->name
, "job-page-limit"))
8895 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
8898 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-page-limit to %d...",
8899 attr
->values
[0].integer
);
8900 cupsdFreeQuotas(printer
);
8902 printer
->page_limit
= attr
->values
[0].integer
;
8904 else if (!strcmp(attr
->name
, "printer-op-policy"))
8906 cupsd_policy_t
*p
; /* Policy */
8909 if (attr
->value_tag
!= IPP_TAG_NAME
)
8912 if ((p
= cupsdFindPolicy(attr
->values
[0].string
.text
)) != NULL
)
8914 cupsdLogMessage(CUPSD_LOG_DEBUG
,
8915 "Setting printer-op-policy to \"%s\"...",
8916 attr
->values
[0].string
.text
);
8917 cupsdSetString(&printer
->op_policy
, attr
->values
[0].string
.text
);
8918 printer
->op_policy_ptr
= p
;
8922 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8923 _("Unknown printer-op-policy \"%s\"."),
8924 attr
->values
[0].string
.text
);
8928 else if (!strcmp(attr
->name
, "printer-error-policy"))
8930 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
8933 if (strcmp(attr
->values
[0].string
.text
, "abort-job") &&
8934 strcmp(attr
->values
[0].string
.text
, "retry-job") &&
8935 strcmp(attr
->values
[0].string
.text
, "stop-printer"))
8937 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8938 _("Unknown printer-error-policy \"%s\"."),
8939 attr
->values
[0].string
.text
);
8943 cupsdLogMessage(CUPSD_LOG_DEBUG
,
8944 "Setting printer-error-policy to \"%s\"...",
8945 attr
->values
[0].string
.text
);
8946 cupsdSetString(&printer
->error_policy
, attr
->values
[0].string
.text
);
8950 * Skip any other non-default attributes...
8953 namelen
= strlen(attr
->name
);
8954 if (namelen
< 9 || strcmp(attr
->name
+ namelen
- 8, "-default") ||
8955 namelen
> (sizeof(name
) - 1) || attr
->num_values
!= 1)
8959 * OK, anything else must be a user-defined default...
8962 strlcpy(name
, attr
->name
, sizeof(name
));
8963 name
[namelen
- 8] = '\0'; /* Strip "-default" */
8965 switch (attr
->value_tag
)
8967 case IPP_TAG_DELETEATTR
:
8968 printer
->num_options
= cupsRemoveOption(name
,
8969 printer
->num_options
,
8970 &(printer
->options
));
8971 cupsdLogMessage(CUPSD_LOG_DEBUG
,
8972 "Deleting %s", attr
->name
);
8976 case IPP_TAG_KEYWORD
:
8978 printer
->num_options
= cupsAddOption(name
,
8979 attr
->values
[0].string
.text
,
8980 printer
->num_options
,
8981 &(printer
->options
));
8982 cupsdLogMessage(CUPSD_LOG_DEBUG
,
8983 "Setting %s to \"%s\"...", attr
->name
,
8984 attr
->values
[0].string
.text
);
8987 case IPP_TAG_BOOLEAN
:
8988 printer
->num_options
= cupsAddOption(name
,
8989 attr
->values
[0].boolean
?
8991 printer
->num_options
,
8992 &(printer
->options
));
8993 cupsdLogMessage(CUPSD_LOG_DEBUG
,
8994 "Setting %s to %s...", attr
->name
,
8995 attr
->values
[0].boolean
? "true" : "false");
8998 case IPP_TAG_INTEGER
:
9000 sprintf(value
, "%d", attr
->values
[0].integer
);
9001 printer
->num_options
= cupsAddOption(name
, value
,
9002 printer
->num_options
,
9003 &(printer
->options
));
9004 cupsdLogMessage(CUPSD_LOG_DEBUG
,
9005 "Setting %s to %s...", attr
->name
, value
);
9008 case IPP_TAG_RANGE
:
9009 sprintf(value
, "%d-%d", attr
->values
[0].range
.lower
,
9010 attr
->values
[0].range
.upper
);
9011 printer
->num_options
= cupsAddOption(name
, value
,
9012 printer
->num_options
,
9013 &(printer
->options
));
9014 cupsdLogMessage(CUPSD_LOG_DEBUG
,
9015 "Setting %s to %s...", attr
->name
, value
);
9018 case IPP_TAG_RESOLUTION
:
9019 sprintf(value
, "%dx%d%s", attr
->values
[0].resolution
.xres
,
9020 attr
->values
[0].resolution
.yres
,
9021 attr
->values
[0].resolution
.units
== IPP_RES_PER_INCH
?
9023 printer
->num_options
= cupsAddOption(name
, value
,
9024 printer
->num_options
,
9025 &(printer
->options
));
9026 cupsdLogMessage(CUPSD_LOG_DEBUG
,
9027 "Setting %s to %s...", attr
->name
, value
);
9031 /* Do nothing for other values */
9039 * 'start_printer()' - Start a printer.
9043 start_printer(cupsd_client_t
*con
, /* I - Client connection */
9044 ipp_attribute_t
*uri
) /* I - Printer URI */
9046 http_status_t status
; /* Policy status */
9047 cups_ptype_t dtype
; /* Destination type (printer or class) */
9048 cupsd_printer_t
*printer
; /* Printer data */
9051 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_printer(%p[%d], %s)", con
,
9052 con
->http
.fd
, uri
->values
[0].string
.text
);
9055 * Is the destination valid?
9058 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9064 send_ipp_status(con
, IPP_NOT_FOUND
,
9065 _("The printer or class was not found."));
9073 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
9075 send_http_error(con
, status
);
9080 * Start the printer...
9083 printer
->state_message
[0] = '\0';
9085 cupsdStartPrinter(printer
, 1);
9087 if (dtype
& CUPS_PRINTER_CLASS
)
9088 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" started by \"%s\".",
9089 printer
->name
, get_username(con
));
9091 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" started by \"%s\".",
9092 printer
->name
, get_username(con
));
9097 * Everything was ok, so return OK status...
9100 con
->response
->request
.status
.status_code
= IPP_OK
;
9105 * 'stop_printer()' - Stop a printer.
9109 stop_printer(cupsd_client_t
*con
, /* I - Client connection */
9110 ipp_attribute_t
*uri
) /* I - Printer URI */
9112 http_status_t status
; /* Policy status */
9113 cups_ptype_t dtype
; /* Destination type (printer or class) */
9114 cupsd_printer_t
*printer
; /* Printer data */
9115 ipp_attribute_t
*attr
; /* printer-state-message attribute */
9118 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "stop_printer(%p[%d], %s)", con
,
9119 con
->http
.fd
, uri
->values
[0].string
.text
);
9122 * Is the destination valid?
9125 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9131 send_ipp_status(con
, IPP_NOT_FOUND
,
9132 _("The printer or class was not found."));
9140 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
9142 send_http_error(con
, status
);
9147 * Stop the printer...
9150 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
9151 IPP_TAG_TEXT
)) == NULL
)
9152 strcpy(printer
->state_message
, "Paused");
9155 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
9156 sizeof(printer
->state_message
));
9159 cupsdStopPrinter(printer
, 1);
9161 if (dtype
& CUPS_PRINTER_CLASS
)
9162 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" stopped by \"%s\".",
9163 printer
->name
, get_username(con
));
9165 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" stopped by \"%s\".",
9166 printer
->name
, get_username(con
));
9169 * Everything was ok, so return OK status...
9172 con
->response
->request
.status
.status_code
= IPP_OK
;
9177 * 'url_encode_attr()' - URL-encode a string attribute.
9181 url_encode_attr(ipp_attribute_t
*attr
, /* I - Attribute */
9182 char *buffer
,/* I - String buffer */
9183 int bufsize
)/* I - Size of buffer */
9185 int i
; /* Looping var */
9186 char *bufptr
, /* Pointer into buffer */
9187 *bufend
, /* End of buffer */
9188 *valptr
; /* Pointer into value */
9191 strlcpy(buffer
, attr
->name
, bufsize
);
9192 bufptr
= buffer
+ strlen(buffer
);
9193 bufend
= buffer
+ bufsize
- 1;
9195 for (i
= 0; i
< attr
->num_values
; i
++)
9197 if (bufptr
>= bufend
)
9205 if (bufptr
>= bufend
)
9210 for (valptr
= attr
->values
[i
].string
.text
;
9211 *valptr
&& bufptr
< bufend
;
9215 if (bufptr
>= (bufend
- 2))
9222 else if (*valptr
== '\'' || *valptr
== '\\')
9225 *bufptr
++ = *valptr
;
9228 *bufptr
++ = *valptr
;
9230 if (bufptr
>= bufend
)
9241 * 'user_allowed()' - See if a user is allowed to print to a queue.
9244 static int /* O - 0 if not allowed, 1 if allowed */
9245 user_allowed(cupsd_printer_t
*p
, /* I - Printer or class */
9246 const char *username
) /* I - Username */
9248 int i
; /* Looping var */
9249 struct passwd
*pw
; /* User password data */
9252 if (p
->num_users
== 0)
9255 if (!strcmp(username
, "root"))
9258 pw
= getpwnam(username
);
9261 for (i
= 0; i
< p
->num_users
; i
++)
9263 if (p
->users
[i
][0] == '@')
9266 * Check group membership...
9269 if (cupsdCheckGroup(username
, pw
, p
->users
[i
] + 1))
9272 else if (!strcasecmp(username
, p
->users
[i
]))
9276 return ((i
< p
->num_users
) != p
->deny_users
);
9281 * 'validate_job()' - Validate printer options and destination.
9285 validate_job(cupsd_client_t
*con
, /* I - Client connection */
9286 ipp_attribute_t
*uri
) /* I - Printer URI */
9288 http_status_t status
; /* Policy status */
9289 ipp_attribute_t
*attr
; /* Current attribute */
9290 ipp_attribute_t
*format
; /* Document-format attribute */
9291 cups_ptype_t dtype
; /* Destination type (printer or class) */
9292 char super
[MIME_MAX_SUPER
],
9293 /* Supertype of file */
9294 type
[MIME_MAX_TYPE
];
9295 /* Subtype of file */
9296 cupsd_printer_t
*printer
; /* Printer */
9299 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_job(%p[%d], %s)", con
,
9300 con
->http
.fd
, uri
->values
[0].string
.text
);
9303 * OK, see if the client is sending the document compressed - CUPS
9304 * doesn't support compression yet...
9307 if ((attr
= ippFindAttribute(con
->request
, "compression",
9308 IPP_TAG_KEYWORD
)) != NULL
&&
9309 !strcmp(attr
->values
[0].string
.text
, "none"))
9311 send_ipp_status(con
, IPP_ATTRIBUTES
,
9312 _("Unsupported compression attribute %s!"),
9313 attr
->values
[0].string
.text
);
9314 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
9315 "compression", NULL
, attr
->values
[0].string
.text
);
9320 * Is it a format we support?
9323 if ((format
= ippFindAttribute(con
->request
, "document-format",
9324 IPP_TAG_MIMETYPE
)) != NULL
)
9326 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]", super
, type
) != 2)
9328 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"!"),
9329 format
->values
[0].string
.text
);
9333 if ((strcmp(super
, "application") || strcmp(type
, "octet-stream")) &&
9334 !mimeType(MimeDatabase
, super
, type
))
9336 cupsdLogMessage(CUPSD_LOG_INFO
,
9337 "Hint: Do you have the raw file printing rules enabled?");
9338 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9339 _("Unsupported format \"%s\"!"),
9340 format
->values
[0].string
.text
);
9341 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9342 "document-format", NULL
, format
->values
[0].string
.text
);
9348 * Is the destination valid?
9351 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9357 send_ipp_status(con
, IPP_NOT_FOUND
,
9358 _("The printer or class was not found."));
9366 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
9368 send_http_error(con
, status
);
9373 * Everything was ok, so return OK status...
9376 con
->response
->request
.status
.status_code
= IPP_OK
;
9381 * 'validate_name()' - Make sure the printer name only contains valid chars.
9384 static int /* O - 0 if name is no good, 1 if name is good */
9385 validate_name(const char *name
) /* I - Name to check */
9387 const char *ptr
; /* Pointer into name */
9391 * Scan the whole name...
9394 for (ptr
= name
; *ptr
; ptr
++)
9395 if ((*ptr
> 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
9399 * All the characters are good; validate the length, too...
9402 return ((ptr
- name
) < 128);
9407 * 'validate_user()' - Validate the user for the request.
9410 static int /* O - 1 if permitted, 0 otherwise */
9411 validate_user(cupsd_job_t
*job
, /* I - Job */
9412 cupsd_client_t
*con
, /* I - Client connection */
9413 const char *owner
, /* I - Owner of job/resource */
9414 char *username
, /* O - Authenticated username */
9415 int userlen
) /* I - Length of username */
9417 cupsd_printer_t
*printer
; /* Printer for job */
9420 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
9421 "validate_user(job=%d, con=%d, owner=\"%s\", username=%p, "
9423 job
? job
->id
: 0, con
->http
.fd
, owner
? owner
: "(null)",
9430 if (!con
|| !owner
|| !username
|| userlen
<= 0)
9434 * Get the best authenticated username that is available.
9437 strlcpy(username
, get_username(con
), userlen
);
9440 * Check the username against the owner...
9443 printer
= cupsdFindDest(job
->dest
);
9445 return (cupsdCheckPolicy(printer
? printer
->op_policy_ptr
: DefaultPolicyPtr
,
9446 con
, owner
) == HTTP_OK
);
9451 * End of "$Id: ipp.c 6370 2007-03-20 14:36:12Z mike $".