]> git.ipfire.org Git - thirdparty/cups.git/blob - scheduler/dirsvc.c
Added LDAP printer browsing support (STR #338)
[thirdparty/cups.git] / scheduler / dirsvc.c
1 /*
2 * "$Id$"
3 *
4 * Directory services routines for the Common UNIX Printing System (CUPS).
5 *
6 * Copyright 1997-2006 by Easy Software Products, all rights reserved.
7 *
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
13 * at:
14 *
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
19 *
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
23 *
24 * Contents:
25 *
26 * cupsdLoadRemoteCache() - Load the remote printer cache.
27 * cupsdSaveRemoteCache() - Save the remote printer cache.
28 * cupsdSendBrowseDelete() - Send a "browse delete" message for a
29 * printer.
30 * cupsdSendBrowseList() - Send new browsing information as necessary.
31 * cupsdSendCUPSBrowse() - Send new browsing information using the
32 * CUPS protocol.
33 * cupsdSendSLPBrowse() - Register the specified printer with SLP.
34 * cupsdStartBrowsing() - Start sending and receiving broadcast
35 * information.
36 * cupsdStartPolling() - Start polling servers as needed.
37 * cupsdStopBrowsing() - Stop sending and receiving broadcast
38 * information.
39 * cupsdStopPolling() - Stop polling servers as needed.
40 * cupsdUpdateCUPSBrowse() - Update the browse lists using the CUPS
41 * protocol.
42 * cupsdUpdatePolling() - Read status messages from the poll daemons.
43 * cupsdUpdateSLPBrowse() - Get browsing information via SLP.
44 * dequote() - Remote quotes from a string.
45 * process_browse_data() - Process new browse data.
46 * process_implicit_classes() - Create/update implicit classes as needed.
47 * slp_attr_callback() - SLP attribute callback
48 * slp_dereg_printer() - SLPDereg() the specified printer
49 * slp_get_attr() - Get an attribute from an SLP registration.
50 * slp_reg_callback() - Empty SLPRegReport.
51 * slp_url_callback() - SLP service url callback
52 */
53
54 /*
55 * Include necessary headers...
56 */
57
58 #include "cupsd.h"
59 #include <grp.h>
60
61
62 /*
63 * Local functions...
64 */
65
66 static char *dequote(char *d, const char *s, int dlen);
67 static int is_local_queue(const char *uri, char *host, int hostlen,
68 char *resource, int resourcelen);
69 static void process_browse_data(const char *uri, const char *host,
70 const char *resource, cups_ptype_t type,
71 ipp_pstate_t state, const char *location,
72 const char *info, const char *make_model,
73 int num_attrs, cups_option_t *attrs);
74 static void process_implicit_classes(void);
75
76
77 #ifdef HAVE_OPENLDAP
78 static const char * const ldap_attrs[] =/* CUPS LDAP attributes */
79 {
80 "printerDescription",
81 "printerLocation",
82 "printerMakeAndModel",
83 "printerType",
84 "printerURI",
85 NULL
86 };
87 #endif /* HAVE_OPENLDAP */
88
89 #ifdef HAVE_LIBSLP
90 /*
91 * SLP definitions...
92 */
93
94 /*
95 * SLP service name for CUPS...
96 */
97
98 # define SLP_CUPS_SRVTYPE "service:printer"
99 # define SLP_CUPS_SRVLEN 15
100
101
102 /*
103 * Printer service URL structure
104 */
105
106 typedef struct _slpsrvurl_s /**** SLP URL list ****/
107 {
108 struct _slpsrvurl_s *next; /* Next URL in list */
109 char url[HTTP_MAX_URI];
110 /* URL */
111 } slpsrvurl_t;
112
113
114 /*
115 * Local functions...
116 */
117
118 static SLPBoolean slp_attr_callback(SLPHandle hslp, const char *attrlist,
119 SLPError errcode, void *cookie);
120 static void slp_dereg_printer(cupsd_printer_t *p);
121 static int slp_get_attr(const char *attrlist, const char *tag,
122 char **valbuf);
123 static void slp_reg_callback(SLPHandle hslp, SLPError errcode,
124 void *cookie);
125 static SLPBoolean slp_url_callback(SLPHandle hslp, const char *srvurl,
126 unsigned short lifetime,
127 SLPError errcode, void *cookie);
128 #endif /* HAVE_LIBSLP */
129
130
131 /*
132 * 'cupsdLoadRemoteCache()' - Load the remote printer cache.
133 */
134
135 void
136 cupsdLoadRemoteCache(void)
137 {
138 cups_file_t *fp; /* remote.cache file */
139 int linenum; /* Current line number */
140 char line[1024], /* Line from file */
141 *value, /* Pointer to value */
142 *valueptr, /* Pointer into value */
143 scheme[32], /* Scheme portion of URI */
144 username[64], /* Username portion of URI */
145 host[HTTP_MAX_HOST],
146 /* Hostname portion of URI */
147 resource[HTTP_MAX_URI];
148 /* Resource portion of URI */
149 int port; /* Port number */
150 cupsd_printer_t *p; /* Current printer */
151 time_t now; /* Current time */
152
153
154 /*
155 * Open the remote.cache file...
156 */
157
158 snprintf(line, sizeof(line), "%s/remote.cache", CacheDir);
159 if ((fp = cupsFileOpen(line, "r")) == NULL)
160 return;
161
162 /*
163 * Read printer configurations until we hit EOF...
164 */
165
166 linenum = 0;
167 p = NULL;
168 now = time(NULL);
169
170 while (cupsFileGetConf(fp, line, sizeof(line), &value, &linenum))
171 {
172 /*
173 * Decode the directive...
174 */
175
176 if (!strcasecmp(line, "<Printer") ||
177 !strcasecmp(line, "<DefaultPrinter"))
178 {
179 /*
180 * <Printer name> or <DefaultPrinter name>
181 */
182
183 if (p == NULL && value)
184 {
185 /*
186 * Add the printer and a base file type...
187 */
188
189 cupsdLogMessage(CUPSD_LOG_DEBUG,
190 "cupsdLoadRemoteCache: Loading printer %s...", value);
191
192 if ((p = cupsdFindDest(value)) != NULL)
193 {
194 if (p->type & CUPS_PRINTER_CLASS)
195 {
196 cupsdLogMessage(CUPSD_LOG_WARN,
197 "Cached remote printer \"%s\" conflicts with "
198 "existing class!",
199 value);
200 p = NULL;
201 continue;
202 }
203 }
204 else
205 p = cupsdAddPrinter(value);
206
207 p->accepting = 1;
208 p->state = IPP_PRINTER_IDLE;
209 p->type |= CUPS_PRINTER_REMOTE;
210 p->browse_time = now + BrowseTimeout;
211
212 /*
213 * Set the default printer as needed...
214 */
215
216 if (!strcasecmp(line, "<DefaultPrinter"))
217 DefaultPrinter = p;
218 }
219 else
220 {
221 cupsdLogMessage(CUPSD_LOG_ERROR,
222 "Syntax error on line %d of remote.cache.", linenum);
223 return;
224 }
225 }
226 else if (!strcasecmp(line, "<Class") ||
227 !strcasecmp(line, "<DefaultClass"))
228 {
229 /*
230 * <Class name> or <DefaultClass name>
231 */
232
233 if (p == NULL && value)
234 {
235 /*
236 * Add the printer and a base file type...
237 */
238
239 cupsdLogMessage(CUPSD_LOG_DEBUG,
240 "cupsdLoadRemoteCache: Loading class %s...", value);
241
242 if ((p = cupsdFindDest(value)) != NULL)
243 p->type = CUPS_PRINTER_CLASS;
244 else
245 p = cupsdAddClass(value);
246
247 p->accepting = 1;
248 p->state = IPP_PRINTER_IDLE;
249 p->type |= CUPS_PRINTER_REMOTE;
250 p->browse_time = now + BrowseTimeout;
251
252 /*
253 * Set the default printer as needed...
254 */
255
256 if (!strcasecmp(line, "<DefaultClass"))
257 DefaultPrinter = p;
258 }
259 else
260 {
261 cupsdLogMessage(CUPSD_LOG_ERROR,
262 "Syntax error on line %d of remote.cache.", linenum);
263 return;
264 }
265 }
266 else if (!strcasecmp(line, "</Printer>") ||
267 !strcasecmp(line, "</Class>"))
268 {
269 if (p != NULL)
270 {
271 /*
272 * Close out the current printer...
273 */
274
275 cupsdSetPrinterAttrs(p);
276
277 p = NULL;
278 }
279 else
280 {
281 cupsdLogMessage(CUPSD_LOG_ERROR,
282 "Syntax error on line %d of remote.cache.", linenum);
283 return;
284 }
285 }
286 else if (!p)
287 {
288 cupsdLogMessage(CUPSD_LOG_ERROR,
289 "Syntax error on line %d of remote.cache.", linenum);
290 return;
291 }
292 else if (!strcasecmp(line, "Info"))
293 {
294 if (value)
295 cupsdSetString(&p->info, value);
296 }
297 else if (!strcasecmp(line, "MakeModel"))
298 {
299 if (value)
300 cupsdSetString(&p->make_model, value);
301 }
302 else if (!strcasecmp(line, "Location"))
303 {
304 if (value)
305 cupsdSetString(&p->location, value);
306 }
307 else if (!strcasecmp(line, "DeviceURI"))
308 {
309 if (value)
310 {
311 httpSeparateURI(HTTP_URI_CODING_ALL, value, scheme, sizeof(scheme),
312 username, sizeof(username), host, sizeof(host), &port,
313 resource, sizeof(resource));
314
315 cupsdSetString(&p->hostname, host);
316 cupsdSetString(&p->uri, value);
317 cupsdSetString(&p->device_uri, value);
318 }
319 else
320 {
321 cupsdLogMessage(CUPSD_LOG_ERROR,
322 "Syntax error on line %d of remote.cache.", linenum);
323 return;
324 }
325 }
326 else if (!strcasecmp(line, "Option") && value)
327 {
328 /*
329 * Option name value
330 */
331
332 for (valueptr = value; *valueptr && !isspace(*valueptr & 255); valueptr ++);
333
334 if (!*valueptr)
335 cupsdLogMessage(CUPSD_LOG_ERROR,
336 "Syntax error on line %d of remote.cache.", linenum);
337 else
338 {
339 for (; *valueptr && isspace(*valueptr & 255); *valueptr++ = '\0');
340
341 p->num_options = cupsAddOption(value, valueptr, p->num_options,
342 &(p->options));
343 }
344 }
345 else if (!strcasecmp(line, "State"))
346 {
347 /*
348 * Set the initial queue state...
349 */
350
351 if (value && !strcasecmp(value, "idle"))
352 p->state = IPP_PRINTER_IDLE;
353 else if (value && !strcasecmp(value, "stopped"))
354 p->state = IPP_PRINTER_STOPPED;
355 else
356 {
357 cupsdLogMessage(CUPSD_LOG_ERROR,
358 "Syntax error on line %d of remote.cache.", linenum);
359 return;
360 }
361 }
362 else if (!strcasecmp(line, "StateMessage"))
363 {
364 /*
365 * Set the initial queue state message...
366 */
367
368 if (value)
369 strlcpy(p->state_message, value, sizeof(p->state_message));
370 }
371 else if (!strcasecmp(line, "Accepting"))
372 {
373 /*
374 * Set the initial accepting state...
375 */
376
377 if (value &&
378 (!strcasecmp(value, "yes") ||
379 !strcasecmp(value, "on") ||
380 !strcasecmp(value, "true")))
381 p->accepting = 1;
382 else if (value &&
383 (!strcasecmp(value, "no") ||
384 !strcasecmp(value, "off") ||
385 !strcasecmp(value, "false")))
386 p->accepting = 0;
387 else
388 {
389 cupsdLogMessage(CUPSD_LOG_ERROR,
390 "Syntax error on line %d of remote.cache.", linenum);
391 return;
392 }
393 }
394 else if (!strcasecmp(line, "Type"))
395 {
396 if (value)
397 p->type = atoi(value);
398 else
399 {
400 cupsdLogMessage(CUPSD_LOG_ERROR,
401 "Syntax error on line %d of remote.cache.", linenum);
402 return;
403 }
404 }
405 else if (!strcasecmp(line, "BrowseTime"))
406 {
407 if (value)
408 {
409 time_t t = atoi(value);
410
411 if (t > (now + BrowseInterval))
412 p->browse_time = t;
413 }
414 else
415 {
416 cupsdLogMessage(CUPSD_LOG_ERROR,
417 "Syntax error on line %d of remote.cache.", linenum);
418 return;
419 }
420 }
421 else if (!strcasecmp(line, "JobSheets"))
422 {
423 /*
424 * Set the initial job sheets...
425 */
426
427 if (value)
428 {
429 for (valueptr = value; *valueptr && !isspace(*valueptr & 255); valueptr ++);
430
431 if (*valueptr)
432 *valueptr++ = '\0';
433
434 cupsdSetString(&p->job_sheets[0], value);
435
436 while (isspace(*valueptr & 255))
437 valueptr ++;
438
439 if (*valueptr)
440 {
441 for (value = valueptr; *valueptr && !isspace(*valueptr & 255); valueptr ++);
442
443 if (*valueptr)
444 *valueptr++ = '\0';
445
446 cupsdSetString(&p->job_sheets[1], value);
447 }
448 }
449 else
450 {
451 cupsdLogMessage(CUPSD_LOG_ERROR,
452 "Syntax error on line %d of remote.cache.", linenum);
453 return;
454 }
455 }
456 else if (!strcasecmp(line, "AllowUser"))
457 {
458 if (value)
459 {
460 p->deny_users = 0;
461 cupsdAddPrinterUser(p, value);
462 }
463 else
464 {
465 cupsdLogMessage(CUPSD_LOG_ERROR,
466 "Syntax error on line %d of remote.cache.", linenum);
467 return;
468 }
469 }
470 else if (!strcasecmp(line, "DenyUser"))
471 {
472 if (value)
473 {
474 p->deny_users = 1;
475 cupsdAddPrinterUser(p, value);
476 }
477 else
478 {
479 cupsdLogMessage(CUPSD_LOG_ERROR,
480 "Syntax error on line %d of remote.cache.", linenum);
481 return;
482 }
483 }
484 else
485 {
486 /*
487 * Something else we don't understand...
488 */
489
490 cupsdLogMessage(CUPSD_LOG_ERROR,
491 "Unknown configuration directive %s on line %d of remote.cache.",
492 line, linenum);
493 }
494 }
495
496 cupsFileClose(fp);
497
498 /*
499 * Do auto-classing if needed...
500 */
501
502 process_implicit_classes();
503 }
504
505
506 /*
507 * 'cupsdSaveRemoteCache()' - Save the remote printer cache.
508 */
509
510 void
511 cupsdSaveRemoteCache(void)
512 {
513 int i; /* Looping var */
514 cups_file_t *fp; /* printers.conf file */
515 char temp[1024]; /* Temporary string */
516 cupsd_printer_t *printer; /* Current printer class */
517 time_t curtime; /* Current time */
518 struct tm *curdate; /* Current date */
519 cups_option_t *option; /* Current option */
520
521
522 /*
523 * Create the remote.cache file...
524 */
525
526 snprintf(temp, sizeof(temp), "%s/remote.cache", CacheDir);
527
528 if ((fp = cupsFileOpen(temp, "w")) == NULL)
529 {
530 cupsdLogMessage(CUPSD_LOG_ERROR,
531 "Unable to save remote.cache - %s", strerror(errno));
532 return;
533 }
534 else
535 cupsdLogMessage(CUPSD_LOG_INFO, "Saving remote.cache...");
536
537 /*
538 * Restrict access to the file...
539 */
540
541 fchown(cupsFileNumber(fp), getuid(), Group);
542 fchmod(cupsFileNumber(fp), ConfigFilePerm);
543
544 /*
545 * Write a small header to the file...
546 */
547
548 curtime = time(NULL);
549 curdate = localtime(&curtime);
550 strftime(temp, sizeof(temp) - 1, "%Y-%m-%d %H:%M", curdate);
551
552 cupsFilePuts(fp, "# Remote cache file for " CUPS_SVERSION "\n");
553 cupsFilePrintf(fp, "# Written by cupsd on %s\n", temp);
554
555 /*
556 * Write each local printer known to the system...
557 */
558
559 for (printer = (cupsd_printer_t *)cupsArrayFirst(Printers);
560 printer;
561 printer = (cupsd_printer_t *)cupsArrayNext(Printers))
562 {
563 /*
564 * Skip local destinations...
565 */
566
567 if (!(printer->type & CUPS_PRINTER_REMOTE))
568 continue;
569
570 /*
571 * Write printers as needed...
572 */
573
574 if (printer == DefaultPrinter)
575 cupsFilePuts(fp, "<Default");
576 else
577 cupsFilePutChar(fp, '<');
578
579 if (printer->type & CUPS_PRINTER_CLASS)
580 cupsFilePrintf(fp, "Class %s>\n", printer->name);
581 else
582 cupsFilePrintf(fp, "Printer %s>\n", printer->name);
583
584 cupsFilePrintf(fp, "Type %d\n", printer->type);
585
586 cupsFilePrintf(fp, "BrowseTime %d\n", (int)printer->browse_time);
587
588 if (printer->info)
589 cupsFilePrintf(fp, "Info %s\n", printer->info);
590
591 if (printer->make_model)
592 cupsFilePrintf(fp, "MakeModel %s\n", printer->make_model);
593
594 if (printer->location)
595 cupsFilePrintf(fp, "Location %s\n", printer->location);
596
597 if (printer->device_uri)
598 cupsFilePrintf(fp, "DeviceURI %s\n", printer->device_uri);
599
600 if (printer->state == IPP_PRINTER_STOPPED)
601 {
602 cupsFilePuts(fp, "State Stopped\n");
603 cupsFilePrintf(fp, "StateMessage %s\n", printer->state_message);
604 }
605 else
606 cupsFilePuts(fp, "State Idle\n");
607
608 if (printer->accepting)
609 cupsFilePuts(fp, "Accepting Yes\n");
610 else
611 cupsFilePuts(fp, "Accepting No\n");
612
613 cupsFilePrintf(fp, "JobSheets %s %s\n", printer->job_sheets[0],
614 printer->job_sheets[1]);
615
616 for (i = 0; i < printer->num_users; i ++)
617 cupsFilePrintf(fp, "%sUser %s\n", printer->deny_users ? "Deny" : "Allow",
618 printer->users[i]);
619
620 for (i = printer->num_options, option = printer->options;
621 i > 0;
622 i --, option ++)
623 cupsFilePrintf(fp, "Option %s %s\n", option->name, option->value);
624
625 if (printer->type & CUPS_PRINTER_CLASS)
626 cupsFilePuts(fp, "</Class>\n");
627 else
628 cupsFilePuts(fp, "</Printer>\n");
629 }
630
631 cupsFileClose(fp);
632 }
633
634
635 /*
636 * 'cupsdSendBrowseDelete()' - Send a "browse delete" message for a printer.
637 */
638
639 void
640 cupsdSendBrowseDelete(
641 cupsd_printer_t *p) /* I - Printer to delete */
642 {
643 /*
644 * Only announce if browsing is enabled...
645 */
646
647 if (!Browsing || !p->shared)
648 return;
649
650 /*
651 * First mark the printer for deletion...
652 */
653
654 p->type |= CUPS_PRINTER_DELETE;
655
656 /*
657 * Announce the deletion...
658 */
659
660 if (BrowseLocalProtocols & BROWSE_CUPS)
661 cupsdSendCUPSBrowse(p);
662 #ifdef HAVE_LIBSLP
663 if (BrowseLocalProtocols & BROWSE_SLP)
664 slp_dereg_printer(p);
665 #endif /* HAVE_LIBSLP */
666 }
667
668
669 /*
670 * 'cupsdSendBrowseList()' - Send new browsing information as necessary.
671 */
672
673 void
674 cupsdSendBrowseList(void)
675 {
676 int count; /* Number of dests to update */
677 cupsd_printer_t *p; /* Current printer */
678 time_t ut, /* Minimum update time */
679 to; /* Timeout time */
680
681
682 if (!Browsing || !BrowseLocalProtocols || !Printers)
683 return;
684
685 /*
686 * Compute the update and timeout times...
687 */
688
689 ut = time(NULL) - BrowseInterval;
690 to = time(NULL) - BrowseTimeout;
691
692 /*
693 * Figure out how many printers need an update...
694 */
695
696 if (BrowseInterval > 0)
697 {
698 int max_count; /* Maximum number to update */
699
700
701 /*
702 * Throttle the number of printers we'll be updating this time
703 * around based on the number of queues that need updating and
704 * the maximum number of queues to update each second...
705 */
706
707 max_count = 2 * cupsArrayCount(Printers) / BrowseInterval + 1;
708
709 for (count = 0, p = (cupsd_printer_t *)cupsArrayFirst(Printers);
710 count < max_count && p != NULL;
711 p = (cupsd_printer_t *)cupsArrayNext(Printers))
712 if (!(p->type & (CUPS_PRINTER_REMOTE | CUPS_PRINTER_IMPLICIT)) &&
713 p->shared && p->browse_time < ut)
714 count ++;
715
716 /*
717 * Loop through all of the printers and send local updates as needed...
718 */
719
720 if (BrowseNext)
721 p = (cupsd_printer_t *)cupsArrayFind(Printers, BrowseNext);
722 else
723 p = (cupsd_printer_t *)cupsArrayFirst(Printers);
724
725 for (;
726 count > 0;
727 p = (cupsd_printer_t *)cupsArrayNext(Printers))
728 {
729 /*
730 * Check for wraparound...
731 */
732
733 if (!p)
734 p = (cupsd_printer_t *)cupsArrayFirst(Printers);
735
736 if (!p)
737 break;
738 else if ((p->type & (CUPS_PRINTER_REMOTE | CUPS_PRINTER_IMPLICIT)) ||
739 !p->shared)
740 continue;
741 else if (p->browse_time < ut)
742 {
743 /*
744 * Need to send an update...
745 */
746
747 count --;
748
749 p->browse_time = time(NULL);
750
751 if (BrowseLocalProtocols & BROWSE_CUPS)
752 cupsdSendCUPSBrowse(p);
753
754 #ifdef HAVE_LIBSLP
755 if (BrowseLocalProtocols & BROWSE_SLP)
756 cupsdSendSLPBrowse(p);
757 #endif /* HAVE_LIBSLP */
758
759 #ifdef HAVE_LDAP
760 if (BrowseLocalProtocols & BROWSE_LDAP)
761 cupsdSendLDAPBrowse(p);
762 #endif /* HAVE_LDAP */
763 }
764 }
765
766 /*
767 * Save where we left off so that all printers get updated...
768 */
769
770 BrowseNext = p;
771 }
772
773 /*
774 * Loop through all of the printers and send local updates as needed...
775 */
776
777 for (p = (cupsd_printer_t *)cupsArrayFirst(Printers);
778 p;
779 p = (cupsd_printer_t *)cupsArrayNext(Printers))
780 {
781 /*
782 * If this is a remote queue, see if it needs to be timed out...
783 */
784
785 if (p->type & CUPS_PRINTER_REMOTE)
786 {
787 if (p->browse_time < to)
788 {
789 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED, p, NULL,
790 "%s \'%s\' deleted by directory services (timeout).",
791 (p->type & CUPS_PRINTER_CLASS) ? "Class" : "Printer",
792 p->name);
793
794 cupsdLogMessage(CUPSD_LOG_INFO,
795 "Remote destination \"%s\" has timed out; deleting it...",
796 p->name);
797
798 cupsArraySave(Printers);
799 cupsdDeletePrinter(p, 1);
800 cupsArrayRestore(Printers);
801 }
802 }
803 }
804 }
805
806
807 /*
808 * 'cupsdSendCUPSBrowse()' - Send new browsing information using the CUPS protocol.
809 */
810
811 void
812 cupsdSendCUPSBrowse(cupsd_printer_t *p) /* I - Printer to send */
813 {
814 int i; /* Looping var */
815 cups_ptype_t type; /* Printer type */
816 cupsd_dirsvc_addr_t *b; /* Browse address */
817 int bytes; /* Length of packet */
818 char packet[1453], /* Browse data packet */
819 uri[1024], /* Printer URI */
820 options[1024], /* Browse local options */
821 location[1024], /* printer-location */
822 info[1024], /* printer-info */
823 make_model[1024];
824 /* printer-make-and-model */
825 cupsd_netif_t *iface; /* Network interface */
826
827
828 /*
829 * Figure out the printer type value...
830 */
831
832 type = p->type | CUPS_PRINTER_REMOTE;
833
834 if (!p->accepting)
835 type |= CUPS_PRINTER_REJECTING;
836
837 if (p == DefaultPrinter)
838 type |= CUPS_PRINTER_DEFAULT;
839
840 /*
841 * Initialize the browse options...
842 */
843
844 if (BrowseLocalOptions)
845 snprintf(options, sizeof(options), " ipp-options=%s", BrowseLocalOptions);
846 else
847 options[0] = '\0';
848
849 /*
850 * Remove quotes from printer-info, printer-location, and
851 * printer-make-and-model attributes...
852 */
853
854 dequote(location, p->location, sizeof(p->location));
855 dequote(info, p->info, sizeof(p->info));
856 dequote(make_model, p->make_model ? p->make_model : "Unknown",
857 sizeof(make_model));
858
859 /*
860 * Send a packet to each browse address...
861 */
862
863 for (i = NumBrowsers, b = Browsers; i > 0; i --, b ++)
864 if (b->iface[0])
865 {
866 /*
867 * Send the browse packet to one or more interfaces...
868 */
869
870 if (!strcmp(b->iface, "*"))
871 {
872 /*
873 * Send to all local interfaces...
874 */
875
876 cupsdNetIFUpdate();
877
878 for (iface = (cupsd_netif_t *)cupsArrayFirst(NetIFList);
879 iface;
880 iface = (cupsd_netif_t *)cupsArrayNext(NetIFList))
881 {
882 /*
883 * Only send to local, IPv4 interfaces...
884 */
885
886 if (!iface->is_local || !iface->port ||
887 iface->address.addr.sa_family != AF_INET)
888 continue;
889
890 httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
891 iface->hostname, iface->port,
892 (p->type & CUPS_PRINTER_CLASS) ? "/classes/%s%s" :
893 "/printers/%s",
894 p->name);
895 snprintf(packet, sizeof(packet), "%x %x %s \"%s\" \"%s\" \"%s\"%s\n",
896 type, p->state, uri, location, info, make_model, options);
897
898 bytes = strlen(packet);
899
900 cupsdLogMessage(CUPSD_LOG_DEBUG2,
901 "cupsdSendBrowseList: (%d bytes to \"%s\") %s", bytes,
902 iface->name, packet);
903
904 iface->broadcast.ipv4.sin_port = htons(BrowsePort);
905
906 sendto(BrowseSocket, packet, bytes, 0,
907 (struct sockaddr *)&(iface->broadcast),
908 sizeof(struct sockaddr_in));
909 }
910 }
911 else if ((iface = cupsdNetIFFind(b->iface)) != NULL)
912 {
913 /*
914 * Send to the named interface using the IPv4 address...
915 */
916
917 while (iface)
918 if (strcmp(b->iface, iface->name))
919 {
920 iface = NULL;
921 break;
922 }
923 else if (iface->address.addr.sa_family == AF_INET && iface->port)
924 break;
925 else
926 iface = (cupsd_netif_t *)cupsArrayNext(NetIFList);
927
928 if (iface)
929 {
930 httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
931 iface->hostname, iface->port,
932 (p->type & CUPS_PRINTER_CLASS) ? "/classes/%s%s" :
933 "/printers/%s",
934 p->name);
935 snprintf(packet, sizeof(packet), "%x %x %s \"%s\" \"%s\" \"%s\"%s\n",
936 type, p->state, uri, location, info, make_model, options);
937
938 bytes = strlen(packet);
939
940 cupsdLogMessage(CUPSD_LOG_DEBUG2,
941 "cupsdSendBrowseList: (%d bytes to \"%s\") %s", bytes,
942 iface->name, packet);
943
944 iface->broadcast.ipv4.sin_port = htons(BrowsePort);
945
946 sendto(BrowseSocket, packet, bytes, 0,
947 (struct sockaddr *)&(iface->broadcast),
948 sizeof(struct sockaddr_in));
949 }
950 }
951 }
952 else
953 {
954 /*
955 * Send the browse packet to the indicated address using
956 * the default server name...
957 */
958
959 snprintf(packet, sizeof(packet), "%x %x %s \"%s\" \"%s\" \"%s\"%s\n",
960 type, p->state, p->uri, location, info, make_model, options);
961
962 bytes = strlen(packet);
963 cupsdLogMessage(CUPSD_LOG_DEBUG2,
964 "cupsdSendBrowseList: (%d bytes) %s", bytes, packet);
965
966 if (sendto(BrowseSocket, packet, bytes, 0,
967 (struct sockaddr *)&(b->to),
968 sizeof(struct sockaddr_in)) <= 0)
969 {
970 /*
971 * Unable to send browse packet, so remove this address from the
972 * list...
973 */
974
975 cupsdLogMessage(CUPSD_LOG_ERROR,
976 "cupsdSendBrowseList: sendto failed for browser %d - %s.",
977 b - Browsers + 1, strerror(errno));
978
979 if (i > 1)
980 memcpy(b, b + 1, (i - 1) * sizeof(cupsd_dirsvc_addr_t));
981
982 b --;
983 NumBrowsers --;
984 }
985 }
986 }
987
988
989 #ifdef HAVE_OPENLDAP
990 /*
991 * cupsdSendLDAPBrowse()' - Send LDAP printer registrations.
992 */
993
994 void
995 cupsdSendLDAPBrowse(cupsd_printer_t *p) /* I - Printer to register */
996 {
997 int i; /* Looping var... */
998 LDAPMod mods[7]; /* The 7 attributes we will be adding */
999 LDAPMod *pmods[8]; /* Pointers to the 7 attributes + NULL */
1000 LDAPMessage *res; /* Search result token */
1001 char *cn_value[2], /* Change records */
1002 *uri[2],
1003 *info[2],
1004 *location[2],
1005 *make_model[2],
1006 *type[2],
1007 typestring[255], /* String to hold printer-type */
1008 filter[256], /* Search filter for possible UPDATEs */
1009 dn[1024]; /* DN of the printer we are adding */
1010 int rc; /* LDAP status */
1011 static const char * const objectClass_values[] =
1012 { /* The 3 objectClass's we use in */
1013 "top", /* our LDAP entries */
1014 "device",
1015 "cupsPrinter",
1016 NULL
1017 };
1018
1019 cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdSendLDAPBrowse: %s\n", p->name);
1020
1021 /*
1022 * Everything in ldap is ** so we fudge around it...
1023 */
1024
1025 sprintf(typestring, "%u", p->type);
1026
1027 cn_value[0] = p->info;
1028 cn_value[1] = NULL;
1029 info[0] = p->info;
1030 info[1] = NULL;
1031 location[0] = p->location;
1032 location[1] = NULL;
1033 make_model[0] = p->make_model;
1034 make_model[1] = NULL;
1035 type[0] = typestring;
1036 type[1] = NULL;
1037 uri[0] = p->uri;
1038 uri[1] = NULL;
1039
1040 snprintf(filter, sizeof(filter),
1041 "(&(objectclass=cupsPrinter)(printerDescription~=%s))", p->info);
1042
1043 ldap_search_s(BrowseLDAPHandle, BrowseLDAPDN, LDAP_SCOPE_SUBTREE,
1044 filter, (char **)ldap_attrs, 0, &res);
1045 cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdSendLDAPBrowse: Searching \"%s\"",
1046 filter);
1047
1048 mods[0].mod_type = "cn";
1049 mods[0].mod_values = cn_value;
1050 mods[1].mod_type = "printerDescription";
1051 mods[1].mod_values = info;
1052 mods[2].mod_type = "printerURI";
1053 mods[2].mod_values = uri;
1054 mods[3].mod_type = "printerLocation";
1055 mods[3].mod_values = location;
1056 mods[4].mod_type = "printerMakeAndModel";
1057 mods[4].mod_values = make_model;
1058 mods[5].mod_type = "printerType";
1059 mods[5].mod_values = type;
1060 mods[6].mod_type = "objectClass";
1061 mods[6].mod_values = (char **)objectClass_values;
1062
1063 snprintf(dn, sizeof(dn), "cn=%s,ou=printers,%s", p->info, BrowseLDAPDN);
1064 cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdSendLDAPBrowse: dn=\"%s\"", dn);
1065
1066 if (ldap_count_entries(BrowseLDAPHandle, res) > 0)
1067 {
1068 /*
1069 * Printer has already been registered, modify the current
1070 * registration...
1071 */
1072
1073 cupsdLogMessage(CUPSD_LOG_DEBUG2,
1074 "cupsdSendLDAPBrowse: Replacing entry...");
1075
1076 for (i = 0; i < 7; i ++)
1077 {
1078 pmods[i] = mods + i;
1079 pmods[i]->mod_op = LDAP_MOD_REPLACE;
1080 }
1081 pmods[i] = NULL;
1082
1083 if ((rc = ldap_modify_s(BrowseLDAPHandle, dn, pmods)) != LDAP_SUCCESS)
1084 cupsdLogMessage(CUPSD_LOG_ERROR,
1085 "LDAP modify for %s failed with status %d: %s",
1086 p->name, rc, ldap_err2string(rc));
1087 }
1088 else
1089 {
1090 /*
1091 * Printer has already been registered, modify the current
1092 * registration...
1093 */
1094
1095 cupsdLogMessage(CUPSD_LOG_DEBUG2,
1096 "cupsdSendLDAPBrowse: Adding entry...");
1097
1098 for (i = 0; i < 7; i ++)
1099 {
1100 pmods[i] = mods + i;
1101 pmods[i]->mod_op = LDAP_MOD_REPLACE;
1102 }
1103 pmods[i] = NULL;
1104
1105 if ((rc = ldap_modify_s(BrowseLDAPHandle, dn, pmods)) != LDAP_SUCCESS)
1106 cupsdLogMessage(CUPSD_LOG_ERROR,
1107 "LDAP add for %s failed with status %d: %s",
1108 p->name, rc, ldap_err2string(rc));
1109 }
1110 }
1111 #endif /* HAVE_OPENLDAP */
1112
1113
1114 #ifdef HAVE_LIBSLP
1115 /*
1116 * 'cupsdSendSLPBrowse()' - Register the specified printer with SLP.
1117 */
1118
1119 void
1120 cupsdSendSLPBrowse(cupsd_printer_t *p) /* I - Printer to register */
1121 {
1122 char srvurl[HTTP_MAX_URI], /* Printer service URI */
1123 attrs[8192], /* Printer attributes */
1124 finishings[1024], /* Finishings to support */
1125 make_model[IPP_MAX_NAME * 2],
1126 /* Make and model, quoted */
1127 location[IPP_MAX_NAME * 2],
1128 /* Location, quoted */
1129 info[IPP_MAX_NAME * 2], /* Info, quoted */
1130 *src, /* Pointer to original string */
1131 *dst; /* Pointer to destination string */
1132 ipp_attribute_t *authentication; /* uri-authentication-supported value */
1133 SLPError error; /* SLP error, if any */
1134
1135
1136 cupsdLogMessage(CUPSD_LOG_DEBUG, "cupsdSendSLPBrowse(%p = \"%s\")", p,
1137 p->name);
1138
1139 /*
1140 * Make the SLP service URL that conforms to the IANA
1141 * 'printer:' template.
1142 */
1143
1144 snprintf(srvurl, sizeof(srvurl), SLP_CUPS_SRVTYPE ":%s", p->uri);
1145
1146 cupsdLogMessage(CUPSD_LOG_DEBUG2, "Service URL = \"%s\"", srvurl);
1147
1148 /*
1149 * Figure out the finishings string...
1150 */
1151
1152 if (p->type & CUPS_PRINTER_STAPLE)
1153 strcpy(finishings, "staple");
1154 else
1155 finishings[0] = '\0';
1156
1157 if (p->type & CUPS_PRINTER_BIND)
1158 {
1159 if (finishings[0])
1160 strlcat(finishings, ",bind", sizeof(finishings));
1161 else
1162 strcpy(finishings, "bind");
1163 }
1164
1165 if (p->type & CUPS_PRINTER_PUNCH)
1166 {
1167 if (finishings[0])
1168 strlcat(finishings, ",punch", sizeof(finishings));
1169 else
1170 strcpy(finishings, "punch");
1171 }
1172
1173 if (p->type & CUPS_PRINTER_COVER)
1174 {
1175 if (finishings[0])
1176 strlcat(finishings, ",cover", sizeof(finishings));
1177 else
1178 strcpy(finishings, "cover");
1179 }
1180
1181 if (p->type & CUPS_PRINTER_SORT)
1182 {
1183 if (finishings[0])
1184 strlcat(finishings, ",sort", sizeof(finishings));
1185 else
1186 strcpy(finishings, "sort");
1187 }
1188
1189 if (!finishings[0])
1190 strcpy(finishings, "none");
1191
1192 /*
1193 * Quote any commas in the make and model, location, and info strings...
1194 */
1195
1196 for (src = p->make_model, dst = make_model;
1197 src && *src && dst < (make_model + sizeof(make_model) - 2);)
1198 {
1199 if (*src == ',' || *src == '\\' || *src == ')')
1200 *dst++ = '\\';
1201
1202 *dst++ = *src++;
1203 }
1204
1205 *dst = '\0';
1206
1207 if (!make_model[0])
1208 strcpy(make_model, "Unknown");
1209
1210 for (src = p->location, dst = location;
1211 src && *src && dst < (location + sizeof(location) - 2);)
1212 {
1213 if (*src == ',' || *src == '\\' || *src == ')')
1214 *dst++ = '\\';
1215
1216 *dst++ = *src++;
1217 }
1218
1219 *dst = '\0';
1220
1221 if (!location[0])
1222 strcpy(location, "Unknown");
1223
1224 for (src = p->info, dst = info;
1225 src && *src && dst < (info + sizeof(info) - 2);)
1226 {
1227 if (*src == ',' || *src == '\\' || *src == ')')
1228 *dst++ = '\\';
1229
1230 *dst++ = *src++;
1231 }
1232
1233 *dst = '\0';
1234
1235 if (!info[0])
1236 strcpy(info, "Unknown");
1237
1238 /*
1239 * Get the authentication value...
1240 */
1241
1242 authentication = ippFindAttribute(p->attrs, "uri-authentication-supported",
1243 IPP_TAG_KEYWORD);
1244
1245 /*
1246 * Make the SLP attribute string list that conforms to
1247 * the IANA 'printer:' template.
1248 */
1249
1250 snprintf(attrs, sizeof(attrs),
1251 "(printer-uri-supported=%s),"
1252 "(uri-authentication-supported=%s>),"
1253 #ifdef HAVE_SSL
1254 "(uri-security-supported=tls>),"
1255 #else
1256 "(uri-security-supported=none>),"
1257 #endif /* HAVE_SSL */
1258 "(printer-name=%s),"
1259 "(printer-location=%s),"
1260 "(printer-info=%s),"
1261 "(printer-more-info=%s),"
1262 "(printer-make-and-model=%s),"
1263 "(printer-type=%d),"
1264 "(charset-supported=utf-8),"
1265 "(natural-language-configured=%s),"
1266 "(natural-language-supported=de,en,es,fr,it),"
1267 "(color-supported=%s),"
1268 "(finishings-supported=%s),"
1269 "(sides-supported=one-sided%s),"
1270 "(multiple-document-jobs-supported=true)"
1271 "(ipp-versions-supported=1.0,1.1)",
1272 p->uri, authentication->values[0].string.text, p->name, location,
1273 info, p->uri, make_model, p->type, DefaultLanguage,
1274 p->type & CUPS_PRINTER_COLOR ? "true" : "false",
1275 finishings,
1276 p->type & CUPS_PRINTER_DUPLEX ?
1277 ",two-sided-long-edge,two-sided-short-edge" : "");
1278
1279 cupsdLogMessage(CUPSD_LOG_DEBUG2, "Attributes = \"%s\"", attrs);
1280
1281 /*
1282 * Register the printer with the SLP server...
1283 */
1284
1285 error = SLPReg(BrowseSLPHandle, srvurl, BrowseTimeout,
1286 SLP_CUPS_SRVTYPE, attrs, SLP_TRUE, slp_reg_callback, 0);
1287
1288 if (error != SLP_OK)
1289 cupsdLogMessage(CUPSD_LOG_ERROR, "SLPReg of \"%s\" failed with status %d!", p->name,
1290 error);
1291 }
1292 #endif /* HAVE_LIBSLP */
1293
1294
1295 /*
1296 * 'cupsdStartBrowsing()' - Start sending and receiving broadcast information.
1297 */
1298
1299 void
1300 cupsdStartBrowsing(void)
1301 {
1302 int val; /* Socket option value */
1303 struct sockaddr_in addr; /* Broadcast address */
1304
1305
1306 BrowseNext = NULL;
1307
1308 if (!Browsing || !(BrowseLocalProtocols | BrowseRemoteProtocols))
1309 return;
1310
1311 if ((BrowseLocalProtocols | BrowseRemoteProtocols) & BROWSE_CUPS)
1312 {
1313 if (BrowseSocket < 0)
1314 {
1315 /*
1316 * Create the broadcast socket...
1317 */
1318
1319 if ((BrowseSocket = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
1320 {
1321 cupsdLogMessage(CUPSD_LOG_ERROR,
1322 "cupsdStartBrowsing: Unable to create broadcast "
1323 "socket - %s.", strerror(errno));
1324 BrowseLocalProtocols &= ~BROWSE_CUPS;
1325 BrowseRemoteProtocols &= ~BROWSE_CUPS;
1326 return;
1327 }
1328
1329 /*
1330 * Bind the socket to browse port...
1331 */
1332
1333 memset(&addr, 0, sizeof(addr));
1334 addr.sin_addr.s_addr = htonl(INADDR_ANY);
1335 addr.sin_family = AF_INET;
1336 addr.sin_port = htons(BrowsePort);
1337
1338 if (bind(BrowseSocket, (struct sockaddr *)&addr, sizeof(addr)))
1339 {
1340 cupsdLogMessage(CUPSD_LOG_ERROR,
1341 "cupsdStartBrowsing: Unable to bind broadcast "
1342 "socket - %s.", strerror(errno));
1343
1344 #ifdef WIN32
1345 closesocket(BrowseSocket);
1346 #else
1347 close(BrowseSocket);
1348 #endif /* WIN32 */
1349
1350 BrowseSocket = -1;
1351 BrowseLocalProtocols &= ~BROWSE_CUPS;
1352 BrowseRemoteProtocols &= ~BROWSE_CUPS;
1353 return;
1354 }
1355 }
1356
1357 /*
1358 * Set the "broadcast" flag...
1359 */
1360
1361 val = 1;
1362 if (setsockopt(BrowseSocket, SOL_SOCKET, SO_BROADCAST, &val, sizeof(val)))
1363 {
1364 cupsdLogMessage(CUPSD_LOG_ERROR,
1365 "cupsdStartBrowsing: Unable to set broadcast mode - %s.",
1366 strerror(errno));
1367
1368 #ifdef WIN32
1369 closesocket(BrowseSocket);
1370 #else
1371 close(BrowseSocket);
1372 #endif /* WIN32 */
1373
1374 BrowseSocket = -1;
1375 BrowseLocalProtocols &= ~BROWSE_CUPS;
1376 BrowseRemoteProtocols &= ~BROWSE_CUPS;
1377 return;
1378 }
1379
1380 /*
1381 * Close the socket on exec...
1382 */
1383
1384 fcntl(BrowseSocket, F_SETFD, fcntl(BrowseSocket, F_GETFD) | FD_CLOEXEC);
1385
1386 /*
1387 * Finally, add the socket to the input selection set...
1388 */
1389
1390 cupsdLogMessage(CUPSD_LOG_DEBUG2,
1391 "cupsdStartBrowsing: Adding fd %d to InputSet...",
1392 BrowseSocket);
1393
1394 FD_SET(BrowseSocket, InputSet);
1395 }
1396 else
1397 BrowseSocket = -1;
1398
1399 #ifdef HAVE_LIBSLP
1400 if ((BrowseLocalProtocols | BrowseRemoteProtocols) & BROWSE_SLP)
1401 {
1402 /*
1403 * Open SLP handle...
1404 */
1405
1406 if (SLPOpen("en", SLP_FALSE, &BrowseSLPHandle) != SLP_OK)
1407 {
1408 cupsdLogMessage(CUPSD_LOG_ERROR,
1409 "Unable to open an SLP handle; disabling SLP browsing!");
1410 BrowseLocalProtocols &= ~BROWSE_SLP;
1411 BrowseRemoteProtocols &= ~BROWSE_SLP;
1412 }
1413
1414 BrowseSLPRefresh = 0;
1415 }
1416 #endif /* HAVE_LIBSLP */
1417
1418 #ifdef HAVE_OPENLDAP
1419 if ((BrowseLocalProtocols | BrowseRemoteProtocols) & BROWSE_LDAP)
1420 {
1421 if (!BrowseLDAPDN)
1422 {
1423 cupsdLogMessage(CUPSD_LOG_ERROR,
1424 "Need to set BrowseLDAPDN to use LDAP browsing!");
1425 BrowseLocalProtocols &= ~BROWSE_LDAP;
1426 BrowseRemoteProtocols &= ~BROWSE_LDAP;
1427 }
1428 else
1429 {
1430 /*
1431 * Open LDAP handle...
1432 */
1433
1434 int rc; /* LDAP API status */
1435 int version = 3; /* LDAP version */
1436 struct berval bv = {0, ""}; /* SASL bind value */
1437
1438
1439 /*
1440 * LDAP stuff currently only supports ldapi EXTERNAL SASL binds...
1441 */
1442
1443 if (!BrowseLDAPServer || !strcasecmp(BrowseLDAPServer, "localhost"))
1444 rc = ldap_initialize(&BrowseLDAPHandle, "ldapi:///");
1445 else
1446 rc = ldap_initialize(&BrowseLDAPHandle, BrowseLDAPServer);
1447
1448 if (rc != LDAP_SUCCESS)
1449 {
1450 cupsdLogMessage(CUPSD_LOG_ERROR,
1451 "Unable to initialize LDAP; disabling LDAP browsing!");
1452 BrowseLocalProtocols &= ~BROWSE_LDAP;
1453 BrowseRemoteProtocols &= ~BROWSE_LDAP;
1454 }
1455 else if (ldap_set_option(BrowseLDAPHandle, LDAP_OPT_PROTOCOL_VERSION,
1456 (const void *)&version) != LDAP_SUCCESS)
1457 {
1458 ldap_unbind_ext(BrowseLDAPHandle, NULL, NULL);
1459 BrowseLDAPHandle = NULL;
1460 cupsdLogMessage(CUPSD_LOG_ERROR,
1461 "Unable to set LDAP protocol version; "
1462 "disabling LDAP browsing!");
1463 BrowseLocalProtocols &= ~BROWSE_LDAP;
1464 BrowseRemoteProtocols &= ~BROWSE_LDAP;
1465 }
1466 else
1467 {
1468 if (!BrowseLDAPServer || !strcasecmp(BrowseLDAPServer, "localhost"))
1469 rc = ldap_sasl_bind_s(BrowseLDAPHandle, NULL, "EXTERNAL", &bv, NULL,
1470 NULL, NULL);
1471 else
1472 rc = ldap_bind_s(BrowseLDAPHandle, BrowseLDAPBindDN,
1473 BrowseLDAPPassword, LDAP_AUTH_SIMPLE);
1474
1475 if (rc != LDAP_SUCCESS)
1476 {
1477 cupsdLogMessage(CUPSD_LOG_ERROR,
1478 "Unable to bind to LDAP server; "
1479 "disabling LDAP browsing!");
1480 ldap_unbind_ext(BrowseLDAPHandle, NULL, NULL);
1481 BrowseLocalProtocols &= ~BROWSE_LDAP;
1482 BrowseRemoteProtocols &= ~BROWSE_LDAP;
1483 }
1484 }
1485 }
1486
1487 BrowseLDAPRefresh = 0;
1488 }
1489 #endif /* HAVE_OPENLDAP */
1490 }
1491
1492
1493 /*
1494 * 'cupsdStartPolling()' - Start polling servers as needed.
1495 */
1496
1497 void
1498 cupsdStartPolling(void)
1499 {
1500 int i; /* Looping var */
1501 cupsd_dirsvc_poll_t *pollp; /* Current polling server */
1502 char polld[1024]; /* Poll daemon path */
1503 char sport[10]; /* Server port */
1504 char bport[10]; /* Browser port */
1505 char interval[10]; /* Poll interval */
1506 int statusfds[2]; /* Status pipe */
1507 char *argv[6]; /* Arguments */
1508 char *envp[100]; /* Environment */
1509
1510
1511 /*
1512 * Don't do anything if we aren't polling...
1513 */
1514
1515 if (NumPolled == 0)
1516 {
1517 PollPipe = -1;
1518 PollStatusBuffer = NULL;
1519 return;
1520 }
1521
1522 /*
1523 * Setup string arguments for polld, port and interval options.
1524 */
1525
1526 snprintf(polld, sizeof(polld), "%s/daemon/cups-polld", ServerBin);
1527
1528 sprintf(bport, "%d", BrowsePort);
1529
1530 if (BrowseInterval)
1531 sprintf(interval, "%d", BrowseInterval);
1532 else
1533 strcpy(interval, "30");
1534
1535 argv[0] = "cups-polld";
1536 argv[2] = sport;
1537 argv[3] = interval;
1538 argv[4] = bport;
1539 argv[5] = NULL;
1540
1541 cupsdLoadEnv(envp, (int)(sizeof(envp) / sizeof(envp[0])));
1542
1543 /*
1544 * Create a pipe that receives the status messages from each
1545 * polling daemon...
1546 */
1547
1548 if (cupsdOpenPipe(statusfds))
1549 {
1550 cupsdLogMessage(CUPSD_LOG_ERROR,
1551 "Unable to create polling status pipes - %s.",
1552 strerror(errno));
1553 PollPipe = -1;
1554 PollStatusBuffer = NULL;
1555 return;
1556 }
1557
1558 PollPipe = statusfds[0];
1559 PollStatusBuffer = cupsdStatBufNew(PollPipe, "[Poll]");
1560
1561 /*
1562 * Run each polling daemon, redirecting stderr to the polling pipe...
1563 */
1564
1565 for (i = 0, pollp = Polled; i < NumPolled; i ++, pollp ++)
1566 {
1567 sprintf(sport, "%d", pollp->port);
1568
1569 argv[1] = pollp->hostname;
1570
1571 if (cupsdStartProcess(polld, argv, envp, -1, -1, statusfds[1], -1,
1572 0, &(pollp->pid)) < 0)
1573 {
1574 cupsdLogMessage(CUPSD_LOG_ERROR,
1575 "cupsdStartPolling: Unable to fork polling daemon - %s",
1576 strerror(errno));
1577 pollp->pid = 0;
1578 break;
1579 }
1580 else
1581 cupsdLogMessage(CUPSD_LOG_DEBUG,
1582 "cupsdStartPolling: Started polling daemon for %s:%d, pid = %d",
1583 pollp->hostname, pollp->port, pollp->pid);
1584 }
1585
1586 close(statusfds[1]);
1587
1588 /*
1589 * Finally, add the pipe to the input selection set...
1590 */
1591
1592 cupsdLogMessage(CUPSD_LOG_DEBUG2,
1593 "cupsdStartPolling: Adding fd %d to InputSet...", PollPipe);
1594
1595 FD_SET(PollPipe, InputSet);
1596 }
1597
1598
1599 /*
1600 * 'cupsdStopBrowsing()' - Stop sending and receiving broadcast information.
1601 */
1602
1603 void
1604 cupsdStopBrowsing(void)
1605 {
1606 if (!Browsing || !(BrowseLocalProtocols | BrowseRemoteProtocols))
1607 return;
1608
1609 if (((BrowseLocalProtocols | BrowseRemoteProtocols) & BROWSE_CUPS) &&
1610 BrowseSocket >= 0)
1611 {
1612 /*
1613 * Close the socket and remove it from the input selection set.
1614 */
1615
1616 #ifdef WIN32
1617 closesocket(BrowseSocket);
1618 #else
1619 close(BrowseSocket);
1620 #endif /* WIN32 */
1621
1622 cupsdLogMessage(CUPSD_LOG_DEBUG2,
1623 "cupsdStopBrowsing: Removing fd %d from InputSet...",
1624 BrowseSocket);
1625
1626 FD_CLR(BrowseSocket, InputSet);
1627 BrowseSocket = -1;
1628 }
1629
1630 #ifdef HAVE_LIBSLP
1631 if (((BrowseLocalProtocols | BrowseRemoteProtocols) & BROWSE_SLP) &&
1632 BrowseSLPHandle)
1633 {
1634 /*
1635 * Close SLP handle...
1636 */
1637
1638 SLPClose(BrowseSLPHandle);
1639 BrowseSLPHandle = NULL;
1640 }
1641 #endif /* HAVE_LIBSLP */
1642
1643 #ifdef HAVE_OPENDAP
1644 if (((BrowseLocalProtocols | BrowseRemoteProtocols) & BROWSE_LDAP) &&
1645 BrowseLDAPHandle)
1646 {
1647 ldap_unbind(BrowseLDAPHandle);
1648 BrowseLDAPHandle = NULL;
1649 }
1650 #endif /* HAVE_OPENLDAP */
1651 }
1652
1653
1654 /*
1655 * 'cupsdStopPolling()' - Stop polling servers as needed.
1656 */
1657
1658 void
1659 cupsdStopPolling(void)
1660 {
1661 int i; /* Looping var */
1662 cupsd_dirsvc_poll_t *pollp; /* Current polling server */
1663
1664
1665 if (PollPipe >= 0)
1666 {
1667 cupsdStatBufDelete(PollStatusBuffer);
1668 close(PollPipe);
1669
1670 cupsdLogMessage(CUPSD_LOG_DEBUG2,
1671 "cupsdStopPolling: removing fd %d from InputSet.", PollPipe);
1672 FD_CLR(PollPipe, InputSet);
1673
1674 PollPipe = -1;
1675 PollStatusBuffer = NULL;
1676 }
1677
1678 for (i = 0, pollp = Polled; i < NumPolled; i ++, pollp ++)
1679 if (pollp->pid)
1680 cupsdEndProcess(pollp->pid, 0);
1681 }
1682
1683
1684 /*
1685 * 'cupsdUpdateCUPSBrowse()' - Update the browse lists using the CUPS protocol.
1686 */
1687
1688 void
1689 cupsdUpdateCUPSBrowse(void)
1690 {
1691 int i; /* Looping var */
1692 int auth; /* Authorization status */
1693 int len; /* Length of name string */
1694 int bytes; /* Number of bytes left */
1695 char packet[1541], /* Broadcast packet */
1696 *pptr; /* Pointer into packet */
1697 socklen_t srclen; /* Length of source address */
1698 http_addr_t srcaddr; /* Source address */
1699 char srcname[1024]; /* Source hostname */
1700 unsigned address[4]; /* Source address */
1701 unsigned type; /* Printer type */
1702 unsigned state; /* Printer state */
1703 char uri[HTTP_MAX_URI], /* Printer URI */
1704 host[HTTP_MAX_URI], /* Host portion of URI */
1705 resource[HTTP_MAX_URI], /* Resource portion of URI */
1706 info[IPP_MAX_NAME], /* Information string */
1707 location[IPP_MAX_NAME], /* Location string */
1708 make_model[IPP_MAX_NAME];/* Make and model string */
1709 int num_attrs; /* Number of attributes */
1710 cups_option_t *attrs; /* Attributes */
1711
1712
1713 /*
1714 * Read a packet from the browse socket...
1715 */
1716
1717 srclen = sizeof(srcaddr);
1718 if ((bytes = recvfrom(BrowseSocket, packet, sizeof(packet) - 1, 0,
1719 (struct sockaddr *)&srcaddr, &srclen)) < 0)
1720 {
1721 /*
1722 * "Connection refused" is returned under Linux if the destination port
1723 * or address is unreachable from a previous sendto(); check for the
1724 * error here and ignore it for now...
1725 */
1726
1727 if (errno != ECONNREFUSED && errno != EAGAIN)
1728 {
1729 cupsdLogMessage(CUPSD_LOG_ERROR, "Browse recv failed - %s.",
1730 strerror(errno));
1731 cupsdLogMessage(CUPSD_LOG_ERROR, "Browsing turned off.");
1732
1733 cupsdStopBrowsing();
1734 Browsing = 0;
1735 }
1736
1737 return;
1738 }
1739
1740 packet[bytes] = '\0';
1741
1742 /*
1743 * If we're about to sleep, ignore incoming browse packets.
1744 */
1745
1746 if (Sleeping)
1747 return;
1748
1749 /*
1750 * Figure out where it came from...
1751 */
1752
1753 #ifdef AF_INET6
1754 if (srcaddr.addr.sa_family == AF_INET6)
1755 {
1756 address[0] = ntohl(srcaddr.ipv6.sin6_addr.s6_addr32[0]);
1757 address[1] = ntohl(srcaddr.ipv6.sin6_addr.s6_addr32[1]);
1758 address[2] = ntohl(srcaddr.ipv6.sin6_addr.s6_addr32[2]);
1759 address[3] = ntohl(srcaddr.ipv6.sin6_addr.s6_addr32[3]);
1760 }
1761 else
1762 #endif /* AF_INET6 */
1763 {
1764 address[0] = 0;
1765 address[1] = 0;
1766 address[2] = 0;
1767 address[3] = ntohl(srcaddr.ipv4.sin_addr.s_addr);
1768 }
1769
1770 if (HostNameLookups)
1771 httpAddrLookup(&srcaddr, srcname, sizeof(srcname));
1772 else
1773 httpAddrString(&srcaddr, srcname, sizeof(srcname));
1774
1775 len = strlen(srcname);
1776
1777 /*
1778 * Do ACL stuff...
1779 */
1780
1781 if (BrowseACL)
1782 {
1783 if (httpAddrLocalhost(&srcaddr) || !strcasecmp(srcname, "localhost"))
1784 {
1785 /*
1786 * Access from localhost (127.0.0.1) is always allowed...
1787 */
1788
1789 auth = AUTH_ALLOW;
1790 }
1791 else
1792 {
1793 /*
1794 * Do authorization checks on the domain/address...
1795 */
1796
1797 switch (BrowseACL->order_type)
1798 {
1799 default :
1800 auth = AUTH_DENY; /* anti-compiler-warning-code */
1801 break;
1802
1803 case AUTH_ALLOW : /* Order Deny,Allow */
1804 auth = AUTH_ALLOW;
1805
1806 if (cupsdCheckAuth(address, srcname, len,
1807 BrowseACL->num_deny, BrowseACL->deny))
1808 auth = AUTH_DENY;
1809
1810 if (cupsdCheckAuth(address, srcname, len,
1811 BrowseACL->num_allow, BrowseACL->allow))
1812 auth = AUTH_ALLOW;
1813 break;
1814
1815 case AUTH_DENY : /* Order Allow,Deny */
1816 auth = AUTH_DENY;
1817
1818 if (cupsdCheckAuth(address, srcname, len,
1819 BrowseACL->num_allow, BrowseACL->allow))
1820 auth = AUTH_ALLOW;
1821
1822 if (cupsdCheckAuth(address, srcname, len,
1823 BrowseACL->num_deny, BrowseACL->deny))
1824 auth = AUTH_DENY;
1825 break;
1826 }
1827 }
1828 }
1829 else
1830 auth = AUTH_ALLOW;
1831
1832 if (auth == AUTH_DENY)
1833 {
1834 cupsdLogMessage(CUPSD_LOG_DEBUG,
1835 "cupsdUpdateCUPSBrowse: Refused %d bytes from %s", bytes,
1836 srcname);
1837 return;
1838 }
1839
1840 cupsdLogMessage(CUPSD_LOG_DEBUG2,
1841 "cupsdUpdateCUPSBrowse: (%d bytes from %s) %s", bytes,
1842 srcname, packet);
1843
1844 /*
1845 * Parse packet...
1846 */
1847
1848 if (sscanf(packet, "%x%x%1023s", &type, &state, uri) < 3)
1849 {
1850 cupsdLogMessage(CUPSD_LOG_WARN,
1851 "cupsdUpdateCUPSBrowse: Garbled browse packet - %s", packet);
1852 return;
1853 }
1854
1855 strcpy(location, "Location Unknown");
1856 strcpy(info, "No Information Available");
1857 make_model[0] = '\0';
1858 num_attrs = 0;
1859 attrs = NULL;
1860
1861 if ((pptr = strchr(packet, '\"')) != NULL)
1862 {
1863 /*
1864 * Have extended information; can't use sscanf for it because not all
1865 * sscanf's allow empty strings with %[^\"]...
1866 */
1867
1868 for (i = 0, pptr ++;
1869 i < (sizeof(location) - 1) && *pptr && *pptr != '\"';
1870 i ++, pptr ++)
1871 location[i] = *pptr;
1872
1873 if (i)
1874 location[i] = '\0';
1875
1876 if (*pptr == '\"')
1877 pptr ++;
1878
1879 while (*pptr && isspace(*pptr & 255))
1880 pptr ++;
1881
1882 if (*pptr == '\"')
1883 {
1884 for (i = 0, pptr ++;
1885 i < (sizeof(info) - 1) && *pptr && *pptr != '\"';
1886 i ++, pptr ++)
1887 info[i] = *pptr;
1888
1889 info[i] = '\0';
1890
1891 if (*pptr == '\"')
1892 pptr ++;
1893
1894 while (*pptr && isspace(*pptr & 255))
1895 pptr ++;
1896
1897 if (*pptr == '\"')
1898 {
1899 for (i = 0, pptr ++;
1900 i < (sizeof(make_model) - 1) && *pptr && *pptr != '\"';
1901 i ++, pptr ++)
1902 make_model[i] = *pptr;
1903
1904 if (*pptr == '\"')
1905 pptr ++;
1906
1907 make_model[i] = '\0';
1908
1909 if (*pptr)
1910 num_attrs = cupsParseOptions(pptr, num_attrs, &attrs);
1911 }
1912 }
1913 }
1914
1915 DEBUG_puts(packet);
1916 DEBUG_printf(("type=%x, state=%x, uri=\"%s\"\n"
1917 "location=\"%s\", info=\"%s\", make_model=\"%s\"\n",
1918 type, state, uri, location, info, make_model));
1919
1920 /*
1921 * Pull the URI apart to see if this is a local or remote printer...
1922 */
1923
1924 if (is_local_queue(uri, host, sizeof(host), resource, sizeof(resource)))
1925 {
1926 cupsFreeOptions(num_attrs, attrs);
1927 return;
1928 }
1929
1930 /*
1931 * Do relaying...
1932 */
1933
1934 for (i = 0; i < NumRelays; i ++)
1935 if (cupsdCheckAuth(address, srcname, len, 1, &(Relays[i].from)))
1936 if (sendto(BrowseSocket, packet, bytes, 0,
1937 (struct sockaddr *)&(Relays[i].to),
1938 sizeof(http_addr_t)) <= 0)
1939 {
1940 cupsdLogMessage(CUPSD_LOG_ERROR,
1941 "cupsdUpdateCUPSBrowse: sendto failed for relay %d - %s.",
1942 i + 1, strerror(errno));
1943 cupsFreeOptions(num_attrs, attrs);
1944 return;
1945 }
1946
1947 /*
1948 * Process the browse data...
1949 */
1950
1951 process_browse_data(uri, host, resource, (cups_ptype_t)type,
1952 (ipp_pstate_t)state, location, info, make_model,
1953 num_attrs, attrs);
1954 cupsFreeOptions(num_attrs, attrs);
1955 }
1956
1957
1958 #ifdef HAVE_OPENLDAP
1959 /*
1960 * 'cupsdUpdateLDAPBrowse()' - Scan for new printers via LDAP...
1961 */
1962
1963 void
1964 cupsdUpdateLDAPBrowse(void)
1965 {
1966 char uri[HTTP_MAX_URI], /* Printer URI */
1967 host[HTTP_MAX_URI], /* Hostname */
1968 resource[HTTP_MAX_URI], /* Resource path */
1969 location[1024], /* Printer location */
1970 info[1024], /* Printer information */
1971 make_model[1024], /* Printer make and model */
1972 **value; /* Holds the returned data from LDAP */
1973 int type; /* Printer type */
1974 int rc; /* LDAP status */
1975 int limit; /* Size limit */
1976 LDAPMessage *res, /* LDAP search results */
1977 *e; /* Current entry from search */
1978
1979
1980 /*
1981 * Search for printers...
1982 */
1983
1984 cupsdLogMessage(CUPSD_LOG_DEBUG2, "UpdateLDAPBrowse: %s", ServerName);
1985
1986 BrowseLDAPRefresh = time(NULL) + BrowseInterval;
1987
1988 rc = ldap_search_s(BrowseLDAPHandle, BrowseLDAPDN, LDAP_SCOPE_SUBTREE,
1989 "(objectclass=cupsPrinter)", (char **)ldap_attrs, 0, &res);
1990 if (rc != LDAP_SUCCESS)
1991 {
1992 cupsdLogMessage(CUPSD_LOG_ERROR,
1993 "LDAP search returned error %d: %s", rc,
1994 ldap_err2string(rc));
1995 return;
1996 }
1997
1998 limit = ldap_count_entries(BrowseLDAPHandle, res);
1999 cupsdLogMessage(CUPSD_LOG_DEBUG2, "LDAP search returned %d entries", limit);
2000 if (limit < 1)
2001 return;
2002
2003 /*
2004 * Loop through the available printers...
2005 */
2006
2007 if ((e = ldap_first_entry(BrowseLDAPHandle, res)) == NULL)
2008 {
2009 cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to get LDAP printer entry!");
2010 return;
2011 }
2012
2013 while (e)
2014 {
2015 value = ldap_get_values(BrowseLDAPHandle, e, "printerDescription");
2016 strlcpy(info, *value, sizeof(info));
2017 ldap_value_free(value);
2018
2019 value = ldap_get_values(BrowseLDAPHandle, e, "printerLocation");
2020 strlcpy(location, *value, sizeof(location));
2021 ldap_value_free(value);
2022
2023 value = ldap_get_values(BrowseLDAPHandle, e, "printerMakeAndModel");
2024 strlcpy(make_model, *value, sizeof(make_model));
2025 ldap_value_free(value);
2026
2027 value = ldap_get_values(BrowseLDAPHandle, e, "printerType");
2028 type = atoi(*value);
2029 ldap_value_free(value);
2030
2031 value = ldap_get_values(BrowseLDAPHandle, e, "printerURI");
2032 strlcpy(uri, *value, sizeof(uri));
2033 ldap_value_free(value);
2034
2035 if (!is_local_queue(uri, host, sizeof(host), resource, sizeof(resource)))
2036 process_browse_data(uri, host, resource, type, IPP_PRINTER_IDLE,
2037 location, info, make_model, 0, NULL);
2038
2039 e = ldap_next_entry(BrowseLDAPHandle, e);
2040 }
2041 }
2042 #endif /* HAVE_OPENLDAP */
2043
2044
2045 /*
2046 * 'cupsdUpdatePolling()' - Read status messages from the poll daemons.
2047 */
2048
2049 void
2050 cupsdUpdatePolling(void)
2051 {
2052 char *ptr, /* Pointer to end of line in buffer */
2053 message[1024]; /* Pointer to message text */
2054 int loglevel; /* Log level for message */
2055
2056
2057 while ((ptr = cupsdStatBufUpdate(PollStatusBuffer, &loglevel,
2058 message, sizeof(message))) != NULL)
2059 if (!strchr(PollStatusBuffer->buffer, '\n'))
2060 break;
2061
2062 if (ptr == NULL)
2063 {
2064 /*
2065 * All polling processes have died; stop polling...
2066 */
2067
2068 cupsdLogMessage(CUPSD_LOG_ERROR,
2069 "cupsdUpdatePolling: all polling processes have exited!");
2070 cupsdStopPolling();
2071 }
2072 }
2073
2074
2075 #ifdef HAVE_LIBSLP
2076 /*
2077 * 'cupsdUpdateSLPBrowse()' - Get browsing information via SLP.
2078 */
2079
2080 void
2081 cupsdUpdateSLPBrowse(void)
2082 {
2083 slpsrvurl_t *s, /* Temporary list of service URLs */
2084 *next; /* Next service in list */
2085 cupsd_printer_t p; /* Printer information */
2086 const char *uri; /* Pointer to printer URI */
2087 char host[HTTP_MAX_URI], /* Host portion of URI */
2088 resource[HTTP_MAX_URI]; /* Resource portion of URI */
2089
2090
2091 /*
2092 * Reset the refresh time...
2093 */
2094
2095 BrowseSLPRefresh = time(NULL) + BrowseInterval;
2096
2097 /*
2098 * Poll for remote printers using SLP...
2099 */
2100
2101 s = NULL;
2102
2103 SLPFindSrvs(BrowseSLPHandle, SLP_CUPS_SRVTYPE, "", "",
2104 slp_url_callback, &s);
2105
2106 /*
2107 * Loop through the list of available printers...
2108 */
2109
2110 for (; s; s = next)
2111 {
2112 /*
2113 * Save the "next" pointer...
2114 */
2115
2116 next = s->next;
2117
2118 /*
2119 * Load a cupsd_printer_t structure with the SLP service attributes...
2120 */
2121
2122 SLPFindAttrs(BrowseSLPHandle, s->url, "", "", slp_attr_callback, &p);
2123
2124 /*
2125 * Process this printer entry...
2126 */
2127
2128 uri = s->url + SLP_CUPS_SRVLEN + 1;
2129
2130 if (!strncmp(uri, "http://", 7) || !strncmp(uri, "ipp://", 6))
2131 {
2132 /*
2133 * Pull the URI apart to see if this is a local or remote printer...
2134 */
2135
2136 if (!is_local_queue(uri, host, sizeof(host), resource, sizeof(resource)))
2137 process_browse_data(uri, host, resource, p.type, IPP_PRINTER_IDLE,
2138 p.location, p.info, p.make_model, 0, NULL);
2139 }
2140
2141 /*
2142 * Free this listing...
2143 */
2144
2145 cupsdClearString(&p.info);
2146 cupsdClearString(&p.location);
2147 cupsdClearString(&p.make_model);
2148
2149 free(s);
2150 }
2151 }
2152 #endif /* HAVE_LIBSLP */
2153
2154
2155 /*
2156 * 'dequote()' - Remote quotes from a string.
2157 */
2158
2159 static char * /* O - Dequoted string */
2160 dequote(char *d, /* I - Destination string */
2161 const char *s, /* I - Source string */
2162 int dlen) /* I - Destination length */
2163 {
2164 char *dptr; /* Pointer into destination */
2165
2166
2167 if (s)
2168 {
2169 for (dptr = d, dlen --; *s && dlen > 0; s ++)
2170 if (*s != '\"')
2171 {
2172 *dptr++ = *s;
2173 dlen --;
2174 }
2175
2176 *dptr = '\0';
2177 }
2178 else
2179 *d = '\0';
2180
2181 return (d);
2182 }
2183
2184
2185 /*
2186 * 'is_local_queue()' - Determine whether the URI points at a local queue.
2187 */
2188
2189 static int /* O - 1 = local, 0 = remote, -1 = bad URI */
2190 is_local_queue(const char *uri, /* I - Printer URI */
2191 char *host, /* O - Host string */
2192 int hostlen, /* I - Length of host buffer */
2193 char *resource, /* O - Resource string */
2194 int resourcelen) /* I - Length of resource buffer */
2195 {
2196 char scheme[32], /* Scheme portion of URI */
2197 username[HTTP_MAX_URI]; /* Username portion of URI */
2198 int port; /* Port portion of URI */
2199 cupsd_netif_t *iface; /* Network interface */
2200
2201
2202 /*
2203 * Pull the URI apart to see if this is a local or remote printer...
2204 */
2205
2206 if (httpSeparateURI(HTTP_URI_CODING_ALL, uri, scheme, sizeof(scheme),
2207 username, sizeof(username), host, hostlen, &port,
2208 resource, resourcelen) < HTTP_URI_OK)
2209 return (-1);
2210
2211 DEBUG_printf(("host=\"%s\", ServerName=\"%s\"\n", host, ServerName));
2212
2213 /*
2214 * Check for local server addresses...
2215 */
2216
2217 if (!strcasecmp(host, ServerName) && port == LocalPort)
2218 return (1);
2219
2220 cupsdNetIFUpdate();
2221
2222 for (iface = (cupsd_netif_t *)cupsArrayFirst(NetIFList);
2223 iface;
2224 iface = (cupsd_netif_t *)cupsArrayNext(NetIFList))
2225 if (!strcasecmp(host, iface->hostname) && port == iface->port)
2226 return (1);
2227
2228 /*
2229 * If we get here, the printer is remote...
2230 */
2231
2232 return (0);
2233 }
2234
2235
2236 /*
2237 * 'process_browse_data()' - Process new browse data.
2238 */
2239
2240 static void
2241 process_browse_data(
2242 const char *uri, /* I - URI of printer/class */
2243 const char *host, /* I - Hostname */
2244 const char *resource, /* I - Resource path */
2245 cups_ptype_t type, /* I - Printer type */
2246 ipp_pstate_t state, /* I - Printer state */
2247 const char *location, /* I - Printer location */
2248 const char *info, /* I - Printer information */
2249 const char *make_model, /* I - Printer make and model */
2250 int num_attrs, /* I - Number of attributes */
2251 cups_option_t *attrs) /* I - Attributes */
2252 {
2253 int update; /* Update printer attributes? */
2254 char finaluri[HTTP_MAX_URI], /* Final URI for printer */
2255 name[IPP_MAX_NAME], /* Name of printer */
2256 *hptr, /* Pointer into hostname */
2257 *sptr; /* Pointer into ServerName */
2258 char local_make_model[IPP_MAX_NAME];
2259 /* Local make and model */
2260 cupsd_printer_t *p; /* Printer information */
2261 const char *ipp_options; /* ipp-options value */
2262
2263
2264 /*
2265 * Determine if the URI contains any illegal characters in it...
2266 */
2267
2268 if (strncmp(uri, "ipp://", 6) || !host[0] ||
2269 (strncmp(resource, "/printers/", 10) &&
2270 strncmp(resource, "/classes/", 9)))
2271 {
2272 cupsdLogMessage(CUPSD_LOG_ERROR,
2273 "process_browse_data: Bad printer URI in browse data: %s",
2274 uri);
2275 return;
2276 }
2277
2278 if (strchr(resource, '?') ||
2279 (!strncmp(resource, "/printers/", 10) && strchr(resource + 10, '/')) ||
2280 (!strncmp(resource, "/classes/", 9) && strchr(resource + 9, '/')))
2281 {
2282 cupsdLogMessage(CUPSD_LOG_ERROR,
2283 "process_browse_data: Bad resource in browse data: %s",
2284 resource);
2285 return;
2286 }
2287
2288 /*
2289 * OK, this isn't a local printer; add any remote options...
2290 */
2291
2292 ipp_options = cupsGetOption("ipp-options", num_attrs, attrs);
2293
2294 if (BrowseRemoteOptions)
2295 {
2296 if (BrowseRemoteOptions[0] == '?')
2297 {
2298 /*
2299 * Override server-supplied options...
2300 */
2301
2302 snprintf(finaluri, sizeof(finaluri), "%s%s", uri, BrowseRemoteOptions);
2303 }
2304 else if (ipp_options)
2305 {
2306 /*
2307 * Combine the server and local options...
2308 */
2309
2310 snprintf(finaluri, sizeof(finaluri), "%s?%s+%s", uri, ipp_options,
2311 BrowseRemoteOptions);
2312 }
2313 else
2314 {
2315 /*
2316 * Just use the local options...
2317 */
2318
2319 snprintf(finaluri, sizeof(finaluri), "%s?%s", uri, BrowseRemoteOptions);
2320 }
2321
2322 uri = finaluri;
2323 }
2324 else if (ipp_options)
2325 {
2326 /*
2327 * Just use the server-supplied options...
2328 */
2329
2330 snprintf(finaluri, sizeof(finaluri), "%s?%s", uri, ipp_options);
2331 uri = finaluri;
2332 }
2333
2334 /*
2335 * See if we already have it listed in the Printers list, and add it if not...
2336 */
2337
2338 type |= CUPS_PRINTER_REMOTE;
2339 type &= ~CUPS_PRINTER_IMPLICIT;
2340 update = 0;
2341 hptr = strchr(host, '.');
2342 sptr = strchr(ServerName, '.');
2343
2344 if (sptr != NULL && hptr != NULL)
2345 {
2346 /*
2347 * Strip the common domain name components...
2348 */
2349
2350 while (hptr != NULL)
2351 {
2352 if (!strcasecmp(hptr, sptr))
2353 {
2354 *hptr = '\0';
2355 break;
2356 }
2357 else
2358 hptr = strchr(hptr + 1, '.');
2359 }
2360 }
2361
2362 if (type & CUPS_PRINTER_CLASS)
2363 {
2364 /*
2365 * Remote destination is a class...
2366 */
2367
2368 if (!strncmp(resource, "/classes/", 9))
2369 snprintf(name, sizeof(name), "%s@%s", resource + 9, host);
2370 else
2371 return;
2372
2373 if ((p = cupsdFindClass(name)) == NULL && BrowseShortNames)
2374 {
2375 if ((p = cupsdFindClass(resource + 9)) != NULL)
2376 {
2377 if (p->hostname && strcasecmp(p->hostname, host))
2378 {
2379 /*
2380 * Nope, this isn't the same host; if the hostname isn't the local host,
2381 * add it to the other class and then find a class using the full host
2382 * name...
2383 */
2384
2385 if (p->type & CUPS_PRINTER_REMOTE)
2386 {
2387 cupsdLogMessage(CUPSD_LOG_INFO,
2388 "Renamed remote class \"%s\" to \"%s@%s\"...",
2389 p->name, p->name, p->hostname);
2390 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED, p, NULL,
2391 "Class \'%s\' deleted by directory services.",
2392 p->name);
2393
2394 cupsArrayRemove(Printers, p);
2395 cupsdSetStringf(&p->name, "%s@%s", p->name, p->hostname);
2396 cupsdSetPrinterAttrs(p);
2397 cupsArrayAdd(Printers, p);
2398
2399 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED, p, NULL,
2400 "Class \'%s\' added by directory services.",
2401 p->name);
2402 }
2403
2404 p = NULL;
2405 }
2406 else if (!p->hostname)
2407 {
2408 /*
2409 * Hostname not set, so this must be a cached remote printer
2410 * that was created for a pending print job...
2411 */
2412
2413 cupsdSetString(&p->hostname, host);
2414 cupsdSetString(&p->uri, uri);
2415 cupsdSetString(&p->device_uri, uri);
2416 update = 1;
2417 }
2418 }
2419 else
2420 {
2421 /*
2422 * Use the short name for this shared class.
2423 */
2424
2425 strlcpy(name, resource + 9, sizeof(name));
2426 }
2427 }
2428 else if (p && !p->hostname)
2429 {
2430 /*
2431 * Hostname not set, so this must be a cached remote printer
2432 * that was created for a pending print job...
2433 */
2434
2435 cupsdSetString(&p->hostname, host);
2436 cupsdSetString(&p->uri, uri);
2437 cupsdSetString(&p->device_uri, uri);
2438 update = 1;
2439 }
2440
2441 if (!p)
2442 {
2443 /*
2444 * Class doesn't exist; add it...
2445 */
2446
2447 p = cupsdAddClass(name);
2448
2449 cupsdLogMessage(CUPSD_LOG_INFO, "Added remote class \"%s\"...", name);
2450
2451 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED, p, NULL,
2452 "Class \'%s\' added by directory services.", name);
2453
2454 /*
2455 * Force the URI to point to the real server...
2456 */
2457
2458 p->type = type & ~CUPS_PRINTER_REJECTING;
2459 p->accepting = 1;
2460 cupsdSetString(&p->uri, uri);
2461 cupsdSetString(&p->device_uri, uri);
2462 cupsdSetString(&p->hostname, host);
2463
2464 update = 1;
2465 }
2466 }
2467 else
2468 {
2469 /*
2470 * Remote destination is a printer...
2471 */
2472
2473 if (!strncmp(resource, "/printers/", 10))
2474 snprintf(name, sizeof(name), "%s@%s", resource + 10, host);
2475 else
2476 return;
2477
2478 if ((p = cupsdFindPrinter(name)) == NULL && BrowseShortNames)
2479 {
2480 if ((p = cupsdFindPrinter(resource + 10)) != NULL)
2481 {
2482 if (p->hostname && strcasecmp(p->hostname, host))
2483 {
2484 /*
2485 * Nope, this isn't the same host; if the hostname isn't the local host,
2486 * add it to the other printer and then find a printer using the full host
2487 * name...
2488 */
2489
2490 if (p->type & CUPS_PRINTER_REMOTE)
2491 {
2492 cupsdLogMessage(CUPSD_LOG_INFO,
2493 "Renamed remote printer \"%s\" to \"%s@%s\"...",
2494 p->name, p->name, p->hostname);
2495 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED, p, NULL,
2496 "Printer \'%s\' deleted by directory services.",
2497 p->name);
2498
2499 cupsArrayRemove(Printers, p);
2500 cupsdSetStringf(&p->name, "%s@%s", p->name, p->hostname);
2501 cupsdSetPrinterAttrs(p);
2502 cupsArrayAdd(Printers, p);
2503
2504 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED, p, NULL,
2505 "Printer \'%s\' added by directory services.",
2506 p->name);
2507 }
2508
2509 p = NULL;
2510 }
2511 else if (!p->hostname)
2512 {
2513 /*
2514 * Hostname not set, so this must be a cached remote printer
2515 * that was created for a pending print job...
2516 */
2517
2518 cupsdSetString(&p->hostname, host);
2519 cupsdSetString(&p->uri, uri);
2520 cupsdSetString(&p->device_uri, uri);
2521 update = 1;
2522 }
2523 }
2524 else
2525 {
2526 /*
2527 * Use the short name for this shared printer.
2528 */
2529
2530 strlcpy(name, resource + 10, sizeof(name));
2531 }
2532 }
2533 else if (p && !p->hostname)
2534 {
2535 /*
2536 * Hostname not set, so this must be a cached remote printer
2537 * that was created for a pending print job...
2538 */
2539
2540 cupsdSetString(&p->hostname, host);
2541 cupsdSetString(&p->uri, uri);
2542 cupsdSetString(&p->device_uri, uri);
2543 update = 1;
2544 }
2545
2546 if (!p)
2547 {
2548 /*
2549 * Printer doesn't exist; add it...
2550 */
2551
2552 p = cupsdAddPrinter(name);
2553
2554 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED, p, NULL,
2555 "Printer \'%s\' added by directory services.", name);
2556
2557 cupsdLogMessage(CUPSD_LOG_INFO, "Added remote printer \"%s\"...", name);
2558
2559 /*
2560 * Force the URI to point to the real server...
2561 */
2562
2563 p->type = type & ~CUPS_PRINTER_REJECTING;
2564 p->accepting = 1;
2565 cupsdSetString(&p->hostname, host);
2566 cupsdSetString(&p->uri, uri);
2567 cupsdSetString(&p->device_uri, uri);
2568
2569 update = 1;
2570 }
2571 }
2572
2573 /*
2574 * Update the state...
2575 */
2576
2577 p->state = state;
2578 p->browse_time = time(NULL);
2579
2580 if (type & CUPS_PRINTER_REJECTING)
2581 {
2582 type &= ~CUPS_PRINTER_REJECTING;
2583
2584 if (p->accepting)
2585 {
2586 update = 1;
2587 p->accepting = 0;
2588 }
2589 }
2590 else if (!p->accepting)
2591 {
2592 update = 1;
2593 p->accepting = 1;
2594 }
2595
2596 if (p->type != type)
2597 {
2598 p->type = type;
2599 update = 1;
2600 }
2601
2602 if (location && (!p->location || strcmp(p->location, location)))
2603 {
2604 cupsdSetString(&p->location, location);
2605 update = 1;
2606 }
2607
2608 if (info && (!p->info || strcmp(p->info, info)))
2609 {
2610 cupsdSetString(&p->info, info);
2611 update = 1;
2612 }
2613
2614 if (!make_model || !make_model[0])
2615 {
2616 if (type & CUPS_PRINTER_CLASS)
2617 snprintf(local_make_model, sizeof(local_make_model),
2618 "Remote Class on %s", host);
2619 else
2620 snprintf(local_make_model, sizeof(local_make_model),
2621 "Remote Printer on %s", host);
2622 }
2623 else
2624 snprintf(local_make_model, sizeof(local_make_model),
2625 "%s on %s", make_model, host);
2626
2627 if (!p->make_model || strcmp(p->make_model, local_make_model))
2628 {
2629 cupsdSetString(&p->make_model, local_make_model);
2630 update = 1;
2631 }
2632
2633 if (type & CUPS_PRINTER_DELETE)
2634 {
2635 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED, p, NULL,
2636 "%s \'%s\' deleted by directory services.",
2637 (type & CUPS_PRINTER_CLASS) ? "Class" : "Printer", p->name);
2638
2639 cupsdExpireSubscriptions(p, NULL);
2640
2641 cupsdDeletePrinter(p, 1);
2642 cupsdUpdateImplicitClasses();
2643 }
2644 else if (update)
2645 {
2646 cupsdSetPrinterAttrs(p);
2647 cupsdUpdateImplicitClasses();
2648 }
2649
2650 /*
2651 * See if we have a default printer... If not, make the first printer the
2652 * default.
2653 */
2654
2655 if (DefaultPrinter == NULL && Printers != NULL && UseNetworkDefault)
2656 {
2657 /*
2658 * Find the first network default printer and use it...
2659 */
2660
2661 for (p = (cupsd_printer_t *)cupsArrayFirst(Printers);
2662 p;
2663 p = (cupsd_printer_t *)cupsArrayNext(Printers))
2664 if (p->type & CUPS_PRINTER_DEFAULT)
2665 {
2666 DefaultPrinter = p;
2667 break;
2668 }
2669 }
2670
2671 /*
2672 * Do auto-classing if needed...
2673 */
2674
2675 process_implicit_classes();
2676
2677 /*
2678 * Update the printcap file...
2679 */
2680
2681 cupsdWritePrintcap();
2682 }
2683
2684
2685 /*
2686 * 'process_implicit_classes()' - Create/update implicit classes as needed.
2687 */
2688
2689 static void
2690 process_implicit_classes(void)
2691 {
2692 int i; /* Looping var */
2693 int update; /* Update printer attributes? */
2694 char name[IPP_MAX_NAME], /* Name of printer */
2695 *hptr; /* Pointer into hostname */
2696 cupsd_printer_t *p, /* Printer information */
2697 *pclass, /* Printer class */
2698 *first; /* First printer in class */
2699 int offset, /* Offset of name */
2700 len; /* Length of name */
2701
2702
2703 if (!ImplicitClasses || !Printers)
2704 return;
2705
2706 /*
2707 * Loop through all available printers and create classes as needed...
2708 */
2709
2710 for (p = (cupsd_printer_t *)cupsArrayFirst(Printers), len = 0, offset = 0,
2711 update = 0, pclass = NULL, first = NULL;
2712 p != NULL;
2713 p = (cupsd_printer_t *)cupsArrayNext(Printers))
2714 {
2715 /*
2716 * Skip implicit classes...
2717 */
2718
2719 if (p->type & CUPS_PRINTER_IMPLICIT)
2720 {
2721 len = 0;
2722 continue;
2723 }
2724
2725 /*
2726 * If len == 0, get the length of this printer name up to the "@"
2727 * sign (if any).
2728 */
2729
2730 cupsArraySave(Printers);
2731
2732 if (len > 0 &&
2733 !strncasecmp(p->name, name + offset, len) &&
2734 (p->name[len] == '\0' || p->name[len] == '@'))
2735 {
2736 /*
2737 * We have more than one printer with the same name; see if
2738 * we have a class, and if this printer is a member...
2739 */
2740
2741 if (pclass && strcasecmp(pclass->name, name))
2742 {
2743 if (update)
2744 cupsdSetPrinterAttrs(pclass);
2745
2746 update = 0;
2747 pclass = NULL;
2748 }
2749
2750 if (!pclass && (pclass = cupsdFindDest(name)) == NULL)
2751 {
2752 /*
2753 * Need to add the class...
2754 */
2755
2756 pclass = cupsdAddPrinter(name);
2757 cupsArrayAdd(ImplicitPrinters, pclass);
2758
2759 pclass->type |= CUPS_PRINTER_IMPLICIT;
2760 pclass->accepting = 1;
2761 pclass->state = IPP_PRINTER_IDLE;
2762
2763 cupsdSetString(&pclass->location, p->location);
2764 cupsdSetString(&pclass->info, p->info);
2765
2766 update = 1;
2767
2768 cupsdLogMessage(CUPSD_LOG_INFO, "Added implicit class \"%s\"...",
2769 name);
2770 }
2771
2772 if (first != NULL)
2773 {
2774 for (i = 0; i < pclass->num_printers; i ++)
2775 if (pclass->printers[i] == first)
2776 break;
2777
2778 if (i >= pclass->num_printers)
2779 {
2780 first->in_implicit_class = 1;
2781 cupsdAddPrinterToClass(pclass, first);
2782 }
2783
2784 first = NULL;
2785 }
2786
2787 for (i = 0; i < pclass->num_printers; i ++)
2788 if (pclass->printers[i] == p)
2789 break;
2790
2791 if (i >= pclass->num_printers)
2792 {
2793 p->in_implicit_class = 1;
2794 cupsdAddPrinterToClass(pclass, p);
2795 update = 1;
2796 }
2797 }
2798 else
2799 {
2800 /*
2801 * First time around; just get name length and mark it as first
2802 * in the list...
2803 */
2804
2805 if ((hptr = strchr(p->name, '@')) != NULL)
2806 len = hptr - p->name;
2807 else
2808 len = strlen(p->name);
2809
2810 strncpy(name, p->name, len);
2811 name[len] = '\0';
2812 offset = 0;
2813
2814 if ((first = (hptr ? cupsdFindDest(name) : p)) != NULL &&
2815 !(first->type & CUPS_PRINTER_IMPLICIT))
2816 {
2817 /*
2818 * Can't use same name as a local printer; add "Any" to the
2819 * front of the name, unless we have explicitly disabled
2820 * the "ImplicitAnyClasses"...
2821 */
2822
2823 if (ImplicitAnyClasses && len < (sizeof(name) - 4))
2824 {
2825 /*
2826 * Add "Any" to the class name...
2827 */
2828
2829 strcpy(name, "Any");
2830 strncpy(name + 3, p->name, len);
2831 name[len + 3] = '\0';
2832 offset = 3;
2833 }
2834 else
2835 {
2836 /*
2837 * Don't create an implicit class if we have a local printer
2838 * with the same name...
2839 */
2840
2841 len = 0;
2842 cupsArrayRestore(Printers);
2843 continue;
2844 }
2845 }
2846
2847 first = p;
2848 }
2849
2850 cupsArrayRestore(Printers);
2851 }
2852
2853 /*
2854 * Update the last printer class as needed...
2855 */
2856
2857 if (pclass && update)
2858 cupsdSetPrinterAttrs(pclass);
2859 }
2860
2861
2862 #ifdef HAVE_LIBSLP
2863 /*
2864 * 'slp_attr_callback()' - SLP attribute callback
2865 */
2866
2867 static SLPBoolean /* O - SLP_TRUE for success */
2868 slp_attr_callback(
2869 SLPHandle hslp, /* I - SLP handle */
2870 const char *attrlist, /* I - Attribute list */
2871 SLPError errcode, /* I - Parsing status for this attr */
2872 void *cookie) /* I - Current printer */
2873 {
2874 char *tmp = 0; /* Temporary string */
2875 cupsd_printer_t *p = (cupsd_printer_t*)cookie;
2876 /* Current printer */
2877
2878
2879 (void)hslp; /* anti-compiler-warning-code */
2880
2881 /*
2882 * Bail if there was an error
2883 */
2884
2885 if (errcode != SLP_OK)
2886 return (SLP_TRUE);
2887
2888 /*
2889 * Parse the attrlist to obtain things needed to build CUPS browse packet
2890 */
2891
2892 memset(p, 0, sizeof(cupsd_printer_t));
2893
2894 if (slp_get_attr(attrlist, "(printer-location=", &(p->location)))
2895 return (SLP_FALSE);
2896 if (slp_get_attr(attrlist, "(printer-info=", &(p->info)))
2897 return (SLP_FALSE);
2898 if (slp_get_attr(attrlist, "(printer-make-and-model=", &(p->make_model)))
2899 return (SLP_FALSE);
2900 if (!slp_get_attr(attrlist, "(printer-type=", &tmp))
2901 p->type = atoi(tmp);
2902 else
2903 p->type = CUPS_PRINTER_REMOTE;
2904
2905 cupsdClearString(&tmp);
2906
2907 return (SLP_TRUE);
2908 }
2909
2910
2911 /*
2912 * 'slp_dereg_printer()' - SLPDereg() the specified printer
2913 */
2914
2915 static void
2916 slp_dereg_printer(cupsd_printer_t *p) /* I - Printer */
2917 {
2918 char srvurl[HTTP_MAX_URI]; /* Printer service URI */
2919
2920
2921 cupsdLogMessage(CUPSD_LOG_DEBUG, "slp_dereg_printer: printer=\"%s\"", p->name);
2922
2923 if (!(p->type & CUPS_PRINTER_REMOTE))
2924 {
2925 /*
2926 * Make the SLP service URL that conforms to the IANA
2927 * 'printer:' template.
2928 */
2929
2930 snprintf(srvurl, sizeof(srvurl), SLP_CUPS_SRVTYPE ":%s", p->uri);
2931
2932 /*
2933 * Deregister the printer...
2934 */
2935
2936 SLPDereg(BrowseSLPHandle, srvurl, slp_reg_callback, 0);
2937 }
2938 }
2939
2940
2941 /*
2942 * 'slp_get_attr()' - Get an attribute from an SLP registration.
2943 */
2944
2945 static int /* O - 0 on success */
2946 slp_get_attr(const char *attrlist, /* I - Attribute list string */
2947 const char *tag, /* I - Name of attribute */
2948 char **valbuf) /* O - Value */
2949 {
2950 char *ptr1, /* Pointer into string */
2951 *ptr2; /* ... */
2952
2953
2954 cupsdClearString(valbuf);
2955
2956 if ((ptr1 = strstr(attrlist, tag)) != NULL)
2957 {
2958 ptr1 += strlen(tag);
2959
2960 if ((ptr2 = strchr(ptr1,')')) != NULL)
2961 {
2962 /*
2963 * Copy the value...
2964 */
2965
2966 *valbuf = calloc(ptr2 - ptr1 + 1, 1);
2967 strncpy(*valbuf, ptr1, ptr2 - ptr1);
2968
2969 /*
2970 * Dequote the value...
2971 */
2972
2973 for (ptr1 = *valbuf; *ptr1; ptr1 ++)
2974 if (*ptr1 == '\\' && ptr1[1])
2975 _cups_strcpy(ptr1, ptr1 + 1);
2976
2977 return (0);
2978 }
2979 }
2980
2981 return (-1);
2982 }
2983
2984
2985 /*
2986 * 'slp_reg_callback()' - Empty SLPRegReport.
2987 */
2988
2989 static void
2990 slp_reg_callback(SLPHandle hslp, /* I - SLP handle */
2991 SLPError errcode, /* I - Error code, if any */
2992 void *cookie) /* I - App data */
2993 {
2994 (void)hslp;
2995 (void)errcode;
2996 (void)cookie;
2997
2998 return;
2999 }
3000
3001
3002 /*
3003 * 'slp_url_callback()' - SLP service url callback
3004 */
3005
3006 static SLPBoolean /* O - TRUE = OK, FALSE = error */
3007 slp_url_callback(
3008 SLPHandle hslp, /* I - SLP handle */
3009 const char *srvurl, /* I - URL of service */
3010 unsigned short lifetime, /* I - Life of service */
3011 SLPError errcode, /* I - Existing error code */
3012 void *cookie) /* I - Pointer to service list */
3013 {
3014 slpsrvurl_t *s, /* New service entry */
3015 **head; /* Pointer to head of entry */
3016
3017
3018 /*
3019 * Let the compiler know we won't be using these vars...
3020 */
3021
3022 (void)hslp;
3023 (void)lifetime;
3024
3025 /*
3026 * Bail if there was an error
3027 */
3028
3029 if (errcode != SLP_OK)
3030 return (SLP_TRUE);
3031
3032 /*
3033 * Grab the head of the list...
3034 */
3035
3036 head = (slpsrvurl_t**)cookie;
3037
3038 /*
3039 * Allocate a *temporary* slpsrvurl_t to hold this entry.
3040 */
3041
3042 if ((s = (slpsrvurl_t *)calloc(1, sizeof(slpsrvurl_t))) == NULL)
3043 return (SLP_FALSE);
3044
3045 /*
3046 * Copy the SLP service URL...
3047 */
3048
3049 strlcpy(s->url, srvurl, sizeof(s->url));
3050
3051 /*
3052 * Link the SLP service URL into the head of the list
3053 */
3054
3055 if (*head)
3056 s->next = *head;
3057
3058 *head = s;
3059
3060 return (SLP_TRUE);
3061 }
3062 #endif /* HAVE_LIBSLP */
3063
3064
3065 /*
3066 * End of "$Id$".
3067 */