]> git.ipfire.org Git - thirdparty/cups.git/blob - scheduler/printers.c
Merge changes from CUPS 1.4svn-r7614.
[thirdparty/cups.git] / scheduler / printers.c
1 /*
2 * "$Id: printers.c 7608 2008-05-21 01:37:21Z mike $"
3 *
4 * Printer routines for the Common UNIX Printing System (CUPS).
5 *
6 * Copyright 2007-2008 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
8 *
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
14 *
15 * Contents:
16 *
17 * cupsdAddPrinter() - Add a printer to the system.
18 * cupsdAddPrinterHistory() - Add the current printer state to the history.
19 * cupsdAddPrinterUser() - Add a user to the ACL.
20 * cupsdCreateCommonData() - Create the common printer data.
21 * cupsdDeleteAllPrinters() - Delete all printers from the system.
22 * cupsdDeletePrinter() - Delete a printer from the system.
23 * cupsdFindPrinter() - Find a printer in the list.
24 * cupsdFreePrinterUsers() - Free allow/deny users.
25 * cupsdLoadAllPrinters() - Load printers from the printers.conf file.
26 * cupsdRenamePrinter() - Rename a printer.
27 * cupsdSaveAllPrinters() - Save all printer definitions to the
28 * printers.conf file.
29 * cupsdSetAuthInfoRequired() - Set the required authentication info.
30 * cupsdSetPrinterAttr() - Set a printer attribute.
31 * cupsdSetPrinterAttrs() - Set printer attributes based upon the PPD
32 * file.
33 * cupsdSetPrinterReasons() - Set/update the reasons strings.
34 * cupsdSetPrinterState() - Update the current state of a printer.
35 * cupsdStopPrinter() - Stop a printer from printing any jobs...
36 * cupsdUpdatePrinters() - Update printers after a partial reload.
37 * cupsdValidateDest() - Validate a printer/class destination.
38 * cupsdWritePrintcap() - Write a pseudo-printcap file for older
39 * applications that need it...
40 * cupsdSanitizeURI() - Sanitize a device URI...
41 * add_printer_defaults() - Add name-default attributes to the printer
42 * attributes.
43 * add_printer_filter() - Add a MIME filter for a printer.
44 * add_printer_formats() - Add document-format-supported values for
45 * a printer.
46 * compare_printers() - Compare two printers.
47 * delete_printer_filters() - Delete all MIME filters for a printer.
48 * write_irix_config() - Update the config files used by the IRIX
49 * desktop tools.
50 * write_irix_state() - Update the status files used by IRIX
51 * printing desktop tools.
52 */
53
54 /*
55 * Include necessary headers...
56 */
57
58 #include "cupsd.h"
59 #include <cups/dir.h>
60
61
62 /*
63 * Local functions...
64 */
65
66 static void add_printer_defaults(cupsd_printer_t *p);
67 static void add_printer_filter(cupsd_printer_t *p, mime_type_t *type,
68 const char *filter);
69 static void add_printer_formats(cupsd_printer_t *p);
70 static int compare_printers(void *first, void *second, void *data);
71 static void delete_printer_filters(cupsd_printer_t *p);
72 #ifdef __sgi
73 static void write_irix_config(cupsd_printer_t *p);
74 static void write_irix_state(cupsd_printer_t *p);
75 #endif /* __sgi */
76
77
78 /*
79 * 'cupsdAddPrinter()' - Add a printer to the system.
80 */
81
82 cupsd_printer_t * /* O - New printer */
83 cupsdAddPrinter(const char *name) /* I - Name of printer */
84 {
85 cupsd_printer_t *p; /* New printer */
86
87
88 /*
89 * Range check input...
90 */
91
92 cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdAddPrinter(\"%s\")", name);
93
94 /*
95 * Create a new printer entity...
96 */
97
98 if ((p = calloc(1, sizeof(cupsd_printer_t))) == NULL)
99 {
100 cupsdLogMessage(CUPSD_LOG_CRIT, "Unable to allocate memory for printer - %s",
101 strerror(errno));
102 return (NULL);
103 }
104
105 cupsdSetString(&p->name, name);
106 cupsdSetString(&p->info, name);
107 cupsdSetString(&p->hostname, ServerName);
108
109 cupsdSetStringf(&p->uri, "ipp://%s:%d/printers/%s", ServerName, LocalPort, name);
110 cupsdSetStringf(&p->device_uri, "file:/dev/null");
111
112 p->state = IPP_PRINTER_STOPPED;
113 p->state_time = time(NULL);
114 p->accepting = 0;
115 p->shared = DefaultShared;
116 p->filetype = mimeAddType(MimeDatabase, "printer", name);
117
118 cupsdSetString(&p->job_sheets[0], "none");
119 cupsdSetString(&p->job_sheets[1], "none");
120
121 cupsdSetString(&p->error_policy, ErrorPolicy);
122 cupsdSetString(&p->op_policy, DefaultPolicy);
123
124 p->op_policy_ptr = DefaultPolicyPtr;
125
126 if (MaxPrinterHistory)
127 p->history = calloc(MaxPrinterHistory, sizeof(ipp_t *));
128
129 /*
130 * Insert the printer in the printer list alphabetically...
131 */
132
133 if (!Printers)
134 Printers = cupsArrayNew(compare_printers, NULL);
135
136 cupsArrayAdd(Printers, p);
137
138 if (!ImplicitPrinters)
139 ImplicitPrinters = cupsArrayNew(compare_printers, NULL);
140
141 /*
142 * Return the new printer...
143 */
144
145 return (p);
146 }
147
148
149 /*
150 * 'cupsdAddPrinterHistory()' - Add the current printer state to the history.
151 */
152
153 void
154 cupsdAddPrinterHistory(
155 cupsd_printer_t *p) /* I - Printer */
156 {
157 ipp_t *history; /* History collection */
158
159
160 /*
161 * Stop early if we aren't keeping history data...
162 */
163
164 if (MaxPrinterHistory <= 0)
165 return;
166
167 /*
168 * Retire old history data as needed...
169 */
170
171 p->sequence_number ++;
172
173 if (p->num_history >= MaxPrinterHistory)
174 {
175 p->num_history --;
176 ippDelete(p->history[0]);
177 memmove(p->history, p->history + 1, p->num_history * sizeof(ipp_t *));
178 }
179
180 /*
181 * Create a collection containing the current printer-state, printer-up-time,
182 * printer-state-message, and printer-state-reasons attributes.
183 */
184
185 history = ippNew();
186 ippAddInteger(history, IPP_TAG_PRINTER, IPP_TAG_ENUM, "printer-state",
187 p->state);
188 ippAddBoolean(history, IPP_TAG_PRINTER, "printer-is-accepting-jobs",
189 p->accepting);
190 ippAddBoolean(history, IPP_TAG_PRINTER, "printer-is-shared", p->shared);
191 ippAddString(history, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-state-message",
192 NULL, p->state_message);
193 #ifdef __APPLE__
194 if (p->recoverable)
195 ippAddString(history, IPP_TAG_PRINTER, IPP_TAG_TEXT,
196 "com.apple.print.recoverable-message", NULL, p->recoverable);
197 #endif /* __APPLE__ */
198 if (p->num_reasons == 0)
199 ippAddString(history, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
200 "printer-state-reasons", NULL,
201 p->state == IPP_PRINTER_STOPPED ? "paused" : "none");
202 else
203 ippAddStrings(history, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
204 "printer-state-reasons", p->num_reasons, NULL,
205 (const char * const *)p->reasons);
206 ippAddInteger(history, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
207 "printer-state-change-time", p->state_time);
208 ippAddInteger(history, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
209 "printer-state-sequence-number", p->sequence_number);
210
211 p->history[p->num_history] = history;
212 p->num_history ++;
213 }
214
215
216 /*
217 * 'cupsdAddPrinterUser()' - Add a user to the ACL.
218 */
219
220 void
221 cupsdAddPrinterUser(
222 cupsd_printer_t *p, /* I - Printer */
223 const char *username) /* I - User */
224 {
225 const char **temp; /* Temporary array pointer */
226
227
228 if (!p || !username)
229 return;
230
231 if (p->num_users == 0)
232 temp = malloc(sizeof(char **));
233 else
234 temp = realloc(p->users, sizeof(char **) * (p->num_users + 1));
235
236 if (!temp)
237 return;
238
239 p->users = temp;
240 temp += p->num_users;
241
242 if ((*temp = strdup(username)) != NULL)
243 p->num_users ++;
244 }
245
246
247 /*
248 * 'cupsdCreateCommonData()' - Create the common printer data.
249 */
250
251 void
252 cupsdCreateCommonData(void)
253 {
254 int i; /* Looping var */
255 ipp_attribute_t *attr; /* Attribute data */
256 cups_dir_t *dir; /* Notifier directory */
257 cups_dentry_t *dent; /* Notifier directory entry */
258 cups_array_t *notifiers; /* Notifier array */
259 char filename[1024], /* Filename */
260 *notifier; /* Current notifier */
261 cupsd_policy_t *p; /* Current policy */
262 static const int nups[] = /* number-up-supported values */
263 { 1, 2, 4, 6, 9, 16 };
264 static const int orients[4] =/* orientation-requested-supported values */
265 {
266 IPP_PORTRAIT,
267 IPP_LANDSCAPE,
268 IPP_REVERSE_LANDSCAPE,
269 IPP_REVERSE_PORTRAIT
270 };
271 static const char * const holds[] = /* job-hold-until-supported values */
272 {
273 "no-hold",
274 "indefinite",
275 "day-time",
276 "evening",
277 "night",
278 "second-shift",
279 "third-shift",
280 "weekend"
281 };
282 static const char * const versions[] =/* ipp-versions-supported values */
283 {
284 "1.0",
285 "1.1"
286 };
287 static const int ops[] = /* operations-supported values */
288 {
289 IPP_PRINT_JOB,
290 IPP_VALIDATE_JOB,
291 IPP_CREATE_JOB,
292 IPP_SEND_DOCUMENT,
293 IPP_CANCEL_JOB,
294 IPP_GET_JOB_ATTRIBUTES,
295 IPP_GET_JOBS,
296 IPP_GET_PRINTER_ATTRIBUTES,
297 IPP_HOLD_JOB,
298 IPP_RELEASE_JOB,
299 IPP_PAUSE_PRINTER,
300 IPP_RESUME_PRINTER,
301 IPP_PURGE_JOBS,
302 IPP_SET_JOB_ATTRIBUTES,
303 IPP_CREATE_PRINTER_SUBSCRIPTION,
304 IPP_CREATE_JOB_SUBSCRIPTION,
305 IPP_GET_SUBSCRIPTION_ATTRIBUTES,
306 IPP_GET_SUBSCRIPTIONS,
307 IPP_RENEW_SUBSCRIPTION,
308 IPP_CANCEL_SUBSCRIPTION,
309 IPP_GET_NOTIFICATIONS,
310 IPP_ENABLE_PRINTER,
311 IPP_DISABLE_PRINTER,
312 CUPS_GET_DEFAULT,
313 CUPS_GET_PRINTERS,
314 CUPS_ADD_PRINTER,
315 CUPS_DELETE_PRINTER,
316 CUPS_GET_CLASSES,
317 CUPS_ADD_CLASS,
318 CUPS_DELETE_CLASS,
319 CUPS_ACCEPT_JOBS,
320 CUPS_REJECT_JOBS,
321 CUPS_SET_DEFAULT,
322 CUPS_GET_DEVICES,
323 CUPS_GET_PPDS,
324 CUPS_MOVE_JOB,
325 CUPS_AUTHENTICATE_JOB,
326 CUPS_GET_PPD,
327 CUPS_GET_DOCUMENT,
328 IPP_RESTART_JOB
329 };
330 static const char * const charsets[] =/* charset-supported values */
331 {
332 "us-ascii",
333 "utf-8"
334 };
335 static const char * const compressions[] =
336 { /* document-compression-supported values */
337 "none"
338 #ifdef HAVE_LIBZ
339 ,"gzip"
340 #endif /* HAVE_LIBZ */
341 };
342 static const char * const multiple_document_handling[] =
343 { /* multiple-document-handling-supported values */
344 "separate-documents-uncollated-copies",
345 "separate-documents-collated-copies"
346 };
347 static const char * const errors[] = /* printer-error-policy-supported values */
348 {
349 "abort-job",
350 "retry-job",
351 "stop-printer"
352 };
353 static const char * const notify_attrs[] =
354 { /* notify-attributes-supported values */
355 "printer-state-change-time",
356 "notify-lease-expiration-time",
357 "notify-subscriber-user-name"
358 };
359 static const char * const notify_events[] =
360 { /* notify-events-supported values */
361 "job-completed",
362 "job-config-changed",
363 "job-created",
364 "job-progress",
365 "job-state-changed",
366 "job-stopped",
367 "printer-added",
368 "printer-changed",
369 "printer-config-changed",
370 "printer-deleted",
371 "printer-finishings-changed",
372 "printer-media-changed",
373 "printer-modified",
374 "printer-restarted",
375 "printer-shutdown",
376 "printer-state-changed",
377 "printer-stopped",
378 "server-audit",
379 "server-restarted",
380 "server-started",
381 "server-stopped"
382 };
383
384
385 if (CommonData)
386 ippDelete(CommonData);
387
388 CommonData = ippNew();
389
390 /*
391 * This list of attributes is sorted to improve performance when the
392 * client provides a requested-attributes attribute...
393 */
394
395 /* charset-configured */
396 ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_CHARSET,
397 "charset-configured", NULL, DefaultCharset);
398
399 /* charset-supported */
400 ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_CHARSET,
401 "charset-supported", sizeof(charsets) / sizeof(charsets[0]),
402 NULL, charsets);
403
404 /* compression-supported */
405 ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
406 "compression-supported",
407 sizeof(compressions) / sizeof(compressions[0]),
408 NULL, compressions);
409
410 /* copies-supported */
411 ippAddRange(CommonData, IPP_TAG_PRINTER, "copies-supported", 1, MaxCopies);
412
413 /* cups-version */
414 ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_TEXT, "cups-version",
415 NULL, CUPS_SVERSION + 6);
416
417 /* generated-natural-language-supported */
418 ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_LANGUAGE,
419 "generated-natural-language-supported", NULL, DefaultLanguage);
420
421 /* ipp-versions-supported */
422 ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
423 "ipp-versions-supported", sizeof(versions) / sizeof(versions[0]),
424 NULL, versions);
425
426 /* job-hold-until-supported */
427 ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
428 "job-hold-until-supported", sizeof(holds) / sizeof(holds[0]),
429 NULL, holds);
430
431 /* job-priority-supported */
432 ippAddInteger(CommonData, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
433 "job-priority-supported", 100);
434
435 /* job-sheets-supported */
436 if (cupsArrayCount(Banners) > 0)
437 {
438 /*
439 * Setup the job-sheets-supported attribute...
440 */
441
442 if (Classification && !ClassifyOverride)
443 attr = ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_NAME,
444 "job-sheets-supported", NULL, Classification);
445 else
446 attr = ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_NAME,
447 "job-sheets-supported", cupsArrayCount(Banners) + 1,
448 NULL, NULL);
449
450 if (attr == NULL)
451 cupsdLogMessage(CUPSD_LOG_EMERG,
452 "Unable to allocate memory for "
453 "job-sheets-supported attribute: %s!", strerror(errno));
454 else if (!Classification || ClassifyOverride)
455 {
456 cupsd_banner_t *banner; /* Current banner */
457
458
459 attr->values[0].string.text = _cupsStrAlloc("none");
460
461 for (i = 1, banner = (cupsd_banner_t *)cupsArrayFirst(Banners);
462 banner;
463 i ++, banner = (cupsd_banner_t *)cupsArrayNext(Banners))
464 attr->values[i].string.text = _cupsStrAlloc(banner->name);
465 }
466 }
467 else
468 ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_NAME,
469 "job-sheets-supported", NULL, "none");
470
471 /* multiple-document-handling-supported */
472 ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
473 "multiple-document-handling-supported",
474 sizeof(multiple_document_handling) /
475 sizeof(multiple_document_handling[0]), NULL,
476 multiple_document_handling);
477
478 /* multiple-document-jobs-supported */
479 ippAddBoolean(CommonData, IPP_TAG_PRINTER,
480 "multiple-document-jobs-supported", 1);
481
482 /* multiple-operation-time-out */
483 ippAddInteger(CommonData, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
484 "multiple-operation-time-out", 60);
485
486 /* natural-language-configured */
487 ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_LANGUAGE,
488 "natural-language-configured", NULL, DefaultLanguage);
489
490 /* notify-attributes-supported */
491 ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
492 "notify-attributes-supported",
493 (int)(sizeof(notify_attrs) / sizeof(notify_attrs[0])),
494 NULL, notify_attrs);
495
496 /* notify-lease-duration-supported */
497 ippAddRange(CommonData, IPP_TAG_PRINTER,
498 "notify-lease-duration-supported", 0,
499 MaxLeaseDuration ? MaxLeaseDuration : 2147483647);
500
501 /* notify-max-events-supported */
502 ippAddInteger(CommonData, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
503 "notify-max-events-supported", MaxEvents);
504
505 /* notify-events-supported */
506 ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
507 "notify-events-supported",
508 (int)(sizeof(notify_events) / sizeof(notify_events[0])),
509 NULL, notify_events);
510
511 /* notify-pull-method-supported */
512 ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
513 "notify-pull-method-supported", NULL, "ippget");
514
515 /* notify-schemes-supported */
516 snprintf(filename, sizeof(filename), "%s/notifier", ServerBin);
517 if ((dir = cupsDirOpen(filename)) != NULL)
518 {
519 notifiers = cupsArrayNew((cups_array_func_t)strcmp, NULL);
520
521 while ((dent = cupsDirRead(dir)) != NULL)
522 if (S_ISREG(dent->fileinfo.st_mode) &&
523 (dent->fileinfo.st_mode & S_IXOTH) != 0)
524 cupsArrayAdd(notifiers, _cupsStrAlloc(dent->filename));
525
526 if (cupsArrayCount(notifiers) > 0)
527 {
528 attr = ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
529 "notify-schemes-supported",
530 cupsArrayCount(notifiers), NULL, NULL);
531
532 for (i = 0, notifier = (char *)cupsArrayFirst(notifiers);
533 notifier;
534 i ++, notifier = (char *)cupsArrayNext(notifiers))
535 attr->values[i].string.text = notifier;
536 }
537
538 cupsArrayDelete(notifiers);
539 cupsDirClose(dir);
540 }
541
542 /* number-up-supported */
543 ippAddIntegers(CommonData, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
544 "number-up-supported", sizeof(nups) / sizeof(nups[0]), nups);
545
546 /* operations-supported */
547 ippAddIntegers(CommonData, IPP_TAG_PRINTER, IPP_TAG_ENUM,
548 "operations-supported",
549 sizeof(ops) / sizeof(ops[0]) + JobFiles - 1, ops);
550
551 /* orientation-requested-supported */
552 ippAddIntegers(CommonData, IPP_TAG_PRINTER, IPP_TAG_ENUM,
553 "orientation-requested-supported", 4, orients);
554
555 /* page-ranges-supported */
556 ippAddBoolean(CommonData, IPP_TAG_PRINTER, "page-ranges-supported", 1);
557
558 /* pdf-override-supported */
559 ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
560 "pdl-override-supported", NULL, "not-attempted");
561
562 /* printer-error-policy-supported */
563 ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_NAME,
564 "printer-error-policy-supported",
565 sizeof(errors) / sizeof(errors[0]), NULL, errors);
566
567 /* printer-op-policy-supported */
568 attr = ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_NAME,
569 "printer-op-policy-supported", cupsArrayCount(Policies),
570 NULL, NULL);
571 for (i = 0, p = (cupsd_policy_t *)cupsArrayFirst(Policies);
572 p;
573 i ++, p = (cupsd_policy_t *)cupsArrayNext(Policies))
574 attr->values[i].string.text = _cupsStrAlloc(p->name);
575
576 ippAddBoolean(CommonData, IPP_TAG_PRINTER, "server-is-sharing-printers",
577 BrowseLocalProtocols != 0 && Browsing);
578 }
579
580
581 /*
582 * 'cupsdDeleteAllPrinters()' - Delete all printers from the system.
583 */
584
585 void
586 cupsdDeleteAllPrinters(void)
587 {
588 cupsd_printer_t *p; /* Pointer to current printer/class */
589
590
591 for (p = (cupsd_printer_t *)cupsArrayFirst(Printers);
592 p;
593 p = (cupsd_printer_t *)cupsArrayNext(Printers))
594 if (!(p->type & CUPS_PRINTER_CLASS))
595 cupsdDeletePrinter(p, 0);
596 }
597
598
599 /*
600 * 'cupsdDeletePrinter()' - Delete a printer from the system.
601 */
602
603 void
604 cupsdDeletePrinter(
605 cupsd_printer_t *p, /* I - Printer to delete */
606 int update) /* I - Update printers.conf? */
607 {
608 int i; /* Looping var */
609 #ifdef __sgi
610 char filename[1024]; /* Interface script filename */
611 #endif /* __sgi */
612
613
614 cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdDeletePrinter(p=%p(%s), update=%d)",
615 p, p->name, update);
616
617 /*
618 * Save the current position in the Printers array...
619 */
620
621 cupsArraySave(Printers);
622
623 /*
624 * Stop printing on this printer...
625 */
626
627 cupsdStopPrinter(p, update);
628
629 /*
630 * If this printer is the next for browsing, point to the next one...
631 */
632
633 if (p == BrowseNext)
634 {
635 cupsArrayFind(Printers, p);
636 BrowseNext = (cupsd_printer_t *)cupsArrayNext(Printers);
637 }
638
639 /*
640 * Remove the printer from the list...
641 */
642
643 cupsArrayRemove(Printers, p);
644
645 if (p->type & CUPS_PRINTER_IMPLICIT)
646 cupsArrayRemove(ImplicitPrinters, p);
647
648 /*
649 * Remove the dummy interface/icon/option files under IRIX...
650 */
651
652 #ifdef __sgi
653 snprintf(filename, sizeof(filename), "/var/spool/lp/interface/%s", p->name);
654 unlink(filename);
655
656 snprintf(filename, sizeof(filename), "/var/spool/lp/gui_interface/ELF/%s.gui",
657 p->name);
658 unlink(filename);
659
660 snprintf(filename, sizeof(filename), "/var/spool/lp/activeicons/%s", p->name);
661 unlink(filename);
662
663 snprintf(filename, sizeof(filename), "/var/spool/lp/pod/%s.config", p->name);
664 unlink(filename);
665
666 snprintf(filename, sizeof(filename), "/var/spool/lp/pod/%s.status", p->name);
667 unlink(filename);
668
669 snprintf(filename, sizeof(filename), "/var/spool/lp/member/%s", p->name);
670 unlink(filename);
671 #endif /* __sgi */
672
673 /*
674 * If p is the default printer, assign a different one...
675 */
676
677 if (p == DefaultPrinter)
678 {
679 DefaultPrinter = NULL;
680
681 if (UseNetworkDefault)
682 {
683 /*
684 * Find the first network default printer and use it...
685 */
686
687 cupsd_printer_t *dp; /* New default printer */
688
689
690 for (dp = (cupsd_printer_t *)cupsArrayFirst(Printers);
691 dp;
692 dp = (cupsd_printer_t *)cupsArrayNext(Printers))
693 if (dp != p && (dp->type & CUPS_PRINTER_DEFAULT))
694 {
695 DefaultPrinter = dp;
696 break;
697 }
698 }
699 }
700
701 /*
702 * Remove this printer from any classes...
703 */
704
705 if (!(p->type & CUPS_PRINTER_IMPLICIT))
706 {
707 cupsdDeletePrinterFromClasses(p);
708
709 /*
710 * Deregister from any browse protocols...
711 */
712
713 cupsdDeregisterPrinter(p, 1);
714 }
715
716 /*
717 * Free all memory used by the printer...
718 */
719
720 if (p->printers != NULL)
721 free(p->printers);
722
723 if (MaxPrinterHistory)
724 {
725 for (i = 0; i < p->num_history; i ++)
726 ippDelete(p->history[i]);
727
728 free(p->history);
729 }
730
731 for (i = 0; i < p->num_reasons; i ++)
732 free(p->reasons[i]);
733
734 ippDelete(p->attrs);
735
736 delete_printer_filters(p);
737
738 mimeDeleteType(MimeDatabase, p->filetype);
739 mimeDeleteType(MimeDatabase, p->prefiltertype);
740
741 cupsdFreePrinterUsers(p);
742 cupsdFreeQuotas(p);
743
744 cupsdClearString(&p->uri);
745 cupsdClearString(&p->hostname);
746 cupsdClearString(&p->name);
747 cupsdClearString(&p->location);
748 cupsdClearString(&p->make_model);
749 cupsdClearString(&p->info);
750 cupsdClearString(&p->job_sheets[0]);
751 cupsdClearString(&p->job_sheets[1]);
752 cupsdClearString(&p->device_uri);
753 cupsdClearString(&p->port_monitor);
754 cupsdClearString(&p->op_policy);
755 cupsdClearString(&p->error_policy);
756
757 cupsdClearString(&p->alert);
758 cupsdClearString(&p->alert_description);
759
760 #ifdef HAVE_DNSSD
761 cupsdClearString(&p->product);
762 cupsdClearString(&p->pdl);
763 #endif /* HAVE_DNSSD */
764
765 cupsArrayDelete(p->filetypes);
766
767 if (p->browse_attrs)
768 free(p->browse_attrs);
769
770 #ifdef __APPLE__
771 cupsdClearString(&p->recoverable);
772 #endif /* __APPLE__ */
773
774 cupsFreeOptions(p->num_options, p->options);
775
776 free(p);
777
778 /*
779 * Restore the previous position in the Printers array...
780 */
781
782 cupsArrayRestore(Printers);
783 }
784
785
786 /*
787 * 'cupsdFindDest()' - Find a destination in the list.
788 */
789
790 cupsd_printer_t * /* O - Destination in list */
791 cupsdFindDest(const char *name) /* I - Name of printer or class to find */
792 {
793 cupsd_printer_t key; /* Search key */
794
795
796 key.name = (char *)name;
797 return ((cupsd_printer_t *)cupsArrayFind(Printers, &key));
798 }
799
800
801 /*
802 * 'cupsdFindPrinter()' - Find a printer in the list.
803 */
804
805 cupsd_printer_t * /* O - Printer in list */
806 cupsdFindPrinter(const char *name) /* I - Name of printer to find */
807 {
808 cupsd_printer_t *p; /* Printer in list */
809
810
811 if ((p = cupsdFindDest(name)) != NULL && (p->type & CUPS_PRINTER_CLASS))
812 return (NULL);
813 else
814 return (p);
815 }
816
817
818 /*
819 * 'cupsdFreePrinterUsers()' - Free allow/deny users.
820 */
821
822 void
823 cupsdFreePrinterUsers(
824 cupsd_printer_t *p) /* I - Printer */
825 {
826 int i; /* Looping var */
827
828
829 if (!p || !p->num_users)
830 return;
831
832 for (i = 0; i < p->num_users; i ++)
833 free((void *)p->users[i]);
834
835 free(p->users);
836
837 p->num_users = 0;
838 p->users = NULL;
839 }
840
841
842 /*
843 * 'cupsdLoadAllPrinters()' - Load printers from the printers.conf file.
844 */
845
846 void
847 cupsdLoadAllPrinters(void)
848 {
849 cups_file_t *fp; /* printers.conf file */
850 int linenum; /* Current line number */
851 char line[1024], /* Line from file */
852 *value, /* Pointer to value */
853 *valueptr; /* Pointer into value */
854 cupsd_printer_t *p; /* Current printer */
855
856
857 /*
858 * Open the printers.conf file...
859 */
860
861 snprintf(line, sizeof(line), "%s/printers.conf", ServerRoot);
862 if ((fp = cupsFileOpen(line, "r")) == NULL)
863 {
864 if (errno != ENOENT)
865 cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to open %s - %s", line,
866 strerror(errno));
867 return;
868 }
869
870 /*
871 * Read printer configurations until we hit EOF...
872 */
873
874 linenum = 0;
875 p = NULL;
876
877 while (cupsFileGetConf(fp, line, sizeof(line), &value, &linenum))
878 {
879 /*
880 * Decode the directive...
881 */
882
883 if (!strcasecmp(line, "<Printer") ||
884 !strcasecmp(line, "<DefaultPrinter"))
885 {
886 /*
887 * <Printer name> or <DefaultPrinter name>
888 */
889
890 if (p == NULL && value)
891 {
892 /*
893 * Add the printer and a base file type...
894 */
895
896 cupsdLogMessage(CUPSD_LOG_DEBUG, "Loading printer %s...", value);
897
898 p = cupsdAddPrinter(value);
899 p->accepting = 1;
900 p->state = IPP_PRINTER_IDLE;
901
902 /*
903 * Set the default printer as needed...
904 */
905
906 if (!strcasecmp(line, "<DefaultPrinter"))
907 DefaultPrinter = p;
908 }
909 else
910 {
911 cupsdLogMessage(CUPSD_LOG_ERROR,
912 "Syntax error on line %d of printers.conf.", linenum);
913 break;
914 }
915 }
916 else if (!strcasecmp(line, "</Printer>"))
917 {
918 if (p != NULL)
919 {
920 /*
921 * Close out the current printer...
922 */
923
924 cupsdSetPrinterAttrs(p);
925 cupsdAddPrinterHistory(p);
926
927 if (p->device_uri && strncmp(p->device_uri, "file:", 5) &&
928 p->state != IPP_PRINTER_STOPPED)
929 {
930 /*
931 * See if the backend exists...
932 */
933
934 snprintf(line, sizeof(line), "%s/backend/%s", ServerBin,
935 p->device_uri);
936
937 if ((valueptr = strchr(line + strlen(ServerBin), ':')) != NULL)
938 *valueptr = '\0'; /* Chop everything but URI scheme */
939
940 if (access(line, 0))
941 {
942 /*
943 * Backend does not exist, stop printer...
944 */
945
946 p->state = IPP_PRINTER_STOPPED;
947 snprintf(p->state_message, sizeof(p->state_message),
948 "Backend %s does not exist!", line);
949 }
950 }
951
952 p = NULL;
953 }
954 else
955 {
956 cupsdLogMessage(CUPSD_LOG_ERROR,
957 "Syntax error on line %d of printers.conf.", linenum);
958 break;
959 }
960 }
961 else if (!p)
962 {
963 cupsdLogMessage(CUPSD_LOG_ERROR,
964 "Syntax error on line %d of printers.conf.", linenum);
965 break;
966 }
967 else if (!strcasecmp(line, "AuthInfoRequired"))
968 {
969 if (!cupsdSetAuthInfoRequired(p, value, NULL))
970 cupsdLogMessage(CUPSD_LOG_ERROR,
971 "Bad AuthInfoRequired on line %d of printers.conf.",
972 linenum);
973 }
974 else if (!strcasecmp(line, "Info"))
975 {
976 if (value)
977 cupsdSetString(&p->info, value);
978 }
979 else if (!strcasecmp(line, "Location"))
980 {
981 if (value)
982 cupsdSetString(&p->location, value);
983 }
984 else if (!strcasecmp(line, "DeviceURI"))
985 {
986 if (value)
987 cupsdSetString(&p->device_uri, value);
988 else
989 {
990 cupsdLogMessage(CUPSD_LOG_ERROR,
991 "Syntax error on line %d of printers.conf.", linenum);
992 break;
993 }
994 }
995 else if (!strcasecmp(line, "Option") && value)
996 {
997 /*
998 * Option name value
999 */
1000
1001 for (valueptr = value; *valueptr && !isspace(*valueptr & 255); valueptr ++);
1002
1003 if (!*valueptr)
1004 cupsdLogMessage(CUPSD_LOG_ERROR,
1005 "Syntax error on line %d of printers.conf.", linenum);
1006 else
1007 {
1008 for (; *valueptr && isspace(*valueptr & 255); *valueptr++ = '\0');
1009
1010 p->num_options = cupsAddOption(value, valueptr, p->num_options,
1011 &(p->options));
1012 }
1013 }
1014 else if (!strcasecmp(line, "PortMonitor"))
1015 {
1016 if (value && strcmp(value, "none"))
1017 cupsdSetString(&p->port_monitor, value);
1018 else if (value)
1019 cupsdClearString(&p->port_monitor);
1020 else
1021 {
1022 cupsdLogMessage(CUPSD_LOG_ERROR,
1023 "Syntax error on line %d of printers.conf.", linenum);
1024 break;
1025 }
1026 }
1027 else if (!strcasecmp(line, "State"))
1028 {
1029 /*
1030 * Set the initial queue state...
1031 */
1032
1033 if (value && !strcasecmp(value, "idle"))
1034 p->state = IPP_PRINTER_IDLE;
1035 else if (value && !strcasecmp(value, "stopped"))
1036 p->state = IPP_PRINTER_STOPPED;
1037 else
1038 {
1039 cupsdLogMessage(CUPSD_LOG_ERROR,
1040 "Syntax error on line %d of printers.conf.", linenum);
1041 break;
1042 }
1043 }
1044 else if (!strcasecmp(line, "StateMessage"))
1045 {
1046 /*
1047 * Set the initial queue state message...
1048 */
1049
1050 if (value)
1051 strlcpy(p->state_message, value, sizeof(p->state_message));
1052 }
1053 else if (!strcasecmp(line, "StateTime"))
1054 {
1055 /*
1056 * Set the state time...
1057 */
1058
1059 if (value)
1060 p->state_time = atoi(value);
1061 }
1062 else if (!strcasecmp(line, "Accepting"))
1063 {
1064 /*
1065 * Set the initial accepting state...
1066 */
1067
1068 if (value &&
1069 (!strcasecmp(value, "yes") ||
1070 !strcasecmp(value, "on") ||
1071 !strcasecmp(value, "true")))
1072 p->accepting = 1;
1073 else if (value &&
1074 (!strcasecmp(value, "no") ||
1075 !strcasecmp(value, "off") ||
1076 !strcasecmp(value, "false")))
1077 p->accepting = 0;
1078 else
1079 {
1080 cupsdLogMessage(CUPSD_LOG_ERROR,
1081 "Syntax error on line %d of printers.conf.", linenum);
1082 break;
1083 }
1084 }
1085 else if (!strcasecmp(line, "Shared"))
1086 {
1087 /*
1088 * Set the initial shared state...
1089 */
1090
1091 if (value &&
1092 (!strcasecmp(value, "yes") ||
1093 !strcasecmp(value, "on") ||
1094 !strcasecmp(value, "true")))
1095 p->shared = 1;
1096 else if (value &&
1097 (!strcasecmp(value, "no") ||
1098 !strcasecmp(value, "off") ||
1099 !strcasecmp(value, "false")))
1100 p->shared = 0;
1101 else
1102 {
1103 cupsdLogMessage(CUPSD_LOG_ERROR,
1104 "Syntax error on line %d of printers.conf.", linenum);
1105 break;
1106 }
1107 }
1108 else if (!strcasecmp(line, "JobSheets"))
1109 {
1110 /*
1111 * Set the initial job sheets...
1112 */
1113
1114 if (value)
1115 {
1116 for (valueptr = value; *valueptr && !isspace(*valueptr & 255); valueptr ++);
1117
1118 if (*valueptr)
1119 *valueptr++ = '\0';
1120
1121 cupsdSetString(&p->job_sheets[0], value);
1122
1123 while (isspace(*valueptr & 255))
1124 valueptr ++;
1125
1126 if (*valueptr)
1127 {
1128 for (value = valueptr; *valueptr && !isspace(*valueptr & 255); valueptr ++);
1129
1130 if (*valueptr)
1131 *valueptr++ = '\0';
1132
1133 cupsdSetString(&p->job_sheets[1], value);
1134 }
1135 }
1136 else
1137 {
1138 cupsdLogMessage(CUPSD_LOG_ERROR,
1139 "Syntax error on line %d of printers.conf.", linenum);
1140 break;
1141 }
1142 }
1143 else if (!strcasecmp(line, "AllowUser"))
1144 {
1145 if (value)
1146 {
1147 p->deny_users = 0;
1148 cupsdAddPrinterUser(p, value);
1149 }
1150 else
1151 {
1152 cupsdLogMessage(CUPSD_LOG_ERROR,
1153 "Syntax error on line %d of printers.conf.", linenum);
1154 break;
1155 }
1156 }
1157 else if (!strcasecmp(line, "DenyUser"))
1158 {
1159 if (value)
1160 {
1161 p->deny_users = 1;
1162 cupsdAddPrinterUser(p, value);
1163 }
1164 else
1165 {
1166 cupsdLogMessage(CUPSD_LOG_ERROR,
1167 "Syntax error on line %d of printers.conf.", linenum);
1168 break;
1169 }
1170 }
1171 else if (!strcasecmp(line, "QuotaPeriod"))
1172 {
1173 if (value)
1174 p->quota_period = atoi(value);
1175 else
1176 {
1177 cupsdLogMessage(CUPSD_LOG_ERROR,
1178 "Syntax error on line %d of printers.conf.", linenum);
1179 break;
1180 }
1181 }
1182 else if (!strcasecmp(line, "PageLimit"))
1183 {
1184 if (value)
1185 p->page_limit = atoi(value);
1186 else
1187 {
1188 cupsdLogMessage(CUPSD_LOG_ERROR,
1189 "Syntax error on line %d of printers.conf.", linenum);
1190 break;
1191 }
1192 }
1193 else if (!strcasecmp(line, "KLimit"))
1194 {
1195 if (value)
1196 p->k_limit = atoi(value);
1197 else
1198 {
1199 cupsdLogMessage(CUPSD_LOG_ERROR,
1200 "Syntax error on line %d of printers.conf.", linenum);
1201 break;
1202 }
1203 }
1204 else if (!strcasecmp(line, "OpPolicy"))
1205 {
1206 if (value)
1207 {
1208 cupsd_policy_t *pol; /* Policy */
1209
1210
1211 if ((pol = cupsdFindPolicy(value)) != NULL)
1212 {
1213 cupsdSetString(&p->op_policy, value);
1214 p->op_policy_ptr = pol;
1215 }
1216 else
1217 cupsdLogMessage(CUPSD_LOG_ERROR,
1218 "Bad policy \"%s\" on line %d of printers.conf",
1219 value, linenum);
1220 }
1221 else
1222 {
1223 cupsdLogMessage(CUPSD_LOG_ERROR,
1224 "Syntax error on line %d of printers.conf.", linenum);
1225 break;
1226 }
1227 }
1228 else if (!strcasecmp(line, "ErrorPolicy"))
1229 {
1230 if (value)
1231 cupsdSetString(&p->error_policy, value);
1232 else
1233 {
1234 cupsdLogMessage(CUPSD_LOG_ERROR,
1235 "Syntax error on line %d of printers.conf.", linenum);
1236 break;
1237 }
1238 }
1239 else if (!strcasecmp(line, "Attribute") && value)
1240 {
1241 for (valueptr = value; *valueptr && !isspace(*valueptr & 255); valueptr ++);
1242
1243 if (!*valueptr)
1244 cupsdLogMessage(CUPSD_LOG_ERROR,
1245 "Syntax error on line %d of printers.conf.", linenum);
1246 else
1247 {
1248 for (; *valueptr && isspace(*valueptr & 255); *valueptr++ = '\0');
1249
1250 if (!p->attrs)
1251 cupsdSetPrinterAttrs(p);
1252
1253 cupsdSetPrinterAttr(p, value, valueptr);
1254
1255 if (!strncmp(value, "marker-", 7))
1256 p->marker_time = time(NULL);
1257 }
1258 }
1259 else
1260 {
1261 /*
1262 * Something else we don't understand...
1263 */
1264
1265 cupsdLogMessage(CUPSD_LOG_ERROR,
1266 "Unknown configuration directive %s on line %d of printers.conf.",
1267 line, linenum);
1268 }
1269 }
1270
1271 cupsFileClose(fp);
1272 }
1273
1274
1275 /*
1276 * 'cupsdRenamePrinter()' - Rename a printer.
1277 */
1278
1279 void
1280 cupsdRenamePrinter(
1281 cupsd_printer_t *p, /* I - Printer */
1282 const char *name) /* I - New name */
1283 {
1284 /*
1285 * Remove the printer from the array(s) first...
1286 */
1287
1288 cupsArrayRemove(Printers, p);
1289
1290 if (p->type & CUPS_PRINTER_IMPLICIT)
1291 cupsArrayRemove(ImplicitPrinters, p);
1292
1293 /*
1294 * Rename the printer type...
1295 */
1296
1297 mimeDeleteType(MimeDatabase, p->filetype);
1298 p->filetype = mimeAddType(MimeDatabase, "printer", name);
1299
1300 mimeDeleteType(MimeDatabase, p->prefiltertype);
1301 p->prefiltertype = mimeAddType(MimeDatabase, "prefilter", name);
1302
1303 /*
1304 * Rename the printer...
1305 */
1306
1307 cupsdSetString(&p->name, name);
1308
1309 /*
1310 * Reset printer attributes...
1311 */
1312
1313 cupsdSetPrinterAttrs(p);
1314
1315 /*
1316 * Add the printer back to the printer array(s)...
1317 */
1318
1319 cupsArrayAdd(Printers, p);
1320
1321 if (p->type & CUPS_PRINTER_IMPLICIT)
1322 cupsArrayAdd(ImplicitPrinters, p);
1323 }
1324
1325
1326 /*
1327 * 'cupsdSaveAllPrinters()' - Save all printer definitions to the printers.conf
1328 * file.
1329 */
1330
1331 void
1332 cupsdSaveAllPrinters(void)
1333 {
1334 int i; /* Looping var */
1335 cups_file_t *fp; /* printers.conf file */
1336 char temp[1024]; /* Temporary string */
1337 char backup[1024]; /* printers.conf.O file */
1338 cupsd_printer_t *printer; /* Current printer class */
1339 time_t curtime; /* Current time */
1340 struct tm *curdate; /* Current date */
1341 cups_option_t *option; /* Current option */
1342 const char *ptr; /* Pointer into info/location */
1343 ipp_attribute_t *marker; /* Current marker attribute */
1344
1345
1346 /*
1347 * Create the printers.conf file...
1348 */
1349
1350 snprintf(temp, sizeof(temp), "%s/printers.conf", ServerRoot);
1351 snprintf(backup, sizeof(backup), "%s/printers.conf.O", ServerRoot);
1352
1353 if (rename(temp, backup))
1354 {
1355 if (errno != ENOENT)
1356 cupsdLogMessage(CUPSD_LOG_ERROR,
1357 "Unable to backup printers.conf - %s", strerror(errno));
1358 }
1359
1360 if ((fp = cupsFileOpen(temp, "w")) == NULL)
1361 {
1362 cupsdLogMessage(CUPSD_LOG_ERROR,
1363 "Unable to save printers.conf - %s", strerror(errno));
1364
1365 if (rename(backup, temp))
1366 cupsdLogMessage(CUPSD_LOG_ERROR,
1367 "Unable to restore printers.conf - %s", strerror(errno));
1368 return;
1369 }
1370 else
1371 cupsdLogMessage(CUPSD_LOG_INFO, "Saving printers.conf...");
1372
1373 /*
1374 * Restrict access to the file...
1375 */
1376
1377 fchown(cupsFileNumber(fp), getuid(), Group);
1378 fchmod(cupsFileNumber(fp), 0600);
1379
1380 /*
1381 * Write a small header to the file...
1382 */
1383
1384 curtime = time(NULL);
1385 curdate = localtime(&curtime);
1386 strftime(temp, sizeof(temp) - 1, "%Y-%m-%d %H:%M", curdate);
1387
1388 cupsFilePuts(fp, "# Printer configuration file for " CUPS_SVERSION "\n");
1389 cupsFilePrintf(fp, "# Written by cupsd on %s\n", temp);
1390
1391 /*
1392 * Write each local printer known to the system...
1393 */
1394
1395 for (printer = (cupsd_printer_t *)cupsArrayFirst(Printers);
1396 printer;
1397 printer = (cupsd_printer_t *)cupsArrayNext(Printers))
1398 {
1399 /*
1400 * Skip remote destinations and printer classes...
1401 */
1402
1403 if ((printer->type & CUPS_PRINTER_DISCOVERED) ||
1404 (printer->type & CUPS_PRINTER_CLASS) ||
1405 (printer->type & CUPS_PRINTER_IMPLICIT))
1406 continue;
1407
1408 /*
1409 * Write printers as needed...
1410 */
1411
1412 if (printer == DefaultPrinter)
1413 cupsFilePrintf(fp, "<DefaultPrinter %s>\n", printer->name);
1414 else
1415 cupsFilePrintf(fp, "<Printer %s>\n", printer->name);
1416
1417 if (printer->num_auth_info_required > 0)
1418 {
1419 cupsFilePrintf(fp, "AuthInfoRequired %s", printer->auth_info_required[0]);
1420 for (i = 1; i < printer->num_auth_info_required; i ++)
1421 cupsFilePrintf(fp, ",%s", printer->auth_info_required[i]);
1422 cupsFilePutChar(fp, '\n');
1423 }
1424
1425 if (printer->info)
1426 {
1427 if ((ptr = strchr(printer->info, '#')) != NULL)
1428 {
1429 /*
1430 * Need to quote the first # in the info string...
1431 */
1432
1433 cupsFilePuts(fp, "Info ");
1434 cupsFileWrite(fp, printer->info, ptr - printer->info);
1435 cupsFilePutChar(fp, '\\');
1436 cupsFilePuts(fp, ptr);
1437 cupsFilePutChar(fp, '\n');
1438 }
1439 else
1440 cupsFilePrintf(fp, "Info %s\n", printer->info);
1441 }
1442
1443 if (printer->location)
1444 {
1445 if ((ptr = strchr(printer->info, '#')) != NULL)
1446 {
1447 /*
1448 * Need to quote the first # in the location string...
1449 */
1450
1451 cupsFilePuts(fp, "Location ");
1452 cupsFileWrite(fp, printer->location, ptr - printer->location);
1453 cupsFilePutChar(fp, '\\');
1454 cupsFilePuts(fp, ptr);
1455 cupsFilePutChar(fp, '\n');
1456 }
1457 else
1458 cupsFilePrintf(fp, "Location %s\n", printer->location);
1459 }
1460 if (printer->device_uri)
1461 cupsFilePrintf(fp, "DeviceURI %s\n", printer->device_uri);
1462
1463 if (printer->port_monitor)
1464 cupsFilePrintf(fp, "PortMonitor %s\n", printer->port_monitor);
1465
1466 if (printer->state == IPP_PRINTER_STOPPED)
1467 {
1468 cupsFilePuts(fp, "State Stopped\n");
1469 cupsFilePrintf(fp, "StateMessage %s\n", printer->state_message);
1470 }
1471 else
1472 cupsFilePuts(fp, "State Idle\n");
1473
1474 cupsFilePrintf(fp, "StateTime %d\n", (int)printer->state_time);
1475
1476 if (printer->accepting)
1477 cupsFilePuts(fp, "Accepting Yes\n");
1478 else
1479 cupsFilePuts(fp, "Accepting No\n");
1480
1481 if (printer->shared)
1482 cupsFilePuts(fp, "Shared Yes\n");
1483 else
1484 cupsFilePuts(fp, "Shared No\n");
1485
1486 cupsFilePrintf(fp, "JobSheets %s %s\n", printer->job_sheets[0],
1487 printer->job_sheets[1]);
1488
1489 cupsFilePrintf(fp, "QuotaPeriod %d\n", printer->quota_period);
1490 cupsFilePrintf(fp, "PageLimit %d\n", printer->page_limit);
1491 cupsFilePrintf(fp, "KLimit %d\n", printer->k_limit);
1492
1493 for (i = 0; i < printer->num_users; i ++)
1494 {
1495 if ((ptr = strchr(printer->users[i], '#')) != NULL)
1496 {
1497 /*
1498 * Need to quote the first # in the user string...
1499 */
1500
1501 cupsFilePrintf(fp, "%sUser ", printer->deny_users ? "Deny" : "Allow");
1502 cupsFileWrite(fp, printer->users[i], ptr - printer->users[i]);
1503 cupsFilePutChar(fp, '\\');
1504 cupsFilePuts(fp, ptr);
1505 cupsFilePutChar(fp, '\n');
1506 }
1507 else
1508 cupsFilePrintf(fp, "%sUser %s\n",
1509 printer->deny_users ? "Deny" : "Allow",
1510 printer->users[i]);
1511 }
1512
1513 if (printer->op_policy)
1514 cupsFilePrintf(fp, "OpPolicy %s\n", printer->op_policy);
1515 if (printer->error_policy)
1516 cupsFilePrintf(fp, "ErrorPolicy %s\n", printer->error_policy);
1517
1518 for (i = printer->num_options, option = printer->options;
1519 i > 0;
1520 i --, option ++)
1521 {
1522 if ((ptr = strchr(option->value, '#')) != NULL)
1523 {
1524 /*
1525 * Need to quote the first # in the option string...
1526 */
1527
1528 cupsFilePrintf(fp, "Option %s ", option->name);
1529 cupsFileWrite(fp, option->value, ptr - option->value);
1530 cupsFilePutChar(fp, '\\');
1531 cupsFilePuts(fp, ptr);
1532 cupsFilePutChar(fp, '\n');
1533 }
1534 else
1535 cupsFilePrintf(fp, "Option %s %s\n", option->name, option->value);
1536 }
1537
1538 if ((marker = ippFindAttribute(printer->attrs, "marker-colors",
1539 IPP_TAG_NAME)) != NULL)
1540 {
1541 cupsFilePrintf(fp, "Attribute %s ", marker->name);
1542
1543 for (i = 0, ptr = NULL; i < marker->num_values; i ++)
1544 {
1545 if (i)
1546 cupsFilePutChar(fp, ',');
1547
1548 if (!ptr && (ptr = strchr(marker->values[i].string.text, '#')) != NULL)
1549 {
1550 cupsFileWrite(fp, marker->values[i].string.text,
1551 ptr - marker->values[i].string.text);
1552 cupsFilePutChar(fp, '\\');
1553 cupsFilePuts(fp, ptr);
1554 }
1555 else
1556 cupsFilePuts(fp, marker->values[i].string.text);
1557 }
1558
1559 cupsFilePuts(fp, "\n");
1560 }
1561
1562 if ((marker = ippFindAttribute(printer->attrs, "marker-levels",
1563 IPP_TAG_INTEGER)) != NULL)
1564 {
1565 cupsFilePrintf(fp, "Attribute %s %d", marker->name,
1566 marker->values[0].integer);
1567 for (i = 1; i < marker->num_values; i ++)
1568 cupsFilePrintf(fp, ",%d", marker->values[i].integer);
1569 cupsFilePuts(fp, "\n");
1570 }
1571
1572 if ((marker = ippFindAttribute(printer->attrs, "marker-names",
1573 IPP_TAG_NAME)) != NULL)
1574 {
1575 cupsFilePrintf(fp, "Attribute %s ", marker->name);
1576
1577 for (i = 0, ptr = NULL; i < marker->num_values; i ++)
1578 {
1579 if (i)
1580 cupsFilePutChar(fp, ',');
1581
1582 if (!ptr && (ptr = strchr(marker->values[i].string.text, '#')) != NULL)
1583 {
1584 cupsFileWrite(fp, marker->values[i].string.text,
1585 ptr - marker->values[i].string.text);
1586 cupsFilePutChar(fp, '\\');
1587 cupsFilePuts(fp, ptr);
1588 }
1589 else
1590 cupsFilePuts(fp, marker->values[i].string.text);
1591 }
1592
1593 cupsFilePuts(fp, "\n");
1594 }
1595
1596 if ((marker = ippFindAttribute(printer->attrs, "marker-types",
1597 IPP_TAG_KEYWORD)) != NULL)
1598 {
1599 cupsFilePrintf(fp, "Attribute %s ", marker->name);
1600
1601 for (i = 0, ptr = NULL; i < marker->num_values; i ++)
1602 {
1603 if (i)
1604 cupsFilePutChar(fp, ',');
1605
1606 if (!ptr && (ptr = strchr(marker->values[i].string.text, '#')) != NULL)
1607 {
1608 cupsFileWrite(fp, marker->values[i].string.text,
1609 ptr - marker->values[i].string.text);
1610 cupsFilePutChar(fp, '\\');
1611 cupsFilePuts(fp, ptr);
1612 }
1613 else
1614 cupsFilePuts(fp, marker->values[i].string.text);
1615 }
1616
1617 cupsFilePuts(fp, "\n");
1618 }
1619
1620 cupsFilePuts(fp, "</Printer>\n");
1621
1622 #ifdef __sgi
1623 /*
1624 * Make IRIX desktop & printer status happy
1625 */
1626
1627 write_irix_state(printer);
1628 #endif /* __sgi */
1629 }
1630
1631 cupsFileClose(fp);
1632 }
1633
1634
1635 /*
1636 * 'cupsdSetAuthInfoRequired()' - Set the required authentication info.
1637 */
1638
1639 int /* O - 1 if value OK, 0 otherwise */
1640 cupsdSetAuthInfoRequired(
1641 cupsd_printer_t *p, /* I - Printer */
1642 const char *values, /* I - Plain text value (or NULL) */
1643 ipp_attribute_t *attr) /* I - IPP attribute value (or NULL) */
1644 {
1645 int i; /* Looping var */
1646
1647
1648 p->num_auth_info_required = 0;
1649
1650 /*
1651 * Do we have a plain text value?
1652 */
1653
1654 if (values)
1655 {
1656 /*
1657 * Yes, grab the keywords...
1658 */
1659
1660 const char *end; /* End of current value */
1661
1662
1663 while (*values && p->num_auth_info_required < 4)
1664 {
1665 if ((end = strchr(values, ',')) == NULL)
1666 end = values + strlen(values);
1667
1668 if ((end - values) == 4 && !strncmp(values, "none", 4))
1669 {
1670 if (p->num_auth_info_required != 0 || *end)
1671 return (0);
1672
1673 p->auth_info_required[p->num_auth_info_required] = "none";
1674 p->num_auth_info_required ++;
1675
1676 return (1);
1677 }
1678 else if ((end - values) == 9 && !strncmp(values, "negotiate", 9))
1679 {
1680 if (p->num_auth_info_required != 0 || *end)
1681 return (0);
1682
1683 p->auth_info_required[p->num_auth_info_required] = "negotiate";
1684 p->num_auth_info_required ++;
1685 }
1686 else if ((end - values) == 6 && !strncmp(values, "domain", 6))
1687 {
1688 p->auth_info_required[p->num_auth_info_required] = "domain";
1689 p->num_auth_info_required ++;
1690 }
1691 else if ((end - values) == 8 && !strncmp(values, "password", 8))
1692 {
1693 p->auth_info_required[p->num_auth_info_required] = "password";
1694 p->num_auth_info_required ++;
1695 }
1696 else if ((end - values) == 8 && !strncmp(values, "username", 8))
1697 {
1698 p->auth_info_required[p->num_auth_info_required] = "username";
1699 p->num_auth_info_required ++;
1700 }
1701 else
1702 return (0);
1703
1704 values = (*end) ? end + 1 : end;
1705 }
1706
1707 if (p->num_auth_info_required == 0)
1708 {
1709 p->auth_info_required[0] = "none";
1710 p->num_auth_info_required = 1;
1711 }
1712
1713 /*
1714 * Update the printer-type value as needed...
1715 */
1716
1717 if (p->num_auth_info_required > 1 ||
1718 strcmp(p->auth_info_required[0], "none"))
1719 p->type |= CUPS_PRINTER_AUTHENTICATED;
1720 else
1721 p->type &= ~CUPS_PRINTER_AUTHENTICATED;
1722
1723 return (1);
1724 }
1725
1726 /*
1727 * Grab values from an attribute instead...
1728 */
1729
1730 if (!attr || attr->num_values > 4)
1731 return (0);
1732
1733 /*
1734 * Update the printer-type value as needed...
1735 */
1736
1737 if (attr->num_values > 1 ||
1738 strcmp(attr->values[0].string.text, "none"))
1739 p->type |= CUPS_PRINTER_AUTHENTICATED;
1740 else
1741 p->type &= ~CUPS_PRINTER_AUTHENTICATED;
1742
1743 for (i = 0; i < attr->num_values; i ++)
1744 {
1745 if (!strcmp(attr->values[i].string.text, "none"))
1746 {
1747 if (p->num_auth_info_required != 0 || attr->num_values != 1)
1748 return (0);
1749
1750 p->auth_info_required[p->num_auth_info_required] = "none";
1751 p->num_auth_info_required ++;
1752
1753 return (1);
1754 }
1755 else if (!strcmp(attr->values[i].string.text, "negotiate"))
1756 {
1757 if (p->num_auth_info_required != 0 || attr->num_values != 1)
1758 return (0);
1759
1760 p->auth_info_required[p->num_auth_info_required] = "negotiate";
1761 p->num_auth_info_required ++;
1762
1763 return (1);
1764 }
1765 else if (!strcmp(attr->values[i].string.text, "domain"))
1766 {
1767 p->auth_info_required[p->num_auth_info_required] = "domain";
1768 p->num_auth_info_required ++;
1769 }
1770 else if (!strcmp(attr->values[i].string.text, "password"))
1771 {
1772 p->auth_info_required[p->num_auth_info_required] = "password";
1773 p->num_auth_info_required ++;
1774 }
1775 else if (!strcmp(attr->values[i].string.text, "username"))
1776 {
1777 p->auth_info_required[p->num_auth_info_required] = "username";
1778 p->num_auth_info_required ++;
1779 }
1780 else
1781 return (0);
1782 }
1783
1784 return (1);
1785 }
1786
1787
1788 /*
1789 * 'cupsdSetPrinterAttr()' - Set a printer attribute.
1790 */
1791
1792 void
1793 cupsdSetPrinterAttr(
1794 cupsd_printer_t *p, /* I - Printer */
1795 const char *name, /* I - Attribute name */
1796 char *value) /* I - Attribute value string */
1797 {
1798 ipp_attribute_t *attr; /* Attribute */
1799 int i, /* Looping var */
1800 count; /* Number of values */
1801 char *ptr; /* Pointer into value */
1802 ipp_tag_t value_tag; /* Value tag for this attribute */
1803
1804
1805 /*
1806 * Count the number of values...
1807 */
1808
1809 for (count = 1, ptr = value;
1810 (ptr = strchr(ptr, ',')) != NULL;
1811 ptr ++, count ++);
1812
1813 /*
1814 * Then add or update the attribute as needed...
1815 */
1816
1817 if (!strcmp(name, "marker-levels"))
1818 {
1819 /*
1820 * Integer values...
1821 */
1822
1823 if ((attr = ippFindAttribute(p->attrs, name, IPP_TAG_INTEGER)) != NULL &&
1824 attr->num_values < count)
1825 {
1826 ippDeleteAttribute(p->attrs, attr);
1827 attr = NULL;
1828 }
1829
1830 if (attr)
1831 attr->num_values = count;
1832 else
1833 attr = ippAddIntegers(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, name,
1834 count, NULL);
1835
1836 if (!attr)
1837 {
1838 cupsdLogMessage(CUPSD_LOG_ERROR,
1839 "Unable to allocate memory for printer attribute "
1840 "(%d values)", count);
1841 return;
1842 }
1843
1844 for (i = 0; i < count; i ++)
1845 {
1846 if ((ptr = strchr(value, ',')) != NULL)
1847 *ptr++ = '\0';
1848
1849 attr->values[i].integer = strtol(value, NULL, 10);
1850
1851 if (ptr)
1852 value = ptr;
1853 }
1854 }
1855 else
1856 {
1857 /*
1858 * Name or keyword values...
1859 */
1860
1861 if (!strcmp(name, "marker-types"))
1862 value_tag = IPP_TAG_KEYWORD;
1863 else
1864 value_tag = IPP_TAG_NAME;
1865
1866 if ((attr = ippFindAttribute(p->attrs, name, value_tag)) != NULL &&
1867 attr->num_values < count)
1868 {
1869 ippDeleteAttribute(p->attrs, attr);
1870 attr = NULL;
1871 }
1872
1873 if (attr)
1874 attr->num_values = count;
1875 else
1876 attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, value_tag, name,
1877 count, NULL, NULL);
1878
1879 if (!attr)
1880 {
1881 cupsdLogMessage(CUPSD_LOG_ERROR,
1882 "Unable to allocate memory for printer attribute "
1883 "(%d values)", count);
1884 return;
1885 }
1886
1887 for (i = 0; i < count; i ++)
1888 {
1889 if ((ptr = strchr(value, ',')) != NULL)
1890 *ptr++ = '\0';
1891
1892 _cupsStrFree(attr->values[i].string.text);
1893 attr->values[i].string.text = _cupsStrAlloc(value);
1894
1895 if (ptr)
1896 value = ptr;
1897 }
1898 }
1899
1900 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS);
1901 }
1902
1903
1904 /*
1905 * 'cupsdSetPrinterAttrs()' - Set printer attributes based upon the PPD file.
1906 */
1907
1908 void
1909 cupsdSetPrinterAttrs(cupsd_printer_t *p)/* I - Printer to setup */
1910 {
1911 int i, /* Looping var */
1912 length; /* Length of browse attributes */
1913 char uri[HTTP_MAX_URI]; /* URI for printer */
1914 char resource[HTTP_MAX_URI]; /* Resource portion of URI */
1915 char filename[1024]; /* Name of PPD file */
1916 int num_air; /* Number of auth-info-required values */
1917 const char * const *air; /* auth-info-required values */
1918 int num_media; /* Number of media options */
1919 cupsd_location_t *auth; /* Pointer to authentication element */
1920 const char *auth_supported; /* Authentication supported */
1921 ppd_file_t *ppd; /* PPD file data */
1922 ppd_option_t *input_slot, /* InputSlot options */
1923 *media_type, /* MediaType options */
1924 *page_size, /* PageSize options */
1925 *output_bin, /* OutputBin options */
1926 *media_quality, /* EFMediaQualityMode options */
1927 *duplex; /* Duplex options */
1928 ppd_attr_t *ppdattr; /* PPD attribute */
1929 ipp_t *oldattrs; /* Old printer attributes */
1930 ipp_attribute_t *attr; /* Attribute data */
1931 ipp_value_t *val; /* Attribute value */
1932 int num_finishings; /* Number of finishings */
1933 int finishings[5]; /* finishings-supported values */
1934 cups_option_t *option; /* Current printer option */
1935 static const char * const sides[3] = /* sides-supported values */
1936 {
1937 "one-sided",
1938 "two-sided-long-edge",
1939 "two-sided-short-edge"
1940 };
1941 static const char * const air_userpass[] =
1942 { /* Basic/Digest authentication */
1943 "username",
1944 "password"
1945 };
1946 #ifdef HAVE_GSSAPI
1947 static const char * const air_negotiate[] =
1948 { /* Kerberos authentication */
1949 "negotiate"
1950 };
1951 #endif /* HAVE_GSSAPI */
1952 static const char * const air_none[] =
1953 { /* No authentication */
1954 "none"
1955 };
1956 static const char * const standard_commands[] =
1957 { /* Standard CUPS commands */
1958 "AutoConfigure",
1959 "Clean",
1960 "PrintSelfTestPage",
1961 "ReportLevels"
1962 };
1963
1964
1965 DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p->name,
1966 p->type));
1967
1968 /*
1969 * Make sure that we have the common attributes defined...
1970 */
1971
1972 if (!CommonData)
1973 cupsdCreateCommonData();
1974
1975 /*
1976 * Clear out old filters, if any...
1977 */
1978
1979 delete_printer_filters(p);
1980
1981 /*
1982 * Figure out the authentication that is required for the printer.
1983 */
1984
1985 auth_supported = "requesting-user-name";
1986 num_air = 1;
1987 air = air_none;
1988
1989 if (p->num_auth_info_required > 0 && strcmp(p->auth_info_required[0], "none"))
1990 {
1991 num_air = p->num_auth_info_required;
1992 air = p->auth_info_required;
1993
1994 if (!strcmp(air[0], "username"))
1995 auth_supported = "basic";
1996 else
1997 auth_supported = "negotiate";
1998 }
1999 else if (!(p->type & CUPS_PRINTER_DISCOVERED))
2000 {
2001 if (p->type & CUPS_PRINTER_CLASS)
2002 snprintf(resource, sizeof(resource), "/classes/%s", p->name);
2003 else
2004 snprintf(resource, sizeof(resource), "/printers/%s", p->name);
2005
2006 if ((auth = cupsdFindBest(resource, HTTP_POST)) == NULL ||
2007 auth->type == CUPSD_AUTH_NONE)
2008 auth = cupsdFindPolicyOp(p->op_policy_ptr, IPP_PRINT_JOB);
2009
2010 if (auth)
2011 {
2012 if (auth->type == CUPSD_AUTH_BASIC || auth->type == CUPSD_AUTH_BASICDIGEST)
2013 {
2014 auth_supported = "basic";
2015 num_air = 2;
2016 air = air_userpass;
2017 }
2018 else if (auth->type == CUPSD_AUTH_DIGEST)
2019 {
2020 auth_supported = "digest";
2021 num_air = 2;
2022 air = air_userpass;
2023 }
2024 #ifdef HAVE_GSSAPI
2025 else if (auth->type == CUPSD_AUTH_NEGOTIATE)
2026 {
2027 auth_supported = "negotiate";
2028 num_air = 1;
2029 air = air_negotiate;
2030 }
2031 #endif /* HAVE_GSSAPI */
2032
2033 if (auth->type != CUPSD_AUTH_NONE)
2034 p->type |= CUPS_PRINTER_AUTHENTICATED;
2035 else
2036 p->type &= ~CUPS_PRINTER_AUTHENTICATED;
2037 }
2038 else
2039 p->type &= ~CUPS_PRINTER_AUTHENTICATED;
2040 }
2041 else if (p->type & CUPS_PRINTER_AUTHENTICATED)
2042 {
2043 num_air = 2;
2044 air = air_userpass;
2045 }
2046
2047 /*
2048 * Create the required IPP attributes for a printer...
2049 */
2050
2051 oldattrs = p->attrs;
2052 p->attrs = ippNew();
2053
2054 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
2055 "uri-authentication-supported", NULL, auth_supported);
2056 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
2057 "uri-security-supported", NULL, "none");
2058 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME, "printer-name", NULL,
2059 p->name);
2060 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-location",
2061 NULL, p->location ? p->location : "");
2062 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-info",
2063 NULL, p->info ? p->info : "");
2064 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, "printer-more-info",
2065 NULL, p->uri);
2066
2067 if (p->num_users)
2068 {
2069 if (p->deny_users)
2070 ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME,
2071 "requesting-user-name-denied", p->num_users, NULL,
2072 p->users);
2073 else
2074 ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME,
2075 "requesting-user-name-allowed", p->num_users, NULL,
2076 p->users);
2077 }
2078
2079 ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
2080 "job-quota-period", p->quota_period);
2081 ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
2082 "job-k-limit", p->k_limit);
2083 ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
2084 "job-page-limit", p->page_limit);
2085 ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
2086 "auth-info-required", num_air, NULL, air);
2087
2088 if (cupsArrayCount(Banners) > 0 && !(p->type & CUPS_PRINTER_DISCOVERED))
2089 {
2090 /*
2091 * Setup the job-sheets-default attribute...
2092 */
2093
2094 attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME,
2095 "job-sheets-default", 2, NULL, NULL);
2096
2097 if (attr != NULL)
2098 {
2099 attr->values[0].string.text = _cupsStrAlloc(Classification ?
2100 Classification : p->job_sheets[0]);
2101 attr->values[1].string.text = _cupsStrAlloc(Classification ?
2102 Classification : p->job_sheets[1]);
2103 }
2104 }
2105
2106 p->raw = 0;
2107 p->remote = 0;
2108
2109 if (p->type & CUPS_PRINTER_DISCOVERED)
2110 {
2111 /*
2112 * Tell the client this is a remote printer of some type...
2113 */
2114
2115 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI,
2116 "printer-uri-supported", NULL, p->uri);
2117
2118 if (p->make_model)
2119 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,
2120 "printer-make-and-model", NULL, p->make_model);
2121
2122 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, "device-uri", NULL,
2123 p->uri);
2124
2125 p->raw = 1;
2126 p->remote = 1;
2127 }
2128 else
2129 {
2130 /*
2131 * Assign additional attributes depending on whether this is a printer
2132 * or class...
2133 */
2134
2135 p->type &= ~CUPS_PRINTER_OPTIONS;
2136
2137 if (p->type & (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT))
2138 {
2139 p->raw = 1;
2140
2141 /*
2142 * Add class-specific attributes...
2143 */
2144
2145 if ((p->type & CUPS_PRINTER_IMPLICIT) && p->num_printers > 0 &&
2146 p->printers[0]->make_model)
2147 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,
2148 "printer-make-and-model", NULL, p->printers[0]->make_model);
2149 else
2150 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,
2151 "printer-make-and-model", NULL, "Local Printer Class");
2152
2153 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, "device-uri", NULL,
2154 "file:///dev/null");
2155
2156 if (p->num_printers > 0)
2157 {
2158 /*
2159 * Add a list of member URIs and names...
2160 */
2161
2162 attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI,
2163 "member-uris", p->num_printers, NULL, NULL);
2164 p->type |= CUPS_PRINTER_OPTIONS;
2165
2166 for (i = 0; i < p->num_printers; i ++)
2167 {
2168 if (attr != NULL)
2169 attr->values[i].string.text = _cupsStrAlloc(p->printers[i]->uri);
2170
2171 p->type &= ~CUPS_PRINTER_OPTIONS | p->printers[i]->type;
2172 }
2173
2174 attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME,
2175 "member-names", p->num_printers, NULL, NULL);
2176
2177 if (attr != NULL)
2178 {
2179 for (i = 0; i < p->num_printers; i ++)
2180 attr->values[i].string.text = _cupsStrAlloc(p->printers[i]->name);
2181 }
2182 }
2183 }
2184 else
2185 {
2186 /*
2187 * Add printer-specific attributes... Start by sanitizing the device
2188 * URI so it doesn't have a username or password in it...
2189 */
2190
2191 if (!p->device_uri)
2192 strcpy(uri, "file:/dev/null");
2193 else if (strstr(p->device_uri, "://") != NULL)
2194 {
2195 /*
2196 * http://..., ipp://..., etc.
2197 */
2198
2199 cupsdSanitizeURI(p->device_uri, uri, sizeof(uri));
2200 }
2201 else
2202 {
2203 /*
2204 * file:..., serial:..., etc.
2205 */
2206
2207 strlcpy(uri, p->device_uri, sizeof(uri));
2208 }
2209
2210 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, "device-uri", NULL,
2211 uri);
2212
2213 /*
2214 * Assign additional attributes from the PPD file (if any)...
2215 */
2216
2217 p->type |= CUPS_PRINTER_BW;
2218 finishings[0] = IPP_FINISHINGS_NONE;
2219 num_finishings = 1;
2220
2221 snprintf(filename, sizeof(filename), "%s/ppd/%s.ppd", ServerRoot,
2222 p->name);
2223
2224 if ((ppd = ppdOpenFile(filename)) != NULL)
2225 {
2226 /*
2227 * Add make/model and other various attributes...
2228 */
2229
2230 if (ppd->color_device)
2231 p->type |= CUPS_PRINTER_COLOR;
2232 if (ppd->variable_sizes)
2233 p->type |= CUPS_PRINTER_VARIABLE;
2234 if (!ppd->manual_copies)
2235 p->type |= CUPS_PRINTER_COPIES;
2236 if ((ppdattr = ppdFindAttr(ppd, "cupsFax", NULL)) != NULL)
2237 if (ppdattr->value && !strcasecmp(ppdattr->value, "true"))
2238 p->type |= CUPS_PRINTER_FAX;
2239
2240 ippAddBoolean(p->attrs, IPP_TAG_PRINTER, "color-supported",
2241 ppd->color_device);
2242 if (ppd->throughput)
2243 ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
2244 "pages-per-minute", ppd->throughput);
2245
2246 if (ppd->nickname)
2247 {
2248 /*
2249 * The NickName can be localized in the character set specified
2250 * by the LanugageEncoding attribute. However, ppdOpen2() has
2251 * already converted the ppd->nickname member to UTF-8 for us
2252 * (the original attribute value is available separately)
2253 */
2254
2255 cupsdSetString(&p->make_model, ppd->nickname);
2256 }
2257 else if (ppd->modelname)
2258 {
2259 /*
2260 * Model name can only contain specific characters...
2261 */
2262
2263 cupsdSetString(&p->make_model, ppd->modelname);
2264 }
2265 else
2266 cupsdSetString(&p->make_model, "Bad PPD File");
2267
2268 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,
2269 "printer-make-and-model", NULL, p->make_model);
2270
2271 /*
2272 * Add media options from the PPD file...
2273 */
2274
2275 if ((input_slot = ppdFindOption(ppd, "InputSlot")) != NULL)
2276 num_media = input_slot->num_choices;
2277 else
2278 num_media = 0;
2279
2280 if ((media_type = ppdFindOption(ppd, "MediaType")) != NULL)
2281 num_media += media_type->num_choices;
2282
2283 if ((page_size = ppdFindOption(ppd, "PageSize")) != NULL)
2284 num_media += page_size->num_choices;
2285
2286 if ((media_quality = ppdFindOption(ppd, "EFMediaQualityMode")) != NULL)
2287 num_media += media_quality->num_choices;
2288
2289 if (num_media == 0)
2290 {
2291 cupsdLogMessage(CUPSD_LOG_CRIT,
2292 "The PPD file for printer %s contains no media "
2293 "options and is therefore invalid!", p->name);
2294 }
2295 else
2296 {
2297 attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
2298 "media-supported", num_media, NULL, NULL);
2299 if (attr != NULL)
2300 {
2301 val = attr->values;
2302
2303 if (input_slot != NULL)
2304 for (i = 0; i < input_slot->num_choices; i ++, val ++)
2305 val->string.text = _cupsStrAlloc(input_slot->choices[i].choice);
2306
2307 if (media_type != NULL)
2308 for (i = 0; i < media_type->num_choices; i ++, val ++)
2309 val->string.text = _cupsStrAlloc(media_type->choices[i].choice);
2310
2311 if (media_quality != NULL)
2312 for (i = 0; i < media_quality->num_choices; i ++, val ++)
2313 val->string.text = _cupsStrAlloc(media_quality->choices[i].choice);
2314
2315 if (page_size != NULL)
2316 {
2317 for (i = 0; i < page_size->num_choices; i ++, val ++)
2318 val->string.text = _cupsStrAlloc(page_size->choices[i].choice);
2319
2320 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
2321 "media-default", NULL, page_size->defchoice);
2322 }
2323 else if (input_slot != NULL)
2324 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
2325 "media-default", NULL, input_slot->defchoice);
2326 else if (media_type != NULL)
2327 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
2328 "media-default", NULL, media_type->defchoice);
2329 else if (media_quality != NULL)
2330 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
2331 "media-default", NULL, media_quality->defchoice);
2332 else
2333 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
2334 "media-default", NULL, "none");
2335 }
2336 }
2337
2338 /*
2339 * Output bin...
2340 */
2341
2342 if ((output_bin = ppdFindOption(ppd, "OutputBin")) != NULL)
2343 {
2344 attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
2345 "output-bin-supported", output_bin->num_choices,
2346 NULL, NULL);
2347
2348 if (attr != NULL)
2349 {
2350 for (i = 0, val = attr->values;
2351 i < output_bin->num_choices;
2352 i ++, val ++)
2353 val->string.text = _cupsStrAlloc(output_bin->choices[i].choice);
2354 }
2355 }
2356
2357 /*
2358 * Duplexing, etc...
2359 */
2360
2361 if ((duplex = ppdFindOption(ppd, "Duplex")) == NULL)
2362 if ((duplex = ppdFindOption(ppd, "EFDuplex")) == NULL)
2363 if ((duplex = ppdFindOption(ppd, "EFDuplexing")) == NULL)
2364 if ((duplex = ppdFindOption(ppd, "KD03Duplex")) == NULL)
2365 duplex = ppdFindOption(ppd, "JCLDuplex");
2366
2367 if (duplex && duplex->num_choices > 1)
2368 {
2369 p->type |= CUPS_PRINTER_DUPLEX;
2370
2371 ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
2372 "sides-supported", 3, NULL, sides);
2373
2374 if (!strcasecmp(duplex->defchoice, "DuplexTumble"))
2375 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
2376 "sides-default", NULL, "two-sided-short-edge");
2377 else if (!strcasecmp(duplex->defchoice, "DuplexNoTumble"))
2378 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
2379 "sides-default", NULL, "two-sided-long-edge");
2380 else
2381 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
2382 "sides-default", NULL, "one-sided");
2383 }
2384
2385 if (ppdFindOption(ppd, "Collate") != NULL)
2386 p->type |= CUPS_PRINTER_COLLATE;
2387
2388 if (ppdFindOption(ppd, "StapleLocation") != NULL)
2389 {
2390 p->type |= CUPS_PRINTER_STAPLE;
2391 finishings[num_finishings++] = IPP_FINISHINGS_STAPLE;
2392 }
2393
2394 if (ppdFindOption(ppd, "BindEdge") != NULL)
2395 {
2396 p->type |= CUPS_PRINTER_BIND;
2397 finishings[num_finishings++] = IPP_FINISHINGS_BIND;
2398 }
2399
2400 for (i = 0; i < ppd->num_sizes; i ++)
2401 if (ppd->sizes[i].length > 1728)
2402 p->type |= CUPS_PRINTER_LARGE;
2403 else if (ppd->sizes[i].length > 1008)
2404 p->type |= CUPS_PRINTER_MEDIUM;
2405 else
2406 p->type |= CUPS_PRINTER_SMALL;
2407
2408 /*
2409 * Add a filter from application/vnd.cups-raw to printer/name to
2410 * handle "raw" printing by users.
2411 */
2412
2413 add_printer_filter(p, p->filetype, "application/vnd.cups-raw 0 -");
2414
2415 /*
2416 * Add any pre-filters in the PPD file...
2417 */
2418
2419 if ((ppdattr = ppdFindAttr(ppd, "cupsPreFilter", NULL)) != NULL)
2420 {
2421 p->prefiltertype = mimeAddType(MimeDatabase, "prefilter", p->name);
2422
2423 for (; ppdattr; ppdattr = ppdFindNextAttr(ppd, "cupsPreFilter", NULL))
2424 if (ppdattr->value)
2425 add_printer_filter(p, p->prefiltertype, ppdattr->value);
2426 }
2427
2428 /*
2429 * Add any filters in the PPD file...
2430 */
2431
2432 DEBUG_printf(("ppd->num_filters = %d\n", ppd->num_filters));
2433 for (i = 0; i < ppd->num_filters; i ++)
2434 {
2435 DEBUG_printf(("ppd->filters[%d] = \"%s\"\n", i, ppd->filters[i]));
2436 add_printer_filter(p, p->filetype, ppd->filters[i]);
2437 }
2438
2439 if (ppd->num_filters == 0)
2440 {
2441 /*
2442 * If there are no filters, add PostScript printing filters.
2443 */
2444
2445 add_printer_filter(p, p->filetype,
2446 "application/vnd.cups-command 0 commandtops");
2447 add_printer_filter(p, p->filetype,
2448 "application/vnd.cups-postscript 0 -");
2449
2450 p->type |= CUPS_PRINTER_COMMANDS;
2451 }
2452 else if (!(p->type & CUPS_PRINTER_COMMANDS))
2453 {
2454 /*
2455 * See if this is a PostScript device without a command filter...
2456 */
2457
2458 for (i = 0; i < ppd->num_filters; i ++)
2459 if (!strncasecmp(ppd->filters[i],
2460 "application/vnd.cups-postscript", 31))
2461 break;
2462
2463 if (i < ppd->num_filters)
2464 {
2465 /*
2466 * Add the generic PostScript command filter...
2467 */
2468
2469 add_printer_filter(p, p->filetype,
2470 "application/vnd.cups-command 0 commandtops");
2471 p->type |= CUPS_PRINTER_COMMANDS;
2472 }
2473 }
2474
2475 if (p->type & CUPS_PRINTER_COMMANDS)
2476 {
2477 char *commands, /* Copy of commands */
2478 *start, /* Start of name */
2479 *end; /* End of name */
2480 int count; /* Number of commands */
2481
2482
2483 if ((ppdattr = ppdFindAttr(ppd, "cupsCommands", NULL)) != NULL &&
2484 ppdattr->value && ppdattr->value[0])
2485 {
2486 for (count = 0, start = ppdattr->value; *start; count ++)
2487 {
2488 while (isspace(*start & 255))
2489 start ++;
2490
2491 if (!*start)
2492 break;
2493
2494 while (*start && !isspace(*start & 255))
2495 start ++;
2496 }
2497 }
2498 else
2499 count = 0;
2500
2501 if (count > 0)
2502 {
2503 /*
2504 * Make a copy of the commands string and count how many ...
2505 */
2506
2507 attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
2508 "printer-commands", count, NULL, NULL);
2509
2510 commands = strdup(ppdattr->value);
2511
2512 for (count = 0, start = commands; *start; count ++)
2513 {
2514 while (isspace(*start & 255))
2515 start ++;
2516
2517 if (!*start)
2518 break;
2519
2520 end = start;
2521 while (*end && !isspace(*end & 255))
2522 end ++;
2523
2524 if (*end)
2525 *end++ = '\0';
2526
2527 attr->values[count].string.text = _cupsStrAlloc(start);
2528
2529 start = end;
2530 }
2531
2532 free(commands);
2533 }
2534 else
2535 {
2536 /*
2537 * Add the standard list of commands...
2538 */
2539
2540 ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
2541 "printer-commands",
2542 (int)(sizeof(standard_commands) /
2543 sizeof(standard_commands[0])), NULL,
2544 standard_commands);
2545 }
2546 }
2547 else
2548 {
2549 /*
2550 * No commands supported...
2551 */
2552
2553 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
2554 "printer-commands", NULL, "none");
2555 }
2556
2557 /*
2558 * Show current and available port monitors for this printer...
2559 */
2560
2561 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME, "port-monitor",
2562 NULL, p->port_monitor ? p->port_monitor : "none");
2563
2564 for (i = 1, ppdattr = ppdFindAttr(ppd, "cupsPortMonitor", NULL);
2565 ppdattr;
2566 i ++, ppdattr = ppdFindNextAttr(ppd, "cupsPortMonitor", NULL));
2567
2568 if (ppd->protocols)
2569 {
2570 if (strstr(ppd->protocols, "TBCP"))
2571 i ++;
2572 else if (strstr(ppd->protocols, "BCP"))
2573 i ++;
2574 }
2575
2576 attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME,
2577 "port-monitor-supported", i, NULL, NULL);
2578
2579 attr->values[0].string.text = _cupsStrAlloc("none");
2580
2581 for (i = 1, ppdattr = ppdFindAttr(ppd, "cupsPortMonitor", NULL);
2582 ppdattr;
2583 i ++, ppdattr = ppdFindNextAttr(ppd, "cupsPortMonitor", NULL))
2584 attr->values[i].string.text = _cupsStrAlloc(ppdattr->value);
2585
2586 if (ppd->protocols)
2587 {
2588 if (strstr(ppd->protocols, "TBCP"))
2589 attr->values[i].string.text = _cupsStrAlloc("tbcp");
2590 else if (strstr(ppd->protocols, "BCP"))
2591 attr->values[i].string.text = _cupsStrAlloc("bcp");
2592 }
2593
2594 #ifdef HAVE_DNSSD
2595 cupsdSetString(&p->product, ppd->product);
2596 #endif /* HAVE_DNSSD */
2597
2598 if (ppdFindAttr(ppd, "APRemoteQueueID", NULL))
2599 p->type |= CUPS_PRINTER_REMOTE;
2600
2601 /*
2602 * Close the PPD and set the type...
2603 */
2604
2605 ppdClose(ppd);
2606 }
2607 else if (!access(filename, 0))
2608 {
2609 int pline; /* PPD line number */
2610 ppd_status_t pstatus; /* PPD load status */
2611
2612
2613 pstatus = ppdLastError(&pline);
2614
2615 cupsdLogMessage(CUPSD_LOG_ERROR, "PPD file for %s cannot be loaded!",
2616 p->name);
2617
2618 if (pstatus <= PPD_ALLOC_ERROR)
2619 cupsdLogMessage(CUPSD_LOG_ERROR, "%s", strerror(errno));
2620 else
2621 cupsdLogMessage(CUPSD_LOG_ERROR, "%s on line %d.",
2622 ppdErrorString(pstatus), pline);
2623
2624 cupsdLogMessage(CUPSD_LOG_INFO,
2625 "Hint: Run \"cupstestppd %s\" and fix any errors.",
2626 filename);
2627
2628 /*
2629 * Add a filter from application/vnd.cups-raw to printer/name to
2630 * handle "raw" printing by users.
2631 */
2632
2633 add_printer_filter(p, p->filetype, "application/vnd.cups-raw 0 -");
2634
2635 /*
2636 * Add a PostScript filter, since this is still possibly PS printer.
2637 */
2638
2639 add_printer_filter(p, p->filetype,
2640 "application/vnd.cups-postscript 0 -");
2641 }
2642 else
2643 {
2644 /*
2645 * If we have an interface script, add a filter entry for it...
2646 */
2647
2648 snprintf(filename, sizeof(filename), "%s/interfaces/%s", ServerRoot,
2649 p->name);
2650 if (!access(filename, X_OK))
2651 {
2652 /*
2653 * Yes, we have a System V style interface script; use it!
2654 */
2655
2656 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,
2657 "printer-make-and-model", NULL,
2658 "Local System V Printer");
2659
2660 snprintf(filename, sizeof(filename), "*/* 0 %s/interfaces/%s",
2661 ServerRoot, p->name);
2662 add_printer_filter(p, p->filetype, filename);
2663 }
2664 else if (p->device_uri &&
2665 !strncmp(p->device_uri, "ipp://", 6) &&
2666 (strstr(p->device_uri, "/printers/") != NULL ||
2667 strstr(p->device_uri, "/classes/") != NULL))
2668 {
2669 /*
2670 * Tell the client this is really a hard-wired remote printer.
2671 */
2672
2673 p->type |= CUPS_PRINTER_REMOTE;
2674
2675 /*
2676 * Point the printer-uri-supported attribute to the
2677 * remote printer...
2678 */
2679
2680 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI,
2681 "printer-uri-supported", NULL, p->device_uri);
2682
2683 /*
2684 * Then set the make-and-model accordingly...
2685 */
2686
2687 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,
2688 "printer-make-and-model", NULL, "Remote Printer");
2689
2690 /*
2691 * Print all files directly...
2692 */
2693
2694 p->raw = 1;
2695 p->remote = 1;
2696 }
2697 else
2698 {
2699 /*
2700 * Otherwise we have neither - treat this as a "dumb" printer
2701 * with no PPD file...
2702 */
2703
2704 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,
2705 "printer-make-and-model", NULL, "Local Raw Printer");
2706
2707 p->raw = 1;
2708 }
2709 }
2710
2711 ippAddIntegers(p->attrs, IPP_TAG_PRINTER, IPP_TAG_ENUM,
2712 "finishings-supported", num_finishings, finishings);
2713 ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_ENUM,
2714 "finishings-default", IPP_FINISHINGS_NONE);
2715 }
2716 }
2717
2718 /*
2719 * Copy marker attributes as needed...
2720 */
2721
2722 if (oldattrs)
2723 {
2724 ipp_attribute_t *oldattr; /* Old attribute */
2725
2726
2727 if ((oldattr = ippFindAttribute(oldattrs, "marker-colors",
2728 IPP_TAG_NAME)) != NULL)
2729 {
2730 if ((attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME,
2731 "marker-colors", oldattr->num_values, NULL,
2732 NULL)) != NULL)
2733 {
2734 for (i = 0; i < oldattr->num_values; i ++)
2735 attr->values[i].string.text =
2736 _cupsStrAlloc(oldattr->values[i].string.text);
2737 }
2738 }
2739
2740 if ((oldattr = ippFindAttribute(oldattrs, "marker-levels",
2741 IPP_TAG_INTEGER)) != NULL)
2742 {
2743 if ((attr = ippAddIntegers(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
2744 "marker-levels", oldattr->num_values,
2745 NULL)) != NULL)
2746 {
2747 for (i = 0; i < oldattr->num_values; i ++)
2748 attr->values[i].integer = oldattr->values[i].integer;
2749 }
2750 }
2751
2752 if ((oldattr = ippFindAttribute(oldattrs, "marker-names",
2753 IPP_TAG_NAME)) != NULL)
2754 {
2755 if ((attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME,
2756 "marker-names", oldattr->num_values, NULL,
2757 NULL)) != NULL)
2758 {
2759 for (i = 0; i < oldattr->num_values; i ++)
2760 attr->values[i].string.text =
2761 _cupsStrAlloc(oldattr->values[i].string.text);
2762 }
2763 }
2764
2765 if ((oldattr = ippFindAttribute(oldattrs, "marker-types",
2766 IPP_TAG_KEYWORD)) != NULL)
2767 {
2768 if ((attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
2769 "marker-types", oldattr->num_values, NULL,
2770 NULL)) != NULL)
2771 {
2772 for (i = 0; i < oldattr->num_values; i ++)
2773 attr->values[i].string.text =
2774 _cupsStrAlloc(oldattr->values[i].string.text);
2775 }
2776 }
2777
2778 ippDelete(oldattrs);
2779 }
2780
2781 /*
2782 * Force sharing off for remote queues...
2783 */
2784
2785 if (p->type & (CUPS_PRINTER_REMOTE | CUPS_PRINTER_IMPLICIT))
2786 p->shared = 0;
2787 else
2788 {
2789 /*
2790 * Copy the printer options into a browse attributes string we can re-use.
2791 */
2792
2793 const char *valptr; /* Pointer into value */
2794 char *attrptr; /* Pointer into attribute string */
2795
2796
2797 /*
2798 * Free the old browse attributes as needed...
2799 */
2800
2801 if (p->browse_attrs)
2802 free(p->browse_attrs);
2803
2804 /*
2805 * Compute the length of all attributes + job-sheets, lease-duration,
2806 * and BrowseLocalOptions.
2807 */
2808
2809 for (length = 1, i = p->num_options, option = p->options;
2810 i > 0;
2811 i --, option ++)
2812 {
2813 length += strlen(option->name) + 2;
2814
2815 if (option->value)
2816 {
2817 for (valptr = option->value; *valptr; valptr ++)
2818 if (strchr(" \"\'\\", *valptr))
2819 length += 2;
2820 else
2821 length ++;
2822 }
2823 }
2824
2825 length += 13 + strlen(p->job_sheets[0]) + strlen(p->job_sheets[1]);
2826 length += 32;
2827 if (BrowseLocalOptions)
2828 length += 12 + strlen(BrowseLocalOptions);
2829
2830 if (p->num_auth_info_required > 0)
2831 {
2832 length += 18; /* auth-info-required */
2833
2834 for (i = 0; i < p->num_auth_info_required; i ++)
2835 length += strlen(p->auth_info_required[i]) + 1;
2836 }
2837
2838 /*
2839 * Allocate the new string...
2840 */
2841
2842 if ((p->browse_attrs = calloc(1, length)) == NULL)
2843 cupsdLogMessage(CUPSD_LOG_ERROR,
2844 "Unable to allocate %d bytes for browse data!",
2845 length);
2846 else
2847 {
2848 /*
2849 * Got the allocated string, now copy the options and attributes over...
2850 */
2851
2852 sprintf(p->browse_attrs, "job-sheets=%s,%s lease-duration=%d",
2853 p->job_sheets[0], p->job_sheets[1], BrowseTimeout);
2854 attrptr = p->browse_attrs + strlen(p->browse_attrs);
2855
2856 if (BrowseLocalOptions)
2857 {
2858 sprintf(attrptr, " ipp-options=%s", BrowseLocalOptions);
2859 attrptr += strlen(attrptr);
2860 }
2861
2862 for (i = p->num_options, option = p->options;
2863 i > 0;
2864 i --, option ++)
2865 {
2866 *attrptr++ = ' ';
2867 strcpy(attrptr, option->name);
2868 attrptr += strlen(attrptr);
2869
2870 if (option->value)
2871 {
2872 *attrptr++ = '=';
2873
2874 for (valptr = option->value; *valptr; valptr ++)
2875 {
2876 if (strchr(" \"\'\\", *valptr))
2877 *attrptr++ = '\\';
2878
2879 *attrptr++ = *valptr;
2880 }
2881 }
2882 }
2883
2884 if (p->num_auth_info_required > 0)
2885 {
2886 strcpy(attrptr, "auth-info-required");
2887 attrptr += 18;
2888
2889 for (i = 0; i < p->num_auth_info_required; i ++)
2890 {
2891 *attrptr++ = i ? ',' : '=';
2892 strcpy(attrptr, p->auth_info_required[i]);
2893 attrptr += strlen(attrptr);
2894 }
2895 }
2896 else
2897 *attrptr = '\0';
2898 }
2899 }
2900
2901 /*
2902 * Populate the document-format-supported attribute...
2903 */
2904
2905 add_printer_formats(p);
2906
2907 DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p->name,
2908 p->type));
2909
2910 /*
2911 * Add name-default attributes...
2912 */
2913
2914 add_printer_defaults(p);
2915
2916 #ifdef __sgi
2917 /*
2918 * Write the IRIX printer config and status files...
2919 */
2920
2921 write_irix_config(p);
2922 write_irix_state(p);
2923 #endif /* __sgi */
2924
2925 /*
2926 * Let the browse protocols reflect the change
2927 */
2928
2929 cupsdRegisterPrinter(p);
2930 }
2931
2932
2933 /*
2934 * 'cupsdSetPrinterReasons()' - Set/update the reasons strings.
2935 */
2936
2937 void
2938 cupsdSetPrinterReasons(
2939 cupsd_printer_t *p, /* I - Printer */
2940 const char *s) /* I - Reasons strings */
2941 {
2942 int i; /* Looping var */
2943 const char *sptr; /* Pointer into reasons */
2944 char reason[255], /* Reason string */
2945 *rptr; /* Pointer into reason */
2946
2947
2948 if (s[0] == '-' || s[0] == '+')
2949 {
2950 /*
2951 * Add/remove reasons...
2952 */
2953
2954 sptr = s + 1;
2955 }
2956 else
2957 {
2958 /*
2959 * Replace reasons...
2960 */
2961
2962 sptr = s;
2963
2964 for (i = 0; i < p->num_reasons; i ++)
2965 free(p->reasons[i]);
2966
2967 p->num_reasons = 0;
2968 }
2969
2970 if (!strcmp(s, "none"))
2971 return;
2972
2973 /*
2974 * Loop through all of the reasons...
2975 */
2976
2977 while (*sptr)
2978 {
2979 /*
2980 * Skip leading whitespace and commas...
2981 */
2982
2983 while (isspace(*sptr & 255) || *sptr == ',')
2984 sptr ++;
2985
2986 for (rptr = reason; *sptr && !isspace(*sptr & 255) && *sptr != ','; sptr ++)
2987 if (rptr < (reason + sizeof(reason) - 1))
2988 *rptr++ = *sptr;
2989
2990 if (rptr == reason)
2991 break;
2992
2993 *rptr = '\0';
2994
2995 if (s[0] == '-')
2996 {
2997 /*
2998 * Remove reason...
2999 */
3000
3001 for (i = 0; i < p->num_reasons; i ++)
3002 if (!strcasecmp(reason, p->reasons[i]))
3003 {
3004 /*
3005 * Found a match, so remove it...
3006 */
3007
3008 p->num_reasons --;
3009 free(p->reasons[i]);
3010
3011 if (i < p->num_reasons)
3012 memmove(p->reasons + i, p->reasons + i + 1,
3013 (p->num_reasons - i) * sizeof(char *));
3014
3015 i --;
3016
3017 if (!strcmp(reason, "paused") && p->state == IPP_PRINTER_STOPPED)
3018 cupsdSetPrinterState(p, IPP_PRINTER_IDLE, 1);
3019 }
3020 }
3021 else if (p->num_reasons < (int)(sizeof(p->reasons) / sizeof(p->reasons[0])))
3022 {
3023 /*
3024 * Add reason...
3025 */
3026
3027 for (i = 0; i < p->num_reasons; i ++)
3028 if (!strcasecmp(reason, p->reasons[i]))
3029 break;
3030
3031 if (i >= p->num_reasons)
3032 {
3033 p->reasons[i] = strdup(reason);
3034 p->num_reasons ++;
3035
3036 if (!strcmp(reason, "paused") && p->state != IPP_PRINTER_STOPPED)
3037 cupsdSetPrinterState(p, IPP_PRINTER_STOPPED, 1);
3038 }
3039 }
3040 }
3041 }
3042
3043
3044 /*
3045 * 'cupsdSetPrinterState()' - Update the current state of a printer.
3046 */
3047
3048 void
3049 cupsdSetPrinterState(
3050 cupsd_printer_t *p, /* I - Printer to change */
3051 ipp_pstate_t s, /* I - New state */
3052 int update) /* I - Update printers.conf? */
3053 {
3054 ipp_pstate_t old_state; /* Old printer state */
3055
3056
3057 /*
3058 * Can't set status of remote printers...
3059 */
3060
3061 if (p->type & CUPS_PRINTER_DISCOVERED)
3062 return;
3063
3064 /*
3065 * Set the new state...
3066 */
3067
3068 old_state = p->state;
3069 p->state = s;
3070
3071 if (old_state != s)
3072 {
3073 cupsdAddEvent(s == IPP_PRINTER_STOPPED ? CUPSD_EVENT_PRINTER_STOPPED :
3074 CUPSD_EVENT_PRINTER_STATE, p, NULL,
3075 "%s \"%s\" state changed.",
3076 (p->type & CUPS_PRINTER_CLASS) ? "Class" : "Printer",
3077 p->name);
3078
3079 /*
3080 * Let the browse code know this needs to be updated...
3081 */
3082
3083 BrowseNext = p;
3084 p->state_time = time(NULL);
3085 p->browse_time = 0;
3086
3087 #ifdef __sgi
3088 write_irix_state(p);
3089 #endif /* __sgi */
3090 }
3091
3092 cupsdAddPrinterHistory(p);
3093
3094 /*
3095 * Let the browse protocols reflect the change...
3096 */
3097
3098 if (update)
3099 cupsdRegisterPrinter(p);
3100
3101 /*
3102 * Save the printer configuration if a printer goes from idle or processing
3103 * to stopped (or visa-versa)...
3104 */
3105
3106 if ((old_state == IPP_PRINTER_STOPPED) != (s == IPP_PRINTER_STOPPED) &&
3107 update)
3108 {
3109 if (p->type & CUPS_PRINTER_CLASS)
3110 cupsdMarkDirty(CUPSD_DIRTY_CLASSES);
3111 else
3112 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS);
3113 }
3114 }
3115
3116
3117 /*
3118 * 'cupsdStopPrinter()' - Stop a printer from printing any jobs...
3119 */
3120
3121 void
3122 cupsdStopPrinter(cupsd_printer_t *p, /* I - Printer to stop */
3123 int update)/* I - Update printers.conf? */
3124 {
3125 cupsd_job_t *job; /* Active print job */
3126
3127
3128 /*
3129 * Set the printer state...
3130 */
3131
3132 cupsdSetPrinterState(p, IPP_PRINTER_STOPPED, update);
3133
3134 /*
3135 * See if we have a job printing on this printer...
3136 */
3137
3138 if (p->job)
3139 {
3140 /*
3141 * Get pointer to job...
3142 */
3143
3144 job = (cupsd_job_t *)p->job;
3145
3146 /*
3147 * Stop it...
3148 */
3149
3150 cupsdStopJob(job, 0);
3151
3152 /*
3153 * Reset the state to pending...
3154 */
3155
3156 job->state->values[0].integer = IPP_JOB_PENDING;
3157 job->state_value = IPP_JOB_PENDING;
3158 job->dirty = 1;
3159
3160 cupsdMarkDirty(CUPSD_DIRTY_JOBS);
3161
3162 cupsdAddEvent(CUPSD_EVENT_JOB_STOPPED, p, job,
3163 "Job stopped due to printer being paused");
3164 }
3165 }
3166
3167
3168 /*
3169 * 'cupsdUpdatePrinterPPD()' - Update keywords in a printer's PPD file.
3170 */
3171
3172 int /* O - 1 if successful, 0 otherwise */
3173 cupsdUpdatePrinterPPD(
3174 cupsd_printer_t *p, /* I - Printer */
3175 int num_keywords, /* I - Number of keywords */
3176 cups_option_t *keywords) /* I - Keywords */
3177 {
3178 int i; /* Looping var */
3179 cups_file_t *src, /* Original file */
3180 *dst; /* New file */
3181 char srcfile[1024], /* Original filename */
3182 dstfile[1024], /* New filename */
3183 line[1024], /* Line from file */
3184 keystring[41]; /* Keyword from line */
3185 cups_option_t *keyword; /* Current keyword */
3186
3187
3188 cupsdLogMessage(CUPSD_LOG_INFO, "Updating keywords in PPD file for %s...",
3189 p->name);
3190
3191 /*
3192 * Get the old and new PPD filenames...
3193 */
3194
3195 snprintf(srcfile, sizeof(srcfile), "%s/ppd/%s.ppd.O", ServerRoot, p->name);
3196 snprintf(dstfile, sizeof(srcfile), "%s/ppd/%s.ppd", ServerRoot, p->name);
3197
3198 /*
3199 * Rename the old file and open the old and new...
3200 */
3201
3202 if (rename(dstfile, srcfile))
3203 {
3204 cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to backup PPD file for %s: %s",
3205 p->name, strerror(errno));
3206 return (0);
3207 }
3208
3209 if ((src = cupsFileOpen(srcfile, "r")) == NULL)
3210 {
3211 cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to open PPD file \"%s\": %s",
3212 srcfile, strerror(errno));
3213 rename(srcfile, dstfile);
3214 return (0);
3215 }
3216
3217 if ((dst = cupsFileOpen(dstfile, "w")) == NULL)
3218 {
3219 cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to create PPD file \"%s\": %s",
3220 dstfile, strerror(errno));
3221 cupsFileClose(src);
3222 rename(srcfile, dstfile);
3223 return (0);
3224 }
3225
3226 /*
3227 * Copy the first line and then write out all of the keywords...
3228 */
3229
3230 if (!cupsFileGets(src, line, sizeof(line)))
3231 {
3232 cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to read PPD file \"%s\": %s",
3233 srcfile, strerror(errno));
3234 cupsFileClose(src);
3235 cupsFileClose(dst);
3236 rename(srcfile, dstfile);
3237 return (0);
3238 }
3239
3240 cupsFilePrintf(dst, "%s\n", line);
3241
3242 for (i = num_keywords, keyword = keywords; i > 0; i --, keyword ++)
3243 {
3244 cupsdLogMessage(CUPSD_LOG_DEBUG, "*%s: %s", keyword->name, keyword->value);
3245 cupsFilePrintf(dst, "*%s: %s\n", keyword->name, keyword->value);
3246 }
3247
3248 /*
3249 * Then copy the rest of the PPD file, dropping any keywords we changed.
3250 */
3251
3252 while (cupsFileGets(src, line, sizeof(line)))
3253 {
3254 /*
3255 * Skip keywords we've already set...
3256 */
3257
3258 if (sscanf(line, "*%40[^:]:", keystring) == 1 &&
3259 cupsGetOption(keystring, num_keywords, keywords))
3260 continue;
3261
3262 /*
3263 * Otherwise write the line...
3264 */
3265
3266 cupsFilePrintf(dst, "%s\n", line);
3267 }
3268
3269 /*
3270 * Close files and return...
3271 */
3272
3273 cupsFileClose(src);
3274 cupsFileClose(dst);
3275
3276 return (1);
3277 }
3278
3279
3280 /*
3281 * 'cupsdUpdatePrinters()' - Update printers after a partial reload.
3282 */
3283
3284 void
3285 cupsdUpdatePrinters(void)
3286 {
3287 cupsd_printer_t *p; /* Current printer */
3288
3289
3290 /*
3291 * Loop through the printers and recreate the printer attributes
3292 * for any local printers since the policy and/or access control
3293 * stuff may have changed. Also, if browsing is disabled, remove
3294 * any remote printers...
3295 */
3296
3297 for (p = (cupsd_printer_t *)cupsArrayFirst(Printers);
3298 p;
3299 p = (cupsd_printer_t *)cupsArrayNext(Printers))
3300 {
3301 /*
3302 * Remove remote printers if we are no longer browsing...
3303 */
3304
3305 if (!Browsing &&
3306 (p->type & (CUPS_PRINTER_IMPLICIT | CUPS_PRINTER_DISCOVERED)))
3307 {
3308 if (p->type & CUPS_PRINTER_IMPLICIT)
3309 cupsArrayRemove(ImplicitPrinters, p);
3310
3311 cupsArraySave(Printers);
3312 cupsdDeletePrinter(p, 0);
3313 cupsArrayRestore(Printers);
3314 continue;
3315 }
3316
3317 /*
3318 * Update the operation policy pointer...
3319 */
3320
3321 if ((p->op_policy_ptr = cupsdFindPolicy(p->op_policy)) == NULL)
3322 p->op_policy_ptr = DefaultPolicyPtr;
3323
3324 /*
3325 * Update printer attributes as needed...
3326 */
3327
3328 if (!(p->type & CUPS_PRINTER_DISCOVERED))
3329 cupsdSetPrinterAttrs(p);
3330 }
3331 }
3332
3333
3334 /*
3335 * 'cupsdValidateDest()' - Validate a printer/class destination.
3336 */
3337
3338 const char * /* O - Printer or class name */
3339 cupsdValidateDest(
3340 const char *uri, /* I - Printer URI */
3341 cups_ptype_t *dtype, /* O - Type (printer or class) */
3342 cupsd_printer_t **printer) /* O - Printer pointer */
3343 {
3344 cupsd_printer_t *p; /* Current printer */
3345 char localname[1024],/* Localized hostname */
3346 *lptr, /* Pointer into localized hostname */
3347 *sptr, /* Pointer into server name */
3348 *rptr, /* Pointer into resource */
3349 scheme[32], /* Scheme portion of URI */
3350 username[64], /* Username portion of URI */
3351 hostname[HTTP_MAX_HOST],
3352 /* Host portion of URI */
3353 resource[HTTP_MAX_URI];
3354 /* Resource portion of URI */
3355 int port; /* Port portion of URI */
3356
3357
3358 DEBUG_printf(("cupsdValidateDest(uri=\"%s\", dtype=%p, printer=%p)\n", uri,
3359 dtype, printer));
3360
3361 /*
3362 * Initialize return values...
3363 */
3364
3365 if (printer)
3366 *printer = NULL;
3367
3368 if (dtype)
3369 *dtype = (cups_ptype_t)0;
3370
3371 /*
3372 * Pull the hostname and resource from the URI...
3373 */
3374
3375 httpSeparateURI(HTTP_URI_CODING_ALL, uri, scheme, sizeof(scheme),
3376 username, sizeof(username), hostname, sizeof(hostname),
3377 &port, resource, sizeof(resource));
3378
3379 /*
3380 * See if the resource is a class or printer...
3381 */
3382
3383 if (!strncmp(resource, "/classes/", 9))
3384 {
3385 /*
3386 * Class...
3387 */
3388
3389 rptr = resource + 9;
3390 }
3391 else if (!strncmp(resource, "/printers/", 10))
3392 {
3393 /*
3394 * Printer...
3395 */
3396
3397 rptr = resource + 10;
3398 }
3399 else
3400 {
3401 /*
3402 * Bad resource name...
3403 */
3404
3405 return (NULL);
3406 }
3407
3408 /*
3409 * See if the printer or class name exists...
3410 */
3411
3412 p = cupsdFindDest(rptr);
3413
3414 if (p == NULL && strchr(rptr, '@') == NULL)
3415 return (NULL);
3416 else if (p != NULL)
3417 {
3418 if (printer)
3419 *printer = p;
3420
3421 if (dtype)
3422 *dtype = p->type & (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT |
3423 CUPS_PRINTER_REMOTE | CUPS_PRINTER_DISCOVERED);
3424
3425 return (p->name);
3426 }
3427
3428 /*
3429 * Change localhost to the server name...
3430 */
3431
3432 if (!strcasecmp(hostname, "localhost"))
3433 strlcpy(hostname, ServerName, sizeof(hostname));
3434
3435 strlcpy(localname, hostname, sizeof(localname));
3436
3437 if (!strcasecmp(hostname, ServerName))
3438 {
3439 /*
3440 * Localize the hostname...
3441 */
3442
3443 lptr = strchr(localname, '.');
3444 sptr = strchr(ServerName, '.');
3445
3446 if (sptr != NULL && lptr != NULL)
3447 {
3448 /*
3449 * Strip the common domain name components...
3450 */
3451
3452 while (lptr != NULL)
3453 {
3454 if (!strcasecmp(lptr, sptr))
3455 {
3456 *lptr = '\0';
3457 break;
3458 }
3459 else
3460 lptr = strchr(lptr + 1, '.');
3461 }
3462 }
3463 }
3464
3465 DEBUG_printf(("localized hostname is \"%s\"...\n", localname));
3466
3467 /*
3468 * Find a matching printer or class...
3469 */
3470
3471 for (p = (cupsd_printer_t *)cupsArrayFirst(Printers);
3472 p;
3473 p = (cupsd_printer_t *)cupsArrayNext(Printers))
3474 if (!strcasecmp(p->hostname, localname) &&
3475 !strcasecmp(p->name, rptr))
3476 {
3477 if (printer)
3478 *printer = p;
3479
3480 if (dtype)
3481 *dtype = p->type & (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT |
3482 CUPS_PRINTER_REMOTE | CUPS_PRINTER_DISCOVERED);
3483
3484 return (p->name);
3485 }
3486
3487 return (NULL);
3488 }
3489
3490
3491 /*
3492 * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications
3493 * that need it...
3494 */
3495
3496 void
3497 cupsdWritePrintcap(void)
3498 {
3499 cups_file_t *fp; /* printcap file */
3500 cupsd_printer_t *p; /* Current printer */
3501
3502
3503 #ifdef __sgi
3504 /*
3505 * Update the IRIX printer state for the default printer; if
3506 * no printers remain, then the default printer file will be
3507 * removed...
3508 */
3509
3510 write_irix_state(DefaultPrinter);
3511 #endif /* __sgi */
3512
3513 /*
3514 * See if we have a printcap file; if not, don't bother writing it.
3515 */
3516
3517 if (!Printcap || !*Printcap)
3518 return;
3519
3520 /*
3521 * Open the printcap file...
3522 */
3523
3524 if ((fp = cupsFileOpen(Printcap, "w")) == NULL)
3525 return;
3526
3527 /*
3528 * Put a comment header at the top so that users will know where the
3529 * data has come from...
3530 */
3531
3532 cupsFilePuts(fp,
3533 "# This file was automatically generated by cupsd(8) from the\n");
3534 cupsFilePrintf(fp, "# %s/printers.conf file. All changes to this file\n",
3535 ServerRoot);
3536 cupsFilePuts(fp, "# will be lost.\n");
3537
3538 if (Printers)
3539 {
3540 /*
3541 * Write a new printcap with the current list of printers.
3542 */
3543
3544 switch (PrintcapFormat)
3545 {
3546 case PRINTCAP_BSD:
3547 /*
3548 * Each printer is put in the file as:
3549 *
3550 * Printer1:
3551 * Printer2:
3552 * Printer3:
3553 * ...
3554 * PrinterN:
3555 */
3556
3557 if (DefaultPrinter)
3558 cupsFilePrintf(fp, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter->name,
3559 DefaultPrinter->info, ServerName,
3560 DefaultPrinter->name);
3561
3562 for (p = (cupsd_printer_t *)cupsArrayFirst(Printers);
3563 p;
3564 p = (cupsd_printer_t *)cupsArrayNext(Printers))
3565 if (p != DefaultPrinter)
3566 cupsFilePrintf(fp, "%s|%s:rm=%s:rp=%s:\n", p->name, p->info,
3567 ServerName, p->name);
3568 break;
3569
3570 case PRINTCAP_SOLARIS:
3571 /*
3572 * Each printer is put in the file as:
3573 *
3574 * _all:all=Printer1,Printer2,Printer3,...,PrinterN
3575 * _default:use=DefaultPrinter
3576 * Printer1:\
3577 * :bsdaddr=ServerName,Printer1:\
3578 * :description=Description:
3579 * Printer2:
3580 * :bsdaddr=ServerName,Printer2:\
3581 * :description=Description:
3582 * Printer3:
3583 * :bsdaddr=ServerName,Printer3:\
3584 * :description=Description:
3585 * ...
3586 * PrinterN:
3587 * :bsdaddr=ServerName,PrinterN:\
3588 * :description=Description:
3589 */
3590
3591 cupsFilePuts(fp, "_all:all=");
3592 for (p = (cupsd_printer_t *)cupsArrayFirst(Printers);
3593 p;
3594 p = (cupsd_printer_t *)cupsArrayCurrent(Printers))
3595 cupsFilePrintf(fp, "%s%c", p->name,
3596 cupsArrayNext(Printers) ? ',' : '\n');
3597
3598 if (DefaultPrinter)
3599 cupsFilePrintf(fp, "_default:use=%s\n", DefaultPrinter->name);
3600
3601 for (p = (cupsd_printer_t *)cupsArrayFirst(Printers);
3602 p;
3603 p = (cupsd_printer_t *)cupsArrayNext(Printers))
3604 cupsFilePrintf(fp, "%s:\\\n"
3605 "\t:bsdaddr=%s,%s:\\\n"
3606 "\t:description=%s:\n",
3607 p->name, ServerName, p->name,
3608 p->info ? p->info : "");
3609 break;
3610 }
3611 }
3612
3613 /*
3614 * Close the file...
3615 */
3616
3617 cupsFileClose(fp);
3618 }
3619
3620
3621 /*
3622 * 'cupsdSanitizeURI()' - Sanitize a device URI...
3623 */
3624
3625 char * /* O - New device URI */
3626 cupsdSanitizeURI(const char *uri, /* I - Original device URI */
3627 char *buffer, /* O - New device URI */
3628 int buflen) /* I - Size of new device URI buffer */
3629 {
3630 char *start, /* Start of data after scheme */
3631 *slash, /* First slash after scheme:// */
3632 *ptr; /* Pointer into user@host:port part */
3633
3634
3635 /*
3636 * Range check input...
3637 */
3638
3639 if (!uri || !buffer || buflen < 2)
3640 return (NULL);
3641
3642 /*
3643 * Copy the device URI to the new buffer...
3644 */
3645
3646 strlcpy(buffer, uri, buflen);
3647
3648 /*
3649 * Find the end of the scheme:// part...
3650 */
3651
3652 if ((ptr = strchr(buffer, ':')) == NULL)
3653 return (buffer); /* No scheme: part... */
3654
3655 for (start = ptr + 1; *start; start ++)
3656 if (*start != '/')
3657 break;
3658
3659 /*
3660 * Find the next slash (/) in the URI...
3661 */
3662
3663 if ((slash = strchr(start, '/')) == NULL)
3664 slash = start + strlen(start); /* No slash, point to the end */
3665
3666 /*
3667 * Check for an @ sign before the slash...
3668 */
3669
3670 if ((ptr = strchr(start, '@')) != NULL && ptr < slash)
3671 {
3672 /*
3673 * Found an @ sign and it is before the resource part, so we have
3674 * an authentication string. Copy the remaining URI over the
3675 * authentication string...
3676 */
3677
3678 _cups_strcpy(start, ptr + 1);
3679 }
3680
3681 /*
3682 * Return the new device URI...
3683 */
3684
3685 return (buffer);
3686 }
3687
3688
3689 /*
3690 * 'add_printer_defaults()' - Add name-default attributes to the printer attributes.
3691 */
3692
3693 static void
3694 add_printer_defaults(cupsd_printer_t *p)/* I - Printer */
3695 {
3696 int i; /* Looping var */
3697 int num_options; /* Number of default options */
3698 cups_option_t *options, /* Default options */
3699 *option; /* Current option */
3700 char name[256]; /* name-default */
3701
3702
3703 /*
3704 * Maintain a common array of default attribute names...
3705 */
3706
3707 if (!CommonDefaults)
3708 {
3709 CommonDefaults = cupsArrayNew((cups_array_func_t)strcmp, NULL);
3710
3711 cupsArrayAdd(CommonDefaults, _cupsStrAlloc("copies-default"));
3712 cupsArrayAdd(CommonDefaults, _cupsStrAlloc("document-format-default"));
3713 cupsArrayAdd(CommonDefaults, _cupsStrAlloc("finishings-default"));
3714 cupsArrayAdd(CommonDefaults, _cupsStrAlloc("job-hold-until-default"));
3715 cupsArrayAdd(CommonDefaults, _cupsStrAlloc("job-priority-default"));
3716 cupsArrayAdd(CommonDefaults, _cupsStrAlloc("job-sheets-default"));
3717 cupsArrayAdd(CommonDefaults, _cupsStrAlloc("media-default"));
3718 cupsArrayAdd(CommonDefaults, _cupsStrAlloc("number-up-default"));
3719 cupsArrayAdd(CommonDefaults,
3720 _cupsStrAlloc("orientation-requested-default"));
3721 cupsArrayAdd(CommonDefaults, _cupsStrAlloc("sides-default"));
3722 }
3723
3724 /*
3725 * Add all of the default options from the .conf files...
3726 */
3727
3728 for (num_options = 0, i = p->num_options, option = p->options;
3729 i > 0;
3730 i --, option ++)
3731 {
3732 if (strcmp(option->name, "ipp-options") &&
3733 strcmp(option->name, "job-sheets") &&
3734 strcmp(option->name, "lease-duration"))
3735 {
3736 snprintf(name, sizeof(name), "%s-default", option->name);
3737 num_options = cupsAddOption(name, option->value, num_options, &options);
3738
3739 if (!cupsArrayFind(CommonDefaults, name))
3740 cupsArrayAdd(CommonDefaults, _cupsStrAlloc(name));
3741 }
3742 }
3743
3744 /*
3745 * Convert options to IPP attributes...
3746 */
3747
3748 cupsEncodeOptions2(p->attrs, num_options, options, IPP_TAG_PRINTER);
3749 cupsFreeOptions(num_options, options);
3750
3751 /*
3752 * Add standard -default attributes as needed...
3753 */
3754
3755 if (!cupsGetOption("copies", p->num_options, p->options))
3756 ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, "copies-default",
3757 1);
3758
3759 if (!cupsGetOption("document-format", p->num_options, p->options))
3760 ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_MIMETYPE,
3761 "document-format-default", NULL, "application/octet-stream");
3762
3763 if (!cupsGetOption("job-hold-until", p->num_options, p->options))
3764 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
3765 "job-hold-until-default", NULL, "no-hold");
3766
3767 if (!cupsGetOption("job-priority", p->num_options, p->options))
3768 ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
3769 "job-priority-default", 50);
3770
3771 if (!cupsGetOption("number-up", p->num_options, p->options))
3772 ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
3773 "number-up-default", 1);
3774
3775 if (!cupsGetOption("orientation-requested", p->num_options, p->options))
3776 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NOVALUE,
3777 "orientation-requested-default", NULL, NULL);
3778
3779 if (!cupsGetOption("notify-lease-duration", p->num_options, p->options))
3780 ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
3781 "notify-lease-duration-default", DefaultLeaseDuration);
3782
3783 if (!cupsGetOption("notify-events", p->num_options, p->options))
3784 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
3785 "notify-events-default", NULL, "job-completed");
3786 }
3787
3788
3789 /*
3790 * 'add_printer_filter()' - Add a MIME filter for a printer.
3791 */
3792
3793 static void
3794 add_printer_filter(
3795 cupsd_printer_t *p, /* I - Printer to add to */
3796 mime_type_t *filtertype, /* I - Filter or prefilter MIME type */
3797 const char *filter) /* I - Filter to add */
3798 {
3799 char super[MIME_MAX_SUPER], /* Super-type for filter */
3800 type[MIME_MAX_TYPE], /* Type for filter */
3801 program[1024]; /* Program/filter name */
3802 int cost; /* Cost of filter */
3803 mime_type_t *temptype; /* MIME type looping var */
3804 char filename[1024]; /* Full filter filename */
3805
3806
3807 /*
3808 * Parse the filter string; it should be in the following format:
3809 *
3810 * super/type cost program
3811 */
3812
3813 if (sscanf(filter, "%15[^/]/%31s%d%1023s", super, type, &cost, program) != 4)
3814 {
3815 cupsdLogMessage(CUPSD_LOG_ERROR, "%s: invalid filter string \"%s\"!",
3816 p->name, filter);
3817 return;
3818 }
3819
3820 /*
3821 * See if the filter program exists; if not, stop the printer and flag
3822 * the error!
3823 */
3824
3825 if (strcmp(program, "-"))
3826 {
3827 if (program[0] == '/')
3828 strlcpy(filename, program, sizeof(filename));
3829 else
3830 snprintf(filename, sizeof(filename), "%s/filter/%s", ServerBin, program);
3831
3832 if (access(filename, X_OK))
3833 {
3834 snprintf(p->state_message, sizeof(p->state_message),
3835 "Filter \"%s\" for printer \"%s\" not available: %s",
3836 program, p->name, strerror(errno));
3837 cupsdSetPrinterReasons(p, "+cups-missing-filter-error");
3838 cupsdSetPrinterState(p, IPP_PRINTER_STOPPED, 0);
3839
3840 cupsdLogMessage(CUPSD_LOG_ERROR, "%s", p->state_message);
3841 }
3842 }
3843
3844 /*
3845 * Mark the CUPS_PRINTER_COMMANDS bit if we have a filter for
3846 * application/vnd.cups-command...
3847 */
3848
3849 if (!strcasecmp(super, "application") &&
3850 !strcasecmp(type, "vnd.cups-command"))
3851 p->type |= CUPS_PRINTER_COMMANDS;
3852
3853 /*
3854 * Add the filter to the MIME database, supporting wildcards as needed...
3855 */
3856
3857 for (temptype = mimeFirstType(MimeDatabase);
3858 temptype;
3859 temptype = mimeNextType(MimeDatabase))
3860 if (((super[0] == '*' && strcasecmp(temptype->super, "printer")) ||
3861 !strcasecmp(temptype->super, super)) &&
3862 (type[0] == '*' || !strcasecmp(temptype->type, type)))
3863 {
3864 cupsdLogMessage(CUPSD_LOG_DEBUG2,
3865 "add_printer_filter: %s: adding filter %s/%s %s/%s %d %s",
3866 p->name, temptype->super, temptype->type,
3867 filtertype->super, filtertype->type,
3868 cost, program);
3869 mimeAddFilter(MimeDatabase, temptype, filtertype, cost, program);
3870 }
3871 }
3872
3873
3874 /*
3875 * 'add_printer_formats()' - Add document-format-supported values for a printer.
3876 */
3877
3878 static void
3879 add_printer_formats(cupsd_printer_t *p) /* I - Printer */
3880 {
3881 int i; /* Looping var */
3882 mime_type_t *type; /* Current MIME type */
3883 cups_array_t *filters; /* Filters */
3884 ipp_attribute_t *attr; /* document-format-supported attribute */
3885 char mimetype[MIME_MAX_SUPER + MIME_MAX_TYPE + 2];
3886 /* MIME type name */
3887
3888
3889 /*
3890 * Raw (and remote) queues advertise all of the supported MIME
3891 * types...
3892 */
3893
3894 cupsArrayDelete(p->filetypes);
3895 p->filetypes = NULL;
3896
3897 if (p->raw)
3898 {
3899 ippAddStrings(p->attrs, IPP_TAG_PRINTER,
3900 (ipp_tag_t)(IPP_TAG_MIMETYPE | IPP_TAG_COPY),
3901 "document-format-supported", NumMimeTypes, NULL, MimeTypes);
3902 return;
3903 }
3904
3905 /*
3906 * Otherwise, loop through the supported MIME types and see if there
3907 * are filters for them...
3908 */
3909
3910 cupsdLogMessage(CUPSD_LOG_DEBUG2, "add_printer_formats: %d types, %d filters",
3911 mimeNumTypes(MimeDatabase), mimeNumFilters(MimeDatabase));
3912
3913 p->filetypes = cupsArrayNew(NULL, NULL);
3914
3915 for (type = mimeFirstType(MimeDatabase);
3916 type;
3917 type = mimeNextType(MimeDatabase))
3918 {
3919 snprintf(mimetype, sizeof(mimetype), "%s/%s", type->super, type->type);
3920
3921 if ((filters = mimeFilter(MimeDatabase, type, p->filetype, NULL)) != NULL)
3922 {
3923 cupsdLogMessage(CUPSD_LOG_DEBUG2,
3924 "add_printer_formats: %s: %s needs %d filters",
3925 p->name, mimetype, cupsArrayCount(filters));
3926
3927 cupsArrayDelete(filters);
3928 cupsArrayAdd(p->filetypes, type);
3929 }
3930 else
3931 cupsdLogMessage(CUPSD_LOG_DEBUG2,
3932 "add_printer_formats: %s: %s not supported",
3933 p->name, mimetype);
3934 }
3935
3936 cupsdLogMessage(CUPSD_LOG_DEBUG2,
3937 "add_printer_formats: %s: %d supported types",
3938 p->name, cupsArrayCount(p->filetypes) + 1);
3939
3940 /*
3941 * Add the file formats that can be filtered...
3942 */
3943
3944 if ((type = mimeType(MimeDatabase, "application", "octet-stream")) == NULL ||
3945 !cupsArrayFind(p->filetypes, type))
3946 i = 1;
3947 else
3948 i = 0;
3949
3950 attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_MIMETYPE,
3951 "document-format-supported",
3952 cupsArrayCount(p->filetypes) + 1, NULL, NULL);
3953
3954 if (i)
3955 attr->values[0].string.text = _cupsStrAlloc("application/octet-stream");
3956
3957 for (type = (mime_type_t *)cupsArrayFirst(p->filetypes);
3958 type;
3959 i ++, type = (mime_type_t *)cupsArrayNext(p->filetypes))
3960 {
3961 snprintf(mimetype, sizeof(mimetype), "%s/%s", type->super, type->type);
3962
3963 attr->values[i].string.text = _cupsStrAlloc(mimetype);
3964 }
3965
3966 #ifdef HAVE_DNSSD
3967 {
3968 char pdl[1024]; /* Buffer to build pdl list */
3969 mime_filter_t *filter; /* MIME filter looping var */
3970
3971
3972 pdl[0] = '\0';
3973
3974 if (mimeType(MimeDatabase, "application", "pdf"))
3975 strlcat(pdl, "application/pdf,", sizeof(pdl));
3976
3977 if (mimeType(MimeDatabase, "application", "postscript"))
3978 strlcat(pdl, "application/postscript,", sizeof(pdl));
3979
3980 if (mimeType(MimeDatabase, "application", "vnd.cups-raster"))
3981 strlcat(pdl, "application/vnd.cups-raster,", sizeof(pdl));
3982
3983 /*
3984 * Determine if this is a Tioga PrintJobMgr based queue...
3985 */
3986
3987 for (filter = (mime_filter_t *)cupsArrayFirst(MimeDatabase->filters);
3988 filter;
3989 filter = (mime_filter_t *)cupsArrayNext(MimeDatabase->filters))
3990 {
3991 if (filter->dst == p->filetype && filter->filter &&
3992 strstr(filter->filter, "PrintJobMgr"))
3993 break;
3994 }
3995
3996 /*
3997 * We only support raw printing if this is not a Tioga PrintJobMgr based
3998 * queue and if application/octet-stream is a known conversion...
3999 */
4000
4001 if (!filter && mimeType(MimeDatabase, "application", "octet-stream"))
4002 strlcat(pdl, "application/octet-stream,", sizeof(pdl));
4003
4004 if (mimeType(MimeDatabase, "image", "png"))
4005 strlcat(pdl, "image/png,", sizeof(pdl));
4006
4007 if (pdl[0])
4008 pdl[strlen(pdl) - 1] = '\0'; /* Remove trailing comma */
4009
4010 cupsdSetString(&p->pdl, pdl);
4011 }
4012 #endif /* HAVE_DNSSD */
4013 }
4014
4015
4016 /*
4017 * 'compare_printers()' - Compare two printers.
4018 */
4019
4020 static int /* O - Result of comparison */
4021 compare_printers(void *first, /* I - First printer */
4022 void *second, /* I - Second printer */
4023 void *data) /* I - App data (not used) */
4024 {
4025 return (strcasecmp(((cupsd_printer_t *)first)->name,
4026 ((cupsd_printer_t *)second)->name));
4027 }
4028
4029
4030 /*
4031 * 'delete_printer_filters()' - Delete all MIME filters for a printer.
4032 */
4033
4034 static void
4035 delete_printer_filters(
4036 cupsd_printer_t *p) /* I - Printer to remove from */
4037 {
4038 mime_filter_t *filter; /* MIME filter looping var */
4039
4040
4041 /*
4042 * Range check input...
4043 */
4044
4045 if (p == NULL)
4046 return;
4047
4048 /*
4049 * Remove all filters from the MIME database that have a destination
4050 * type == printer...
4051 */
4052
4053 for (filter = mimeFirstFilter(MimeDatabase);
4054 filter;
4055 filter = mimeNextFilter(MimeDatabase))
4056 if (filter->dst == p->filetype)
4057 {
4058 /*
4059 * Delete the current filter...
4060 */
4061
4062 mimeDeleteFilter(MimeDatabase, filter);
4063 }
4064 }
4065
4066
4067 #ifdef __sgi
4068 /*
4069 * 'write_irix_config()' - Update the config files used by the IRIX
4070 * desktop tools.
4071 */
4072
4073 static void
4074 write_irix_config(cupsd_printer_t *p) /* I - Printer to update */
4075 {
4076 char filename[1024]; /* Interface script filename */
4077 cups_file_t *fp; /* Interface script file */
4078 ipp_attribute_t *attr; /* Attribute data */
4079
4080
4081 /*
4082 * Add dummy interface and GUI scripts to fool SGI's "challenged" printing
4083 * tools. First the interface script that tells the tools what kind of
4084 * printer we have...
4085 */
4086
4087 snprintf(filename, sizeof(filename), "/var/spool/lp/interface/%s", p->name);
4088
4089 if (p->type & CUPS_PRINTER_CLASS)
4090 unlink(filename);
4091 else if ((fp = cupsFileOpen(filename, "w")) != NULL)
4092 {
4093 cupsFilePuts(fp, "#!/bin/sh\n");
4094
4095 if ((attr = ippFindAttribute(p->attrs, "printer-make-and-model",
4096 IPP_TAG_TEXT)) != NULL)
4097 cupsFilePrintf(fp, "NAME=\"%s\"\n", attr->values[0].string.text);
4098 else if (p->type & CUPS_PRINTER_CLASS)
4099 cupsFilePuts(fp, "NAME=\"Printer Class\"\n");
4100 else
4101 cupsFilePuts(fp, "NAME=\"Remote Destination\"\n");
4102
4103 if (p->type & CUPS_PRINTER_COLOR)
4104 cupsFilePuts(fp, "TYPE=ColorPostScript\n");
4105 else
4106 cupsFilePuts(fp, "TYPE=MonoPostScript\n");
4107
4108 cupsFilePrintf(fp, "HOSTNAME=%s\n", ServerName);
4109 cupsFilePrintf(fp, "HOSTPRINTER=%s\n", p->name);
4110
4111 cupsFileClose(fp);
4112
4113 chmod(filename, 0755);
4114 chown(filename, User, Group);
4115 }
4116
4117 /*
4118 * Then the member file that tells which device file the queue is connected
4119 * to... Networked printers use "/dev/null" in this file, so that's what
4120 * we use (the actual device URI can confuse some apps...)
4121 */
4122
4123 snprintf(filename, sizeof(filename), "/var/spool/lp/member/%s", p->name);
4124
4125 if (p->type & CUPS_PRINTER_CLASS)
4126 unlink(filename);
4127 else if ((fp = cupsFileOpen(filename, "w")) != NULL)
4128 {
4129 cupsFilePuts(fp, "/dev/null\n");
4130
4131 cupsFileClose(fp);
4132
4133 chmod(filename, 0644);
4134 chown(filename, User, Group);
4135 }
4136
4137 /*
4138 * The gui_interface file is a script or program that launches a GUI
4139 * option panel for the printer, using options specified on the
4140 * command-line in the third argument. The option panel must send
4141 * any printing options to stdout on a single line when the user
4142 * accepts them, or nothing if the user cancels the dialog.
4143 *
4144 * The default options panel program is /usr/bin/glpoptions, from
4145 * the ESP Print Pro software. You can select another using the
4146 * PrintcapGUI option.
4147 */
4148
4149 snprintf(filename, sizeof(filename), "/var/spool/lp/gui_interface/ELF/%s.gui", p->name);
4150
4151 if (p->type & CUPS_PRINTER_CLASS)
4152 unlink(filename);
4153 else if ((fp = cupsFileOpen(filename, "w")) != NULL)
4154 {
4155 cupsFilePuts(fp, "#!/bin/sh\n");
4156 cupsFilePrintf(fp, "%s -d %s -o \"$3\"\n", PrintcapGUI, p->name);
4157
4158 cupsFileClose(fp);
4159
4160 chmod(filename, 0755);
4161 chown(filename, User, Group);
4162 }
4163
4164 /*
4165 * The POD config file is needed by the printstatus command to show
4166 * the printer location and device.
4167 */
4168
4169 snprintf(filename, sizeof(filename), "/var/spool/lp/pod/%s.config", p->name);
4170
4171 if (p->type & CUPS_PRINTER_CLASS)
4172 unlink(filename);
4173 else if ((fp = cupsFileOpen(filename, "w")) != NULL)
4174 {
4175 cupsFilePrintf(fp, "Printer Class | %s\n",
4176 (p->type & CUPS_PRINTER_COLOR) ? "ColorPostScript" : "MonoPostScript");
4177 cupsFilePrintf(fp, "Printer Model | %s\n", p->make_model ? p->make_model : "");
4178 cupsFilePrintf(fp, "Location Code | %s\n", p->location ? p->location : "");
4179 cupsFilePrintf(fp, "Physical Location | %s\n", p->info ? p->info : "");
4180 cupsFilePrintf(fp, "Port Path | %s\n", p->device_uri ? p->device_uri : "");
4181 cupsFilePrintf(fp, "Config Path | /var/spool/lp/pod/%s.config\n", p->name);
4182 cupsFilePrintf(fp, "Active Status Path | /var/spool/lp/pod/%s.status\n", p->name);
4183 cupsFilePuts(fp, "Status Update Wait | 10 seconds\n");
4184
4185 cupsFileClose(fp);
4186
4187 chmod(filename, 0664);
4188 chown(filename, User, Group);
4189 }
4190 }
4191
4192
4193 /*
4194 * 'write_irix_state()' - Update the status files used by IRIX printing
4195 * desktop tools.
4196 */
4197
4198 static void
4199 write_irix_state(cupsd_printer_t *p) /* I - Printer to update */
4200 {
4201 char filename[1024]; /* Interface script filename */
4202 cups_file_t *fp; /* Interface script file */
4203 int tag; /* Status tag value */
4204
4205
4206 if (p)
4207 {
4208 /*
4209 * The POD status file is needed for the printstatus window to
4210 * provide the current status of the printer.
4211 */
4212
4213 snprintf(filename, sizeof(filename), "/var/spool/lp/pod/%s.status", p->name);
4214
4215 if (p->type & CUPS_PRINTER_CLASS)
4216 unlink(filename);
4217 else if ((fp = cupsFileOpen(filename, "w")) != NULL)
4218 {
4219 cupsFilePrintf(fp, "Operational Status | %s\n",
4220 (p->state == IPP_PRINTER_IDLE) ? "Idle" :
4221 (p->state == IPP_PRINTER_PROCESSING) ? "Busy" :
4222 "Faulted");
4223 cupsFilePrintf(fp, "Information | 01 00 00 | %s\n", CUPS_SVERSION);
4224 cupsFilePrintf(fp, "Information | 02 00 00 | Device URI: %s\n",
4225 p->device_uri ? p->device_uri : "");
4226 cupsFilePrintf(fp, "Information | 03 00 00 | %s jobs\n",
4227 p->accepting ? "Accepting" : "Not accepting");
4228 cupsFilePrintf(fp, "Information | 04 00 00 | %s\n", p->state_message);
4229
4230 cupsFileClose(fp);
4231
4232 chmod(filename, 0664);
4233 chown(filename, User, Group);
4234 }
4235
4236 /*
4237 * The activeicons file is needed to provide desktop icons for printers:
4238 *
4239 * [ quoted from /usr/lib/print/tagit ]
4240 *
4241 * --- Type of printer tags (base values)
4242 *
4243 * Dumb=66048 # 0x10200
4244 * DumbColor=66080 # 0x10220
4245 * Raster=66112 # 0x10240
4246 * ColorRaster=66144 # 0x10260
4247 * Plotter=66176 # 0x10280
4248 * PostScript=66208 # 0x102A0
4249 * ColorPostScript=66240 # 0x102C0
4250 * MonoPostScript=66272 # 0x102E0
4251 *
4252 * --- Printer state modifiers for local printers
4253 *
4254 * Idle=0 # 0x0
4255 * Busy=1 # 0x1
4256 * Faulted=2 # 0x2
4257 * Unknown=3 # 0x3 (Faulted due to unknown reason)
4258 *
4259 * --- Printer state modifiers for network printers
4260 *
4261 * NetIdle=8 # 0x8
4262 * NetBusy=9 # 0x9
4263 * NetFaulted=10 # 0xA
4264 * NetUnknown=11 # 0xB (Faulted due to unknown reason)
4265 */
4266
4267 snprintf(filename, sizeof(filename), "/var/spool/lp/activeicons/%s", p->name);
4268
4269 if (p->type & CUPS_PRINTER_CLASS)
4270 unlink(filename);
4271 else if ((fp = cupsFileOpen(filename, "w")) != NULL)
4272 {
4273 if (p->type & CUPS_PRINTER_COLOR)
4274 tag = 66240;
4275 else
4276 tag = 66272;
4277
4278 if (p->type & CUPS_PRINTER_REMOTE)
4279 tag |= 8;
4280
4281 if (p->state == IPP_PRINTER_PROCESSING)
4282 tag |= 1;
4283
4284 else if (p->state == IPP_PRINTER_STOPPED)
4285 tag |= 2;
4286
4287 cupsFilePuts(fp, "#!/bin/sh\n");
4288 cupsFilePrintf(fp, "#Tag %d\n", tag);
4289
4290 cupsFileClose(fp);
4291
4292 chmod(filename, 0755);
4293 chown(filename, User, Group);
4294 }
4295 }
4296
4297 /*
4298 * The default file is needed by the printers window to show
4299 * the default printer.
4300 */
4301
4302 snprintf(filename, sizeof(filename), "/var/spool/lp/default");
4303
4304 if (DefaultPrinter != NULL)
4305 {
4306 if ((fp = cupsFileOpen(filename, "w")) != NULL)
4307 {
4308 cupsFilePrintf(fp, "%s\n", DefaultPrinter->name);
4309
4310 cupsFileClose(fp);
4311
4312 chmod(filename, 0644);
4313 chown(filename, User, Group);
4314 }
4315 }
4316 else
4317 unlink(filename);
4318 }
4319 #endif /* __sgi */
4320
4321
4322 /*
4323 * End of "$Id: printers.c 7608 2008-05-21 01:37:21Z mike $".
4324 */